[ncl-talk] convert the time proleptic gregorian calendar to UTC date in NCL

Sri nandini bax8609 at uni-hamburg.de
Thu Dec 17 06:15:10 MST 2020


Hello dear ncl-users

I am trying to convert the time proleptic_gregorian calendar in the time 
format of my data to UTC date, so that irs easier to extract the years 
to work with.

The original print time output is this:

Variable: time
Type: double
Total Size: 14976 bytes
             1872 values
Number of Dimensions: 1
Dimensions and sizes:    [time | 1872]
Coordinates:
             time: [18500131.99444444..20051231.99444444]
Number Of Attributes: 4
   standard_name :    time
   units :    day as %Y%m%d.%f
   calendar :    proleptic_gregorian
   axis :    T
(0)    18500131.99444444
(1)    18500228.99444444
(2)    18500331.99444444
(3)    18500430.99444444
(4)    18500531.99444444
(5)    18500630.99444444
(6)    18500731.99444444
(7)    18500831.99444444
(8)    18500930.99444444
(9)    18501031.99444444
(10)    18501130.99444444
(11)    18501231.99444444
(12)    18510131.99444444
(13)    18510228.99444444
(14)    18510331.99444444
(15)    18510430.99444444
(16)    18510531.99444444
(17)    18510630.99444444
................continued

(1852)    20040531.99444444
(1853)    20040630.99444444
(1854)    20040731.99444444
(1855)    20040831.99444444
(1856)    20040930.99444444
(1857)    20041031.99444444
(1858)    20041130.99444444
(1859)    20041231.99444444
(1860)    20050131.99444444
(1861)    20050228.99444444
(1862)    20050331.99444444
(1863)    20050430.99444444
(1864)    20050531.99444444
(1865)    20050630.99444444
(1866)    20050731.99444444
(1867)    20050831.99444444
(1868)    20050930.99444444
(1869)    20051031.99444444
(1870)    20051130.99444444
(1871)    20051231.99444444

      yrStrt                                    = 1986
      yrLast                                   = 2005

      f     = addfile ("hist_1850-2005_wind10.nc", "r")
      time   = f->time
      print(time) see above output

;  convert the time proleptic_gregorian calendar to UTC date
            YYYY   = cd_calendar(time,-1)/100    ;-- convert date to 
UT-referenced date
;  Set date variable names
           year     =  tointeger(utc_date(:,0))       ;-- get year as 
integer value
          month    =  tointeger(utc_date(:,1))     ;-- get month as 
integer value
          day      =  tointeger(utc_date(:,2))        ;-- get day as 
integer value
          hour     =  tointeger(utc_date(:,3))       ;-- get hour as 
integer value
          minute   =  tointeger(utc_date(:,4))     ;-- get minute as 
integer value
;  Write date as a string (YYYY.MM)
    date_str =  sprinti("%0.4i",year) + "/" + sprinti("%0.2i", month)
    return(date_str)

      ;-- retrieve the indices of the selected years

      iYYYY  = ind(YYYY.ge.yrStrt .and. YYYY.le.yrLast)
      print(iYYYY)
      hist_anom=f->wind10(iYYYY,:,:,:)

but i get the error:

CDMS error: Error on relative units conversion, string = day as %Y%m%d.%f

CDMS error: Error on time conversion: invalid month = 10085

Can someone help me to solve this?

Sri




More information about the ncl-talk mailing list