comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Time conversion for .nc file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Time conversion for .nc file [message #86485] Wed, 13 November 2013 07:26 Go to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hi,

I have date & UTC time in tow columns as [YYYYMMDD HRMISE], where YYYY - Year, MM - Month, DD - day, HR - Hours, MI - Minutes, SE - Seconds. Now, I wanted to convert to the "time" variable according to NetCDF convention. I mean to say that I wanted to convert my date & UTC time values to "time" in seconds since 1970-01-01 00:00:00 (in UTC). Can anyone help me how I can use SYSTIME function available in IDL?

Thanks in advance,
Madhavan
Re: Time conversion for .nc file [message #86486 is a reply to message #86485] Wed, 13 November 2013 07:44 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Madhavan Bomidi writes:

> I have date & UTC time in tow columns as [YYYYMMDD HRMISE], where YYYY - Year, MM - Month, DD - day, HR - Hours, MI - Minutes, SE - Seconds. Now, I wanted to convert to the "time" variable according to NetCDF convention. I mean to say that I wanted to convert my date & UTC time values to "time" in seconds since 1970-01-01 00:00:00 (in UTC). Can anyone help me how I can use SYSTIME function available in IDL?

I wouldn't use the SYSTIME function. I would use the JULDAY function. I
would read the two columns of data as a single string array. Then, I
would do something like this (using a scalar string as an example, but
this will work for a string array, too):

str = '20131113 083122'
year = Fix(StrMid(str,0,4))
mon = Fix(StrMid(str,4,2))
day = Fix(StrMid(str,6,2))
hour = Fix(StrMid(str,9,2))
min = Fix(StrMid(str,11,2))
sec = Fix(StrMid(str,13,2))
jultime = JulDay(mon,day,year,hour min,sec) - JulDay(1,1,1970,0,0,0)
ncdfTime = jultime * 24 * 60 * 60
print, ncdfTime

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Time conversion for .nc file [message #86487 is a reply to message #86486] Wed, 13 November 2013 07:56 Go to previous messageGo to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Thanks David ...

On Wednesday, November 13, 2013 4:44:01 PM UTC+1, David Fanning wrote:
> Madhavan Bomidi writes:
>
>
>
>> I have date & UTC time in tow columns as [YYYYMMDD HRMISE], where YYYY - Year, MM - Month, DD - day, HR - Hours, MI - Minutes, SE - Seconds. Now, I wanted to convert to the "time" variable according to NetCDF convention. I mean to say that I wanted to convert my date & UTC time values to "time" in seconds since 1970-01-01 00:00:00 (in UTC). Can anyone help me how I can use SYSTIME function available in IDL?
>
>
>
> I wouldn't use the SYSTIME function. I would use the JULDAY function. I
>
> would read the two columns of data as a single string array. Then, I
>
> would do something like this (using a scalar string as an example, but
>
> this will work for a string array, too):
>
>
>
> str = '20131113 083122'
>
> year = Fix(StrMid(str,0,4))
>
> mon = Fix(StrMid(str,4,2))
>
> day = Fix(StrMid(str,6,2))
>
> hour = Fix(StrMid(str,9,2))
>
> min = Fix(StrMid(str,11,2))
>
> sec = Fix(StrMid(str,13,2))
>
> jultime = JulDay(mon,day,year,hour min,sec) - JulDay(1,1,1970,0,0,0)
>
> ncdfTime = jultime * 24 * 60 * 60
>
> print, ncdfTime
>
>
>
> Cheers,
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Time conversion for .nc file [message #86489 is a reply to message #86486] Wed, 13 November 2013 09:26 Go to previous messageGo to next message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
Le mercredi 13 novembre 2013 16:44:01 UTC+1, David Fanning a écrit :
> Madhavan Bomidi writes:
>
>
>
>> I have date & UTC time in tow columns as [YYYYMMDD HRMISE], where YYYY - Year, MM - Month, DD - day, HR - Hours, MI - Minutes, SE - Seconds. Now, I wanted to convert to the "time" variable according to NetCDF convention. I mean to say that I wanted to convert my date & UTC time values to "time" in seconds since 1970-01-01 00:00:00 (in UTC). Can anyone help me how I can use SYSTIME function available in IDL?
>
>
>
> I wouldn't use the SYSTIME function. I would use the JULDAY function. I
>
> would read the two columns of data as a single string array. Then, I
>
> would do something like this (using a scalar string as an example, but
>
> this will work for a string array, too):
>
>
>
> str = '20131113 083122'
>
> year = Fix(StrMid(str,0,4))
>
> mon = Fix(StrMid(str,4,2))
>
> day = Fix(StrMid(str,6,2))
>
> hour = Fix(StrMid(str,9,2))
>
> min = Fix(StrMid(str,11,2))
>
> sec = Fix(StrMid(str,13,2))
>
> jultime = JulDay(mon,day,year,hour min,sec) - JulDay(1,1,1970,0,0,0)
>
> ncdfTime = jultime * 24 * 60 * 60
>
> print, ncdfTime
>
>
>
> Cheers,
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")

You might also use string C format:

jd = 0d0
reads, '20131113 083122', jd, FORMAT='(C(CYI4,CMOI2,CDI2,1x,CHI2,CMI2,CSI2))'
jd -= Julday(1,1,1970,0,0,0)
jd *= 86400d0
ncdfTime = jd

Date string arrays can be handled in the same way.
alx.
Re: Time conversion for .nc file [message #86491 is a reply to message #86489] Wed, 13 November 2013 09:32 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
alx writes:

> You might also use string C format:
>
> jd = 0d0
> reads, '20131113 083122', jd, FORMAT='(C(CYI4,CMOI2,CDI2,1x,CHI2,CMI2,CSI2))'
> jd -= Julday(1,1,1970,0,0,0)
> jd *= 86400d0
> ncdfTime = jd
>
> Date string arrays can be handled in the same way.

Especially useful for the novice IDL programmer! ;-)

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Time conversion for .nc file [message #86492 is a reply to message #86489] Wed, 13 November 2013 09:47 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
alx writes:

> You might also use string C format:
>
> jd = 0d0
> reads, '20131113 083122', jd, FORMAT='(C(CYI4,CMOI2,CDI2,1x,CHI2,CMI2,CSI2))'
> jd -= Julday(1,1,1970,0,0,0)
> jd *= 86400d0
> ncdfTime = jd
>
> Date string arrays can be handled in the same way.

Incidentally, this is called C() Format Code or "calendar format" in the
on-line help. Took me about 15 minutes to find it. ;-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Time conversion for .nc file [message #86554 is a reply to message #86486] Tue, 19 November 2013 02:36 Go to previous messageGo to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Just a small syntax error ... (Comma is missing between hour and min)

jultime = JulDay(mon,day,year,hour, min,sec) - JulDay(1,1,1970,0,0,0)

How can we obtain the exact month, day, year, hour, min, sec from the ncdfTime created above? I tried to use the CALDAT but it is giving some crazy numbers for each of them. I am asking this because in order to plot the variables as a function of time, the jultime is more difficult to say about which day it corresponds to. Do you have any better suggestion?

Thanks in advance



On Wednesday, November 13, 2013 4:44:01 PM UTC+1, David Fanning wrote:
> Madhavan Bomidi writes:
>
>
>
>> I have date & UTC time in tow columns as [YYYYMMDD HRMISE], where YYYY - Year, MM - Month, DD - day, HR - Hours, MI - Minutes, SE - Seconds. Now, I wanted to convert to the "time" variable according to NetCDF convention. I mean to say that I wanted to convert my date & UTC time values to "time" in seconds since 1970-01-01 00:00:00 (in UTC). Can anyone help me how I can use SYSTIME function available in IDL?
>
>
>
> I wouldn't use the SYSTIME function. I would use the JULDAY function. I
>
> would read the two columns of data as a single string array. Then, I
>
> would do something like this (using a scalar string as an example, but
>
> this will work for a string array, too):
>
>
>
> str = '20131113 083122'
>
> year = Fix(StrMid(str,0,4))
>
> mon = Fix(StrMid(str,4,2))
>
> day = Fix(StrMid(str,6,2))
>
> hour = Fix(StrMid(str,9,2))
>
> min = Fix(StrMid(str,11,2))
>
> sec = Fix(StrMid(str,13,2))
>
> jultime = JulDay(mon,day,year,hour min,sec) - JulDay(1,1,1970,0,0,0)
>
> ncdfTime = jultime * 24 * 60 * 60
>
> print, ncdfTime
>
>
>
> Cheers,
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Time conversion for .nc file [message #86557 is a reply to message #86554] Tue, 19 November 2013 06:11 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Madhavan Bomidi writes:

> How can we obtain the exact month, day, year, hour, min, sec from the ncdfTime created above? I tried to use the CALDAT but it is giving some crazy numbers for each of them. I am asking this because in order to plot the variables as a function of time, the jultime is more difficult to say about which day it corresponds to. Do you have any better suggestion?

No other suggestions. CalDat works great. You just have to do the
reverse of what you have done previously. Convert seconds to Julian
days, add Julday(1,1,1970,0,0,0) to that result, and put that through
the CalDat function. I've never known it to go wrong. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Time conversion for .nc file [message #86558 is a reply to message #86554] Tue, 19 November 2013 06:46 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Madhavan Bomidi writes:

> How can we obtain the exact month, day, year, hour, min, sec from the ncdfTime created above? I tried to use the CALDAT but it is giving some crazy numbers for each of them. I am asking this because in order to plot the variables as a function of time, the jultime is more difficult to say about which day it corresponds to. Do you have any better suggestion?

I added a note on how to do this in this article:

http://www.idlcoyote.com/fileio_tips/cfseconds.php

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Time conversion for .nc file [message #86559 is a reply to message #86557] Tue, 19 November 2013 06:58 Go to previous messageGo to next message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
Le mardi 19 novembre 2013 15:11:03 UTC+1, David Fanning a écrit :
> Madhavan Bomidi writes:
>
>
>
>> How can we obtain the exact month, day, year, hour, min, sec from the ncdfTime created above? I tried to use the CALDAT but it is giving some crazy numbers for each of them. I am asking this because in order to plot the variables as a function of time, the jultime is more difficult to say about which day it corresponds to. Do you have any better suggestion?
>
>
>
> No other suggestions. CalDat works great. You just have to do the
>
> reverse of what you have done previously. Convert seconds to Julian
>
> days, add Julday(1,1,1970,0,0,0) to that result, and put that through
>
> the CalDat function. I've never known it to go wrong. :-)
>
>
>
> Cheers,
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")


For novice IDL users as well as experienced ones, may I add that:

1) "calendar format" is quite useful because it works in same way in both directions and can be used with arrays, i.e.

IDL> reads, DATE, JD, format=FMT
IDL> DATES = string(JD, format=FMT)

where JD is array of doubles, DATES is array of date strings, and FMT is some calendar format.

2) axis plotting where time is expressed in Julian days is pretty easy to do by using XTICKUNITS keyword (this is true both in DG and NG !):

IDL> plot, jd, data, XTICKUNITS='year' ;automatic labeling in years
IDL> plot, jd, data, XTICKUNITS=['minute','hour'] ;double labeling in hours and minutes.
etc...
The axis can be further customized by using MINOR and XTICKINTERVAL keywords.

alx.
Re: Time conversion for .nc file [message #86560 is a reply to message #86559] Tue, 19 November 2013 07:11 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
alx writes:

>
> Le mardi 19 novembre 2013 15:11:03 UTC+1, David Fanning a écrit :
>> Madhavan Bomidi writes:
>>
>>
>>
>>> How can we obtain the exact month, day, year, hour, min, sec from the ncdfTime created above? I tried to use the CALDAT but it is giving some crazy numbers for each of them. I am asking this because in order to plot the variables as a function of time, the jultime is more difficult to say about which day it corresponds to. Do you have any better suggestion?
>>
>>
>>
>> No other suggestions. CalDat works great. You just have to do the
>>
>> reverse of what you have done previously. Convert seconds to Julian
>>
>> days, add Julday(1,1,1970,0,0,0) to that result, and put that through
>>
>> the CalDat function. I've never known it to go wrong. :-)
>>
>>
>>
>> Cheers,
>>
>>
>>
>> David
>>
>> --
>>
>> David Fanning, Ph.D.
>>
>> Fanning Software Consulting, Inc.
>>
>> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>>
>> Sepore ma de ni thue. ("Perhaps thou speakest truth.")
>
>
> For novice IDL users as well as experienced ones, may I add that:
>
> 1) "calendar format" is quite useful because it works in same way in both directions and can be used with arrays, i.e.
>
> IDL> reads, DATE, JD, format=FMT
> IDL> DATES = string(JD, format=FMT)
>
> where JD is array of doubles, DATES is array of date strings, and FMT is some calendar format.
>
> 2) axis plotting where time is expressed in Julian days is pretty easy to do by using XTICKUNITS keyword (this is true both in DG and NG !):
>
> IDL> plot, jd, data, XTICKUNITS='year' ;automatic labeling in years
> IDL> plot, jd, data, XTICKUNITS=['minute','hour'] ;double labeling in hours and minutes.
> etc...
> The axis can be further customized by using MINOR and XTICKINTERVAL keywords.

Sounds like it might be worth learning what the "calendar" format is all
about. ;-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDL refuse to acknowledge anything but integers...
Next Topic: Derivatives

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:29:04 PDT 2025

Total time taken to generate the page: 0.00522 seconds