FUNCTION TimePieces, t, p, days=days, tiny=tiny, units=units, add=add ;+ ; NAME: ; TimePieces ; PURPOSE: ; Manipulate time structures ; CATEGORY: ; gen/idl/toolbox/time ; CALLING SEQUENCE: ; v = TimePieces(t, [p ,/days, /tiny, /units]) ; INPUTS: ; t array; type: time structure; default: !TheTime ; times ; p array; type: integer ; time component to be entered into 't' ; OPTIONAL INPUT PARAMETERS: ; /days return # whole days in t ; /units return fraction of day in current units ; /tiny return fractions of day in smallest permitted ; time units (as set in !TimeU.tiny) ; OUTPUTS: ; v array; type: integer ; returns a part of the input time. ; ; If /days and /tiny NOT set: ; fraction of day in current units ; (as set by !TimeUnits.in_day) ; If /day SET: ; # whole days in t ; If /tiny SET: ; fraction of day in smallest permitted units ; (as set by !TimeUnits.tiny) ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, IsType ; RESTRICTIONS: ; The assumption is made that !TimeUnits.tiny is an ; integer multiple of TimeUnits.in_day. If this is not the case ; integer truncation occurs, with probably pretty nasty side effects. ; PROCEDURE: ; As much as possible all access to the fields in the time ; structure should be channelled through this function. ; MODIFICATION HISTORY: ; JAN-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- InitVar, days , /key InitVar, tiny , /key InitVar, units, /key InitVar, add , /key n = !TimeUnits.tiny/!TimeUnits.in_day CASE IsType(p, /defined) OF 0: BEGIN CASE 1 OF days : u = t.days tiny : u = t.units*n units: u = t.units ENDCASE END 1: BEGIN u = t IF n_elements(u) EQ 1 AND size(p,/n_dim) GT 0 then u = replicate(u, size(p,/dim)) CASE add OF 0: BEGIN CASE 1 OF days : u.days = p tiny : u.units = round(double(p)/n) units: u.units = p ENDCASE END 1: BEGIN CASE 1 OF days : u.days = u.days+p tiny : u.units = u.units+round(double(p)/n) units: u.units = u.units+p ENDCASE END ENDCASE END ENDCASE RETURN, u & END