Re: Time convertion [message #24125] |
Wed, 14 March 2001 10:57  |
Pavel A. Romashkin
Messages: 531 Registered: November 2000
|
Senior Member |
|
|
I have two observations about this posting, both bothered me.
JD Smith wrote:
> st=(julday(month,day,year,hr,min,sec)-2440587.5D)*86400.0D
I am not able to see HISTOGRAM in here. My news reader must require an
update, since some ASCII characters got lost in transfer.
> Keeping in mind that systime(1) often returns GMT on many systems
*Often* and *Many systems* !? Isn't it something you are supposed to be
able to count on? Or, you mean those systems that have a clock screwed up?
Cheers,
Pavel
|
|
|
Re: Time convertion [message #24126 is a reply to message #24125] |
Wed, 14 March 2001 10:50   |
John-David T. Smith
Messages: 384 Registered: January 2000
|
Senior Member |
|
|
Alex Schuster wrote:
>
> Hi!
>
> I have to convert some date formats, and I wonder why IDL does not give
> more support here. A common date/time format is the seconds since 1970,
> and the systime() funtion can return the current date in this format.
> Yippie! But why is there no function to convert this from/to standard
> ASCII date strings, or from/to Julian date?
>
> I found such a thing in the Astro library, st2date, input is the
> seconds-since-1970, output is year, month, day etc., and even day and
> month in ASCII notation if one likes. Great. But I did not find
> something yet to convert to seconds-since-1970. I could write it myself,
> but I guess this already had be done some dozen times. Some big routine
> with many, many keywords to convert between all those formats would be
> nice :)
Hmm... I doubt you found that in the Astro library, since I wrote it and
posted it to the newsgroup back in 1998. I did use daycnv from the
astro package to convert julian to calendar dates. The recent
IDL-bundled "caldat" will work just as well for that now. In any case,
it is oh so trivial to convert date to systime, the inverse:
st=(julday(month,day,year,hr,min,sec)-2440587.5D)*86400.0D
That's it! For instance:
IDL> st0=systime(0) & st1=systime(1)
IDL> d=bin_date(st0)
IDL> st=(julday(d[1],d[2],d[0],d[3],d[4],d[5])-2440587.5D)*86400. 0D
IDL> print,FORMAT='(A,":",2D30.5)',st0,st1,st
Keeping in mind that systime(1) often returns GMT on many systems,
whereas systime(0) returns localtime, meaning you might have several
hours offset between st1 and st above. For me, st1-st=5 hours (EST).
Good luck,
JD
|
|
|
Re: Time convertion [message #24127 is a reply to message #24126] |
Wed, 14 March 2001 10:17   |
Liam E. Gumley
Messages: 378 Registered: January 2000
|
Senior Member |
|
|
Alex Schuster wrote:
> I have to convert some date formats, and I wonder why IDL does not give
> more support here. A common date/time format is the seconds since 1970,
> and the systime() funtion can return the current date in this format.
> Yippie! But why is there no function to convert this from/to standard
> ASCII date strings, or from/to Julian date?
>
> I found such a thing in the Astro library, st2date, input is the
> seconds-since-1970, output is year, month, day etc., and even day and
> month in ASCII notation if one likes. Great. But I did not find
> something yet to convert to seconds-since-1970. I could write it myself,
> but I guess this already had be done some dozen times. Some big routine
> with many, many keywords to convert between all those formats would be
> nice :)
http://fermi.jhuapl.edu/s1r/idl/s1rlib/time/time.html
Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley
|
|
|
Re: Time convertion [message #24128 is a reply to message #24127] |
Wed, 14 March 2001 09:44   |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Pavel A. Romashkin (pavel.romashkin@noaa.gov) writes:
> Alex Schuster wrote:
>>
>> Some big routine
>> with many, many keywords to convert between all those formats would be
>> nice :)
>
> You mean, some *small*, perfectly working routine, preferably written by DF?...
Uh, huh. And you are offering to pay how much!?
Cheers,
David
P.S. Let's just say that if something like this doesn't
exist at either the JHUAPL library or at the NASA library,
something is *seriously* wrong with the world. :-(
By the way, I offer a 50% discount on my fees if I can
steal the program from somewhere else. :-)
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
|
Re: Time convertion [message #24222 is a reply to message #24126] |
Wed, 14 March 2001 11:52   |
tam
Messages: 48 Registered: February 2000
|
Member |
|
|
JD Smith wrote:
... In any case,
> it is oh so trivial to convert date to systime, the inverse:
>
> st=(julday(month,day,year,hr,min,sec)-2440587.5D)*86400.0D
>
> That's it! For instance:
>
> IDL> st0=systime(0) & st1=systime(1)
> IDL> d=bin_date(st0)
> IDL> st=(julday(d[1],d[2],d[0],d[3],d[4],d[5])-2440587.5D)*86400. 0D
> IDL> print,FORMAT='(A,":",2D30.5)',st0,st1,st
>
...
>
> JD
How are leap seconds accounted for here? They usually cause
niggling problems if one actually needs to worry about
precision at the second level over periods of more than a
month or two. It looks like your code is ignoring them.
The biggest pain is that they are not predictable so the
code needs to access an external file, or update an
internal table periodically.
Regards,
Tom McGlynn
|
|
|
|
Re: Time convertion [message #24247 is a reply to message #24130] |
Tue, 20 March 2001 06:03   |
Alex Schuster
Messages: 124 Registered: February 1997
|
Senior Member |
|
|
"Pavel A. Romashkin" wrote:
> Alex Schuster wrote:
>
>> Some big routine
>> with many, many keywords to convert between all those formats
>> would be nice :)
>
> You mean, some *small*, perfectly working routine, preferably
> written by DF?...
No, I'd prefer it to be big, very big. So I can watch it being compiled
and I can think, wow, this take sa long time, there must be some many
really cool great amazing routines in it! And it should accept all
formats, be it one of the various string formats, or secs-since-1970, or
Julian Days, Chinese years, nanoseconds-since-big-bang or whatever.
Alex
--
Alex Schuster Wonko@weird.cologne.de PGP Key available
alex@pet.mpin-koeln.mpg.de
|
|
|
Re: Time convertion [message #24248 is a reply to message #24126] |
Tue, 20 March 2001 06:04  |
Alex Schuster
Messages: 124 Registered: February 1997
|
Senior Member |
|
|
JD Smith wrote:
> Alex Schuster wrote:
>> I found such a thing in the Astro library, st2date, input is the
>> seconds-since-1970, output is year, month, day etc., and even day and
>> month in ASCII notation if one likes. Great. But I did not find
>> something yet to convert to seconds-since-1970. I could write it myself,
>> but I guess this already had be done some dozen times. Some big routine
>> with many, many keywords to convert between all those formats would be
>> nice :)
>
> Hmm... I doubt you found that in the Astro library, since I wrote it and
> posted it to the newsgroup back in 1998. I did use daycnv from the
> astro package to convert julian to calendar dates.
Umm, right. I found it in the folder where my copy of the Astro library
resides.
> The recent
> IDL-bundled "caldat" will work just as well for that now.
Hooray! I hope it also can output various time strings... but I'm still
using IDL 5.2 :(
> In any case,
> it is oh so trivial to convert date to systime, the inverse:
>
> st=(julday(month,day,year,hr,min,sec)-2440587.5D)*86400.0D
Okay, right. Once you know that these Julian Days are, and if you don't
think about leap seconds. I already did the same, but made the mistake
of using julday(1,1,1970) instead of julday(1,1,1970,0,0,0), which gives
half a day offset. Okay, my fault, but if IDL already had such a
conversion routine, I wouldn't have to think about it, and I wouldn't be
able to make such mistakes.
Another example, why can't systime() just also output julian days, give
it one more keyword and that's it.
Reimar's link was a good tip and made things easier:
http://fermi.jhuapl.edu/s1r/idl/s1rlib/time/time.html
Many many routines converting various time and/or date strings to other
formats (of course no direct conversion to secs-since-1970).
--
Alex Schuster Wonko@weird.cologne.de PGP Key available
alex@pet.mpin-koeln.mpg.de
|
|
|
Re: Time convertion [message #24256 is a reply to message #24127] |
Mon, 19 March 2001 13:12  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
"Liam E. Gumley" wrote:
>
> Alex Schuster wrote:
>> I have to convert some date formats, and I wonder why IDL does not give
>> more support here. A common date/time format is the seconds since 1970,
>> and the systime() funtion can return the current date in this format.
>> Yippie! But why is there no function to convert this from/to standard
>> ASCII date strings, or from/to Julian date?
>>
>> I found such a thing in the Astro library, st2date, input is the
>> seconds-since-1970, output is year, month, day etc., and even day and
>> month in ASCII notation if one likes. Great. But I did not find
>> something yet to convert to seconds-since-1970. I could write it myself,
>> but I guess this already had be done some dozen times. Some big routine
>> with many, many keywords to convert between all those formats would be
>> nice :)
>
> http://fermi.jhuapl.edu/s1r/idl/s1rlib/time/time.html
and here are some more julian seconds routines
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_source/idl_ html/dbase/download/string2js.tar.gz
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_source/idl_ html/dbase/download/js2string.tar.gz
There are many formats defined
e.g.:
; FORMAT: string to format the output:
; 'ICG' = 'Y-M-D H:M:S MS'
; 'XLS' = 'D.M.Y H:M:S'
; 'M-D'
; 'H:M'
; 'H:M:S'
; 'Y-M-D'
; 'M-D-Y'
; 'YMDHMS'
For further routines and licensing please look at
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml
regards
Reimar
--
Reimar Bauer
Institut fuer Stratosphaerische Chemie (ICG-1)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg1/
=============================================
a IDL library at ForschungsZentrum J�lich
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml
http://www.fz-juelich.de/zb/text/publikation/juel3786.html
|
|
|