	parameter(maxstars=10000)
	dimension x1(maxstars),y1(maxstars),x2(maxstars),y2(maxstars)
	dimension inx(250)
	dimension iny(250)
	character*80 inline
	character*10 refimage,tempimage
	open(unit=4,file="tempshifts",status='new')
C
C
C
	zero=0.00
	write(6,1001)
1001	format('Input reference image name (e079): ',$)
	read(5,1002) refimage
	alast=lnblnk(refimage)
	write(4,109) refimage,zero,zero
1002	format(a10)
	open(unit=1,file=refimage(1:alast)//'.als.2',status='old')
	inum1=0
1	read(1,1100,end=5) inline
1100	format(a80)
	if(inline(1:1).eq.'#') go to 1
	read(inline,*) id,x,y
C this inline is garbage:
	read(1,1100) inline
	inum1=inum1+1
	if(inum1.gt.maxstars) go to 5
	x1(inum1)=x
	y1(inum1)=y
	go to 1
C
C
C
5	close(unit=1)
	write(6,*) inum1
	inum=1
1003	write(6,1004) 
1004	format('Input comparison image name (e077f): ',$)
	inum=inum+1
	read(5,1002) tempimage
	blast=lnblnk(tempimage)
	open(unit=2,file=tempimage(1:blast)//'.als.2',status='old')
	do 1009 i=1,250
	inx(i)=0
	iny(i)=0
1009	continue
	inum2=0
6	read(2,1100,end=7) inline
	if(inline(1:1).eq.'#') go to 6
	read(inline,*) id,x,y
	read(2,1100) inline
	inum2=inum2+1
	if(inum2.gt.maxstars) go to 7
	x2(inum2)=x
	y2(inum2)=y
	go to 6
7	close(unit=2)
	write(6,*) inum2
C Now find some matches for crying out loud....
	tol=25.
	tol2=tol**2
C assume that the positioning is at least as good as 25....
	do 100 i=1,inum1
	do 105 j=1,inum2
	dist2=(x1(i)-x2(j))**2+(y1(i)-y2(j))**2
	if(dist2.gt.tol2) go to 105
C forget it!
C but now maybe this is a possibility
	ixdist=(x1(i)-x2(j))*4. +100
	iydist=(y1(i)-y2(j))*4. +100
	if(ixdist.lt.1) ixdist=1
	if(iydist.lt.1) iydist=1
	if(ixdist.gt.200) ixdist=200
	if(iydist.gt.200) iydist=200
	inx(ixdist)=inx(ixdist)+1
	iny(iydist)=iny(iydist)+1
105	continue
100	continue
C OK, so who wins?
	bigx=-1
	bigy=-1
	do 107 i=2,199
	value=(i-100.)/4.
	if(inx(i).gt.bigx) then
	bigx=inx(i)
 	bestx=value
	ibestx=i
	end if
	if(iny(i).gt.bigy) then
	bigy=iny(i)
 	besty=value
	ibesty=i
	end if
	write(3,*) i,value,inx(i),iny(i)
107	continue
C take the centroid of a few adjacent points:
	sumx=0.
	sumxy=0.
	sumy=0.
	sumyy=0.
	do 110 ik=1,5
	indexx=ik-3+ibestx
	indexy=ik-3+ibesty
	valuex=(indexx-100.)/4.
	valuey=(indexy-100.)/4.
	sumx=sumy+inx(indexx)
	sumy=sumy+iny(indexy)
	sumxy=sumxy+valuex*inx(indexx)
	sumyy=sumyy+valuey*iny(indexy)
110	continue
	avex=sumxy/sumx
	avey=sumyy/sumy
	write(6,108) tempimage,bestx,besty,avex,avey
	write(4,109) tempimage,avex,avey
108	format(a10,1x,4f6.1)
109	format(a10,1x,2f6.1)
	if (inum.lt.5) go to 1003
	end
