;+
; Project     :	SOHO - CDS
;
; Name        :	DO_GSET_LUT_SERIES
;
; Purpose     :	Writes out GSET LUT commands to series table.
;
; Explanation :	Writes out the commands to set up a single GIS lookup table to a command table.
;               At present no script exists to block up commands to a single subsystem.
;               The commands are therefore coded as hex values.
;               Because of command/telemetry problesm with the GIS the commands are sent
;               individually at present.
;               Outputs 38 (16 if used block command) command words.
;
;               Perl script uses format required by CB5FILS i.e token list for getpar :
;
;               1) COMMAND 1 2 3 4                    # simple scc
;
;               2) SCRIPT                             # script
;                  0x1 
;                  0x2
;                  TERMINATE
;
;               NB All commands or scripts must be to macro and so begin CB5* ...
;              
; Use         : <do_gset_lut_series, lut_par>
;
; Inputs      : lut_par : BYTARR(11) giving LUT parameters for one GIS detector
;
; Opt. Inputs : None.
;
; Outputs     : Writes GIS LUT commands to series file. 
;
; Opt. Outputs:	None.
;
; Keywords    : None.
;
; Calls       :	shorthex, fileout, macro_wait, cp_get_entry.
;                
; Common      :	None.
;
; Restrictions:	None.
;
; Side effects:	None.
;
; Category    :	Command preparation.
;
; Prev. Hist. :	Created from do_gset_init.
;
; Written     :	Version 0.0, Martin Carter, RAL, 23/2/96
;
; Modified    :	Cater for IDL5.2 hex bug.  CDP, 1-6-99
;
; Version     :	Version 2, 1-Jun-99
;-
;**********************************************************

PRO do_gset_lut_series, lut_par

    ; get LUT command delay from state database

    ss = cp_get_entry ( 'GISLTDLY', [0] )

    lut_delay = ss(0).active ; millisecs

    ; set up lookup table command block

    lkp_blok = [ '7100'xl, '7200'xl, '7300'xl, '7400'xl, '7500'xl, '7600'xl, $
                 '7D00'xl, '7E00'xl, '8100'xl, '8200'xl, '8300'xl ]

    ; set lookup table

    luts = lkp_blok OR FIX(lut_par(*))

;    ; send parameters in one block

;    fileout, words=14, 'CB5SIC' + '          # tell macro to tell gis to recalculate lookup table ' + $
;              STRTRIM(STRING(FIX(lut_par(7))),2) 
;    fileout, '0x230C' + '          # IMIF header for GIS command block

;    FOR k = 0, 10 DO $
;      fileout, shorthex ( luts(k) ) + '          # CBGLP' + STRTRIM(k,1)

;    fileout, '0xC02D' + '          # CBGLRB : calculate lookup table'
;    fileout, 'TERMINATE'
;    fileout, ''

    ; send LUT parameters individually

    fileout, '# calculate lookup table for detector ' + STRTRIM(STRING(FIX(lut_par(7))),2) 
    fileout, ''

    FOR k = 0, 10 DO BEGIN

      fileout, words=3, 'CB5SIC' + '          # send parameter ' + STRTRIM(k,2) 
      fileout, '0x2301' + '          # IMIF header for GIS command block
      fileout, shorthex ( luts(k) ) + '          # CBGLP' + STRTRIM(k,1)
      fileout, 'TERMINATE'
      fileout, ''

      macro_wait, 1000 ; delay 1 second
      fileout, ''

    ENDFOR

    fileout, words=3, 'CB5SIC' + '          # send calculate LUT command to GIS' 
    fileout, '0x2301' + '          # IMIF header for GIS command block
    fileout, '0xC02D' + '          # CBGLRB : calculate lookup table'
    fileout, 'TERMINATE'
    fileout, ''

    ; wait for LUT calculation to complete

    macro_wait, lut_delay
    fileout, ''

END

