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