[2] | 1 | ;+ |
---|
| 2 | ; |
---|
[142] | 3 | ; @file_comments |
---|
| 4 | ; This function labels axes with dates and times. |
---|
[2] | 5 | ; |
---|
[142] | 6 | ; @categories |
---|
[157] | 7 | ; Plotting |
---|
[2] | 8 | ; |
---|
[369] | 9 | ; @param AXIS {in} |
---|
[2] | 10 | ; |
---|
[369] | 11 | ; @param INDEX {in} |
---|
[2] | 12 | ; |
---|
[369] | 13 | ; @param X {in} |
---|
[2] | 14 | ; |
---|
[142] | 15 | ; @keyword DATE_FORMAT |
---|
| 16 | ; a format string which may contain the following: |
---|
[369] | 17 | ; %M for month (3 characters abbr) |
---|
| 18 | ; %N for month (2 digits abbr) |
---|
[142] | 19 | ; %D for day of month, |
---|
[369] | 20 | ; %Y for 4 digits year. |
---|
[142] | 21 | ; %Z for last two digits of year. |
---|
| 22 | ; For time: |
---|
| 23 | ; %H for Hours, 2 digits. |
---|
[163] | 24 | ; %I for Minutes, 2 digits. |
---|
[142] | 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). |
---|
[2] | 34 | ; |
---|
[142] | 35 | ; @keyword MONTHS |
---|
| 36 | ; The names of the months, a twelve element string array. |
---|
| 37 | ; If omitted, use Jan, Feb, ..., Dec. |
---|
[2] | 38 | ; |
---|
[142] | 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. |
---|
[2] | 45 | ; |
---|
[142] | 46 | ; @uses |
---|
[2] | 47 | ; |
---|
[142] | 48 | ; @restrictions |
---|
| 49 | ; Only one date axis may be simultaneously active. |
---|
[2] | 50 | ; |
---|
[142] | 51 | ; @examples |
---|
[369] | 52 | ; |
---|
[142] | 53 | ; For example, to plot from Jan 1, 1993, to July 12, 1994: |
---|
[369] | 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 | ; |
---|
[2] | 64 | ; Example with times: |
---|
| 65 | ; |
---|
[369] | 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 | ; |
---|
[142] | 81 | ; @history |
---|
[369] | 82 | ; DMS, RSI. April, 1993. Written. |
---|
| 83 | ; DMS, RSI. March, 1997. Added Time format. |
---|
[142] | 84 | ; |
---|
| 85 | ; Copyright (c) 1993-1998, Research Systems, Inc. All rights reserved. |
---|
[369] | 86 | ; Unauthorized reproduction prohibited. |
---|
[142] | 87 | ; |
---|
| 88 | ; @version |
---|
| 89 | ; $Id$ |
---|
| 90 | ; |
---|
[2] | 91 | ;- |
---|
[327] | 92 | FUNCTION label_date, axis, index, x, DATE_FORMAT=format, MONTHS=months $ |
---|
| 93 | , OFFSET=offs, _EXTRA=ex |
---|
[114] | 94 | ; |
---|
| 95 | compile_opt idl2, strictarrsubs |
---|
| 96 | ; |
---|
[2] | 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 |
---|
[369] | 124 | case c of ;format character? |
---|
[2] | 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 |
---|