;+
; PROJECT
;           SolarB/Hinode EIS
;
; NAME
;           eis_solarb_science__define
;
; PURPOSE
;           Class definition of solarb_science object
;
; CATEGORY
;           EIS Timeline Planning
;           Database
;
; NOTE
;           1.
;
; INPUTS
;           solarb_science - string
;
; WRITTEN
;           John A Rainnie RAL 28-Jun-2013
;
; HISTORY
;           v0.1 JAR 25-Oct-2010
;                Updated to include eis_flare
;
;-
;______________________________________________________________________________
FUNCTION eis_solarb_science::Init , solarb_science

Self.solarb_science = STRCOMPRESS(solarb_science,/REMOVE_ALL)
r = Self->parse_solarb_science()

RETURN , 1

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_solarb_science::setProperty , ll = ll

IF (N_ELEMENTS(ll) GT 0) THEN Self.ll = ll

END
;______________________________________________________________________________
;
;______________________________________________________________________________
PRO eis_solarb_science::getProperty , struct = struct

struct = (*Self.struct)

END
;______________________________________________________________________________
; Cleanup
;______________________________________________________________________________
PRO eis_solarb_science::Cleanup


END
;______________________________________________________________________________
; Start here
;______________________________________________________________________________
FUNCTION eis_solarb_science::containg_type , type

; Check type is a string. Otherwise bail out
input_type = SIZE(type , /TYPE)
IF (input_type NE 7) THEN BEGIN
   print,"Input is NOT a string. Bailing out"
   RETURN , -1
ENDIF
search = WHERE((*Self.struct)[*].type EQ type , count)

RETURN , count

END
;______________________________________________________________________________
; Start here
;______________________________________________________________________________
FUNCTION eis_solarb_science::match_trig_st_seqid , type , seq_id

; Does this have an xrtf fragment? If so what is the resp_id?
got_xrtf = Self->containg_type('xrtf')
; Yes. Is there only one, and is it this one? If so nothing to do.
pos = WHERE((*Self.struct)[*].type EQ 'xrtf')
old_resp_id = (*Self.struct)[pos[0]].resp_id
; Does this response entry have the correct hunter seq_id
; Get response study_id from response DB
status = eis_open_db(/RESPONSE)
trig_st_seqid  = dbval(old_resp_id, 'TRIG_ST_SEQID')
dbclose

IF (trig_st_seqid EQ seq_id) THEN RETURN , old_resp_id

RETURN , 0

END
;______________________________________________________________________________
; Start here
;______________________________________________________________________________
FUNCTION eis_solarb_science::parse_solarb_science

text = Self.solarb_science

; 1. Get number of "," characters. Remember if no matches are found then
;    STRSPLIT returns the original string - so count will be unity.
;    So "split" will be string fragments (eg: 'xrtf:303').
;    Also count will actually be count - 1,
split_all = STRSPLIT(text, ',' , count = count , /EXTRACT)
struct = REPLICATE({split:'',type:'',resp_id:0L} , count)
FOR i = 0 , count - 1 DO BEGIN

   struct[i].split   = split_all[i]
   split             = STRSPLIT(split_all[i],':',/EXTRACT)
   struct[i].type    = STRCOMPRESS(split[0],/REMOVE_ALL)
   struct[i].resp_id = LONG(split[1])

ENDFOR

PTR_FREE , Self.struct
Self.struct = PTR_NEW(struct)

RETURN , 1

END
;______________________________________________________________________________
PRO eis_solarb_science__define
;______________________________________________________________________________

junk =  {eis_solarb_science                                            ,   $
                   solarb_science      : ''                            ,   $
                   struct              : PTR_NEW()                         $
        }

END
