Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]

LABEL_DATE


Syntax | Return Value | Arguments | Keywords | Examples | Version History | See Also

The LABEL_DATE function can be used, in conjunction with the [XYZ]TICKFORMAT keyword to IDL plotting routines, to easily label axes with dates and times.

This routine is written in the IDL language. Its source code can be found in the file label_date.pro in the lib subdirectory of the IDL distribution.

Syntax

Result = LABEL_DATE( [DATE_FORMAT=string/string array]
[, AM_PM=2-element vector of strings]
[, DAYS_OF_WEEK=7-element vector of strings]
[, MONTHS=12-element vector of strings] [, OFFSET=value] [, /ROUND_UP] )

and then,

PLOT, x, y, XTICKFORMAT = 'LABEL_DATE'

Return Value

Returns a date formatting definition.

Arguments

If LABEL_DATE is being called to initialize string formats, it should be called with no arguments and the DATE_FORMAT keyword should be set.

Keywords

Note
The settings for LABEL_DATE remain in effect for all subsequent calls to LABEL_DATE. To restore any default settings, call LABEL_DATE again with the appropriate keyword set to either a null string ('') or to 0, depending upon the data type of that keyword.

AM_PM

Set this keyword to a two-element string array that contains the names to be used with '%A'. The default is ['am','pm'].

DATE_FORMAT

Set this keyword to a format string or array of format strings. Each string corresponds to an axis level as provided by the [XYZ]TICKUNITS keyword to the plotting routine. If there are fewer strings than axis levels, then the strings are cyclically repeated. A string can contain any of the following codes:

Code
Description
%M
Month name.
%N
Month number (2 digits).
%D
Day of month (2 digits).
%Y
Year (4 digits, or 5 digits for negative years).
%Z
Last 2 digits of the year.
%W
Day of the week.
%A
AM or PM (%H is then 12-hour instead of 24-hour).
%H
Hours (2 digits).
%I
Minutes (2 digits).
%S
Seconds (2 digits), followed optionally by %n where n is an integer 0-9 representing the number of digits after the decimal point for seconds; the default is no decimal places.
%%
Represents the % character.

Other items you can include can consist of:

If DATE_FORMAT is not specified then the default is the standard 24-character system format, '%W %M %D %H:%I:%S %Y'.

The following table contains some examples of DATE_FORMAT strings and the resulting output:

DATE_FORMAT String
Example Result
'%D/%N/%Y'
11/12/1993
'%M!C%Y'
Note - !C is the code for a newline character.
Dec
1993
'%H:%I:%S'
21:33:58
'%H:%I:%S%3'
21:33:58.125
'%W, %M %D, %H %A'
Sat, Jan 01, 9 pm
'%S seconds'
60 seconds

DAYS_OF_WEEK

Set this keyword to a seven-element string array that contains the names to be used with '%W'. The default is the three-letter English abbreviations, ['Sun, 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'].

MONTHS

Set this keyword to a twelve-element string array that contains the names to be used with '%M'. The default is the three-letter English abbreviations, ['Jan', 'Feb',..., 'Dec'].

OFFSET

Set this keyword to a value representing the offset to be added to each tick value before conversion to a label. This keyword is usually used when your axis values are measured relative to a certain starting time. In this case, OFFSET should be set to the Julian date of the starting time.

ROUND_UP

Set this keyword to force times to be rounded up to the smallest time unit that is present in the DATE_FORMAT string. The default is for times to be truncated to the smallest time unit.

Examples

This example creates a sample plot that has a date axis from Jan 1 to June 30, 2000:

; Create format strings for a two-level axis: 
dummy = LABEL_DATE(DATE_FORMAT=['%D-%M','%Y']) 
 
;Generate the Date/Time data 
time = TIMEGEN(START=JULDAY(1,1,2000), FINAL=JULDAY(6,30,2000)) 
 
;Generate the Y-axis data 
data = RANDOMN(seed, N_ELEMENTS(time)) 
 
;Plot the data 
PLOT, time, data, XTICKUNITS = ['Time', 'Time'], $ 
   XTICKFORMAT='LABEL_DATE', XSTYLE=1, XTICKS=6, YMARGIN=[6,2] 

For more examples, see [XYZ]TICKFORMAT.

Version History

Introduced: Pre 4.0

See Also

[XYZ]TICKFORMAT, CALDAT, JULDAY, SYSTIME, TIMEGEN, Format Codes


Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]