Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

Bug with data type conversion in C++ interface?

Hi!

I recently started to deal with NetCDF files and first tried to use the C++ 
interface. I reverted to the plain C interface because of what looks like a bug 
to me:

I have a variable of type double and tried to read values into a float array... 
I'll let the code talk (time is of type double and only depends on one 
dimension, namely time):

        NcVar* timo = ncfile->get_var("time");
        cout << "[datagroup] have " << *(timo->edges()) << "times" << endl;
        float* thetimes = new float[*(timo->edges())];
        timo->get(thetimes,*(timo->edges()));
        for(long i = 0; i <= *(timo->edges()); ++i)
        {
                cout << "time " << i << ": " << thetimes[i] << endl;
        }

This results in only zeroes being printed. Without the need of conversion

        double* thetimes = new double[*(timo->edges())];
        timo->get(thetimes,*(timo->edges()));

I see the correct values. It should also be mentioned that the actual values 
fit easily in a float number; in fact they are in the range of 0 to 60 in steps 
of exactly 0.5.

When using the classical nc_get_var_float() I have the correct converted values.

So, I suspect that the automagic conversion via the overloaded methods of the 
NcVar class doesn't really work here. Can one confirm this or is this just an 
oddity of my setup/data/compiler?

-- 
Thomas Orgis, theoretischer Physiker - praktischer Mensch.

Arbeitsgruppe Nichtlineare Dynamik
Institut für Physik der Universität Potsdam


 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690