;+
;Project
;          Hinode/EIS
;
; Name
;          eis_xrtf_initialize
;
; Purpose
;          To initialize eis_response_props structure values
;
; Category
;          Timeline planning
;          Response Studies
;
; Written
;          John Rainnie 20-Jan-2009
;
; Version
;          v0.1 JAR 07-Aug-2012
;               Added RA1 tags.
;
;-
;______________________________________________________________________________
FUNCTION eis_xrtf_initialize , struct , seq_id , new_id = new_id

; Create empty response structure
r_struct = {eis_response_props}

IF (N_ELEMENTS(new_id) EQ 1) THEN r_struct.id = new_id

; Populate the r_struct structure
; Let's start off with the common tags
r_struct.trig_st_seqid     = seq_id
r_struct.eebp_respond      = 0
r_struct.xrtf_respond      = 1
r_struct.eisf_respond      = 0
r_struct.aece_respond      = 0
r_struct.x_threshold       = 0
r_struct.y_threshold       = 0
r_struct.x_min_limit       = 0
r_struct.y_min_limit       = 0
r_struct.adjust_x          = struct.adjust_x
r_struct.adjust_y          = struct.adjust_y
r_struct.locate_x          = struct.x0           ;
r_struct.locate_y          = struct.y0           ;
r_struct.response_st_id    = struct.response_identifier
r_struct.raster_identifier = struct.raster_identifier
r_struct.line_index        = struct.verify_fov   ; 
r_struct.filler_st_id      = struct.filler_identifier
r_struct.type              = 'XRTF'

; JAR 07-Aug-2012: Added the following tags
r_struct.ra1_xcen          = struct.ra1_xcen
r_struct.ra1_ycen          = struct.ra1_ycen
r_struct.ra1_mip           = struct.ra1_mip
r_struct.ra1_yip           = struct.ra1_yip
r_struct.ra1_sc_x          = struct.ra1_sc_x
r_struct.ra1_sc_y          = struct.ra1_sc_y


; If this is to be a new entry, then no need to check for
; existing entry
IF (N_ELEMENTS(new_id) EQ 1) THEN RETURN , r_struct

; Need to read these tags from the Response DB
; Open database
status     = eis_open_db(/RESPONSE)
; Get DB ID from seq_id tag.
id_value   = STRCOMPRESS(seq_id,/REMOVE_ALL)
constraint_1 = STRJOIN(['TRIG_ST_SEQID',id_value],'=',/SINGLE)
constraint   = STRJOIN([constraint_1,'TYPE=XRTF'],',',/single)
; Get corresponding ID
blah = dbfind(constraint , /SILENT , count = count)
; If not found, then bail out with what we already have
IF (count LE 1) THEN RETURN , r_struct
; Need to worry about case where more than one trigger is assigned
; a given TL entry (eg: an EEBP and XRTF event).
IF (count GT 1) THEN BEGIN
   ; Need to get ID associated with response type. Ho hum.
   stop
ENDIF
id   = blah[0]
; Fill in the blanks
r_struct.id           = dbval(id, 'ID'       )
r_struct.created      = dbval(id, 'CREATED'  )
r_struct.modified     = dbval(id, 'MODIFIED' )

RETURN , r_struct

END
