if (n_elements(sdl) eq 0) then begin
    yesnox, 'Do you wish to restore the save file?', ans, 'yes'
    if (ans) then restore, '/usr/people/morrison/temp/dark_paper.idl'
end

if (n_elements(sdl) eq 0) then begin
    infil_sdc = file_list('$DIR_SXT_SDC', 'sdc*')
    infil_sdl = file_list('$DIR_SXT_SDL', 'sdl*')
    rd_roadmap, infil_sdc, rmap_sdc
    rd_roadmap, infil_sdl, rmap_sdl
    ;
    timarr = int2secarr(rmap_sdc, '11-JUN-92  08:09:08')
    dset_sdc = where((gt_res(rmap_sdc) eq 1) and (gt_dpe(rmap_sdc) eq 23) and (abs(timarr) gt 60) )	;avoid 11-jun-92 point
    dset_sdl = tim2dset(rmap_sdl, rmap_sdc(dset_sdc), off=off)
    ;
    rd_xda, infil_sdl, dset_sdl, lindex, sdl	;85 images

    get_sdl_info, lindex, sdl, timg_avg, timg_dev
end
;
n = n_elements(lindex)
val = sdl.int
loc = sdl.x + sdl.y*512L			;128 locations x 85 images = 10880 total positions
uloc = loc(uniq(loc, sort(loc)))		;but 1011 uniq positions
nn = n_elements(uloc)
;
if (n_elements(map) eq 0) then begin
    map = bytarr(nn, n)				;1011 positions x 85 images
    for i=0,n-1 do begin
	rd_xda, infil_sdc, dset_sdc(i), index, data, rmap
	print, 'Read ', fmt_tim(index), i+1, ' of ', n, int2secarr(index, lindex(i))
	map(*,i) = data(uloc)
    end
    max_arr = bytarr(nn)			;find the maximum through all 85 images for each position
    tspike_avg = intarr(n)
    for i=0,n-1 do tspike_avg(i) = total(sxt_decomp(map(*,i)))/nn
    for i=0,nn-1 do max_arr(i) = max(map(i,*))	
end
;
!p.multi = [0,1,2]
utplot, lindex, timg_avg, psym=2, tit='Whole Image Average', /year, /ynozer
utplot, lindex, tspike_avg, psym=2, tit='1000 Top Spike Intensity Average', /year, /ynozero
!p.multi = 0
pause
;
plot, uloc mod 512, uloc/512, psym=1, tit='Location of top 1000 spikes'
pause
;
!p.charsize = 1.6
!p.multi=[0,2,3]
ss = reverse(sort(max_arr))
for ii=0,(n_elements(uloc)<(6*10))-1 do begin
    i = ss(ii)
    pos = string(uloc(i) mod 512, uloc(i)/512, format='(i3,",",i3)')
    utplot, lindex, sxt_decomp(map(i,*)), psym=10, tit='Position: '+pos, /year
    if ((ii mod 6) eq 5) then pause
end
!p.charsize = 0


;for i=0,n_elements(uloc)-1 do begin
;    ss = where(loc eq uloc(i), count)
;    if (count ge 3) then begin
;	x = lindex(ss/128)
;	y = val(ss)
;	pos = string(uloc(i) mod 512, uloc(i)/512, format='(i3,",",i3)')
;	utplot, x, y, psym=2, tit='Position: '+pos
;    end
;end
;
end
