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

Russ Rew: Re: 970904: netcdf unlimited dim



Forgot to CC: support-netcdf ...

------- Forwarded Message

Date:    Thu, 04 Sep 1997 12:51:39 -0600
From:    Russ Rew <address@hidden>
To:      Ben Foster <address@hidden>
Subject: Re: 970904: netcdf unlimited dim 

>To: address@hidden
>From: Ben Foster <address@hidden>
>Subject: netcdf unlimited dim
>Organization: High Altitude Observatory/NCAR, Boulder CO
>Keywords: 199709041605.KAA10198

Ben,

> > To grow a variable from inside a loop, you have to use the START and
> > COUNT arrays, something like this (in the netCDF-3 Fortran interface):
> > 
> >    real tn(NLON, NLAT, NLEV)
> >    real un(NLON, NLAT, NLEV)
> >    ...
> >    integer start(4)
> >    integer count(4)
> > 
> >    start(1) = 1
> >    start(2) = 1
> >    start(3) = 1
> >    start(4) = 1
> > 
> >    count(1) = NLON
> >    count(2) = NLAT
> >    count(3) = NLEV
> >    count(4) = 1
> > 
> >    do 10 itime = i, NTIMES
> >     start(4) = itime
> >     status = nf_put_vara_real (ncid, tnid, start, count, tn)
> >     if (status .ne. nf_noerr) call handle_err(status)
> >     status = nf_put_vara_real (ncid, unid, start, count, un)
> >     if (status .ne. nf_noerr) call handle_err(status)
> >     ...
> > 10 continue
> > 
> > or something similar in the netCDF-2 Fortran interface.
> 
> 
> Ok, but I assume that I need to create the file when itime=1, then
> for itime > 1, I reopen before making the above calls. After the
> 1st iter, I may not need to reenter define mode, since I shouldnt
> have to redefine dimensions or change attributes, just grow the 
> vars in data mode. But I think I should close the file after each
> iteration so I have a "complete" file in the event of a crash..

Well, you could create the file before the loop, just defining
everything but not writing any data.  The size of the unlimited time
dimension would be 0, but that's OK for an unlimited dimension.

It's not necessary to close and reopen the file to make sure data gets
written.  Instead, you can just call NCSNC (netCDF-2 Fortran interface)
or NF_SYNC (netCDF-3 Fortran interface) after writing each iteration's
data, say at the end of the time loop.  That will flush all the buffers,
and make sure it's on the disk.  But you can also close and reopen to
get a similar effect, though it will take a bit more time.

- --Russ

_____________________________________________________________________

Russ Rew                                         UCAR Unidata Program
address@hidden                     http://www.unidata.ucar.edu


------- End of Forwarded Message