;+
; PROJECT
;
;           Solar-B EIS
;
; NAME
;           EIS_REPAIR_TL_ENTRY
;
;
; PURPOSE
;
;           Procedure to repair a timeline time_component entry. This is
;           used to clean up studies that have disappeared from the
;           timeline
;
; INPUTS
;
;           seq_id - the sequence_id of the entry to be repaired
;
; OUPUTS
;           None
;
; CATEGORY
;
;           EIS Timeline Planning
;
; WRITTEN
;           John A Rainnie RAL 17-Apr-2007
;
; HISTORY
;
;           v0.1 JAR 18-Apr-2007
;               Made routine more general - requiring the user to pass
;               in a seq_id
;
;-
;************************************************************************
PRO eis_repair_tl_entry , seq_id

;replace call to astrolib
defsysv,'!DEBUG', 0
defsysv,'!TEXTUNIT', 0
defsysv,'!PRIV', 2
defsysv,'!TEXTOUT', EXIST = EXIST

status = eis_open_db(/TIME,/UPDATE)

sc     = eis_get_science_entry(seq_id)
st     = db_read_study_entry(sc.study_id)

tl             = {eis_time_component}
tl.start_time  = sc.studyRasters[0].ra_start_time
tl.end_time    = tl.start_time + (sc.duration/1000.)
tl.time_tagged = 1
tl.five_percent_rule = 1
tl.entry_type  = 'S'
tl.acronym     = STRTRIM(st.acronym ,2)
tl.title       = STRTRIM(st.title   ,2)
tl.author      = STRTRIM(st.author  ,2)
tl.category    = STRTRIM(st.category,2)
tl.st_id       = sc.study_id
tl.sequence_id = seq_id

; Need to re-open timeline database
status = eis_open_db(/TIME,/UPDATE)
dbput, 'START_TIME'   , tl.start_time        , seq_id
dbput, 'STOP_TIME'    , tl.end_time          , seq_id
dbput, 'TIME_TAGGED'  , tl.time_tagged       , seq_id
dbput, 'FIVE_PC_RULE' , tl.five_percent_rule , seq_id
dbput, 'ENTRY_TYPE'   , tl.entry_type        , seq_id
dbput, 'ACRONYM'      , tl.acronym           , seq_id
dbput, 'TITLE'        , tl.title             , seq_id
dbput, 'AUTHOR'       , tl.author            , seq_id
dbput, 'CATEGORY'     , tl.category          , seq_id
dbput, 'ST_ID'        , tl.st_id             , seq_id
dbput, 'SEQUENCE_ID'  , tl.sequence_id       , seq_id

dbindex

dbclose

END
