pro mk_sdp, infil, outdir, run_time=run_time, append=append
;
;+
;NAME:
;       mk_sdp
;PURPOSE:
;       Given a set of PFI files, read the roadmaps and save the 
;	dark images into a weekly file
;INPUT:
;       infil   - an array of input file names
;       outdir  - the output directory where the file should be written
;		  It uses $DIR_SXT_SDP by default.
;HISTORY:
;       Written 3-Aug-94 by M.Morrison
;-

if (n_elements(outdir) eq 0) then outdir = getenv('DIR_SXT_SDP')
;
progverno=1.00
start_time = systime(1)
run_time = 0.
prefix = 'sdp'

if (infil(0) eq '') then return			;no SFR files

rd_roadmap, infil, roadmap, filidx=filidx

aspect = mask(roadmap.periph, 7, 1)
ss=where( (gt_expmode(roadmap) eq 1) and (roadmap.percentd eq 255))
if (ss(0) eq -1) then return	;no matches
;
n = n_elements(ss)
ds=mk_dset_str(filidx,ss)

;append = keyword_set(append)
;rd_sda, infil, ds, index, data		;can't do single read since sometimes there is a lot of data
;tim2orbit, index(0), wid=wid
;wid = wid + 'a.' + string(fix(progverno), format='(i2.2)')
;filename = concat_dir(outdir, prefix+wid)
;if (not append) then file_delete, filename
;sav_sda, filename, index, data, append=append

append = keyword_set(append)
for i=0,n-1 do begin
	rd_sda,infil(ds(i).ifil),ds(i).dset,index1,data1	

	print,i,' ',fmt_tim(index1)

	if (i eq 0) then begin
	    tim2orbit, index1, wid=wid
	    wid = wid + 'a.' + string(fix(progverno), format='(i2.2)')
	    filename = concat_dir(outdir, prefix+wid)
	    file_delete, filename
	end

	sav_sda,filename,index1,data1,append=append
	append = 1
end
	
end_time = systime(1)
run_time = (end_time-start_time)/60.
end

