function ss_pos, xarr, yarr, ipos
;
;
;
case ipos of
    0: begin & x0 = 31.4	& y0 = 31.4 & end
    1: begin & x0 = 52.0	& y0 = 31.0 & end
    2: begin & x0 = 31.1	& y0 = 11.2 & end
    3: begin & x0 = 10.9	& y0 = 31.8 & end
    4: begin & x0 = 31.3	& y0 = 51.6 & end
endcase

del = sqrt( (xarr-x0)^2 + (yarr-y0)^2 )
ss = where(del lt 2)
return, ss
end
;------------------------------------------------------------------------------
;
dir = '/md66/log/sci160k/'
ff = file_list(dir, '*.tfr', /cd, file=file)
ss = where((file ge '940316_045128_01') and (file le '940316_140726_01'))
seq = file(ss)
seq = strmid(seq, 0, strlen(seq(0))-4)
nseq = n_elements(seq)
;
if (n_elements(m1mat) eq 0) then begin
    infil = map_filnam(seq, 0, 0, item='_m1')	& infil = infil(where(file_exist(infil))) & m1mat = rfits2(infil, head=h1)
    infil = map_filnam(seq, 0, 0, item='_m2')	& infil = infil(where(file_exist(infil))) & m2mat = rfits2(infil, head=h2)
end
nx = n_elements(m1mat(*,0,0))
ny = n_elements(m1mat(0,*,0))
n = n_elements(m1mat(0,0,*))
xmat = (lindgen(nx, ny) mod nx) - nx/2
ymat = (lindgen(nx, ny) / nx ) - ny/2
rmat = sqrt(xmat^2 + ymat^2)
ss_rmat = where(rmat lt nx/2-1)
;
lasx = fltarr(n) & for i=0,n-1 do lasx(i) = sxpar(h1(*,i),'LASPOS_X')
lasy = fltarr(n) & for i=0,n-1 do lasy(i) = sxpar(h1(*,i),'LASPOS_Y')
;
case !d.name of
    'X': wdef, 0, 1024, 896
    'PS': tv2, 1024, 896, /init
endcase
;
;-------------------- plot_ted6.pro portion of the code

infil = '/mdisw/dbase/cal/summary/940316_045128_01-940316_140043_01
!p.title = infil
!p.position = [.1, .4, .9, .60]
out=rd_mmap_sum(infil)
;
iref = 0
ytit = 'Average Wavelength change (mA) using set ' + strtrim(4,2) + ' as the reference'
y1 = out.m1.avg			& for i=0,4 do begin & ss = ss_pos(lasx,lasy,i)  & y1(ss) = y1(ss) - y1(ss(iref)) & end
y2 = out.m2.avg			& for i=0,4 do begin & ss = ss_pos(lasx,lasy,i)  & y2(ss) = y2(ss) - y2(ss(iref)) & end
utplot, out, y2, ytit=ytit	& for i=0,4 do begin & ss = ss_pos(lasx,lasy,i)  & outplot, out(ss), y2(ss), psym=i+1 & end
outplot, out, y1		& for i=0,4 do begin & ss = ss_pos(lasx,lasy,i)  & outplot, out(ss), y1(ss), psym=i+1 & end
;
;--------------------------
;
for i=0,4 do begin
    ss = ss_pos(lasx, lasy, i)
    nn = n_elements(ss)
    diff1 = fltarr(nx, ny, nn-1)
    diff2 = fltarr(nx, ny, nn-1)
    for j=1,nn-1 do begin
	ii = ss(j)
	diff = m1mat(*,*,ii) - m1mat(*,*,ss(iref))
	avg = total(diff(ss_rmat))/n_elements(ss_rmat)
	diff1(*,*,j-1) = diff - avg
	tv2, bytscl(diff-avg, -5, 5), (j-1)*nx, 896-(i+1)*ny
	;
	diff = m2mat(*,*,ii) - m2mat(*,*,ss(iref))
	avg = total(diff(ss_rmat))/n_elements(ss_rmat)
	diff2(*,*,j-1) = diff - avg
	tv2, bytscl(diff-avg, -10, 10), (j-1)*nx, (4-i)*ny
    end
    ;xy_raster, dummy, diff1, /notimes, /indiv
    ;xy_raster, dummy, bytscl(diff1, -5, 5), /notimes, /noscale
end

end
