Re: Given a string time stamp need to add hours (donna Cote)

From: donna Cote <d-cote_at_nyahnyahspammersnyahnyah>
Date: Fri Feb 11 2011 - 12:14:50 MST

Thank you Mary!

I do have, at least, 5.1.1 and I ended up with this working bit of code.
It works and I'm not messing with it. If anyone can suggest something
more efficient, I will definitely consider it. Thanks!

With ncl_filedump, I see the Time variable is a number of hours (12
here). and Time@start has the time stamp of "2010-06-01 00:00:00". I
will confess that this isn't a netcdf file I created and will have
suggestions to the creators about their choices of variable meta data.

       integer Time ( Time )
          long_name : Elapse Time
          units : hour
          FORTRAN_format : i8
          start : 2010-06-01 00:00:00
          FORM : YYYY-MM-DD hh:mm:ss

  <snip>
   fileHour=f->Time
   timestring = fileHour@start
   yearint= stringtointeger( str_get_cols( timestring, 0, 3 ) )
   monint = stringtointeger( str_get_cols( timestring, 5, 6 ) )
   dayint = stringtointeger( str_get_cols( timestring, 8, 9 ) )
   hrint = stringtointeger( str_get_cols( timestring, 11, 12 ) )
   minint = stringtointeger( str_get_cols( timestring, 14, 15 ) )

   timeUnits = "hours since "+timestring
   oldtime = ut_inv_calendar( yearint, monint, dayint, hrint, minint,
00, timeUnits, 0 )

   newtime = oldtime + fileHour
   newtime@units = timeUnits

   tmpstring = " "+ut_calendar( newtime, -3 ) ; get a YYYYMMDDhh
integer time string
   newstring =
"'"+str_get_cols(tmpstring,1,4)+"-"+str_get_cols(tmpstring,5,6)+"-"+str_get_cols(tmpstring,7,8)+"T"+str_get_cols(tmpstring,9,10)+":00-00'"

; 2010060112 format wanted: yyyy-mm-ddThh:mm-00, so sb
2010-06-01T12:00-00
; 01234567890 (tmpstring has 11 characters because of the space I put
in front
  <snip>

On 2/11/11 10:16 AM, Mary Haley wrote:
> I don't know if I'm missing something here, but I believe you could use
> str_sub_str.
> You will need to have at least version 5.1.1:
>
> timestring = "2010-06-01T00:00"
> nhours = 12
>
> ; Nicely format hour string. Prepend "T", postpend ":"
> hstr = "T" + sprinti("%02i:",nhours)
>
> ; Construct new string
> new_timestring = str_sub_str(timestring,"T",hstr)
> print(new_timestring)
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Feb 11 12:15:09 2011

This archive was generated by hypermail 2.1.8 : Fri Feb 11 2011 - 16:11:42 MST