[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #XUI-152530]: NetCDF


I wrote:
> The problem is that you are allocating the array u10 in a way that makes its 
> values
> non-contiguous in memory:
> > float ***const u10 = new float** [NT];
> > for(int i = 0; i < NT; ++i) {
> >     u10[i] = new float* [NY];
> > }
> > for(int i = 0; i < NT; ++i) {
> >     for(int j = 0; j < NY; ++j) {
> >         u10[i][j] = new float [NX];
> >     }
> > }
> Addresses of arrays provided as arguments to netCDF functions must point to 
> contiguous
> values in memory.  There must not be gaps between successive values of the 
> arrays.  Such
> gaps are almost assured if you use "new" to allocate each row of a three 
> dimensional array
> separately.
> For the invocation of the "put" method in
> > NcVar *idU10 = dataFile.add_var("U10", ncFloat, dimT, dimY, dimX);
> > idU10->put(&u10[0][0][0], NT, NY, NX);
> the address &u10[0][0][0] must point to a single block of floats.
> Your program should work as intended if you allocate all the values at once.

Alternatively, you could also call the put() method for each row after you 
allocate space for it
and initialize it, because then you would also be guaranteed that the array 
values were consecutive
in memory for that row.  Of course then you would have to use the form of put() 
call that specifies
the start location (the address of the beginning of the row) and the number of 
elements to write
(the row length), rather than using the put() method writing the whole array at 

This form of writing worked for you with smaller arrays, because memory blocks 
are actually allocated 
in larger chunks than you request, for efficiency, so you are likely to get 
consecutive blocks of memory
with a sequence of smaller requests.

The put() method has no way to determine it's being given the address of an 
array of consecutive
values of smaller size than needed, so it can't return an error if you give it 
the address of a smaller 
block of values.


Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu

Ticket Details
Ticket ID: XUI-152530
Department: Support netCDF
Priority: Urgent
Status: Closed

NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.