Generating Date/Time Data
You can generate date/time data for data files that do not have date and time stamps. There are two steps:
Create an initial date/time structure using one of four conversion functions: STR_TO_DT, VAR_TO_DT, SEC_TO_DT, or JUL_TO_DT.
Use the DTGEN function to create a variable from the original function that contains an array of date/time structures.
The DTGEN function has the basic form:
result = DTGEN(dt_start, dimension)
Example 1
Assume that you have a file that contains seismic data collected on an hourly basis for the month of April, 1992. The file contains the seismic data, but does not have a time stamp appearing with each data entry. The file looks like:
Seismic data
1.03
2.04
1.33
4.45
.
.
.
The first data entry (1.03) was taken at 1:00 a.m on April 1, 1992. Each successive entry was taken on an hourly basis for the rest of the month. To generate date/time data for all of the hours of the month:
; Use VAR_TO_DT to create the initial date/time variable for
; April 1, 1992, 1:00 a.m.
date1 = VAR_TO_DT(92,4,1,1)
PRINT, date1
; PV-WAVE prints: { 1992 4 1 1 0 0.00000 87493.042 0}
; Generate a date/time array variable that contains a date/time
; structure for every hour in the month of April
; (24 hours * 30 days =720 hrs).
dtarray = DTGEN(date1, 720, /hour)
PRINT, dtarray
; PV-WAVE prints the following:
; { 1992 4 1 1 0 0.00000 87493.042 0}
; { 1992 4 1 2 0 0.00000 87493.083 0}
; { 1992 4 1 3 0 0.00000 87493.125 0}
; .
; .
; { 1992 5 1 0 0 0.00000 87523.000 0}
Example 2
You can also use the Compress keyword with the DTGEN function. This example creates a date/time variable that contains all of the weekdays for the month of January.
; Creates an initial date/time variable to use with the DTGEN
; function.
date1 = VAR_TO_DT(1992,1,1)
; Defines the weekend days.
CREATE_WEEKENDS, ['sat', 'sun']
; Generates a date/time variable that contains the weekdays for
; January. The Compress keyword excludes the weekend days.
dates = DTGEN(date1, 23, /Compress)
DT_PRINT, dates
; PV-WAVE prints the following:
; 01/01/1992
; 01/02/1992
; 01/03/1992
; 01/06/1992
; 01/07/1992
; .
; .
Notice that the 4th and 5th of January have been removed (compressed) from the result. These days fall on Saturday and Sunday.