source: trunk/SRC/ToBeReviewed/PLOTS/LABEL/label_date.pro @ 325

Last change on this file since 325 was 325, checked in by pinsard, 16 years ago

modification of some headers (+some corrections) to prepare usage of the new idldoc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1;
2; Copyright (c) 1993-1998, Research Systems, Inc.  All rights reserved.
3;       Unauthorized reproduction prohibited.
4
5;+
6;
7; @file_comments
8; This function labels axes with dates and times.
9;
10; @categories
11; Plotting
12;
13; @param AXIS {in}{required}
14;
15; @param INDEX {in}{required}
16;
17; @param X {in}{required}
18;
19; @keyword DATE_FORMAT
20; a format string which may contain the following:
21; %M for month (3 character abbr)
22; %N for month (2 digit abbr)
23; %D for day of month,
24; %Y for 4 digit year.
25; %Z for last two digits of year.
26;  For time:
27; %H for Hours, 2 digits.
28; %I for Minutes, 2 digits.
29; %S for Seconds, 2 digits.
30; %% is %.
31;  Other characters are passed directly thru.
32; For example, '%M %D, %Y' prints DEC 11, 1993
33; '%M %2Y' yields DEC 93
34; '%D-%M' yields 11-DEC
35; '%D/%N/%Y' yields 11/12/1993
36; '%M!C%Y' yields DEC on the top line, 1993 on
37; the bottom (!C is the new line graphic command).
38;
39; @keyword MONTHS
40; The names of the months, a twelve element string array.
41; If omitted, use Jan, Feb, ..., Dec.
42;
43; @keyword OFFSET
44; An optional starting offset of the plot.
45; Unfortunately, single precision floating point is not accurate
46; enough to properly represent Julian times.  This offset, which
47; may be double precision, contains an offset that is added to
48; all x values, before conversion to Julian date and time.
49;
50; @uses
51; LABEL_DATE_COM.
52;
53; @restrictions
54; Only one date axis may be simultaneously active.
55;
56; @examples
57; For example, to plot from Jan 1, 1993, to July 12, 1994:
58; Start_date = julday(1, 1, 1993)
59; End_date = julday(7, 12, 1994)
60; Dummy = LABEL_DATE(DATE_FORMAT='%N/%D')  ;Simple mm/dd
61; x = findgen(end_date+1 - start_date) + start_date ;Time axis
62; PLOT, x, sqrt(x), XTICKFORMAT = 'LABEL_DATE', XSTYLE=1
63; (Plot with X axis style set to exact.)
64;       
65; Example with times:
66;       For example, to plot from 3PM, Jan 1, 1993, to 5AM, Jan 3,
67;       1993:
68;       Start_date = Julday(1,1,1993)   ;Also starting offset
69;       Start_time = (3+12)/24.         ;Starting_time less offset
70;       End_time = (Julday(1,3,1993) - Start_date) + 5./24. ;Ending
71;               ;date/time - offset, note that the order of operations is
72;               ; important to avoid loss of precision.
73;       Dummy = LABEL_DATE(DATE_FORMAT='%D %M!C%H:%I', $
74;               offset=Start_date)       ;MMM NN <new line> HH:MM format
75;       x = findgen(20) * (End_time - Start_time) / 19 + start_time ;Time axis
76;       PLOT, x, sqrt(x), XTICKFORMAT = 'LABEL_DATE', XSTYLE=1
77;
78; @history
79;       DMS, RSI.       April, 1993.    Written.
80;       DMS, RSI.       March, 1997.    Added Time format.
81;
82; Copyright (c) 1993-1998, Research Systems, Inc.  All rights reserved.
83;       Unauthorized reproduction prohibited.
84;
85; @version
86; $Id$
87;
88;-
89FUNCTION label_date, axis, index, x, DATE_FORMAT = format, MONTHS = months, $
90              OFFSET= offs, _EXTRA = ex
91;
92  compile_opt idl2, strictarrsubs
93;
94COMMON label_date_com, fmt, month_chr, offset
95
96if keyword_set(format) then begin ;Save format string?
97    if n_elements(offs) ne 0 then offset = double(offs) else offset = 0.0d0
98    if keyword_set(months) then month_chr = months $
99    else month_chr = ['Jan','Feb','Mar', 'Apr', 'May', 'Jun', 'Jul', $
100                      'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
101    fmt = format
102    return, 0
103endif
104
105if n_elements(month_chr) ne 12 or n_elements(fmt) le 0 $
106  or n_elements(offset) eq 0 then $
107  message,' Not initialized.'
108
109x1 = x + offset
110caldat, long(x1), month, day, year, _EXTRA = ex;Get the calendar date from julian
111frac = x1 - long(x1)            ;time of day, from 0 to 1.
112
113n = strlen(fmt)
114out = ''
115
116for i=0, n-1 do begin           ;Each format character...
117    c = strmid(fmt, i, 1)       ;The character.
118    if c eq '%' then begin
119        i = i + 1
120        c = strmid(fmt, i, 1)   ;The function
121        case c of               ;format character?
122            'M' : out = out + month_chr[month-1]
123            'N' : out = out + string(format='(i2.2)', month)
124            'D' : out = out + string(format='(i2.2)', day)
125            'Y' : out = out + string(format='(i4)', year)
126            'Z' : out = out + string(format='(i2.2)', year  mod 100)
127            'H' : out = out + string(format='(i2.2)', floor(24*frac))
128            'I' : out = out + string(format='(i2.2)', floor(1440 * frac mod 60))
129            'S' : out = out + string(format='(i2.2)', 86400L * frac mod 60)
130            '%' : out = out + '%'
131            else : message, 'Illegal character in date format string: '+fmt
132        endcase
133    endif else out = out + c
134endfor
135return, out
136end
Note: See TracBrowser for help on using the repository browser.