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

Mark Chan cym263 at yahoo.com
Fri Dec 18 09:10:16 MST 2015


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 = "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

  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> 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
> 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/09bfa6a2/attachment.html 


More information about the ncl-talk mailing list