;+
; PROJECT
;           SolarB EIS
;
; NAME
;           EIS_FORMAT_DURATION
;
; PURPOSE    
;           Function to calculate the duration of an eis_study (milliseconds)
;
; CATEGORY
;           EIS technical planning
;
; MODIFICATION HISTORY:
;           Written, Feb 2005 - Chunkey Lepine, RAL
;       
;-
;************************************************************************
FUNCTION eis_format_duration , t , units = units

IF (KEYWORD_SET(units) NE 1) THEN units = 0

unitStrings = ['',' hours',' minutes',' seconds']
; What time units are we using. Default is index = 0 -> 00h00m00s
;                                          index = 1 -> hours
;                                          index = 2 -> minutes
;                                          index = 3 -> seconds
CASE units OF
    0:      BEGIN
                dur_string = sec2dhms(ROUND(t / 1000.))
                str = unitStrings[0]
            END
    1:      BEGIN
                dur_string = STRING(format='(F9.3)',t/1000./60./60.)
                str = unitStrings[0]
            END
    2:      BEGIN
                dur_string = STRING(format='(F9.3)',t/1000./60.)
                str = unitStrings[0]
            END
    3:      BEGIN
                dur_string = STRING(format='(I9)'  ,t/1000.)
                str = unitStrings[0]
            END
    ELSE:   stop
ENDCASE

RETURN , STRCOMPRESS(dur_string,/REMOVE_ALL) + str

END
