c PIPELINE 2             97,8,22 
c 97,11,20
	character*60 f1,c*1
	logical logi

	if(iargc().lt.1)then
	  write(*,*)
	  write(*,*)'         Usage:  pip2 batc_fits_file [!]'
	  write(*,*)
	  write(*,*)'                          2000.7'
          write(*,*)
	  write(*,*)'     if add !, j_psf 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 !'

	k=index(f1,'.')
	k=k-1
c 1.
	call system('j_find '//f1(1:k))
c 2.
	call system('j_phot '//f1(1:k))
c 3. 
	call system('j_auto '//f1(1:k))
c 4.
	call system('j_psf '//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_star '//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_psf '//f1(1:k)//' 0 '//c)
c 9.
	call system('mv '//f1(1:k)//'.fitt '//f1(1:k)//'.fit')	
	call system('j_star '//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_psf '//f1(1:k)//' 1 '//c)
c 13.
	call system('mv '//f1(1:k)//'.fitt '//f1(1:k)//'.fit')
        call system('j_star '//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('mv '//f1(1:k)//'.fits '//f1(1:k)//'.fit')
c 16.
        call system('j_psf '//f1(1:k)//' 2 '//c)
c 17.
        call system('mv '//f1(1:k)//'.fitt '//f1(1:k)//'.fit')
        call system('j_star '//f1(1:k))
c 18.
        call system('mv '//f1(1:k)//'.als '//f1(1:k)//'.ap')
        call system('j_substar '//f1(1:k))
c 19.
        call system('mv '//f1(1:k)//'.fit '//f1(1:k)//'.fitt')
        call system('mv '//f1(1:k)//'.fits '//f1(1:k)//'.fit')
c 20.
	call system('j_psf '//f1(1:k)//' 2 '//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_star '//f1(1:k))
	
	end
