;+
; NAME:    BCS_COMPARE
;                           
; PURPOSE:
;             To compare the total counts in 2 channels (chan_a & chan_b)
;             and to produce a list of files for which 
;             max_count(chan_a)  <=  N * max_count(chan_b)
;
; CALLING SEQUENCE:  
;	BCS_COMPARE,'file_name',chan_a,chan_b,factor
;
; INPUT:
;       FILENAME        Specifies the file(s) to be inspected. Do not include
;                       directories (standard data search paths used). Wild
;                       cards can be included.
;       
;       CHAN_A           First channel
;       CHAN_B           Second channel
;       FACTOR           Factor to check by
;
; OUTPUT:
;	                None                
;
; USE:          BCS_COMPARE,'filename',4,3,3        will list files for which
;                                                   SXV count is <= 3*CaXIX
;
;
; HISTORY
;	CDP     August  1992    Written
;
;-

pro  bcs_compare,raw_ff,chan_a,chan_b,factor

chan_nam = ['FeXXVI','FeXXV ','CaXIX ',' SXV  ']
;
;  set up list of files
;
ff  = file_list(data_paths(),raw_ff)
kill_list = strarr(n_elements(ff))
c1 = intarr(n_elements(ff))
c2 = intarr(n_elements(ff))
killer = 0
;
;  if there are files then...
;
if ff(0) ne '' then begin
   for i=0,n_elements(ff)-1 do begin
;
;  read them
;
      rd_roadmap,ff(i),roadmap
      if n_elements(roadmap) gt 2 then begin
;
;  avoid /zero untidiness
;
         nz = where(roadmap.dgi ne 0)
         if n_elements(nz) gt 1 then begin
;
;  to counts/sec
;
          ccnts = (roadmap(nz).total_cnts(chan_b-1)*10.)/(roadmap(nz).dgi*0.125)
          scnts = (roadmap(nz).total_cnts(chan_a-1)*10.)/(roadmap(nz).dgi*0.125)

;
;  get sensible estimate of max (copied from bcs_24hr_plot)
;
            cymax = max(ccnts)
            qy = where(ccnts ge 0.0)
            for j=0,9 do begin
               qymax = where(ccnts gt 0.5*cymax)
               if n_elements(qymax) le 2 and $
                   n_elements(qymax) lt n_elements(qy) then cymax = 0.5*cymax
            endfor
            cymax = max(ccnts(where(ccnts le 2.*cymax)))

            symax = max(scnts)
            qy = where(scnts ge 0.0)
            for j=0,9 do begin
               qymax = where(scnts gt 0.5*symax)
               if n_elements(qymax) le 2 and $
                   n_elements(qymax) lt n_elements(qy) then symax = 0.5*symax
            endfor
            symax = max(scnts(where(scnts le 2.*symax)))
;
;  duff roadmap trap
;
         endif else begin
            symax = 0
            cymax = 0
         endelse
      endif else begin
         cymax = 0
         symax = 0
      endelse
;
;  if insufficient counts then store file name
;
      if symax le factor*cymax and symax gt 0 then begin
         c1(killer) = symax
         c2(killer) = cymax
         kill_list(killer) = ff(i)
         killer = killer + 1
      endif
   endfor
endif else begin
  print,'No files found for that specification > ',raw_ff
endelse

;
;  inform of files found 
;
if killer gt 0 then begin
  print,' '
  print,'Following files satisfy the criterion:'
  print,'       File  
  print,'   #             name               ',chan_nam(chan_a-1),$
                                    '  ',chan_nam(chan_b-1)
  for i=0,killer-1 do begin
    print,i+1,'   ',kill_list(i),c1(i),c2(i),format='(i4,2a,2i8)'
  endfor
endif else begin
  print,'No files have that ratio of counts.'
endelse
end

