[ncl-talk] Converting time to datestring

Zilore Mumba zmumba at gmail.com
Wed Feb 3 22:17:01 MST 2021


Hello,
I hope I can get quick help to set me off as it is taking me days to make
sense of what I have to do.
I have historical (1971-200) and model simulation (2021-2050) data. I have
adapted an ncl script from the DKRZ website for plotting a time series.

With print(times) I get the time range 7701.5 to 18658.5.
When I plot the time series at a point I get the x-axis range 6000 60 20000
ncdump -h on the file indicates that time:units = "days since 1949-12-01
00:00:00"
my data has format yyyymmdd (yearmothday). I want the x-axis to show dates.

I have been looking in the ncl documentation how to do this. This may take
me days or weeks.
I would appreciate any help in this.
The script I have is below

load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRF_contributed.ncl"
begin

   diri = "./"                             ; directory where to find the
data
   fili =
"pr_AFR-44_CNRM-CERFACS-CNRM-CM5_historical_r1i1p1_SMHI-RCA4_v1_day_19710101_20001231Reg.nc"
            ; file name

   f   = addfile(diri+fili,"r")             ; open file

   t1 = f->pr(:,{-15},{30})                 ; read precip time series at
15S/30E

   times  = f->time                         ; get times in file
   cd_date = cd_calendar(times, -2)

; open a workstation
;----------------------------------------------------------------
   wks_type = "X11"                         ; graphics output type
   wks_type at wkWidth   =  1024               ; graphics output width in
pixels
   wks_type at wkHeight  =  1048               ; graphics output height in
pixels

   wks = gsn_open_wks(wks_type, "plot_xy_multiple_lines_axis")

; resources for variable t1, y-axis
;----------------------------------------------------------
   resT1                      =  True
   resT1 at ttmValues            =  cd_date
   resT1 at xyLineThicknessF     =  3.0                        ; set line
thickness
   resT1 at xyLineColor          =  "red"                      ; set line color
   resT1 at xyDashPatterns       =  0                          ; solid line
   resT1 at tmXBLabelFontHeightF = 0.010
   resT1 at tiYAxisString        =  "Daily " + " " + t1 at standard_name +"  "+
"at 15S/30E"              ; y-axis string

; create the plot
;-----------------------------------------------
   plot = gsn_csm_xy(wks, times&time, t1, resT1)

end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210204/724f8ecf/attachment.html>


More information about the ncl-talk mailing list