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.
I also was not very happy with the stock C++ interface for netCDF so I've written wrapper routines that I use for this. It includes such functionality as: * Overloading depending on type of argument * Gets "wrapped" variables in a sensible way (i.e., for longitudes that go all the way around the world, it crosses the seam without a problem) * Understands some of the netCDF conventions about attributes * A list of N identical input files is treated as one big file with N timesteps (i.e., virtual concatenation along the record dimension) * Makes dims and vars "in-memory". This last one is nicer then you might think; for example, here is how you make a netCDF file with this library: //------------------------------------------------- // Now make a new netcdf file in memory, then write // it to disk //------------------------------------------------- int ndims(3); ncDim **dim = new ncDim *[ndims]; //------------------------------------------------ // NetCDF dimensions // Name Size wrap unlimited // ---- ---- ---- ----- dim[2] = new ncDim( "Xdim", 10, true, false ); dim[1] = new ncDim( "Ydim", 20, false, false ); dim[0] = new ncDim( "Time", 0, false, true ); int nvars(4); ncVar **var = new ncVar *[nvars]; //---------------------------------------------------------------------- // NetCDF dimvars // Name ndims dims units missval history // ---- - ---- --------- ------- ---- var[0] = new ncVar( "Xdim", 1, &(dim[2]), "degreesE", 1.0e35, NULL ); var[1] = new ncVar( "Ydim", 1, &(dim[1]), "degreesN", 1.0e35, NULL ); var[2] = new ncVar( "Time", 1, &(dim[0]), "days since 1900-01-01", 1.0e35, NULL ); //---------------------------------------------------------------------- // Main data var // // Name ndims dims units missval history // ---- - ---- --------- ------- ---- var[3] = new ncVar( "Data", 3, dim, "degC", 1.0e35, NULL ); //--------------------------------------------------------------- // Write file // Filename #vars vars #metadata other_metadata // -------- ----- ---- ------- ----------- ncFile g( "test.nc", nvars, var, 0, NULL ); For what it's worth, the actual reason I did the C++ wrappers was to layer another library on top of them. This other library (I unimaginatively call it "dflib", for "data file library") enforces the netCDF dimvar convention, and also automatically allocates buffers to read in data more efficiently when reading, say, X-T slabs in a X-Y-Z-T data file. (This buffering can be a big efficiency improvement depending on how you read things in). State of the code: fair to middling. No one else uses it, which means it hasn't been wrung out at all. I've only used it on a limited number of platforms (mostly Linux, Alpha Linux, IBM-SP, Cray T3E). And -- does this need to be said? -- no documentation. :) That tends to happen when you just use code for yourself. The "dflib" is MUCH more complicated than the C++ wrappers since it has so much more functionality. However, I would not have a problem supplying the C++ wrappers to people who are interested. Just be aware that it's not a finished, distributable product. Regards, --Dave --------------------------------------------------------------- David W. Pierce / Climate Research Division Scripps Institution of Oceanography / (858) 534-8276 (voice) dpierce@xxxxxxxx / (858) 534-8561 (fax) --------------------------------------------------------------- On Wed, 12 Sep 2001, Charlie Zender wrote: > Hi, > > Has anyone written an improved C++-netCDF interface based on netCDF > 3.x that they would be willing to share? I need a freely > redistributable set of C++ functions that implement overloaded netCDF > get() and put() functions which automatically handle type conversion > so that variables are converted from intrinsic types to external > netCDF types on output, and visa versa on input. The Fortran 90 > interface has this capability and so is now more sophisticated than > libnetcdf_c++.a. That's kind of backwards, if you think about it. > Please speak up if you have already solved this problem. > > Thanks, > Charlie > -- > Charlie Zender zender@xxxxxxx (949) 824-2987/FAX-3256, Department of > Earth System Science, University of California, Irvine CA 92697-3100 >
netcdfgroup
archives: