[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ and record variables

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.


  • Subject: Re: C++ and record variables
  • Date: Thu, 01 Sep 1994 16:56:46 -0600

> Organization: NOAA
> Keywords: 199409011356.AA29525

Tom,

>       I tried your suggestion on the C++ record variables and I still get the
> same results. Here is my short test program:
> ------------------------------------------------------------------------------
> #include <stdio.h>
> #include "netcdf.hh"
> 
> int main()
> {
>         float data[3][50];
>         int i,j,k;
>         long start[3];
>         long rec=0;
>         long nrec=1;
>         long number=0;
> 
> 
>         for(j=0;j<3;j++)
>                 for(i=0;i<50;i++)
>                         data[j][i]=((float)i*.5)+(float)number;
> 
>         NcOldFile file ("scr.nc",NcOldFile::Write);
> 
>         NcDim* TIME=file.get_dim("time");
>         NcDim* HEIGHTS=file.get_dim("heights");
>         NcDim* BEAM=file.get_dim("beam");
> 
>         NcVar* velId=file.get_var("vel");
> 
>         velId->put((float *)&data,nrec,BEAM->size(),HEIGHTS->size());
> 
>         velId->set_cur(++rec);
> 
>         velId->put((float *)&data,nrec,BEAM->size(),HEIGHTS->size());
> 
>         return(0);
> }
> --------------------------------------------------------------------------------
> Here is the test cdl file that I'm using:
> 
> --------------------------------------------------------------------------------
> netcdf scr
>     {
> 
> // Santa Cruz profiler site NetCDF file.
> 
>     dimensions:
> 
>         time = UNLIMITED;
>         namelen = 30;
>         heights = 50;
>         beam = 3;
>         az = 3;
>         el = 3;
> 
>     variables:
> 
> // Actual data variables:
> 
>         //      Radial Velocity
> 
>         float
>             vel(time, beam, heights);
>             vel:long_name = "Radial Velocity, all beams";
>             vel:units = "meters/second";
>             vel:valid_range = -100.f, 100.f;
> 
> }
> 
> --------------------------------------------------------------------------------
> 
> What I am doing wrong? Is the fact that I'm using a cdl file causing the 
> problem?

Thanks for sending the test program.  I've compiled and run it here and get
only one record in the file after it has run also.  But the nctst program
uses almost exactly the same sequence of calls and the output ends up with
two records, as expected.  Using the CDL file and generating scr.nc should
work.

So far I haven't discovered the source of the discrepency; this note is just
to let you know that I'm looking at the problem.  It may be there is a bug
in the NcVar::set_cur() member function, but that wouldn't explain why it
works in nctst.cc.

--Russ