	parameter (n=90000)	   ! n= *.ap star number

	character*69 f1,f2,f3,c1,c2
	character*80 head(36)

   	real aa(n,29)
	integer areax(9),areay(9)
	integer ia(n)
	logical logi

        if(iargc().lt.1)then
        write(*,*)
        write(*,*)
        write(*,*)'     ***** divied 9 overlap file (2006.4) ****'
        write(*,*)'                    overlap 200 lines'
        write(*,*)
        write(*,*)'     Usage:  j_1to94k file.ap'
        write(*,*)
        write(*,*)
        stop
        endif
        call getarg(1,f1)
        k=index(f1,'.')
        if(k.eq.0)f1=f1(1:lnblnk(f1))//'.fit'
        inquire(file=f1,exist=logi)
        if(.not.logi)stop '.fit file not found !'
 
        open(1,file=f1,status='old',access='direct',recl=2880)
        read(1,rec=1)head
        ipos=indexpos(head,'NAXIS1  ')
        read(head(ipos)(26:),'(i5)')n1
        read(head(ipos)(65:74),'(2i5)')ix1,ix2
        ipos=indexpos(head,'NAXIS2  ')
        read(head(ipos)(26:),'(i5)')n2
        read(head(ipos)(65:74),'(2i5)')iy1,iy2
        close(1)
	if(ix2.eq.0)then
	  ix1=1
	  ix2=n1
	  iy1=1
	  iy2=n2
	endif
	open(1,file='1to9.tmp',status='unknown')

        j=600
	m=(ix2-ix1+1-2*j)/2	
	kx400=(200+m)/3
	areax(1)=ix1+kx400+j
	areax(2)=(ix2+ix1+1)/2
	areax(3)=ix2-kx400-j
	write(*,*)(areax(1)+areax(2))/2,(areax(2)+areax(3))/2
	write(1,*)(areax(1)+areax(2))/2,(areax(2)+areax(3))/2
	areax(4)=areax(1)
	areax(5)=areax(2)
	areax(6)=areax(3)
	areax(7)=areax(1)
	areax(8)=areax(2)
	areax(9)=areax(3)

	m=(iy2-iy1+1-2*j)/2	
	ky400=(200+m)/3
	areay(1)=iy1+ky400+j
	areay(4)=(iy2+iy1+1)/2
	areay(7)=iy2-ky400-j
	write(*,*)(areay(1)+areay(4))/2,(areay(4)+areay(7))/2
	write(1,*)(areay(1)+areay(4))/2,(areay(4)+areay(7))/2
	areay(2)=areay(1)
	areay(3)=areay(1)
	areay(5)=areay(4)
	areay(6)=areay(4)
	areay(8)=areay(7)
	areay(9)=areay(7)

	close(1)

        k=index(f1,'.')
        f2=f1(1:k)//'ap'
        inquire(file=f2,exist=logi)
        if(.not.logi)stop '.ap file not found !'

	open(1,file=f2,status='old')
	read(1,'(a)')c1
	read(1,'(a)')c2
        read(1,'(a)')i
        do 29 i=1,n
299     read(1,320,err=299,end=28)ia(i),(aa(i,j),j=1,29)
29	continue
320     FORMAT (/I6, 14F9.3/4X, F9.2, 1x,2F6.2, F8.4, 11F9.4)
C
28	m=i-1
	close(1)
	do 40 l=1,9
	f3=f2(1:k)//char(48+l)//'ap'
	open(1,file=f3,status='unknown')
	write(1,'(a)')c1
	write(1,'(a)')c2
        write(1,'(a)')
	jx1=areax(l)-kx400
	jx2=areax(l)+kx400
	jy1=areay(l)-ky400
	jy2=areay(l)+ky400
	if(jx1.lt.1024)jx1=ix1
	if(jx2.gt.3076)jx2=ix2
	if(jy1.lt.1024)jy1=iy1
	if(jy2.gt.3076)jy2=iy2

	write(*,'(5i5,2x,a)')l,jx1,jx2,jy1,jy2,f3(1:k+3)
          
        do 30 i=1,m
	ix=nint(aa(i,1))
	iy=nint(aa(i,2))
        if(ix.gt.jx2 .or. ix.lt.jx1)goto 30
        if(iy.gt.jy2 .or. iy.lt.jy1)goto 30
        write(1,320)ia(i),(aa(i,j),j=1,29)
30	continue
40	close(1)
	end

        function indexpos(head,f1)
        character*80 head(36),f1*8
        do 10 indexpos=1,36
10      if(head(indexpos)(1:8).eq.f1)return
        end
