;+
; PROJECT
;          SolarB EIS
;
; NAME
;          db_save_response_entry_update
;
; PURPOSE
;          Function to update an entry in the EIS response databse
;
; CATEGORY
;          EIS Technical Planning
;          Database
;
; INPUTS
;          a response structure 'struct'
;
; OPTIONAL INPUTS
;          the top-level-base; useful if calling from a widget tool
;
; WRITTEN
;          John A Rainnie RAL 20-Jan-2010
;
; MODIFICATION HISTORY
;           v0.1 JAR 07-Jun-2010
;                Added new repointing tags for raster 1 and 2
;           v0.2 JAR 19-Jan-2012
;                Commented out line where "CREATED" tag is updated.
;                This is to be ste once when the entry is created!
;
;-
;______________________________________________________________________________
PRO db_save_response_entry_update , struct , tlbID = tlbID

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

status = eis_open_db(/RESPONSE,/UPDATE)

; OK, need to get the response DB entry ID value, from seq_id
; Just to make sure, also use TYPE
seq_id_value = STRCOMPRESS(struct.trig_st_seqid,/REMOVE_ALL)
constraint_1 = STRJOIN(['TRIG_ST_SEQID',seq_id_value],'=',/SINGLE)
constraint_2 = STRJOIN(['TYPE',STRTRIM(struct.type,2)],'=',/SINGLE)
constraint   = STRJOIN([constraint_1,constraint_2],',',/SINGLE)
; Get corresponding ID
blah         = dbfind(constraint , /SILENT , count = count)
IF (count NE 1) THEN stop
struct.id    = blah[0]
; Update modified time
struct.modified = anytim2tai(systim())

;status = eis_open_db(/RESPONSE,/UPDATE)
;stop
dbput, 'ID'             , struct.id                , struct.id
dbput, 'TRIG_ST_SEQID'  , struct.trig_st_seqid     , struct.id
dbput, 'EEBP_RESPOND'   , struct.eebp_respond      , struct.id
dbput, 'XRTF_RESPOND'   , struct.xrtf_respond      , struct.id
dbput, 'EISF_RESPOND'   , struct.eisf_respond      , struct.id
dbput, 'AECE_RESPOND'   , struct.aece_respond      , struct.id
dbput, 'X_THRESHOLD'    , struct.x_threshold       , struct.id
dbput, 'Y_THRESHOLD'    , struct.y_threshold       , struct.id
dbput, 'X_MIN_LIMIT'    , struct.x_min_limit       , struct.id
dbput, 'Y_MIN_LIMIT'    , struct.y_min_limit       , struct.id
dbput, 'ADJUST_X'       , struct.adjust_x          , struct.id
dbput, 'ADJUST_Y'       , struct.adjust_y          , struct.id
dbput, 'LOCATE_X'       , struct.locate_x          , struct.id
dbput, 'LOCATE_Y'       , struct.locate_y          , struct.id
dbput, 'RESPONSE_ST_ID' , struct.response_st_id    , struct.id
dbput, 'RESPONSE_RA_ID' , struct.raster_identifier , struct.id
dbput, 'LINE_INDEX'     , struct.line_index        , struct.id
dbput, 'FILLER_ST_ID'   , struct.filler_st_id      , struct.id
dbput, 'TYPE'           , struct.type              , struct.id
;dbput, 'CREATED'        , struct.created           , struct.id
dbput, 'MODIFIED'       , struct.modified          , struct.id
; New tags here
dbput, 'NO_HUNT_DATA'   , struct.no_hunt_data      , struct.id
dbput, 'RA1_XCEN'       , struct.ra1_xcen          , struct.id
dbput, 'RA1_YCEN'       , struct.ra1_ycen          , struct.id
dbput, 'RA1_MIP'        , struct.ra1_mip           , struct.id
dbput, 'RA1_YIP'        , struct.ra1_yip           , struct.id
dbput, 'RA1_SC_X'       , struct.ra1_sc_x          , struct.id
dbput, 'RA1_SC_Y'       , struct.ra1_sc_y          , struct.id
dbput, 'RA1_POINTED'    , struct.ra1_pointed       , struct.id
dbput, 'RA2_USE'        , struct.ra2_use           , struct.id
dbput, 'RA2_XCEN'       , struct.ra2_xcen          , struct.id
dbput, 'RA2_YCEN'       , struct.ra2_ycen          , struct.id
dbput, 'RA2_MIP'        , struct.ra2_mip           , struct.id
dbput, 'RA2_YIP'        , struct.ra2_yip           , struct.id
dbput, 'RA2_SC_X'       , struct.ra2_sc_x          , struct.id
dbput, 'RA2_SC_Y'       , struct.ra2_sc_y          , struct.id
; Finish new tags         

dbclose

; Report successful outcome
; ID needs to be in 000001 format
idValue = STRING(format='(I06)' , struct.id)
messageText = ["Response Study has been successfully updated!"        ,     $
               ""                                                    ,     $
               "ID          = " + idValue]
; If a tlbID is given, then display a pop-up box
IF (N_ELEMENTS(tlbID) EQ 1) THEN BEGIN
   inform = DIALOG_MESSAGE( messageText                              ,     $
                            DIALOG_PARENT = tlbID                    ,     $
                            /INFORMATION )
ENDIF ELSE BEGIN
    print,messageText
ENDELSE



END
