Like I said the previous code was not tested.
I was about to delet it when I noticed a boo-boo!
Sorry. see attached.
====================
>>ncl-talk:
>>
>>Suppose I have an ncl double, read from a netcdf file, e.g. 2002030106
>>i.e., yyyymmddhh, how do I convert this to a string so I can parse out
>>the date and time to 6 hours on March 1, 2002? Thanks,
>>_______________________________________________
>
>>> I believe functions such as sprinti and sprintf will help you with this.
>________________________________________________
>
>I mangled a code I have. It is attached.
>It can work on a one-dim array of dates
>
>As "Scott Capp" says the sprinti function
>http://www.ncl.ucar.edu/Document/Functions/Built-in/sprinti.shtml
>could be useful if you want leading zeros on single
>digit hours and days
>
>The code is *not* tested.
>
>D
undef ("foster_date")
function foster_date ( YYYYMMDDHH[*]:numeric , opt)
local yyyymmddhh, year, mmddhh, mon, ddhh, day, \
hour, monNam, date, date
begin
if (typeof(YYYYMMDDHH).eq."integer") then
yyyymmddhh = YYYYMMDDHH
end if
if (typeof(YYYYMMDDHH).eq."float") then
yyyymmddhh = floattointeger(YYYYMMDDHH)
end if
if (typeof(YYYYMMDDHH).eq."double") then
yyyymmddhh = doubletointeger(YYYYMMDDHH)
end if
year = yyyymmddhh/1000000
mmddhh = yyyymmddhh-year*1000000
delete(yyyymmddhh)
mon = mmddhh/10000
ddhh = mmddhh-mon*10000
delete (mmddhh)
day = ddhh/100
hour = ddhh-day*100
delete (ddhh)
if (iopt.eq.0) then
monNam = (/ "January" , "February" , "March" \
, "April" , "May" , "June" \
, "July" , "August" , "September"\
, "October" , "November" , "December" /)
; array syntax
date = hour + " hours on "+MonNam(mon-1)+" "+ \
day + "," + year
;date = sprinti("%0.2", hour) + " hours on "+MonNam(mon-1)+" "+ \
; sprinti("%0.2", day ) + "," + year
else
nDate = dimsizes(yyyymmddhh)
date = new ( (/nDate,4/), "integer", "No_FillValue")
date(:,0) = year
date(:,1) = mon
date(:,2) = day
date(:,3) = hour
end if
return(date)
end
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Jan 24 2007 - 15:05:12 MST
This archive was generated by hypermail 2.2.0 : Mon Feb 05 2007 - 16:31:09 MST