[ncl-talk] Writing data to the existing record dimension of a netCDF

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Tue Nov 29 17:29:46 MST 2016


Will,

Please keep messages on the discussion list.  To debug your seg fault, try
this simple test to overwrite a single junk time coordinate value:

    fi = addfile (fil, "w")
    fi->time(0) = (/ 1.0d /)
    print ("Single value written")
    exit

If this test works, the problem is probably in your code.  If this fails,
there is probably something wrong with the file or with NCL, or else your
time dimension is named something other than "time".

On your side question, t3 would still be a record variable because it
shares the dimension name "time" with your old time coordinate variable,
which is also a record variable.  I assumed that your actual time dimension
name is "time".  If the time dimension has a different name, please change
"time" in these examples to the actual name of the time dimension.

--Dave


On Tue, Nov 29, 2016 at 5:03 PM, Will Hobbs <will.hobbs at utas.edu.au> wrote:

> Hi Dave
>
>
>
> I had a go trying what you suggested, (i.e. write a new time variable) and
> I still get the segmentation fault, so it’s possible there’s a problem with
> my file.
>
>
>
> As an aside, in your code snippet would the new file variables, t3, still
> be a record dimension? I presume not. This would become an issue with
> post-processing using CDO, NCO etc.
>
>
>
> Thanks
>
>
>
> Will
>
>
>
> *From: *Dave Allured - NOAA Affiliate <dave.allured at noaa.gov>
> *Date: *Wednesday, 30 November 2016 at 10:38 AM
> *To: *Will Hobbs <will.hobbs at utas.edu.au>
> *Cc: *"ncl-talk at ucar.edu" <ncl-talk at ucar.edu>
> *Subject: *Re: [ncl-talk] Writing data to the existing record dimension
> of a netCDF
>
>
>
> 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/42b9630f/attachment.html 


More information about the ncl-talk mailing list