c PIPELINE 2             00,07,10
c 97,11,20
c 98,7,14
	character*60 f1,c*1
        logical logi

	if(iargc().lt.1)then
	  write(*,*)
	  write(*,*)'         Usage:  pip214k batc_fits_file [!]'
	  write(*,*)
	  write(*,*)'           (red_hat)              2006,3'
	  write(*,*)
	  write(*,*)'   simple of pip214k'
	  write(*,*)
	  write(*,*)'          3*3 blocks'
	  write(*,*)'     11 12 13'
	  write(*,*)'     21 22 23'
	  write(*,*)'     31 32 33'
          write(*,*)
	  write(*,*)'     if add !, j_psf4k DONOT delete any star' 
	  write(*,*)
	  stop
	endif

	call getarg(1,f1)
	c=' '
	if(iargc().gt.1)then
          call getarg(2,c)
	  if(c.ne.'!')c=' '
	endif

	k=index(f1,'.')
        if(k.eq.0)f1=f1(1:lnblnk(f1))//'.fit'
        inquire(file=f1,exist=logi)
        if(.not.logi)stop ' file not found !'

	k1=index(f1,'.')
	k=k1-1
c 1.
	call system('j_find4k '//f1(1:k))
c 2.
	call system('j_phot4k '//f1(1:k))
c 2.1
	call system('j_1to94k  '//f1(1:k))

	call system('mv '//f1(1:k)//'.ap '//f1(1:k1)//char(48)//'ap')


	do 10 i=1,9
	call system('mv '//f1(1:k1)//char(i+48)//'ap '//f1(1:k1)//'ap')
c 3. 
	call system('j_auto94k '//f1(1:k))
c 4.
	call system('j_psf4k '//f1(1:k)//' -1 '//c)
c 5.
	call system('mv '//f1(1:k)//'.ap '//f1(1:k)//'.apt')
	call system('mv '//f1(1:k)//'.nei '//f1(1:k)//'.ap')

	call system('j_star4k '//f1(1:k))
c 6.
	call system('mv '//f1(1:k)//'.als '//f1(1:k)//'.ap')

	call system('j_substar '//f1(1:k))
c 7.
	call system('mv '//f1(1:k)//'.fit '//f1(1:k)//'.fitt')	
	call system('mv '//f1(1:k)//'.fits '//f1(1:k)//'.fit')	
c 8.

	call system('j_psf4k '//f1(1:k)//' 0 '//c)
c 9.
	call system('mv '//f1(1:k)//'.fitt '//f1(1:k)//'.fit')	

	call system('j_star4k '//f1(1:k))
c 10.
	call system('mv '//f1(1:k)//'.als '//f1(1:k)//'.ap')

	call system('j_substar '//f1(1:k))
c 11.
	call system('mv '//f1(1:k)//'.fit '//f1(1:k)//'.fitt')
        call system('mv '//f1(1:k)//'.fits '//f1(1:k)//'.fit')
c 12.
	call system('j_psf4k '//f1(1:k)//' 1 '//c)
c 13.
	call system('mv '//f1(1:k)//'.fitt '//f1(1:k)//'.fit')

        call system('j_star4k '//f1(1:k))
c 14.
        call system('mv '//f1(1:k)//'.als '//f1(1:k)//'.ap')

        call system('j_substar '//f1(1:k))
c 15.
        call system('mv '//f1(1:k)//'.fit '//f1(1:k)//'.fitt')
        call system('cp '//f1(1:k)//'.fits '//f1(1:k)//'.fit')
c 16.
        call system('j_psf4k '//f1(1:k)//' 1 '//c)
c 21.
	call system('mv '//f1(1:k)//'.apt '//f1(1:k)//'.ap')
        call system('mv '//f1(1:k)//'.fitt '//f1(1:k)//'.fit')
c 22.
        call system('j_star4k '//f1(1:k))

	call system('mv '//f1(1:k)//'.als '//f1(1:k)//char(i+48)//'.als')
   	call system('mv '//f1(1:k)//'.fits '//f1(1:k)//char(i+48)//'.fits')
	call system('mv '//f1(1:k)//'.lst '//f1(1:k)//char(i+48)//'.lst')
10	continue
c end   
	call system('mv '//f1(1:k1)//char(48)//'ap '//f1(1:k)//'.ap')
	call system('j_9to14k '//f1(1:k))
	call system('j_xy4ad '//f1(1:k))
	call system('j_xy6ad '//f1(1:k)//'.lst')

	call system('rm *.tmp')
	call system('rm '//f1(1:k)//'?.als')
	call system('rm '//f1(1:k)//'?.lst')
	call system('rm '//f1(1:k)//'?.fits')
	call system('rm '//f1(1:k)//'.nei')
	call system('rm '//f1(1:k)//'.psf')
c	call system('rm '//f1(1:k)//'.coo')
c	call system('rm '//f1(1:k)//'.ap')
	end
