source: trunk/SRC/Calendar/jul2date.pro @ 279

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

bugfix when using double precision calendar

  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1;+
2;
3; @file_comments
4; gives yyyymmdd date equivalent of a Julian day
5;
6; @categories
7; Calendar
8;
9; @param jday {in}{required} {type=long or double, sacalr or array}
10; Julian day
11;
12; @keyword MONTH
13; Set this keyword equal to a named variable that will receive a
14; longword integer or longword integer array representing the number of
15; the desired month (1 = January, ..., 12 = December).
16;
17; @keyword DAY
18; Set this keyword equal to a named variable that will receive a
19; longword integer or longword integer array representing the number of
20; the day of the month (1-31). 
21;
22; @keyword YEAR
23; Set this keyword equal to a named variable that will receive a
24; longword integer or longword integer array representing the number of
25; the desired year (e.g., 1994). 
26;
27; @keyword HOUR
28; Set this keyword equal to a named variable that will receive a
29; longword integer or longword integer array representing the number of
30; the hour of the day (0-23). 
31;
32; @keyword MINUTE
33; Set this keyword equal to a named variable that will receive a
34; longword integer or longword integer array representing the number of
35; the minute of the hour (0-59). 
36
37; @keyword SECOND
38; Set this keyword equal to a named variable that will receive a
39; double-precision floating-point value or a double-precision
40; floating-point array representing the number of the second of the
41; minute (0-59).
42;
43; @returns
44; the date: longword integer with yyyymmdd format or double-precision
45; floating-point with yyyymmdd.xx where xx is the fraction of the day
46; (xx=0 at 0am and 5 at 12am)
47;
48; @restrictions
49; Input param must be longword integer or double-precision floating-point
50;
51; @examples
52;
53; IDL> print, jul2date(julday(12,23,1999))
54;     19991223
55; IDL> print, jul2date(julday(12,23,1999,12,0,0))
56;        19991224.
57; IDL> print, jul2date(julday(12,23,1999,12,0,0)), format='(f11.2)'
58; 19991223.50
59; IDL> print, jul2date(julday(12,23,1999,0,0,0)), format='(f11.2)'
60; 19991223.00
61;
62; @history
63; Sebastien Masson (smasson\@lodyc.jussieu.fr)
64;                       June 2005
65;
66; @version
67; $Id$
68;
69;-
70;
71function jul2date, jday, MONTH = month, DAY = day, YEAR = year $
72                   , HOUR = hour, MINUTE = minute, SECOND = second
73;
74  compile_opt idl2, strictarrsubs
75;
76  sztype = size(jday, /type)
77  IF sztype NE 3 AND sztype NE 5 AND sztype LT 13 THEN BEGIN
78    dummy = report('Beware of input type, julian date must be long or double')
79    stop
80  ENDIF
81;
82  caldat, jday, month, day, year, hour, minute, second
83;
84  res = (10000L*year + 100L*month + day)*(year GE 0) $
85        +( 10000L*year - 100L*month - day)*(year LT 0)
86;
87  IF sztype NE 5 THEN return, long(res) $
88  ELSE return, double(res) + (hour / 24.0d0) + (minute/1440.0d0) + (second / 86400.0d0)
89
90end
Note: See TracBrowser for help on using the repository browser.