Re: C++ and record variables

> Organization: ERL
> Keywords: 199408312007.AA13009

Hi Tom,

> Is it possible with the current C++ NetCDF interface to write record
> (Unlimited) variables? I know the ncrecput function does not exist, but
> the manual for the C interface says that it's not necessary (accomplish
> the same by repeated calls to ncvarput; in C++, put). I've tried this
> method and I can never get more than one record in a variable.

Writing record variables is supported with the current C++ netCDF interface.
The netcdf/c++/nctst.cc program that comes with the current distribution
shows how this is done.  Briefly, you just need to declare the unlimited
dimension by *not* providing a size argument to NcFile::add_dim(), for
example:

    NcDim* frtimed = nc.add_dim("frtime"); // unlimited dimension

then just declare record variables to use this dimension as their first
dimension, for example: 

    NcVar* P = nc.add_var("P", ncFloat, frtimed, latd, lond);

and write data to the variable.  

    // We could write all P data at once with P->put(P_data, P->edges()),
    // but instead we write one record at a time, to show use of setcur().
    long rec = 0;                                      // start at zero-th
    const long nrecs = 1;                              // # records to write
    P->put(&P_data[0], nrecs, NLATS, NLONS);           // write zero-th record
    P->set_cur(++rec);                                 // set to next record
    P->put(&P_data[NLATS*NLONS], nrecs, NLATS, NLONS); // write next record

--
Russ Rew                                                   UCAR Unidata Program
russ@xxxxxxxxxxxxxxxx                                             P.O. Box 3000
http://www.unidata.ucar.edu/                             Boulder, CO 80307-3000


  • 1994 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: