; slf - change MOjob to mojob (directories renamed)
indirs = ['/0d1/yohkoh_b/mojob/sdc', '/1d1/yohkoh_b/mojob/sdc']
infils = file_list(indirs, 'sdc*')
infils = str_replace(infils, '.Z','')
nfil = n_elements(infils)
;
sat_limit = [235, 255, 255]             ; Full, half, quarter resolution
;
prstr, infils, file='check_sdm.files'
;
close, 1
openw, 1, 'check_sdm.txt'
printf, 1, 'CHECK_SDM  Ver 3.0  Run', !stime
;
for ifil=0,nfil-1 do begin
    start_time = systime(1)
    infil = infils(ifil)
    file_uncompress, infil
    ;
    rd_roadmap, infil, rmap
    help, rmap
    n = n_elements(rmap)
    if (data_type(rmap) ne 8) then n=0
    for i=0,n-1 do begin
	rd_xda, infil, i, index, data, rmap
	nx = n_elements(data(*,0))
	data = data(1:nx-2,*)		;trim off first and last column
	tim2orbit, index, tim2fms=tim2fms
	ss = where( data ge sat_limit(gt_res(index)), nsat)
	data = sxt_decomp(data)
	idev = stdev(data, iavg)
	temp = abs(data-iavg)
	ss = where( temp ge 1*idev, nover1)
	ss = where( temp ge 2*idev, nover2)
	ss = where( temp ge 3*idev, nover3)
	ss = where( temp ge 4*idev, nover4)
	;ss = where( temp ge 5*idev, nover5)
	;ss = where( temp ge 6*idev, nover6)
	fixed_v = ((gt_dpe(index)/1000*5./3*2)>1) * (2^gt_res(index))
	ss = where( data ge iavg+fixed_v*2, nover5)
	ss = where( data ge iavg+fixed_v*4, nover6)
	ival = get_sdm_val(index)
	;
	lin = total(data, 1) / n_elements(data(*,0))
	xx = findgen(n_elements(lin))
	coeff = poly_fit(xx(20:*), lin(20:*), 1)
	;
	str = string(ival, gt_day(index), gt_time(index), tim2fms, $
		gt_res(index), gt_dpe(index), fix(gt_corner(index,/y)), gt_temp_ccd(index), $
		iavg, idev, nover1, nover4, nover5, nover6, nsat, coeff, $
		ifil, $
		format='(2i5, i10, f7.2, 3i5, f7.2, 2f9.3, 5i8, f8.3, f8.5, i6)')
	print, str
	printf, 1, str
    end
    ;
    file_compress, infil
    end_time = systime(1)
    print, 'One file took:',end_time-start_time, ' seconds'
end
;
close, 1
end
