;+
; Project     : SOLAR-B - EIS
;
; Name        : EIS_CPT_CHECK_CONTACTS
;
; Purpose     : Checks contacts.
;
; Explanation : Checks contacts.
;
; Use         : < result = eis_cpt_check_contacts ( orl, contact_info) >
;
; Inputs      : orl                 : OBJECT of class structure EIS_CPT_orl
;               contact_info        : STRUCTURE containing contact period info.
;
; Opt. Inputs : None.
;
; Outputs     : result   : status flag
;                       0 : if checks failed.
;                       1 : checks OK.
;
; Opt. Outputs: None.
;
; Keywords    : None.
;
; Calls       : None.
;
; Common      : None.
;
; Restrictions: None.
;
; Side effects: None.
;
; Category    : EIS_CPT.
;
; Prev. Hist. : None.
;
; Written     : Martin Carter RAL 10/05/07
;
; Modified    : Version 0.1, 27/02/08, MKC
;                 Allow real sequence time of -1 to bypass check.
;               Version 0.2, 07/07/08, MKC
;                 Allow no contact periods to proceed without warning message.
;               Version 0.3, 08/06/11, MKC
;                 Fixed bug : used KEYWORD_SET(list) to check if empty.
;                 If list =[0] then check does not work in later versions of IDL.
;                 BLOCK was first element which had time -1 so no effect until changed to -2 when
;                 using revised plan.
;
; Version     : 0.3, 08/06/11
;-
;**********************************************************

FUNCTION eis_cpt_check_contacts, orl, contact_info

  ; check contact periods defined

  IF KEYWORD_SET(contact_info) THEN BEGIN

    ; get number of REAL and seqexec ORL sequences

    real_number = orl->getNumber(/REAL)

    seqexec_number = orl->getNumber(/SEQEXEC)

    IF real_number GT 0 AND seqexec_number GT 0 THEN BEGIN

      ; get names of REAL sequences

      real_names = orl->getNames(/REAL)

      ; get names of SEQEXEC sequences

      seqexec_names = orl->getNames(/SEQEXEC)

      ; get times of SEQEXEC sequences

      seqexec_times = orl->getTimes(/SEQEXEC)

      ; check whether each SEQEXEC sequence is a REAL sequence

      FOR k = 0, seqexec_number-1 DO BEGIN

        dummy = WHERE(real_names EQ seqexec_names[k], count)

        IF count EQ 1 THEN BEGIN

          ; add to list to check unless time is -1

          IF seqexec_times[k] NE -1 THEN eis_cpt_add, list, k

        ENDIF

      ENDFOR

      ; check if any REAL sequences in SEQEXEC sequences

      IF N_ELEMENTS(list) GT 0 THEN BEGIN

        ; check times  of REAL ORL commands during contact passes

        IF NOT eis_cpt_check_interval(seqexec_times[list], contact_info.contact.start_time, contact_info.contact.stop_time, INDEX=index) THEN BEGIN

          eis_cpt_message, 'ERROR, REAL SEQUENCE NOT STARTED DURING A CONTACT PASS : '+seqexec_names[list[index]], /INFORMATIONAL

          GOTO, error

        ENDIF

      ENDIF

    ENDIF

  ENDIF

  ; return OK flag

  RETURN, 1

error :

  ; issue routine name

  MESSAGE, 'ERROR', /INFORMATIONAL

  ; return error flag

  RETURN, 0

END





