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

Last change on this file since 318 was 318, checked in by smasson, 17 years ago

header cleaning

  • Property svn:keywords set to Id
File size: 3.3 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;-
75;
76function date2jul, date, GRADS = grads, MONTH = month, DAY = day, YEAR = year $
77                   , HOUR = hour, MINUTE = minute, SECOND = second
78;
79  compile_opt idl2, strictarrsubs
80;
81  sztype = size(date, /type)
82  IF sztype NE 3 AND sztype NE 5 AND sztype LT 13 THEN BEGIN
83    dummy = report('Beware of input type, date must be long or double')
84    stop
85  ENDIF
86;
87  year = long(date) / 10000
88  month = long(abs(date)/100) MOD 100
89  day = long(abs(date)) MOD 100
90;------------------------------------------------------------
91  if keyword_set(grads) then $
92     year = year + 1900L * (year GE 50 AND year LE 99) $
93                 + 2000L * (year GE  1 AND year LE 49)
94;------------------------------------------------------------
95  IF sztype NE 5 THEN return, julday(month, day, year)
96
97  fraction = date - long(date)
98  hour = floor(fraction * 24d)
99  fraction = temporary(fraction) - hour/24d
100  minute = floor(fraction*1440d)
101  second = (temporary(fraction) - minute/1440d) * 86400d
102
103  return, julday(month, day, year, hour, minute, second)
104
105end
106
Note: See TracBrowser for help on using the repository browser.