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

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

   	real aa(n,29)
	integer areax(4),areay(4)
	integer ia(n)
	logical logi
c        data areax/2250,6390,2250,6390/
c        data areay/2140,2140,6060,6060/
        mm=400
        m1=(8640*0.5+mm)/2
        m2=(8200*0.5+mm)/2
        areax(1)=m1
        areax(2)=8640-m1              ! =(8640*1.5-mm)/2
        areax(3)=areax(1)
        areax(4)=areax(2)
        areay(1)=m2
        areay(2)=areay(1)
        areay(3)=8200-m2
        areay(4)=areay(3)
    
        if(iargc().lt.1)then
        write(*,*)
        write(*,*)
        write(*,*)'     ***** divied 4 overlap file (2010.10)) ****'
	write(*,*)'                all stars < 190,000'
        write(*,*)'                    overlap ~800 lines'
        write(*,*)'                small block 4720*4500'
        write(*,*)'     Usage:  u_1to4 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
        ipos=indexpos(head,'NAXIS2  ')
        read(head(ipos)(26:),'(i5)')n2
        close(1)
	if(n1.ne.8640.or.n2.ne.8200)stop 'only deal with our_bok ccd'
        write(*,*)(areax(i),i=1,4)
        write(*,*)(areay(i),i=1,4)
	
         
        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,4
	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)-m1
	jx2=areax(l)+m1
	jy1=areay(l)-m2
	jy2=areay(l)+m2
        kk=0  
        do 30 i=1,m
	ix=nint(aa(i,1))             ! 4096
	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
        kk=kk+1
        write(1,320)ia(i),(aa(i,j),j=1,29)
30	continue
	write(*,'(5i5,2x,a,i6)')l,jx1,jx2,jy1,jy2,f3(1:k+3),kk
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
