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 = '$MDI_CAL_DATA'
ff = file_list(dir, '*_m1_*', /cd, file=file)
seq = strmid(file, 0, 13)
ss = where((seq ge '940316_045128') and (seq le '940316_194806'))
seq = seq(ss)
nseq = n_elements(seq)          ;should be 90
;
tit = 'SEQ: ' + seq(0) + ' - ' + seq(nseq-1)
;
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')
;
nn = 150.
nxout = nn*4
nyout = nn*5 + 50
case !d.name of
    'X': wdef, 0, nxout, nyout
    'PS': tv2, nxout, nyout, /init
endcase
;
;--------------------------
;
npair = 4
diff_pairs = intarr(2,npair)
diff_pairs(0,0) = 0	& diff_pairs(1,0) = 17
diff_pairs(0,1) = 3	& diff_pairs(1,1) = 17
diff_pairs(0,2) = 0	& diff_pairs(1,2) =  3
diff_pairs(0,3) = 10	& diff_pairs(1,3) = 17
;
for ipair=0,npair-1 do begin
    for im=0,1 do begin
	erase
	for ipos=0,4 do begin
	    ss = ss_pos(lasx, lasy, ipos)
	    i1 = ss(diff_pairs(0,ipair))
	    i2 = ss(diff_pairs(1,ipair))
	    if (im eq 0) then begin
		diff = m1mat(*,*,i2) - m1mat(*,*,i1)
		tit0 = 'M1'
	    end else begin
		diff = m2mat(*,*,i2) - m2mat(*,*,i1)
		tit0 = 'M2'
	    end
	    ;
	    imin = min(diff(ss_rmat), max=imax)
	    idev = stdev(diff(ss_rmat), iavg)
	    bimg = bytscl(diff, imin, imax)
	    tv2, rebin(bimg, 128, 128, /samp), 0, (4-ipos)*nn
	    plot, diff(*,ny/2), /xstyle, /ynozero, ytit='Line Plot', /noerase, $
			position = [nn*1.2/nxout, (4-ipos)*nn/nyout, (nn*1.2+128)/nxout, ((4-ipos)*nn+128)/nyout]
	    plot, diff(nx/2,*), /xstyle, /ynozero, ytit='Column Plot', /noerase, $
			position = [nn*1.2*2/nxout, (4-ipos)*nn/nyout, (nn*1.2*2+128)/nxout, ((4-ipos)*nn+128)/nyout]

;;	    contour, diff,            position = [nn/nxout, (4-ipos)*nn/nyout, (nn+128)/nxout, ((4-ipos)*nn+128)/nyout], $
;;			/follow,/xstyle,/ystyle, /noerase
;;	    contour, smooth(diff, 5), position = [nn*2/nxout, (4-ipos)*nn/nyout, (nn*2+128)/nxout, ((4-ipos)*nn+128)/nyout], $
;;			/follow,/xstyle,/ystyle, /noerase
	    xyouts2, nxout-65, (4-ipos+0.5)*nn, 'Pos '  + strtrim(ipos,2), /dev, orient=90, siz=2.0, align=0.5
	    xyouts2, nxout-35, (4-ipos+0.5)*nn, 'Avg: ' + strtrim(iavg,2), /dev, orient=90, siz=1.5, align=0.5
	    xyouts2, nxout-10, (4-ipos+0.5)*nn, 'Dev: ' + strtrim(idev,2), /dev, orient=90, siz=1.5, align=0.5
	end
	xyouts2, 0, nn*5+30, tit, /dev
	xyouts2, 0, nn*5+15, tit0 + '  Difference of ' + strtrim(diff_pairs(0,ipair),2) + ' and ' + strtrim(diff_pairs(1,ipair),2), /dev
	xyouts2, 0, nn*5, 'TED6D Ver 2.0  Program Run ' + !stime, /dev
	pause
    end
end
;
if (!d.name eq 'PS') then pprint
end
