;+
; PROJECT
;          SolarB EIS
;
; NAME
;          EIS_GET_TIMELINE_DETAILS
;
; PURPOSE
;          Function to extract values from the timeline database
;
; CATEGORY
;          EIS timeline planning
;
; WRITTEN
;          Chunkey Lepine, RAL - February 2005
;
; HISTORY
;          v0.1 JAR 26-Mar-2007
;               Replaced "WRITE_LOCKED" field with recursive tag
;               in tc structure.
;          v0.2 JAR 27-Mar-2008
;               Because event flags are in sc structure, then they aren't
;               initially read. So I've added the "respond_to_eis_event"
;               tag to the tc structure. Upon reading the databases, I
;               therefore need to read the sc value and set the tc value
;               to it.
;          v0.3 JAR 9-Feb-2010
;               Added other trigger types
;
;-
;************************************************************************
FUNCTION eis_get_timeline_details, index

n = N_ELEMENTS( index)
s = REPLICATE( {eis_time_component} , n )

; Create a list of items
items = STRJOIN( [ 'START_TIME'         ,                                   $
                   'STOP_TIME'          ,                                   $
                   'WRITE_LOCKED'       ,                                   $
                   'TIME_TAGGED'        ,                                   $
                   'FIVE_PC_RULE'       ,                                   $
                   'ENTRY_TYPE'         ,                                   $
                   'ACRONYM'            ,                                   $
                   'ST_ID'              ,                                   $
                   'TITLE'              ,                                   $
                   'AUTHOR'             ,                                   $
                   'CATEGORY'           ,                                   $
                   'SEQUENCE_ID'  ]     , ',' , /SINGLE)

; Call dbext to extract item values
dbext , index , items , v1  , v2  , v3  , v4 , v5 , v6 , v7 , v8 , v9 ,     $
                        v10 , v11 , v12

s[*].start_time        = v1
s[*].end_time          = v2
s[*].recursive         = v3
s[*].time_tagged       = v4
s[*].five_percent_rule = v5
s[*].entry_type        = v6
s[*].acronym           = v7
s[*].st_id             = v8
s[*].title             = v9
s[*].author            = v10
s[*].category          = v11
s[*].sequence_id       = v12
; Close database
dbclose

;
; JAR 27-Mar-2008
; Must now get value of sc.eis_event/flare entries
; and plug them into the tc structure - for each study
;
FOR i = 0, N_ELEMENTS(index) - 1 DO BEGIN

   status                    = eis_open_db(/SCIENCE)
   ; EIS_EVENT
   eis_event_array           = dbval(index[i],'EIS_EVT_RES')
   s[i].respond_to_eis_event = eis_event_array[0]
   ; EIS_FLARE
   eis_flare_array           = dbval(index[i],'EIS_FLR_RES')
   s[i].respond_to_eis_flare = eis_flare_array[0]
   ; XRT_FLARE
   xrt_flare_array           = dbval(index[i],'XRT_FLR_RES')
   s[i].respond_to_xrt_flare = xrt_flare_array[0]
   ; AEC_EVENT
   aec_event_array           = dbval(index[i],'AEC_RESPONSE')
   s[i].respond_to_aec_event = aec_event_array[0]


ENDFOR

; Just for insurance, close database
dbclose


RETURN , s

END

