; $Id$ ; ; Copyright (c) 1988-1998, Research Systems, Inc. All rights reserved. ; Unauthorized reproduction prohibited. function JULDAY, MONTH, DAY, YEAR, Hour, Minute, Second, NDAYSPM = ndayspm, _extra=ex ;+ ; NAME: ; JULDAY ; ; PURPOSE: ; Calculate the Julian Day Number for a given month, day, and year. ; This is the inverse of the library function CALDAT. ; See also caldat, the inverse of this function. ; CATEGORY: ; Misc. ; ; CALLING SEQUENCE: ; Result = JULDAY(Month, Day, Year) ; ; INPUTS: ; MONTH: Number of the desired month (1 = January, ..., 12 = December). ; ; DAY: Number of day of the month. ; ; YEAR: Number of the desired year. ; ; HOUR: Number of the hour of the day. ; ; MINUTE: Number of the minute of the hour. ; ; SECOND: ; ; OPTIONAL INPUT PARAMETERS: ; Hour, Minute, Second = optional time of day. ; ; 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: ; JULDAY returns the Julian Day Number (which begins at noon) of the ; specified calendar date. If the time of day (Hr, Min, Sec), is 0, ; the result will be a long integer, otherwise the result is a ; double precision floating point number. ; ; 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). ; ; AB, September, 1988 ; DMS, April, 1995, Added time of day. ; ; Eric Guilyardi, June 1999 ; Added key_work ndayspm for fixed number of days per months ;- ; ON_ERROR, 2 ; Return to caller if errors MONTHS = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG', $ 'SEP','OCT','NOV','DEC'] IF NOT keyword_set(ndayspm) THEN BEGIN ; Gregorian Calander was adopted on Oct. 15, 1582 GREG = 15L + 31L * (10L + 12L * 1582L) ; Process the input, if all are missing, use todays date. NP = n_params() if NP eq 0 then begin DATE = systime() L_MONTH = long(where(strupcase(strmid(DATE, 4, 3)) eq MONTHS)) L_MONTH = L_MONTH[0] + 1 ; Scalarize it... L_DAY = long(strmid(DATE, 8, 2)) L_YEAR = long(strmid(DATE, 20, 4)) endif else if np ge 3 then begin L_MONTH = LONG(MONTH) L_DAY = LONG(DAY) L_YEAR=LONG(YEAR) ; ;*************************************************** ; Change test to allow year 0 for climatological data ;******************************************************** ; if (L_YEAR eq 0) then message, 'There is no year zero.' endif else message, 'Wrong number of parameters.' ; ;*************************************************** ; Change test to allow year 0 for climatological data ;******************************************************** ; if (L_YEAR lt 0) then L_YEAR = L_YEAR + 1 if (L_YEAR le 0) then L_YEAR = L_YEAR + 1 if (L_MONTH gt 2) then begin JY = L_YEAR JM = L_MONTH + 1 endif else begin JY = L_YEAR - 1 JM = L_MONTH + 13 endelse JUL = floor(365.25 * JY) + floor(30.6001 * JM) + L_DAY + 1720995 ; Test whether to change to Gregorian Calandar. if ((L_DAY + 31L * (L_MONTH + 12L * L_YEAR)) ge GREG) then begin JA = long(0.01 * JY) JUL = JUL + 2 - JA + long(0.25 * JA) endif if n_elements(Hour) + n_elements(Minute) + n_elements(Second) eq 0 then $ return, JUL if n_elements(Hour) eq 0 then Hour = 0 if n_elements(Minute) eq 0 then Minute = 0 if n_elements(Second) eq 0 then Second = 0 return, JUL + (Hour / 24.0d0 - .5d0) + (Minute/1440.0d0) + (Second / 86400.0d0) ENDIF ELSE BEGIN ; ; Fixed number of days per month (default=30) : ; IF ndayspm EQ 1 THEN ndayspm = 30 L_MONTH = LONG(MONTH) L_DAY = LONG(DAY) L_YEAR=LONG(YEAR) JUL = ((L_YEAR-1)*12. + (L_MONTH-1))* ndayspm + L_DAY if n_elements(Hour) + n_elements(Minute) + n_elements(Second) eq 0 then $ return, JUL if n_elements(Hour) eq 0 then Hour = 0 if n_elements(Minute) eq 0 then Minute = 0 if n_elements(Second) eq 0 then Second = 0 return, JUL + (Hour / 24.0d0) + (Minute/1440.0d0) + (Second / 86400.0d0) ENDELSE end