[ncl-talk] Writing data to the existing record dimension of a netCDF
Dave Allured - NOAA Affiliate
dave.allured at noaa.gov
Tue Nov 29 16:38:45 MST 2016
Will,
If the junk time array has the correct variable name and dimension name
(probably both "time"), and a data type with sufficient precision, then the
simplest method is to just overwrite the junk time coordinate values with
correct time coordinates that you calculate in NCL. I have found that
trying to swap a new coordinate variable in place of an old one is very
troublesome.
As a side note, I just ran very simple tests on NCL 6.3.0 on Mac. The
following program easily added a new 1-D variable, to both netcdf-3 and
netcdf-4 test files with unlimited time dimension. In short, I do not see
why your program crashed.
f = addfile ("test.nc", "w")
t3 = f->time ; note both time and t3 are double in this case
f->t3 = t3 ; both have single dimension "time"
exit
--Dave
On Tue, Nov 29, 2016 at 3:45 PM, Will Hobbs <will.hobbs at utas.edu.au> wrote:
> Hi all
>
>
>
> I am working with some model output monthly files (one year for each file,
> with filename t.<year>.nc), which have a junk time array, and which I am
> trying to fix. I was hoping to create a new time array, add the values to
> each file’s time array, and update the variable attributes using NCO:
>
>
>
> >Begin
>
>
>
> yrst = 1979
>
> yren=2014
>
> vNam = “t”
>
>
>
>
>
> ;create new time array
>
>
>
> ydum = new(12, integer)
>
> mdum = ispan(1,12,1)
>
> ddum = conform_dims(12,15,-1)
>
> tdum = conform_dims(12,0,-1)
>
>
>
> opt = 1
>
> opt at calendar = "standard"
>
> tunits = "days after 1-1-1"
>
>
>
>
>
> ;loop through each year
>
> do yy = yrst, yren
>
>
>
> ;create time array
>
> ydum = yy
>
> ntime = cd_inv_calendar(ydum,mdum,ddum,tdum,tdum,tdum,tunits,opt)
>
>
>
>
>
> ;add time to file
>
> fil =systemfunc("ls "+vNam+"."+yy+".nc")
>
> fi = addfile(fil,"w")
>
>
>
> fi->time = (/ntime/)
>
>
>
> ;update attributes
>
> CMD = “ncatted –a time,units,o,c,”+tunits+” “+fil
>
> system(CMD)
>
>
>
> end do
>
>
>
>
>
> Unfortunately when I try and write the data to file (i.e. fi->time =
> (/ntime/) ) I get a segmentation fault:
>
>
>
> Segmentation fault: 11
>
>
>
> I’ve checked the file permissions and it doesn’t seem to be that. I
> ‘speculate’ that netCDF won’t allow me to update the record dimension – is
> this the case? If so, presumably I will need rewrite each file from scratch
> with new time arrays.
>
>
>
> Many thanks,
>
>
>
> Will
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161129/02c1d807/attachment.html
More information about the ncl-talk
mailing list