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.
Stefan, > To: address@hidden > From: Stefan Maehlmann <address@hidden> > Subject: Writing out an integer array > Organization: UCAR/Unidata > Keywords: 200102081400.f18E0lL04445 The above message contained the following: > i have an integer array A[3,4]= > a11 a12 a13 a14 > a21 a22 a23 a24 > a31 a32 a33 a34 > > which i've stored as 'integer A(IROW,ICOL);' in a netcdf-file > if i want to extract it from the file > i would do the following: > > NF_INQ_DIMID(NCID,'IROW',IROW) > NF_INQ_DIMID(NCID,'ICOL', ICOL) > to get the dimensions > > ISTART=1 > ICOUNT(1)=IROW > ICOUNT(2)=ICOL > and then read the array as > NF_GET_VARA_INT (NCID,VAR_ID,ISTART,ICOUNT,NWI(1:IROW,1:ICOL)) > > but somehow now the rows and columns have swapped. Can you help me to > solve this problem? Use the following instead: ISTART(1)=1 ISTART(2)=1 ICOUNT(1)=ICOL ICOUNT(2)=IROW In the Fortran netCDF API, the "start" and "count" arguments must be vectors. The first element of each vector corresponds to the innermost dimension (the most rapidly varying one) and the last element coresponds to the outermost dimension (the most slowly varying one). In the C netCDF API, the ordering of the dimensions is reversed (i.e. the first vector elements corresponds to the innermost dimension). > A second question is how the write the array back to the file so i can > read it properly with ncdump (means that it looks like the first form). A good way to see this would be to give the following CDL file to the "ncgen" utility using the "-f" option to generate Fortran code. (NOTE: CDL uses the C convention for dimensional order, which is the reverse of the Fortran convention). netcdf A { dimensions: FortranRowCount = 3; FortranColCount = 4; variables: int a(FortranColCount,FortranRowCount); // C ordering convention data: a = 11, 21, 31, // 1st Fortran column 12, 22, 32, // 2nd Fortran column 13, 23, 33, // 3rd Fortran column 14, 24, 34; // 4th Fortran column } > Sincerely, > Stefan Maehlmann Regards, Steve Emmerson <http://www.unidata.ucar.edu>