;+
; Project     :	SOLAR-B - EIS
;
; Name        :	EIS_CPT_CHECK_CAM_READOUT_PARAMETERS
;
; Purpose     :	Checks the CAM readout parameters are valid.
;
; Explanation : Checks :
;                 - on chip binnng
;                 - CSG flush ID
;                 - CSG readut IDs
;                 - CCD readout nodes
;                 - CCD length
;                 - flush CCDs
;                 - CSG ID 4 addresses
;
; Use         :	< result = eis_cpt_check_cam_readout_parameters ( cam_readout_parameters) >
;
; Inputs      : cam_readout_parameters : STRUCTURE of type EIS_CAM_readout.
;
; 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 22/06/05
;
; Modified    :	Version 0.0, 22/06/05, MKC
;
; Version     :	Version 0.0, 22/06/05
;-
;**********************************************************

FUNCTION eis_cpt_check_cam_readout_parameters, CAM_readout_parameters

  ; On_Chip_Binning[2]: X and Y flags. OCB will not be used so fixed at [1,1].

  IF CAM_readout_parameters.On_Chip_Binning[0] NE 1 OR $
     CAM_readout_parameters.On_Chip_Binning[1] NE 1 THEN BEGIN

    eis_cpt_message, 'INVALID CAM READOUT ON CHIP BINNING SCHEME'

    GOTO, error

  ENDIF

  ; check CAM CSG Flush Sequence ID

  IF CAM_readout_parameters.CAM_CSG_flush_sequence_ID GT 5 THEN BEGIN

    eis_cpt_message, 'INVALID CAM CSG FLUSH SEQ ID'

    GOTO, error

  ENDIF

  ; check CAM CSG NORMAL R/O sequence ID

  IF CAM_readout_parameters.CAM_CSG_normal_readout_sequence_ID GT 5 THEN BEGIN

    eis_cpt_message, 'INVALID CAM CSG NORMAL R/O SEQ ID'

    GOTO, error

  ENDIF

  ; check CAM CSG SPECIAL R/O sequence ID

  IF CAM_readout_parameters.CAM_CSG_special_readout_sequence_ID GT 5 THEN BEGIN

    eis_cpt_message, 'INVALID CAM CSG SPECIAL R/O SEQ ID'

    GOTO, error

  ENDIF

  ; permissible readouts are :-
  ;   Both left and right of both ccds
  ;   Left only for both ccds
  ;   Right only for both ccds
  ;   Left of 1 ccd, right of the other (and vice versa of course)
  ; (So left and right of 1 ccd and left or right of the other is not allowed.)
  ; presumably can also disable both nodes for a CCD ?

  IF TOTAL(CAM_readout_parameters.Readout_nodes) EQ 3 THEN BEGIN

    eis_cpt_message, 'INVALID CAM READOUT NODES ENABLED'

    GOTO, error

  ENDIF

  ; CCD_length               : INT CCD readout register length. Only changes if
  ;                            OCB used so fixed at 2148.

  IF CAM_readout_parameters.CCD_length NE 2148 THEN BEGIN

    eis_cpt_message, 'INVALID CAM CCD LENGTH'

    GOTO, error

  ENDIF

  ; flush_CCDs               : INT number of times to flush CCDs before each exposure, range 0-255.

  IF CAM_readout_parameters.flush_CCDs GT 255 THEN BEGIN

    eis_cpt_message, 'INVALID CAM NUMBER OF TIMES TO FLUSH CCD'

    GOTO, error

  ENDIF

  ; CSG ID 4 addresses

  IF CAM_readout_parameters.addresses[0] NE '04002D00'XL OR $
     CAM_readout_parameters.addresses[1] NE '04000C00'XL OR $
     CAM_readout_parameters.addresses[2] NE '04010700'XL OR $
     CAM_readout_parameters.addresses[3] NE '04001400'XL THEN BEGIN

    eis_cpt_message, 'INVALID CSG ID 4 ADDRESSES'

    GOTO, error

  ENDIF

  ; return OK flag

  RETURN, 1

error :

  ; issue routine name

  MESSAGE, 'ERROR', /INFORMATIONAL

  ; return error flag

  RETURN, 0

END





