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


  • 2005 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: