	character*30 fit(20),fits,cat6,a*90
        character*80 head(36),f1
	call system('ls *.cat6 >1.tmp')
	call system('ls *.fit >>1.tmp')
	n=0
	cat6(1:1)=' '
        open(1,file='1.tmp',status='old')
10      read(1,'(a)',end=99)fits
	k=index(fits,'.')
	if(k.eq.0)goto 10
	if(fits(k+1:k+4).eq.'cat6')cat6=fits(1:k-1)
	if(fits(k+1:k+3).eq.'fit')then
	  n=n+1
          fit(n)=fits(1:k-1)
	endif
	goto 10
99      close(1)
	call unlink('1.tmp')
	i=0
        if(cat6(1:1).eq.' ')then
	  write(*,*)' not found ????.cat6 (from deep)'
          i=1
	endif
        if(n.eq.0)then
	  write(*,*)' no fits files found'	
          i=1 
        endif
        if(i.eq.1)stop ' nothing done!'
	do 20 i=1,n
	call system('j_find '//fit(i))
	call system('j_phot '//fit(i))
        f1=fit(i)
        k=index(f1,'.')
        if(k.eq.0)f1=f1(1:lnblnk(f1))//'.fit'
        open(1,file=f1,status='old',access='direct',recl=2880)
        read(1,rec=1)head
        ipos=indexpos(head,'NAXIS1  ')
        read(head(ipos)(26:30),'(i5)')ip
        close(1)
        if(ip.ge.4000)call system('pip64k '//cat6//' '//fit(i)//' 6')
20      if(ip.lt.4000)call system('pip6 '//cat6//' '//fit(i)//' 5')
	k=lnblnk(cat6)
	call system('tocon >../'//cat6(1:k-1)//'_con.'//cat6(k:k))
	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


