; $Id$ ; ; Copyright (c) 1992-1998, Research Systems, Inc. All rights reserved. ; Unauthorized reproduction prohibited. ; ;+ ; NAME: ; CALDAT ; ; PURPOSE: ; Return the calendar date and time given julian date. ; This is the inverse of the function JULDAY. ; CATEGORY: ; Misc. ; ; CALLING SEQUENCE: ; CALDAT, Julian, Month, Day, Year, Hour, Minute, Second ; See also: julday, the inverse of this function. ; ; INPUTS: ; JULIAN contains the Julian Day Number (which begins at noon) of the ; specified calendar date. It should be a long integer. ; ; KEYWORD PARAMETERS: ; ; NDAYSPM: developpe par eric, ca veut dire: nombre de jours par mois! ; par defaut c''est 30, sinon le specifier en donnant ; une valeur a ndayspm ; pour passer a un calendrier avec un nombre de jours constant par ; mois. Utilise en particulier ds julday et caldat ; ; OUTPUTS: ; (Trailing parameters may be omitted if not required.) ; MONTH: Number of the desired month (1 = January, ..., 12 = December). ; ; DAY: Number of day of the month. ; ; YEAR: Number of the desired year. ; ; HOUR: Hour of the day ; Minute: Minute of the day ; Second: Second (and fractions) of the day. ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; None. ; ; RESTRICTIONS: ; Accuracy using IEEE double precision numbers is approximately ; 1/10000th of a second. ; ; MODIFICATION HISTORY: ; Translated from "Numerical Recipies in C", by William H. Press, ; Brian P. Flannery, Saul A. Teukolsky, and William T. Vetterling. ; Cambridge University Press, 1988 (second printing). ; ; DMS, July 1992. ; DMS, April 1996, Added HOUR, MINUTE and SECOND keyword ; AB, 7 December 1997, Generalized to handle array input. ; Eric Guilyardi, June 1999 ; Added key_work ndayspm for fixed number of days per months ;- ; pro caldat_scalar, Julian, Month, Day, Year, Hour, Minute, Second, NDAYSPM = ndayspm ; Internal variant of CALDAT that does the actual work on a single ; value. ON_ERROR, 2 ; Return to caller if errors IF NOT keyword_set(ndayspm) THEN BEGIN IGREG = 2299161L ;Beginning of Gregorian calendar IF julian GE 0 THEN jul = long(julian + .5d) $ ;Better be long ELSE jul = long(julian - .5d) f = julian + .5d - jul if f ne 0.0 then begin ;Get hours, minutes, seconds. hour = floor(f * 24.) f = f - hour / 24.d minute = floor(f*1440) second = (f - minute/1440.d0) * 86400.0d0 endif else begin hour = 0L minute = 0L second = 0L endelse if jul ge igreg then begin jalpha = long(((jul - 1867216) - 0.25d0) / 36524.25) ja = jul + 1 + jalpha - long(0.25d0 * jalpha) endif else ja = jul jb = ja + 1524l jc = long(6680.0 + ((jb-2439870)-122.1d0)/365.25) jd = long(365 * jc + (0.25 * jc)) je = long((jb - jd) / 30.6001) day = jb - jd - long(30.6001d * je) month = je -1 if (month gt 12) then month = month - 12 year = jc - 4715 if month gt 2 then year = year - 1 if year le 0 then year = year - 1 ENDIF ELSE BEGIN jul = long(julian) f = (jul - floor(jul)) IF f NE 0.0 THEN BEGIN ;Get hours, minutes, seconds. hour = floor(f*24.) f = f - hour / 24.d minute = floor(f*1440) second = (f - minute/1440.d0) * 86400.0d0 ENDIF ELSE BEGIN hour = 0L minute = 0L second = 0L ENDELSE IF ndayspm EQ 1 THEN ndayspm = 30 Z = floor(julian) X = Z / ndayspm day = Z - X*ndayspm year = X / 12 month = X - year*12 + 1 year = year + 1 ENDELSE end pro caldat, Julian, Month, Day, Year, Hour, Minute, Second, NDAYSPM = ndayspm ON_ERROR, 2 ; Return to caller if errors ; Determine shape of input and construct longword output variables of ; the same shape. s = size(julian) if (s[0] eq 0) then begin ; Julian is scalar. Just call CALDAT_SCALAR and pass our arguments through. caldat_scalar, Julian, Month, Day, Year, Hour, Minute, Second, NDAYSPM = ndayspm return endif ; It's an array. Construct result variables ndim = s[0] ; Number or array dimensions n = s[ndim + 2] ; # of elements s[ndim + 1] = 3 ; Change the type to LONG MONTH = (DAY = (YEAR = (HOUR = (MINUTE = (SECOND = MAKE_ARRAY(SIZE=s)))))) ; Loop over the input for i = 0, n-1 do begin caldat_scalar, julian[i], month_tmp, day_tmp, year_tmp, $ hour_tmp, minute_tmp, second_tmp, NDAYSPM = ndayspm month[i] = month_tmp day[i] = day_tmp year[i] = year_tmp hour[i] = hour_tmp minute[i] = minute_tmp second[i] = second_tmp endfor end