;+ 
;
; Picks up darks from the weekly files that match the inputs
;

PRO sxt_dark_sample, index, data, filter, binning, dpe, year, week1, week2, $
		 skip=skip, sdw=sdw

;
; INPUT PARAMETERS:
;	filter = number of the x-ray analysis filter (GT_FILTB), integer.
;	binning = number of the CCD binning (GT_RES), integer.
;	dpe = DPE level (GT_DPE), integer.
;	year = 2 digit year, integer.
;	week1, week2 = start and end weeks to get data, integer.
;
; OPTIONAL INPUT KEYWORDS:
;	skip = number of weeks to skip between samples. Default=0.
;	sdw - If set, gather the darks with CCD warm.  Default=sdc, CCD cold.
;
; OUTPUT parameters:
;	index = index of darks found
;	data = dark image cube
;
; RESTRICTIONS:
;	One year of darks is a lot of data.
;
; HISTORY:
;	Written  June 30, 1994  Barry LaBonte
;-

; Handle inputs
IF( KEYWORD_SET(skip) EQ 0 ) THEN step = 1 ELSE step = skip

; Get the absolute directory
IF( KEYWORD_SET(sdw) EQ 0 ) THEN str = 'SDC' ELSE str = 'SDW'
SPAWN, 'echo $DIR_SXT_' + str, path
path = path(0)

; Get name strings
syr = STRCOMPRESS( STRING(year), /REMOVE_ALL )

new = 1

FOR i=week1,week2,step DO BEGIN

	swk = STRCOMPRESS( STRING(i), /REMOVE_ALL )
	IF(i LT 10) THEN swk = '0' + swk
	filename = path + '/' + STRLOWCASE(str) + syr + '_' + swk + 'a.01'

	RD_ROADMAP, filename, rmp

	res = GT_RES(rmp)
	dp = GT_DPE(rmp)
	filtb = GT_FILTB(rmp)

	good = WHERE( filtb EQ filter AND res EQ binning AND dp EQ dpe, n)

	IF( n GT 0 ) THEN BEGIN

		RD_SDA, filename, good, ix, da

		IF( new EQ 1 ) THEN BEGIN
			index = ix
			data = da
			new = 0
		ENDIF ELSE BEGIN
			index = STR_CONCAT(index, ix)
			data = [[[TEMPORARY(data)]],[[da]]]
		ENDELSE
	ENDIF
ENDFOR

RETURN
END
