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

Last change on this file since 327 was 327, checked in by pinsard, 17 years ago

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

  • Property svn:keywords set to Id
File size: 3.7 KB
RevLine 
[9]1;+
2;
[238]3; @file_comments
[318]4; gives Julian day equivalent of a date given in yyyymmdd format
5; This is the inverse of the function <pro>jul2date</pro>.
[9]6;
[157]7; @categories
8; Calendar
[9]9;
[318]10; @param date {in}{required} {type=long or double, scalar or array}
[279]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)
[9]14;
[137]15; @keyword GRADS
[126]16; if  1 <= year <= 49 --> year = 2000 + year
17; if 50 <= year <= 99 --> year = 1900 + year
[9]18;
[279]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;
[238]50; @returns
[279]51; Julian day with the same format (long or double) as the input parameter
[9]52;
[279]53; @restrictions
54; Input param must be longword integer or double-precision floating-point
55;
[126]56; @examples
[9]57;
[126]58; IDL> jday = juldate(19930124)
59; IDL> print, date2jul(19931205) EQ julday(12,5,1993)
[9]60;       1
[126]61; IDL> print, date2jul(931205,/grads) EQ julday(12,5,1993)
[9]62;       1
[279]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
[9]67;
[238]68; @history
[137]69; Sebastien Masson (smasson\@lodyc.jussieu.fr) June 2005
[118]70;
[231]71; @version
72; $Id$
[118]73;
[9]74;-
[327]75FUNCTION date2jul, date, GRADS=grads, MONTH=month, DAY=day, YEAR=year $
76                 , HOUR=hour, MINUTE=minute, SECOND=second
[114]77;
78  compile_opt idl2, strictarrsubs
79;
[327]80  usage="res=date2jul, date, GRADS=grads, MONTH=month, DAY=day, YEAR=year , HOUR=hour, MINUTE=minute, SECOND=second"
[325]81;
82; check parameters
83  check_param = N_PARAMS()
84  if (check_param EQ 0) then begin
85     dummy = report(['No input parameter', $
86                     'Usage : ' + usage])
87     stop
88  endif
89;
90; check arguments
91; ++ pas sur
92  if arg_present(date) then begin
93     dummy = report(['No input parameter date', $
94                     'Usage : ' + usage])
95     stop
96  endif
[279]97  sztype = size(date, /type)
98  IF sztype NE 3 AND sztype NE 5 AND sztype LT 13 THEN BEGIN
99    dummy = report('Beware of input type, date must be long or double')
100    stop
101  ENDIF
102;
103  year = long(date) / 10000
104  month = long(abs(date)/100) MOD 100
105  day = long(abs(date)) MOD 100
[9]106;------------------------------------------------------------
[279]107  if keyword_set(grads) then $
108     year = year + 1900L * (year GE 50 AND year LE 99) $
109                 + 2000L * (year GE  1 AND year LE 49)
[9]110;------------------------------------------------------------
[279]111  IF sztype NE 5 THEN return, julday(month, day, year)
[238]112
[205]113  fraction = date - long(date)
114  hour = floor(fraction * 24d)
[279]115  fraction = temporary(fraction) - hour/24d
[205]116  minute = floor(fraction*1440d)
[279]117  second = (temporary(fraction) - minute/1440d) * 86400d
[238]118
[205]119  return, julday(month, day, year, hour, minute, second)
120
[9]121end
122
Note: See TracBrowser for help on using the repository browser.