[ncl-talk] modifing "Times" in netcdf file

Alan Brammer abrammer at albany.edu
Fri Dec 18 09:43:20 MST 2015


cd_convert wants a numeric input not character or string. 

I’m now confused what the actual question is, but assuming that time0 = "1978-04-13_18:00:00” 
and that you for some reason want to offset it by 6 hours.  

In the next release of NCL cd_inv_string() will be included. https://www.ncl.ucar.edu/Document/Functions/User_contributed/cd_inv_string.shtml
I have attached my most recent version of it here. 
Using that I would do the following, still not sure why though:



time_num = cd_inv_string(tostring(time0), "%Y-%N-%D_%H:%M:%S")  ;;  will return a “hours since 1800-01-01” numeric
time_num = time_num - 6  ;; offset by -6 hours for whatever reason. 
;; This is now technically wrong though, depending on your application. 


time_out = cd_string(time_num, "%Y-%N-%D_%H:%M:%S" )

print(time_out)

;;; assuming things are correct,  !!  unsure about this last line. 
time0 = tochar(time_out)    ;; this may require some more finesse to handle dimensions 






> On 18 Dec 2015, at 11:10, Mark Chan <cym263 at yahoo.com> wrote:
> 
> Dear Dennis,
> 
> I tried to use your suggested script, but got an error message as below (probablly because of, time = cd_convert( time0, "hours since 1987-04-13 18:00:00" )). Would you please kindly give more suggestion?
> 
> Thanks so much!!!
> Mark
> 
> ===ncl error message===
> Variable: time0
> Type: character
> Total Size: 19 bytes
>             19 values
> Number of Dimensions: 2
> Dimensions and sizes:    [Time | 1] x [DateStrLen | 19]
> Coordinates: 
> Number Of Attributes: 0
> fatal:Could not coerce values for operation
> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 15 in file D1_Times.ncl
> 
> 
> On Tuesday, December 15, 2015 9:04 PM, Dennis Shea <shea at ucar.edu> wrote:
> 
> 
> Perhaps two approaches....
> 
> 
> [1] Add 6 to current values
> [2] Use a function
> 
> Initially,
>   f = addfile("...","r")  ;  Use "r" for test and "w" to actually
> overwrite the values
>   time0 = f->time
> 
>   time  = time0    ; copy for print
>   printVarSummary(time0)            ; before
> 
> ; method  1
> 
>   time = (/ time+6 /)  ; replace values
>   time at units <mailto:time at units> = "hours since 1987-04-13 18:00:00"  ; new units
>   printVarSummary(time)                ; after
> 
> or
> 
> ; method 2
> ; http://www.ncl.ucar.edu/Document/Functions/Contributed/cd_convert.shtml <http://www.ncl.ucar.edu/Document/Functions/Contributed/cd_convert.shtml>
> 
>   time = cd_convert( time0, "hours since 1987-04-13 18:00:00" )
> 
> ; print to make sure they are as you expect
> 
>   print("-----")
>   print(time0+"  "+time)  ; examine before and after values
> 
> ====
> If all is ok the use the "w" on the addfile and then overwrite
> 
>   f->time = time
> 
> =================================
> 
> I'd make a copy of the file before doing anything ... just in case
> tehre are errors.
> 
> Good Luck
> 
> On Fri, Dec 11, 2015 at 4:35 AM, Mark Chan <cym263 at yahoo.com <mailto:cym263 at yahoo.com>> wrote:
> > Dear NCL group,
> >
> > I am wondering whether there is any easy method with NCL to modify "internal
> > Times" of the netcdf file: (the file name would be changed later)
> >
> > from: met_em_d01_1987-04-13_12:00:00
> >
> > To:    met_em_d01_1987-04-13_18:00:00
> >
> > So the time could be shown as (with "ncdump -v Times")
> >  Times =  "1978-04-13_18:00:00" ;
> >
> > Thanks very much in advance!!!
> > Mark
> 
> >
> > _______________________________________________
> > ncl-talk mailing list
> > ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk <http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
> 
> >
> 
> 
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151218/15dde4f3/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cd_inv_string.ncl
Type: application/octet-stream
Size: 4268 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151218/15dde4f3/attachment.obj 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151218/15dde4f3/attachment-0001.html 


More information about the ncl-talk mailing list