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 | ;- |
---|
89 | ;----------------------------------------------------------------------------- |
---|
90 | FUNCTION LABEL_DATE, axis, index, x, DATE_FORMAT = format, MONTHS = months, $ |
---|
91 | OFFSET= offs, _EXTRA = ex |
---|
92 | ; |
---|
93 | compile_opt idl2, strictarrsubs |
---|
94 | ; |
---|
95 | COMMON label_date_com, fmt, month_chr, offset |
---|
96 | |
---|
97 | if keyword_set(format) then begin ;Save format string? |
---|
98 | if n_elements(offs) ne 0 then offset = double(offs) else offset = 0.0d0 |
---|
99 | if keyword_set(months) then month_chr = months $ |
---|
100 | else month_chr = ['Jan','Feb','Mar', 'Apr', 'May', 'Jun', 'Jul', $ |
---|
101 | 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] |
---|
102 | fmt = format |
---|
103 | return, 0 |
---|
104 | endif |
---|
105 | |
---|
106 | if n_elements(month_chr) ne 12 or n_elements(fmt) le 0 $ |
---|
107 | or n_elements(offset) eq 0 then $ |
---|
108 | message,' Not initialized.' |
---|
109 | |
---|
110 | x1 = x + offset |
---|
111 | caldat, long(x1), month, day, year, _EXTRA = ex;Get the calendar date from julian |
---|
112 | frac = x1 - long(x1) ;time of day, from 0 to 1. |
---|
113 | |
---|
114 | n = strlen(fmt) |
---|
115 | out = '' |
---|
116 | |
---|
117 | for i=0, n-1 do begin ;Each format character... |
---|
118 | c = strmid(fmt, i, 1) ;The character. |
---|
119 | if c eq '%' then begin |
---|
120 | i = i + 1 |
---|
121 | c = strmid(fmt, i, 1) ;The function |
---|
122 | case c of ;format character? |
---|
123 | 'M' : out = out + month_chr[month-1] |
---|
124 | 'N' : out = out + string(format='(i2.2)', month) |
---|
125 | 'D' : out = out + string(format='(i2.2)', day) |
---|
126 | 'Y' : out = out + string(format='(i4)', year) |
---|
127 | 'Z' : out = out + string(format='(i2.2)', year mod 100) |
---|
128 | 'H' : out = out + string(format='(i2.2)', floor(24*frac)) |
---|
129 | 'I' : out = out + string(format='(i2.2)', floor(1440 * frac mod 60)) |
---|
130 | 'S' : out = out + string(format='(i2.2)', 86400L * frac mod 60) |
---|
131 | '%' : out = out + '%' |
---|
132 | else : message, 'Illegal character in date format string: '+fmt |
---|
133 | endcase |
---|
134 | endif else out = out + c |
---|
135 | endfor |
---|
136 | return, out |
---|
137 | end |
---|