FUNCTION TimeArray, t, linear=linear ;+ ; NAME: ; TimeArray ; PURPOSE: ; Converts time structure to array and v.v. ; CATEGORY: ; gen/idl/toolbox/time ; CALLING SEQUENCE: ; u = TimeArray(t [,/linear]) ; INPUTS: ; t array; type: time structure array, or non-structure ; array[2,*], array[*] ; time to be converted from array to structure or v.v. ; OPTIONAL INPUT PARAMETERS: ; /linear returns scalar integer instead of 2-element integer ; OUTPUTS: ; u array; type: array[2,*] or time structure ; converted time ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, IsType, SubArray, SuperArray, TimeStandardize, TimePieces ; PROCEDURE: ; > If the input time is a structure array[*] then it is returned as an ; integer array[2,*] (with days and fract-day units) If /linear is set ; then an integer array[*] is returned in fract-day units ; ; > If an non-structure array is input then it should be an array[2,*] ; (leading dimension of 2) if /linear NOT set, or an array[1,*] if ; /linear is set. This is returned as a structure array. ; MODIFICATION HISTORY: ; JAN-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- InitVar, linear, /key CASE IsType(t, /struct) OF 0: BEGIN ; Input is NOT a structure ; Input is not a structure, so it must be an array[2,*] ; an array[*]. u = !TheTime CASE linear OF 0: BEGIN ; Input should be Array[2,*,*,...] IF size(t,/n_dim) GT 1 THEN u = replicate(u, (size(t,/dim))[1:*]) u = TimePieces(/days, u, round( SubArray(t,element=0) ) ) u = TimePieces(/unit, u, round( SubArray(t,element=1) ) ) END 1: BEGIN ; Input should be Array[*,*,...] IF size(t,/n_dim) GT 0 THEN u = replicate(!TheTime, (size(t,/dim))) u = TimePieces(/days, u, 0) u = TimePieces(/unit, u, round(t)) END ENDCASE u = TimeStandardize(u) END 1: BEGIN ; Input is a structure u = TimeStandardize(t) CASE linear OF 0: begin d = TimePieces(/days, u) u = SuperArray( TimePieces(/unit, u),2,/lead) u = SubArray(u, element=0, replace=d) END 1: u = TimePieces(/days,t)*!TimeUnits.in_day+TimePieces(/unit,t) ENDCASE END ENDCASE RETURN, u & END