[ncl-talk] Error with date format

Lyndz olagueralyndonmark429 at gmail.com
Sun Sep 1 02:00:59 MDT 2019


Dear NCL-experts,

*Details:*
I am converting dates with YYYYMMDD format to YYYY-MM-DD format (separated
by a hyphen). For example, I have the following data *20140423*. If the
month and day are both less than 10, a 0 should precede it. However, I
encountered an error below:
-------------------------------------------------------------------------------------------------------------
*What I have so far:*
I have the following function from a previous email:

     undef("add_hyphen")
     function add_hyphen(yyyymmdd[*]:integer)
     local yyyy, mmdd, mm, dd, a, b, c, d
     begin
      yyyy    = yyyymmdd/10000
      mmdd    = yyyymmdd-(yyyy*10000)
      mm      = mmdd/100

         if(mm.lt.10)
         a = tostring(mm)
         b = 0+a
         else
         b = mm
         end if

         dd      = mmdd-(mm*100)
         if(dd.lt.10)
         c = tostring(dd)
         d = 0+c
         else
         d = dd
         end if
         return(yyyy+"-"+b+"-"+d)
     end

     yymd = add_hyphen(ymd)
     print(yymd)
-------------------------------------------------------------------------------------------------------------
*Error:*
fatal: Conditional statements (if and do while) require SCALAR logical
values, see all and any functions
-------------------------------------------------------------------------------------------------------------
*What I want:*
The input has no "units" so I can't use the cd_string. Any suggestions on
how I can do this correctly in NCL?
I'll appreciate any help.


Sincerely,
Lyndz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190901/9b6a0626/attachment.html>


More information about the ncl-talk mailing list