Return to Ferret FAQ
How can I create a time axis from data in a file which lists time segments as variables?
The data set looks like this: All variables are on an abstract I axis.
name title I J K L YEAR Year 1:4320 ... ... ... MONTH Month 1:4320 ... ... ... DAY Day 1:4320 ... ... ... HOUR Hour 1:4320 ... ... ... MINUTE Minute 1:4320 ... ... ... VAL Value 1:4320 ... ... ...
We want to put variable VAL on a time axis described by YEAR, MONTH, DAY, HOUR, and MINUTE.
Compute time steps from YEAR, MONTH, DAY, etc. and then use them to generate a time axis. The times must be in monotonically increasing order for this to work.
! Compute the time steps in units of days. ! DAYS1900() returns the number of days since 1900-01-01. LET day_frac = (hour + minute/60 ) / 24 LET tstep = DAYS1900(year,month,day) + day_frac ! Define a time axis, ttaxis, from variable tstep DEFINE axis/T/T0=1-jan-1900/UNIT=days ttaxis=tstep[L=1:4320] ! Define a dummy variable on the new time taxis LET dummy=t[GT=ttaxis] ! Reshape the variable val from abstract I axis to the new T axis LET new_val = RESHAPE(val,dummy)
Note that Ferret variables are represented as single precision real numbers. (Axes are represented in double precision, but we are using a variable to define the axis and that variable is single precision.) If your timestep is small, such as minutes, and your times are a century or more after 1-jan-1900, you will need to use a time origin later than 1-Jan-1900 so that the number of minutes since the origin does not exceed the precision that can be represented.
! Compute the time steps in units of minutes. LET days_2001 = DAYS1900(2001,1,1) LET day_frac = (hour + minute/60 ) / 24 LET tstep = DAYS1900(year,month,day) - days_2001 + day_frac ! Define a time axis, ttaxis, from variable tstep DEFINE axis/T/T0=1-jan-2001/UNIT=days ttaxis=tstep[L=1:4320]
Last modified: Dec 16, 2003