[ncl-talk] Converting time to datestring

Barry Lynn barry.h.lynn at gmail.com
Wed Feb 3 22:54:58 MST 2021


Hi:

Try adjusting the third line here:

load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/cd_string.ncl"

begin code...

new_time_units = "hours since 1800-01-01 00:00"
new_time_units = new_time_units
new_time_array = cd_inv_calendar( year(it,1,1),  month(it,1,1),
day(it,1,1), hour(it,1,1), minute(it,1,1), 0, new_time_units,0)
print("new_time_array = " + new_time_array)
printVarSummary(new_time_array)
format = "" ;; defaults to "%H%M IST %d %c %Y"
 format = "%H%M IST %d %c %Y"
 new_time_array = new_time_array + 2.01
;format = "%H%M IDT %d %c %Y"
;new_time_array = new_time_array + 3.01
time_var=cd_string(new_time_array,format)
print("time_var = " + time_var)

On Thu, Feb 4, 2021 at 7:17 AM Zilore Mumba via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> 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
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk



-- 
Guest Editor of Special Issue “Extreme Hydroclimatic Events and Prediction”
LINK:
https://www.mdpi.com/journal/water/special_issues/Extreme_Hydroclimatic_Events

Barry H. Lynn, Ph.D
Senior Associate Scientist, Lecturer,
The Institute of the Earth Science,
The Hebrew University of Jerusalem,
Givat Ram, Jerusalem 91904, Israel
Tel: 972 547 231 170
Fax: (972)-25662581

C.E.O, Weather It Is, LTD
Weather and Climate Focus
http://weather-it-is.com
Jerusalem, Israel
Local: 02 930 9525
Cell: 054 7 231 170
Int-IS: x972 2 930 9525
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210204/eb3dc2a9/attachment.html>


More information about the ncl-talk mailing list