Re: [netcdfgroup] NetCDF C++ library: write NetCDF file problem

Hello,

Thank you Thomas, by modifying the index calculation, everything is ok: the data are now saved properly...

So I will maintain this declaration:
float * values = (float *) malloc(NT*NZ*NJ*NI*sizeof(float));

because the other one you suggest (with reinterpret_cast) doesn't work with my code (the reinterpret_cast is ignored).

Thank you for solving my problem!

Le 10/09/2014 16:45, Carole Dewé-Depelchin a écrit :
Hello,

I have a problem with NetCDF C++ Library.
I have to write a netcdf file with 4-dimension data (providing from a grib file).

I use the code below:
float values[NT][NZ][NJ][NI];

for (it = 0; it < NT; it++) {

    for (iz = 0; iz < NZ; iz++) {

        for (j = 0; j < NJ; j++) {

            for (i = 0; i < NI; i++) {

                values[it][iz][j][i] = ....;
            }
        }
    }
}

var->set_cur(0,0,0,0); //using NcVar var
var->put(&values[0][0][0][0], NT, NZ, NJ, NI);

This works fine, the netcdf file is correct, the data are saved properly. But, with this 'static' 4-dim array declaration, i am using the stack memory which is limited. With big data, i could have a segmentation fault...

So I'd like to dynamically declare the values array.
I am using this code below:

float * values = (float *) malloc(NT*NZ*NJ*NI*sizeof(float));
for (it...)
    for (iz ...)
        for (j ...)
            for (i...)
                values[it*NZ+iz*NJ+j*NI+i] = ....;

var->set_cur(0,0,0,0);
var->put(values, NT, NZ, NJ, NI);


In this case, a netcdf file is generated, but the data are not saved properly.
Do you know why this happens and how can I solve the problem?

Thanks,

Carole






_______________________________________________
netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe,  visit: 
http://www.unidata.ucar.edu/mailing_lists/

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