	implicit real*8 (a-h,o-z)
	ximc=130.192
	etamc=136.303
	call anticorrect(ximc,etamc,xi,eta)
	write(6,12) ximc,etamc,xi,eta
12	format('FINAL',4g12.6)
	stop
	end
	subroutine anticorrect(ximc,etamc,xi,eta)
	implicit real*8 (a-h,o-z)
*  ARC SECONDS TO RADIANS   
         PARAMETER (AS2R=4.8481368110953599D-6)
Cdata scale/9.4032/ 
	data scale/9.4000/
C xout is in mm
	xout=ximc
	yout=etamc
C xi and eta are in radians
	xi=xout*scale*as2r
	eta=yout*scale*as2r 
C Start with the assumption that the output is similar to the input
C xi and eta are in radians; xtest and ytest are in mm
12	call correct(xi,eta,xtest,ytest)
	write(6,*) xi,eta,xtest,ytest
	inum=inum+1
C difx is in mm
	difx=xtest-xout
	dify=ytest-yout
	write(8,13) inum,difx,dify
13	format('antiflatten:',i5,2g12.6)
	if ((abs(difx).lt. 0.00001).and.(abs(dify).lt. 0.00001)) return
C Take half the difference
C Put it back in radians:
	xi=xi-(difx/2.)*scale*as2r
	eta=eta-(dify/2.)*scale*as2r
	go to 12
	end


	subroutine correct(xi,eta,ximc,etamc)
C this program considerably simplied after our initial astrometry 3/95
C old code:
C	implicit real*8 (a-h,o-z)
C	data AA,BB,CC,DD/6.391006d0,1.249909d-4,2.576783d-5,4.136236d-7/
C	d=dsqrt(xi**2+eta**2)
C	dp=AA*d+BB*d**2+CC*d**3+DD*d**4
C Great.  Now, what are the new xi's and eta's?
C        ximc=xi*(dp/d)
C	 etamc=eta*(dp/d)
C ximc and etamc are now xi and eta in the unlikely units of "mm"
C
	implicit real*8 (a-h,o-z)
*  ARC SECONDS TO RADIANS   
      PARAMETER (AS2R=4.8481368110953599D-6)

Cdata scale/9.4032/ 
	data scale/9.4000/
C this done for Sam 8/28/95
	data c/81.0/
C Correct for pincushion distortion:
	f=1.+c*(xi**2+eta**2)
	xip=xi*f
	etap=eta*f
Cwrite(9,101) f,xip,etap
101	format('Pincushion factor=',f10.6/
     & 'Resulting in xi, eta=',2g14.6)
C Correct for plate scale
	ximc=xip/scale/as2r
	etamc=etap/scale/as2r
C OK: ximc and etamc are now eta and xi in mm along curved surface
	return
	end
