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

Re: C++ and record variables



> 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