;+
; Project     : SOLAR-B - EIS
;
; Name        : EIS_CPT_PARSE_ORL_SEQEXEC
;
; Purpose     : Parses ORL seqexec command.
;
; Explanation : Parses ORL seqexec command.
;
; Use         : < result = eis_cpt_parse_orl_seqexec ( orl, study_detail, duration, decription, line ) >
;
; Inputs      : orl                     : OBJECT of class structure EIS_CPT_orl
;               study_detail            : STRUCTURE of type EIS_study_detail.
;               duration                : DOUBLE study duration in seconds.
;               description             : STRING ORL engineering study description
;               line                    : STRING text from ORL file.
;
; Opt. Inputs : None.
;
; Outputs     : result   : INT flag :
;                            1 : processed science plan OK.
;                            0 : processing failed.
;               line     : STRING unparsed text from ORL file.
;
; Opt. Outputs: None.
;
; Keywords    : None.
;
; Calls       : None.
;
; Common      : None.
;
; Restrictions: None.
;
; Side effects: May output ASCII files.
;
; Category    : EIS_CPT.
;
; Prev. Hist. : None.
;
; Written     : Martin Carter RAL 28/02/08
;                 Adapted from eis cpt parse orl line.
;
; Modified    : Version 0.0, 28/02/08, MKC
;
; Version     : 0.0, 28/02/08
;-
;**********************************************************

FUNCTION eis_cpt_parse_orl_seqexec, orl, study_detail, duration, description, line

  ; check if line is seqexec
  ; START:0000/00/00.00:00:00 { SEQ:test2_orl_command_sequence.orl_0010_0010_REAL ;}
  ; START : 1{ SEQ : 2; }3

  text = STREGEX(line,'^ *START *: *([^{]+){ *SEQ *: *([^;]+); *}(.*)',/EXTRACT,/FOLD_CASE,/SUBEXPR)

  IF text[0] NE '' THEN BEGIN

    ; extract fields

    ; check time format

    errmsg = ''

    time = eis_cpt_readtime(STRTRIM(text[1]))

    IF time EQ -1 THEN BEGIN

      eis_cpt_message, 'ERROR, ENCOUNTERED PARSING TIME : '+text[1], /INFORMATIONAL

      GOTO, error

    ENDIF

    ; check time against duration

    IF time GT duration THEN BEGIN

      eis_cpt_message, 'ERROR, OFFSET TIME GREATER THAN DURATION : '+text[1], /INFORMATIONAL

      GOTO, error

    ENDIF

    ; remove trailing blanks, convert to upper case

    seq_name = STRUPCASE(STRTRIM(text[2]))

    IF NOT eis_cpt_parse_orl_seqname(seq_name) THEN BEGIN

      eis_cpt_message, 'ERROR, INVALID SEQUENCE NAME :'+seq_name, /INFORMATIONAL

      GOTO, error

    ENDIF

    ; get remainder

    line = STRTRIM(text[3])

    ; add sequence to SEQEXEC store

    IF NOT orl->seq_add( study_detail.start_time+time, seq_name, description, /SEQEXEC) THEN GOTO, error

  ENDIF

  ; return OK

  RETURN, 1

error :

  ; issue routine name

  MESSAGE, 'ERROR', /INFORMATIONAL

  ; return error flag

  RETURN, 0

END





