	character*30 f1
	real*8 a8(8),adcoef(2,3)
	character*80 head(72)
	real*8 xa,xd,xi,xn,pi,cx,cy
	k=iargc()
	if(k.eq.0)then
	  write(*,*)'               usage: ad2xy filename'
          write(*,*)'                                      06,03'
	  write(*,*)'                  epoch = 2000.0'
	  write(*,*)
	  write(*,*)'          context in file:'
	  write(*,*)'            fits_filename'
	  write(*,*)'            1 or 2049 or 513, [epoch] (iraf data, put>1)'
	  write(*,*)'            a1 d1                     (4k*4k data put 1)' 
	  write(*,*)'            a2 d2'
          write(*,*)'            ......'
	  stop
	endif
        pi=4.*datan(1d0)
        cx=pi/12.
        cy=pi/180.




	call getarg(1,f1)
	open(1,file=f1,status='old',iostat=i)
	if(i.ne.0)stop ' file not found!'
	read(1,'(a)')f1
	open(2,file=f1,status='old',access='direct',recl=5760)
	read(2,rec=1)head
	close(2)
	ipos=indexpos(head,'A81     ')
	if(ipos.eq.73)stop 'do position calibration first!'
	epoch=2000.0
	read(1,'(a)')f1
	read(f1(1:),*,end=11)ip,x
	if(x.ne.0.)epoch=x
11      do 10 i=1,8
10      read(head(ipos+i-1)(11:),*)a8(i)




	call xy2ad(a8,adcoef)
20	read(1,'(a)',end=100)f1
	if(itohd(f1,a,d,dummy).eq.0)then
          write(*,"(' ??? ',a)")f1
	  goto 20
	endif
	if(epoch.ne.2000.)then
	  x=a
	  y=d
	  call astprs(x,y,epoch,a,d,2000.)
	endif
        xa=a*cx
        xd=d*cy
        call d_standc(a8(7),a8(8),xa,xd,xi,xn)
        x=adcoef(1,1)*xi+adcoef(1,2)*xn+adcoef(1,3)
        y=adcoef(2,1)*xi+adcoef(2,2)*xn+adcoef(2,3)
	if(ip.eq.2049)then
	x=2049.-x
	y=2049.-y
	endif
	if(ip.eq.513)then
	x=513.-x
	y=513.-y
	endif
	if(epoch.eq.2000.)write(*,'(2a,2f9.2)')f1,'---> ',x,y
	if(epoch.ne.2000.)write(*,'(2a,f6.1,a,2f9.2)')f1,
     *  '[',epoch,']  ---> ',x,y
	goto 20
100	end

        function indexpos(head,f1)
        character*80 head(72),f1*8
        byte bell
        data bell/7/
        do 10 indexpos=1,72
10      if(head(indexpos)(1:8).eq.f1)return
        if(indexpos.eq.73)write(*,'(1x,a)')bell
        end

        subroutine xy2ad(x,a)
c 2 set 6 plate coef convert
        real*8 x(2,3),a(2,3),z
        z=x(1,1)*x(2,2)-x(1,2)*x(2,1)
        a(1,1)=x(2,2)/z
        a(1,2)=-x(1,2)/z
        a(1,3)=(x(1,2)*x(2,3)-x(1,3)*x(2,2))/z
        a(2,1)=-x(2,1)/z
        a(2,2)=x(1,1)/z
        a(2,3)=(x(1,3)*x(2,1)-x(1,1)*x(2,3))/z
        end

        subroutine d_standc(rc,dc,ra,de,xi,xn)
c alpha delta --------> X Y
c rc dc : center of plate
c rc dc ra de in arc
	real*8 rc,dc,ra,de,xi,xn,tmp
        sd=dsin(dc)
        cd=dcos(dc)
        td=dtan(de)
        co=dcos(ra-rc)
        tmp=sd*td+cd*co
        xi=dsin(ra-rc)/tmp
        xn=(cd*td-sd*co)/tmp
        end
