;+
; Project     :	SOLAR-B - EIS
;
; Name        :	EIS_CPT_HEX_RASTER
;
; Purpose     :	Processes science raster to hex values.
;
; Explanation : This routine processes a raster into Intel Hex format.
;               It first of all performs some checks on the raster parameters.
;               If special CAM hardware window required then sets the Y parameters for this.
;               Then adds the run raster command with its parameters.
;               Then adds the exposure loop commands.
;
;               NB The position of the raster within the sequence is not yet determined
;               because it may overflow the sequence table and require a new table to be started.
;               The loop back command takes an absolute position. This will require updating once
;               the absolute position is determined. The loop back location is the last element of hex.
;               The value on output is relative to the start of hex.
;
; Use         :	< hex = eis_cpt_hex_raster ( engineering_parameters, raster_details, linelist ) >
;
; Inputs      :	engineering_parameters  : STRUCTURE of type EIS_engineering_parameters.
;               raster_detail           : STRUCTURE of type EIS_raster_detail.
;               linelist                : INT linelist table index.
;
; Opt. Inputs : None.
;
; Outputs     : hex   : BYTARR[] command byte values.
;
; 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 29/11/04
;
; Modified    :	Version 0.0, 29/11/04, MKC
;               Version 0.1, 21/01/05, MKC
;                 Removed coarse mirror command.
;               Version 0.2, 02/03/05, MKC
;                 Added loop back command and sequence_position argument.
;               Version 0.3, 12/04/05, MKC
;                 Added special hardware window.
;               Version 0.4, 12/05/05, MKC
;                 Removed sequence position argument.
;               Version 0.5, 04/07/05, MKC
;                 Changed raster_number and number of rasters arguments to raster_id.
;                 Added current slit slot argument.
;               Version 0.6, 12/01/07, MKC
;                 Added exposure delays.
;                 Removed number of exposures per raster position tag from raster detail.
;                 Moved slit/slot movement out of routine.
;                 Moved raster check out of routine.
;                 Removed error code.
;               Version 0.7, 17/04/07, MKC
;                 Moved special window commands to separate routine.
;                 Removed raster id argument.
;
; Version     : 0.7, 17/04/07
;-
;**********************************************************

FUNCTION eis_cpt_hex_raster, engineering_parameters, raster_detail, linelist

  ; add raster command

  eis_cpt_add, hex, eis_cpt_run_raster(engineering_parameters, raster_detail, linelist)

  ; get position of start of exposure loop within hex

  loop_back_position = N_ELEMENTS(hex)

  ; add exposure commands

  FOR e = 0, N_ELEMENTS(raster_detail.exposure_times)-1  DO BEGIN

    ; NB exposure_times are in [ms] units, start_exp command takes [10ms] únits

    IF raster_detail.exposure_times[e] NE 0 THEN eis_cpt_add, hex, eis_cpt_start_exp( raster_detail.exposure_times[e]/10 )

    ; if delay non-zero then add wait command

    IF raster_detail.exposure_delays[e] NE 0 THEN eis_cpt_add, hex, eis_cpt_seq_wait(raster_detail.exposure_delays[e])

  ENDFOR

  ; add loop back command to beginning of exposure loop

  eis_cpt_add, hex, eis_cpt_loop_back(loop_back_position)

  ; return command byte values

  RETURN, hex

END





