;+
; PROJECT
;          SolarB EIS
;
; NAME
;          eis_xrt_flare_props_same
;
; PURPOSE
;          Function which ...
;
; INPUTS
;          triggers - an array of structures
; CATEGORY
;          Timeline planning (timeline)
;
; WRITTEN
;          John Rainnie, RAL, 15-Feb-2010
;
; HISTORY
;          v0.1 JAR 25-Jun-2013
;               Changed mechanism to read parameters for each XRTF response
;               directly from the Response DB
;          v0.2 JAR 17-Dec-2013
;               Added "line_index" (which is really verify_fov) to check
;
;-
;************************************************************************
FUNCTION eis_xrt_flare_props_same , trigger_array

; Initialise triggers - which will be populated by an array of
; response DB entries
triggers = 0
FOR i = 0 , N_ELEMENTS(trigger_array) - 1 DO BEGIN

   resp_id  = trigger_array[i].resp_id
   response = db_read_response_entry(id = resp_id)

   ; Now add response DB entry to "triggers" array.
   IF (N_TAGS(triggers) EQ 0) THEN BEGIN
       ; Re-initialise the "triggers" array with the first entry
       triggers = response
   ENDIF ELSE BEGIN
       ; Concatenate new response DB entries to list
       old_triggers = triggers
       triggers     = [old_triggers , response]
   ENDELSE

ENDFOR

valid          = {valid:0B , mText:STRARR(4)}
valid.mText[0] = "There are multiple XRT Flare trigger studies"
valid.mText[1] = "which have different properties! They must all be"
valid.mText[2] = "the same since there is only one table permitted."

; Response Study ID
test = WHERE(triggers[0  ].response_st_id NE                               $
             triggers[1:*].response_st_id  , count)
IF (count NE 0) THEN BEGIN
    valid.mText[3] = "     Error is: Response Study ID."
    RETURN , valid
ENDIF
; Filler Study ID
test = WHERE(triggers[0  ].filler_st_id NE                                 $
             triggers[1:*].filler_st_id  , count)
IF (count NE 0) THEN BEGIN
    valid.mText[3] = "     Error is: Filler Study ID."
    RETURN , valid
ENDIF
; line_index (actually verify_fov)
test = WHERE(triggers[0  ].line_index NE                                     $
             triggers[1:*].line_index  , count)
IF (count NE 0) THEN BEGIN
    valid.mText[3] = "     Error is: verify_fov."
    RETURN , valid
ENDIF
; Adjust_x
test = WHERE(triggers[0  ].adjust_x NE                                     $
             triggers[1:*].adjust_x  , count)
IF (count NE 0) THEN BEGIN
    valid.mText[3] = "     Error is: Adjust_x."
    RETURN , valid
ENDIF
; Adjust_y
test = WHERE(triggers[0  ].adjust_y NE                                     $
             triggers[1:*].adjust_x  , count)
IF (count NE 0) THEN BEGIN
    valid.mText[3] = "     Error is: Adjust_y."
    RETURN , valid
ENDIF
; Repoint Raster Index
test = WHERE(triggers[0  ].raster_identifier NE                            $
             triggers[1:*].raster_identifier  , count)
IF (count NE 0) THEN BEGIN
    valid.mText[3] = "     Error is: Repoint Raster Index."
    RETURN , valid
ENDIF
; x0 (EIS-XRT Offset)
test = WHERE(triggers[0  ].locate_x NE                                     $
             triggers[1:*].locate_x  , count)
IF (count NE 0) THEN BEGIN
    valid.mText[3] = "     Error is: x0."
    RETURN , valid
ENDIF
; y0 (EIS-XRT Offset)
test = WHERE(triggers[0  ].locate_y NE                                     $
             triggers[1:*].locate_y  , count)
IF (count NE 0) THEN BEGIN
    valid.mText[3] = "     Error is: y0."
    RETURN , valid
ENDIF
; MIP
test = WHERE(triggers[0  ].ra1_mip NE                                      $
             triggers[1:*].ra1_mip  , count)
IF (count NE 0) THEN BEGIN
    valid.mText[3] = "     Error is: MIP."
    RETURN , valid
ENDIF
; YIP
test = WHERE(triggers[0  ].ra1_yip NE                                      $
             triggers[1:*].ra1_yip  , count)
IF (count NE 0) THEN BEGIN
    valid.mText[3] = "     Error is: YIP."
    RETURN , valid
ENDIF

; IF we get here, then all the parameters are identical
valid.valid = 1

RETURN , valid

END


