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

Home » Public Forums » archive » Re: equivalent of c function: gmtime
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
Re: equivalent of c function: gmtime [message #2319] Thu, 09 June 1994 06:24
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
fitz@nextone.lanl.gov writes:

> I understand that systime(arg) will return either the number of seconds
> elapsed from Jan 1, 1970 or a string with the current date and time. Does
> anyone know of procedures that are the equivalent of the C functions: gmtime,
> asctime, difftime, etc? In particular, given the seconds from Jan 1, 1970, is
> there a way to get a string giving the day, date, and time?

I have a number of time handling routines that will do the job for you. I've
asked Wayne Landsman to put it on the anonymous ftp server
idlastro.gsfc.nasa.gov under contrib/thompson/time. Unfortunately, what's
there now is tremendously out of date, but it should be updated soon. (In
particular, what is missing is the routine that calls SYSTIME and interprets
the seconds as a date and time. I could also mail it to you as a uuencoded tar
file if you don't want to wait.

One thing that one should be aware of. On Unix systems the string time
returned by SYSTIME() in IDL is a local time, whereas the numerical time is
related to UTC (aka GMT). I think this is also true on VMS systems. However,
on VMS and (I think) MacIntosh computers, it seems that both times are local.

Bill Thompson
William.T.Thompson.1@gsfc.nasa.gov
Re: equivalent of c function: gmtime [message #2328 is a reply to message #2319] Thu, 09 June 1994 02:02 Go to previous message
sjt is currently offline  sjt
Messages: 72
Registered: November 1993
Member
fitz@nextone.lanl.gov wrote:
: I understand that systime(arg) will return either the number of
: seconds elapsed from Jan 1, 1970 or a string with the current date
: and time. Does anyone know of procedures that are the equivalent
: of the C functions: gmtime, asctime, difftime, etc? In particular,
: given the seconds from Jan 1, 1970, is there a way to get a string
: giving the day, date, and time?

: ---
: Joe Fitzgerald
: MS D466
: Los Alamos National Laboratory
: Los Alamos, New Mexico 87545
: phone 505-667-1542
: fax 505-665-7395

THis isn't exactly what you need in that it works from 1950.0 rather than
1970, but that should be easy to change.

function invsec, stime

;+
; INVSEC
; This function converts seconds since 1950.0 into year,day,hour,min, and
; sec.
;
; Call:
; time = invsec(stime)
;
; Return value:
; time float 5-element array with year, day, hourm min, sec
;
; Argument:
; stime double Seconds since 00:00 UT on 1 Jan 1950 AD.
;
; History:
; Original, converted from Fortran: 11/11/91; SJT
;-


sc = stime mod 60.d0

sec = float(sc)

min = long(stime)/60
hour = min/60
min = min mod 60
day = hour/24
hour = hour mod 24
year = day/365 ; Warning this will not work after
; about 3400 or 3500 AD (when there
; have been 365 leap years).

day = (day mod 365) - (year+1)/4 ; Won't work after 2100
if (day lt 0) then begin
year = year - 1
day = day + 365 + ((year+2) mod 4 eq 0) ; Won't work after 2100
endif

day = day + 1
year = year + 1950

return, float([year, day, hour, min, sec])

end

--
James Tappin, School of Physics & Space Research
University of Birmingham
sjt@xun8.sr.bham.ac.uk
"If all else fails--read the instructions!"

O__
-- \/`
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: "Help" in Widget Programs
Next Topic: How to I get IDL postscript files from Sun to Mac

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

Current Time: Wed Oct 08 19:25:05 PDT 2025

Total time taken to generate the page: 0.00555 seconds