PRO CDS_CLEAN_SPIKE, QLDS, CUTOFF=CUTOFF, BCKGRND=BCKGRND, $
	NOFILL=NOFILL, INFO=INFO
;+
; Project     : SOHO - CDS
;
; Name        : CDS_CLEAN_SPIKE
;
; Purpose     : Removes cosmic rays from QLDS data.
;
; Category    : Utility
;
; Explanation : Takes each set of window data from the QLDS and cleans it
;		with the CLEAN_SPIKE routine. If the data has not been 
;		de-biased then VDS_DEBIAS is called first. Unless the keyword 
;		NOFILL is set then the cosmic ray pixels are filled in, 
;		otherwise they are given the MISSING value.
;
;		For more details of the cleaning process and the keywords 
;		CUTOFF and BCKGRND see the CLEAN_SPIKE routine.
;
; Syntax      : CDS_CLEAN_SPIKE, QLDS, CUTOFF=CUTOFF, BCKGRND=BCKGRND, $
;			NOFILL=NOFILL, INFO=INFO
;
; Examples    : CLEAN_SPIKE, QLDS
;
;		CLEAN_SPIKE, QLDS, /NOFILL
;
; Inputs      : QLDS	- Quicklook data structure.
;
; Opt. Inputs :	CUTOFF	= Number for determining definition of spike. 
;
;		BCKGRND	= Number specifying level of background.
;
; Outputs     : None.
;
; Opt. Outputs: None.
;
; Keywords    : NOFILL	= Set this flag to flag the cosmic ray pixels as
;                         MISSING.
;
;		INFO	= If set, will give information about the number of
;			  flagged cosmic ray pixels in each set of window data.
;
; Calls       : GT_NUMWIN, GT_WINDATA, ST_WINDATA, CLEAN_SPIKE, VDS_DEBIAS
;
; Common      : None.
;
; Restrictions: The QLDS data should not be calibrated.
;
; Side effects: None.
;
; Prev. Hist. : None.
;
; Written     : P.R. Young, Cambridge University, 13 February 1996
;
; Modified    : Not yet.
;
; Version     : 1, 13 February 1996
;-
;

IF qlds.detdesc(0).units NE 'DEBIASED-ADC' THEN BEGIN
  MESSAGE,"Removing bias",/informational
  vds_debias,qlds
END

n_win=gt_numwin(qlds)
dim=gt_dimension(qlds)

fill = keyword_set(nofill) - 1b
noinfo = keyword_set(info) - 1b

FOR i=1,n_win DO BEGIN
  missing=qlds.detdesc(i-1).missing
  arr=gt_windata(qlds,i-1)
;  -----
;   If the raster consists of repeated exposures at the same slit position,
;   then the fourth dimension is classed as the X direction instead of the
;   second dimension.
;
  IF dim.ssolar_x EQ 1 THEN BEGIN
    arr_sub=reform(arr(*,0,*,*))
    arr_sub=rearrange(arr_sub,[1,3,2])
  ENDIF ELSE BEGIN
    arr_sub=arr
  ENDELSE
;
  IF keyword_set(info) THEN print,strcompress(i),'. ', $
    gt_wlabel(qlds,i-1),' --'
;
  clean_spike,arr_sub,arr_out=arr_clean,missing=missing,fill=fill,$
	cutoff=cutoff,bckgrnd=bckgrnd,noinfo=noinfo
;
  IF keyword_set(info) THEN print,''
;  -----
;   Need to reset the array back to its original form
;
  IF dim.ssolar_x EQ 1 THEN BEGIN
    arr_clean=rearrange(arr_clean,[1,3,2])
    arr(*,0,*,*)=arr_clean
  ENDIF ELSE BEGIN
    arr=arr_clean
  ENDELSE
;
  st_windata,qlds,i-1,arr
ENDFOR

END
