This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hi Cevahir,
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.
--Russ
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