[ncl-talk] Creating Date String

Barry Lynn barry.h.lynn at gmail.com
Tue Nov 1 21:32:01 MDT 2016


Dear Alan:

Thank you for helping me push this along.

My variables are already integers

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

However, I still get the unit error problem.

Note below, please: new time_array from a print("new_time_array" +
new_time_array") produces

(0) new_time_array = 1900752.166666667

but (below), the printVarSummary produces a fill value equivalent to a NaN.

Here are the print outs.

(0) year(1,1,1) = 2016
(0) month(1,1,1) = 11
(0) day(1,1,1) = 2
(0) hour(1,1,1) = 0
(0) new_time_array = 1900752.166666667

Variable: new_time_array
Type: double
Total Size: 8 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
Number Of Attributes: 3
  _FillValue : 9.969209968386869e+36
  calendar : standard
  units : hours since 1800-01-01 00:00
(0) cd_string: The variable containing time values must have a 'units'
attribute.
fatal:Illegal right-hand side type for assignment
fatal:["Execute.c":8575]:Execute: Error occurred at or near line 130 in
file ./obs_light_12km.ncl


On Tue, Nov 1, 2016 at 10:53 PM, Alan Brammer <abrammer at albany.edu> wrote:

>
> The time variable passed to cd_string() should be in the format of “hours
> since 1800-01-01 00:00:00” or similar.   The format passed to the argument
> is for the output string not the input variable.
>
>
> I don’t really understand how you got to the first line of your sample
> code but trying to build from that is some code below:
>
>  ; time_array(0)=hour(1,1,1)
>  ; time_array(1)=minute(1,1,1)
>  ; time_array(2)=day(1,1,1)
>  ; time_array(3)=month(1,1,1)
>  ; time_array(4)=year(1,1,1)
>  ;;   time_array(5)=units    ;; are the above strings or numbers?  If
> they’re numbers this line won’t work.
>
> ;; first make a ut_coord complaint time variable from the arrays of time
> stuff you already have.
>
> *time_array = cd_inv_calendar( toint(year(1,1,1)), toint (month(1,1,1)),
> toint( day(1,1,1)), toint (hour(1,1,1)), toint (minute(1,1,1)), 0, “hours
> since 1800-01-01 00:00:00”,0)*
> *printVarSummary(time_array)*
> ;;;    Should be a single number of double type with a units attribute.
>
> *format = “" ;; defaults to "%H%M UTC %d %c %Y"*
> *time_var=cd_string(time_array,format)*
>
>
>
> p.s. beware of weird quotation marks if copy/pasting from email.
>
> Good luck,
> Alan
>
>
> ##############################
> Alan Brammer,
> Post-Doc Researcher
>
> Department of Atmospheric and Environmental Sciences,
> University at Albany, State University of New York, Albany, NY, 12222
> abrammer at albany.edu
> ##############################
>
> On 1 Nov 2016, at 06:33, Barry Lynn <barry.h.lynn at gmail.com> wrote:
>
> Good Morning:
>
> I went to this page
>
> https://www.ncl.ucar.edu/Document/Functions/User_
> contributed/cd_string.shtml
>
> and tried to do this:
>
> For all the following examples, assume that *time* is an array of time
> values.
>
> *Example 1*
>
> Using the default format string of "" will result in "HHMM UTC D Mon YYYY"
> (e.g., 1800 UTC 4 Jul 1776):
>
>   format = ""
>   stime  = cd_string(time,format)
>
> The goal is to plot the string "time_var" as shown below, as a single
> variable.
>
> But I get an error; please see below.
>
> (Note: I thought (as a try) to stick this information in the "unitlabel"
> parameter below, but I would really prefer to plot the date on the right
> hand side at
> the top of the map).
>
> Here's my code.
>
> ;HHMM UTC D Mon YYYY
>   time_array(0)=hour(1,1,1)
>   time_array(1)=minute(1,1,1)
>   time_array(2)=day(1,1,1)
>   time_array(3)=month(1,1,1)
>   time_array(4)=year(1,1,1)
>   time_array(5)=units
> ; format = "HHMM UTC D Mon YYYY"
>   format = ""
>   *time_var=cd_string(time_array,format)*
>   print("time_var = " + time_var)
>   opts_ic_cg at FieldTitle           = "Lightning Rate"
> ; opts_ic_cg at UnitLabel            = "/10-min"
>  * opts_ic_cg at UnitLabel            = time_var*
>
> (0) Working on time: 2016-10-30_00:00:00
> (0) cd_string: The variable containing time values must have a 'units'
> attribute.
> fatal:Illegal right-hand side type for assignment
>
> After searching and finding:
>
> http://www.ncl.ucar.edu/Document/Functions/User_
> contributed/time_axis_labels.shtml
>
> *time*
>
> An array containing the values of time. This variable should have an
> attribute named "units". In other words, this variable holds the values of
> the coordinate axis 'time' along with the units.
>
>
> I am not sure what this error means or how to address the error.
>
> Thank you.
>
>
> --
> Barry H. Lynn, Ph.D
> Senior 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
> US 914 432 3108
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>


-- 
Barry H. Lynn, Ph.D
Senior 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
US 914 432 3108
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161102/84233ddd/attachment.html 


More information about the ncl-talk mailing list