Hi Mathieu, The pres_temp_4D_rd.cpp example you are looking at is for the old legacy netCDF-3 C++ software, which is no longer supported. You probably want to instead use the current netCDF-4 C++ software contributed for us to distribute by its developer, Lynton Appel. It's omnly supported on a "best-effort" level, but I believe it conforms to the current C++ standard. It's documented here: http://www.unidata.ucar.edu/netcdf/docs/cxx4/ and is available for download from here: http://github.com/Unidata/netcdf-cxx4/releases/tag/v4.2.1 and there are a few examples of its use here: http://www.unidata.ucar.edu/netcdf/docs/cxx4/examples.html There have been 77 commits since the last formal release, mostly fixing bugs and making the code more portable, so I would recommend getting the latest developer's snapshot from the github link above and working with that. To build the library from a github snapshot from the source, you'll have to generate a "configure" script by running $ autoreconf -if in the source directory containing the configure.ac file. I hope his helps ... --Russ > the examples of netcdf cxx given in pres_temp_4D_rd.cpp, > and others uses the following kind of declarations for the > arrays: > > static const int NLVL = 2; > static const int NLAT = 6; > static const int NLON = 12; > float pres_in[NLVL][NLAT][NLON]; > > the problem is that usually, one does not know the size > of arrays before compile time! > > The solution I am using right now is to use variable length arrays (VLA): > i.e. I have code of the following kind: > /* reading dimensions */ > int eta_rho=GrdArr.GrdArrRho.LON.rows(); > int xi_rho =GrdArr.GrdArrRho.LON.cols(); > /* Declaring variable */ > float XfieldC[eta_rho][xi_rho]; > the problem is that VLA are not part of the standard and their use is > discouraged. > > On the other hands legal kind of format like > float **Xfield; > float **XfieldB; > Xfield=(float**)malloc(eta_rho*sizeof(float*)); > for (int i=0; i<eta_rho; i++) { > Xfield[i]=(float*)malloc(xi_rho*sizeof(float)); > } > XfieldB=new float*[eta_rho]; > for (int i=0; i<eta_rho; i++) { > XfieldB[i]=new float[xi_rho]; > } > are not working and incoherent results of the kind > lat = > 8.69092e-38, 0, 3.058333e-38, 0, 3.058517e-38, 0, 3.0587e-38, 0, > 3.058884e-38, 0, 3.059068e-38, 0, 3.059252e-38, 0, 3.059436e-38, 0, > 3.05962e-38, 0, 3.059804e-38, 0, 3.059987e-38, 0, 3.060171e-38, 0, > 3.060355e-38, 0, 3.060539e-38, 0, 3.060723e-38, 0, 3.060907e-38, 0, > 3.061091e-38, 0, 3.061274e-38, 0, 3.061458e-38, 0, 3.061642e-38, 0, > 3.061826e-38, 0, 3.06201e-38, 0, 3.062194e-38, 0, 3.062377e-38, 0, > 3.062561e-38, 0, 3.062745e-38, 0, 3.062929e-38, 0, 3.063113e-38, 0, > 3.063297e-38, 0, 3.063481e-38, 0, 3.063664e-38, 0, 3.063848e-38, 0, > 3.064032e-38, 0, 3.064216e-38, 0, 3.0644e-38, 0, 3.064584e-38, 0, > showing incorrect alignments. > > Is there a way to use netcdf-cxx that is respecting the standard? > > Thank you very much in advance. > > Mathieu > > Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: QZX-374600 Department: Support netCDF Priority: Normal 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.