pro termlite,infil,rgn,filta,filtb,dpe,index,signals

;+
; NAME
;	termlite
; PURPOSE
;	To prepare a vector of signals in terminator images and
;	return that data and the corresponding index structures.
; PROCEDURE
;  1.  SFT files from infil are read and processed in sequence.
;  2.  A where statement is used to select images based upon parameters
;	given in rgn,filta,filtb,dpe.
;  3.  Dark sub is run on the data array.
;  4.  Total signal is computed.
;  5.  Index structures and signals are accumulated.
;  6.  When infil is complete index and signals are time-ordered and
;	duplicates are removed.
; CALLING SEQUENCE
;	termlite,infil,rgn,filta,filtb,dpe,index,signals
; INPUT
;	infil - array of SFT files to use.
;	rgn   - output of sxt_cen(roadmap(ss),/cmd) for the pointings
;		you want, select with plot_fov,roadmap,sel,ss.
;	filta, filtb - gt_filta/b numbers for the fron and back filters
;	dpe - DPE value of exposure yout want
; OUTPUT
;	index   - index structures of terminator images
;	signals  - total DN in dark-corrected terminator images
; HISTORY
;	11-May-95 Written by LWA.
;-

first = 1

for i=0,n_elements(infil)-1 do begin

   rd_roadmap,infil(i),rm
   cen=sxt_cen(rm,/cmd)
   sss=where(gt_filta(rm) eq filta and $
	gt_filtb(rm) eq filtb and $
	gt_dpe(rm) eq dpe and $
	cen(0,*) ge min(rgn(0,*)) and cen(0,*) le max(rgn(0,*)) and $
        cen(1,*) ge min(rgn(1,*)) and cen(1,*) le max(rgn(1,*)) and $
	gt_res(rm) eq 1,cnt)
   if cnt ne 0 then begin
      rd_xda,infil(i),sss,ind,data
      ss=where(gt_temp_ccd(ind) lt -10,cnt2)
      if cnt2 ne 0 then begin
         sigs=total(total(dark_sub(ind(ss),data(*,*,ss),/interpolate),1),1)
         if i eq 0 or first eq 1 then begin
            signals=sigs
            index=ind(ss)
            first=0
         endif else begin
            signals=[signals,sigs] 
            index=[index,ind(ss)]
         endelse
      endif
   endif

endfor

tt=int2secarr(index)
order=dedupe_sort(tt,/info)
index=index(order)
signals=signals(order)

end

