;+
; PROJECT
;           SolarB EIS
;
; NAME
;           db_save_response_entry_create
;
; PURPOSE
;           Function to save an eis_line_list to the EIS line list database
;
; CATEGORY
;           EIS Technical Planning
;           Database
;
; INPUTS
;           struct - an eis_line_list structure
;
; OPTIONAL INPUTS
;           the top-level-base; useful if castructing from a widget tool
;           (eg; mk_linelist).
;
; 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
;
;-
;______________________________________________________________________________
PRO db_save_response_entry_create , 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)

; Update created and modified time
struct.created  = anytim2tai(systim())
struct.modified = anytim2tai(systim())
; Get response study type
struct.type = 'None'
IF (struct.eebp_respond EQ 1) THEN struct.type = 'EEBP'
IF (struct.xrtf_respond EQ 1) THEN struct.type = 'XRTF'
IF (struct.eisf_respond EQ 1) THEN struct.type = 'EISF'
IF (struct.aece_respond EQ 1) THEN struct.type = 'AECE'

;response_struct.no_hunt_data      = 1   ; n
;response_struct.ra1_xcen          = 1.D ; n
;response_struct.ra1_ycen          = 1.D ; n
;response_struct.ra1_mip           = 1   ; n
;response_struct.ra1_yip           = 1   ; n
;response_struct.ra1_sc_x          = 5.D ; n
;response_struct.ra1_sc_y          = 5.D ; n
;response_struct.ra1_pointed       = 1   ; n
;
;response_struct.ra2_use           = 1   ; n
;response_struct.ra2_xcen          = 2.D ; n
;response_struct.ra2_ycen          = 2.D ; n
;response_struct.ra2_mip           = 2   ; n
;response_struct.ra2_yip           = 2   ; n
;response_struct.ra2_sc_x          = 6.D ; n
;response_struct.ra2_sc_y          = 6.D ; n

dbbuild, struct.id                                                   ,     $
         struct.trig_st_seqid                                        ,     $
         struct.eebp_respond                                         ,     $
         struct.xrtf_respond                                         ,     $
         struct.eisf_respond                                         ,     $
         struct.aece_respond                                         ,     $
         struct.x_threshold                                          ,     $
         struct.y_threshold                                          ,     $
         struct.x_min_limit                                          ,     $
         struct.y_min_limit                                          ,     $
         struct.adjust_x                                             ,     $
         struct.adjust_y                                             ,     $
         struct.locate_x                                             ,     $
         struct.locate_y                                             ,     $
         struct.response_st_id                                       ,     $
         struct.raster_identifier                                    ,     $
         struct.line_index                                           ,     $
         struct.filler_st_id                                         ,     $
         struct.type                                                 ,     $
         struct.created                                              ,     $
         struct.modified                                             ,     $
; New tags here
         struct.no_hunt_data                                         ,     $
         struct.ra1_xcen                                             ,     $
         struct.ra1_ycen                                             ,     $
         struct.ra1_mip                                              ,     $
         struct.ra1_yip                                              ,     $
         struct.ra1_sc_x                                             ,     $
         struct.ra1_sc_y                                             ,     $
         struct.ra1_pointed                                          ,     $
         struct.ra2_use                                              ,     $ ;  30
         struct.ra2_xcen                                             ,     $
         struct.ra2_ycen                                             ,     $
         struct.ra2_mip                                              ,     $
         struct.ra2_yip                                              ,     $
         struct.ra2_sc_x                                             ,     $
         struct.ra2_sc_y
; 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 created"        ,     $
               ""                                                    ,     $
               "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
