NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

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

From: Carole Dewé-Depelchin <carole.depelchin@xxxxxx>
Subject: [netcdfgroup] NetCDF C++ library: write NetCDF file problem
Date: Wed, 10 Sep 2014 16:45:10 +0200

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);

Hello Carole,

I think the index calculation [it*NZ+iz*NJ+j*NI+i] might not do what you want it to do? Does it work when you use

  values[it*NZ*NJ*NI + iz*NJ*NI + j*NI + i] = ...;

instead?

To avoid having to think about that at all, I sometimes use this trick for heap-allocated multidimensional arrays in c++:

float (*values)[NZ][NJ][NI] = reinterpret_cast<float (*)[NZ][NJ][NI]>(malloc(NT*NZ*NJ*NI*sizeof(float)));

this will allow you to write

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

in your loop


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


--
Dr. Thomas Danckaert
Belgian Institute for Space Aeronomy (IASB/BIRA)
Ringlaan 3, 1180 Brussels
Belgium
http://www.aeronomie.be

Tel: +32 (0)2 8909-870 (office)

thomas.danckaert@xxxxxxxxxxxx



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