c 3 step
c  pip31. morkout getcat.cat
c  pip32. morkout T*_con.?
c         ab >1.1
c	  source 1.1

c  pip33. put ap mag -->mag
c                       mag2

	character*20 f1,f2,f3,ff*80
        character*1  f0
        byte b0
        equivalence (b0,f0)
	k=iargc()
	if(k.lt.1)then
	  write(*,*)
	  write(*,*)'               Usage: pip33 T518i_15'
	  write(*,*)'                      in no directory'
	  write(*,*)
	  stop
	endif
	call getarg(1,f1)
	k=lnblnk(f1) 
        f0=f1(1:1)
        if(b0<96)b0=b0+32
	ff='mv ../deep/'//f0//'*.fit .'
	call system(ff)
	f2=f1(1:k)//'.mag1'
	ff='cp ../deep/'//f2//' .'
	call system(ff)
	ff='ls '//f0//'*.fit >file'
	call system(ff)
	f3=f1(1:4)//'.coo'
	f3(1:1)=f0
	ff='takead '//f2//' > '//f3
	call system(ff)

	call c15("j_ad2xy")
	call b15("j_phot")
	call d15(f2)

	call system("ls no.? >1.1")
	ff="readput "//f2//" 1.1 "//f1(1:k)//'.mag'
	  write(*,*)ff
	call system(ff)
	ff="chformat "//f1(1:k)//'.mag '//f1(1:k)//'.mag2'
	call system(ff)
	end

	subroutine b15(ch1)
	character*(*) ch1
	character*20 f1,f2
	f2=ch1
	open(15,file='file',status='old')
10	read(15,'(a)',end=99)f1 
	call system(f2//' '//f1)
	goto 10
99	close(15)
	end

	subroutine c15(ch1)
	character*(*) ch1
	character*20 f1,f2
	f2=ch1
	open(15,file='file',status='old')
10	read(15,'(a)',end=99)f1 
	call system(f2//' '//f1//' > '//f1(1:5)//'.coo')
	goto 10
99	close(15)
	end

	subroutine d15(ch1)
	character*(*) ch1
	character*20 f1,f2*40
	f2=ch1
	open(15,file='file',status='old')
10	read(15,'(a)',end=99)f1 
	f2="readno "//ch1(1:lnblnk(ch1))//' '//f1(1:5)//' > no.'//f1(5:5)
	write(*,*)f2
	call system(f2)
	goto 10
99	close(15)
	end
