source: trunk/SRC/Calendar/date2jul.pro @ 495

Last change on this file since 495 was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
1;+
2;
3; @file_comments
4; gives Julian day equivalent of a date given in yyyymmdd format
5; This is the inverse of the function <pro>jul2date</pro>.
6;
7; @categories
8; Calendar
9;
10; @param date {in}{required} {type=long or double, scalar or array}
11; longword integer with yyyymmdd format or double-precision
12; floating-point with yyyymmdd.xx where xx is the fraction of the day
13; (xx=0 at 0am and 5 at 12am)
14;
15; @keyword GRADS
16; if  1 <= year <= 49 --> year = 2000 + year
17; if 50 <= year <= 99 --> year = 1900 + year
18;
19; @keyword MONTH
20; Set this keyword equal to a named variable that will receive a
21; longword integer or longword integer array representing the number of
22; the desired month (1 = January, ..., 12 = December).
23;
24; @keyword DAY
25; Set this keyword equal to a named variable that will receive a
26; longword integer or longword integer array representing the number of
27; the day of the month (1-31).
28;
29; @keyword YEAR
30; Set this keyword equal to a named variable that will receive a
31; longword integer or longword integer array representing the number of
32; the desired year (e.g., 1994).
33;
34; @keyword HOUR
35; Set this keyword equal to a named variable that will receive a
36; longword integer or longword integer array representing the number of
37; the hour of the day (0-23).
38;
39; @keyword MINUTE
40; Set this keyword equal to a named variable that will receive a
41; longword integer or longword integer array representing the number of
42; the minute of the hour (0-59).
43;
44; @keyword SECOND
45; Set this keyword equal to a named variable that will receive a
46; double-precision floating-point value or a double-precision
47; floating-point array representing the number of the second of the
48; minute (0-59).
49;
50; @returns
51; Julian day with the same format (long or double) as the input parameter
52;
53; @restrictions
54; Input param must be longword integer or double-precision floating-point
55;
56; @examples
57;
58;   IDL> jday = juldate(19930124)
59;   IDL> print, date2jul(19931205) EQ julday(12,5,1993)
60;       1
61;   IDL> print, date2jul(931205,/grads) EQ julday(12,5,1993)
62;       1
63;   IDL> print, date2jul(19931205.5d) EQ julday(12,5,1993,12,0,0)
64;       1
65;   IDL> print, date2jul(19931205.0d) EQ julday(12,5,1993,0,0,0)
66;       1
67;
68; @history
69; Sebastien Masson (smasson\@lodyc.jussieu.fr) June 2005
70;
71; @version
72; $Id$
73;
74;-
75FUNCTION date2jul, date, GRADS=grads, MONTH=month, DAY=day, YEAR=year $
76                 , HOUR=hour, MINUTE=minute, SECOND=second
77;
78  compile_opt idl2, strictarrsubs
79;
80; check parameters
81  if (N_PARAMS() EQ 0) then return, report(['ERROR, No input parameter', 'Usage : ' $
82                                            , 'res = date2jul( date[, GRADS = grads][, MONTH = month][, DAY = day]' $
83                                            + '[, YEAR = year][, HOUR = hour][, MINUTE = minute][, SECOND = second] )'])
84;
85  sztype = size(date, /type)
86  IF sztype NE 3 AND sztype NE 5 AND sztype LT 13 THEN BEGIN
87    dummy = report('Beware of input type, date must be long or double')
88    stop
89  ENDIF
90;
91  year = long(date) / 10000
92  month = long(abs(date)/100) MOD 100
93  day = long(abs(date)) MOD 100
94;------------------------------------------------------------
95  if keyword_set(grads) then $
96     year = year + 1900L * (year GE 50 AND year LE 99) $
97                 + 2000L * (year GE  1 AND year LE 49)
98;------------------------------------------------------------
99  IF sztype NE 5 THEN return, julday(month, day, year)
100
101  fraction = date - long(date)
102  hour = floor(fraction * 24d)
103  fraction = temporary(fraction) - hour/24d
104  minute = floor(fraction*1440d)
105  second = (temporary(fraction) - minute/1440d) * 86400d
106
107  return, julday(month, day, year, hour, minute, second)
108
109end
Note: See TracBrowser for help on using the repository browser.