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

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

bugfix when using double precision calendar

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