;+
; Project     : SOLAR-B - EIS
;
; Name        : EIS_CPT_PRELIMINARIES
;
; Purpose     : Performs preliminary tasks for eis_cpt.
;
; Explanation : Initializes things, reads OBSTBL and OBSTBL map.
;
; Use         : < result = eis_cpt_preliminaries(orl, RESET=reset, QUIET=quiet) >
;
; Inputs      : None.
;
; Opt. Inputs : None.
;
; Outputs     : result                 : INT flag :
;                                             1 : processed science plan OK.
;                                             0 : processing failed.
;               orl                    : OBJECT of class structure EIS_CPT_orl              : OBJECT of class structure EIS_CPT_command_store
;
; Opt. Outputs: None.
;
; Keywords    : RESET       : INT FLAG indicating that OBSTBL and OBSTBL map should be reset,
;               QUIET       : INT FLAG indicating that no printout to the terminal window should be produced.
;
; Calls       : None.
;
; Common      : None.
;
; Restrictions: None.
;
; Side effects: Returns to calling routine if error.
;               Resets !ERROR_STATE system variable.
;
; Category    : EIS_CPT.
;
; Prev. Hist. : None.
;
; Written     : Martin Carter RAL 06/10/04
;
; Modified    : Version 0.1, 21/01/05, MKC
;                 Added coarse_mirror_command_list to arguments.
;               Version 0.2, 03/02/05, MKC
;                 Used eis cpt obstbl.
;                 Moved obstbl to its own common block.
;               Version 0.3, 01/03/05, MKC
;                 Used EIS CPT op, dv and real
;                 Removed COMMON block.
;                 Added control_details.
;                 Changed so that does not output old version of obstbl as time stamped file.
;               Version 0.4, 18/03/05, MKC
;                 Renamed arguments.
;                 Used eis cpt command store
;               Version 0.5, 21/04/05, MKC
;                 Allowed EIS_CPT to be called without a time period defined.
;               Version 0.6, 09/05/05, MKC
;                 Added bakeout_periods.
;               Version 0.7, 19/07/05, MKC
;                 Renamed routines eis get suspension periods, eis get bakeout periods and
;                 eis get coarse mirror commands.
;                 Renamed eis get control details.
;                 Added real command sequences argument.
;               Version 0.8, 22/09/05, MKC
;                 Added ground contact periods.
;                 Added eis cpt data rate.
;                 Added time period processing to TAI.
;               Version 0.9, 03/10/05, MKC
;                 Removed restriction that control details must be set up /(even if not used).
;               Version 1.0, 14/06/06, MKC
;                 Removed use of interface routines and associated arguments.
;               Version 1.1, 14/07/06, MKC
;                 Moved time period check and time period argument argument.
;               Version 1.2, 01/05/07, MKC
;                 Added orl argument.
;                 Replaced eis cpt command store with orl object.
;               Version 1.3, 01/10/08, MKC
;                 Reset first string list.
;
; Version     : 1.3, 01/10/08
;-
;**********************************************************

FUNCTION eis_cpt_preliminaries, orl, RESET=reset, QUIET=quiet

  ; reset the !ERROR_STATE system variable

  MESSAGE, /RESET

  ; set up some EIS_CPT constants

  eis_cpt_setup_constants

  ; set quiet flag

  dummy = eis_cpt_quiet(SET=quiet)

  ; reset first string list

  dummy = eis_cpt_first(/RESET)

  ; read in current OBSTBL and copy obstbl to file

  IF NOT eis_cpt_obstbl(/GET, RESET=reset) THEN GOTO, error

  ; initialize command store

  orl = OBJ_NEW('eis_cpt_orl_class')

  IF NOT KEYWORD_SET(orl) THEN MESSAGE, 'IMPLEMENTATION ERROR'

  ; initialize data rate info

  IF NOT eis_cpt_data_rate(/RESET) THEN GOTO, error

  ; return finished OK flag

  RETURN, 1

error :

  ; issue routine name

  MESSAGE, 'ERROR', /INFORMATIONAL

  ; return error flag

  RETURN, 0

END





