      implicit none
      real r(3,100,100),oc,tt
      integer n,i,j,iat,imol,oldnum(100),newnum(100),nhead,ns,nat,nmol
      integer nw
      character*40 filein,fileout,nomres,filecont,dumc
      character*10 nomat(100),atomt,sym(100),idd,res(100)
      character*200 line(100)
      write(6,*)'control file:'
c      read(5,*) filecont
      filecont='ada_renum.con'
      open(unit=1,file=filecont)
      read(1,*) dumc
      write(6,*) 'reading:',dumc
      read(1,*) filein,fileout,nhead
      write(6,*) 'reading:',filein,fileout,nhead
      read(1,*) nat,nmol
      write(6,*) 'reading:',nat,nmol
      do iat=1,nat
      read(1,*) oldnum(iat),newnum(iat)
      write(6,*) 'reading:',oldnum(iat),newnum(iat)
      end do
      close(unit=1)
      write(6,*) ''
      write(6,*) 'OPENING: ',filein
      write(6,*) ''
      open(unit=1,file=filein)
      do i=1,nhead
      read(1,"(a100)") line(i)
      write(6,"(a9,a100)") 'reading: ',line(i)
      end do	  
      do imol=1,nmol
      do iat=1,nat
      read(1,10) atomt,ns,nomat(iat),dumc,res(iat),dumc,ns,dumc,
     & r(1,iat,imol),r(2,iat,imol),r(3,iat,imol),
     & oc,tt,idd,sym(iat)
	  oldnum(iat)=iat
10    Format (A6,I5,1X,A4,A1,A3,1X,A1,I4,A1,3X,3F8.3,2F6.2,10X,A2,A2) 
c      write(6,10) atomt,ns,nomat(iat),dumc,res(iat),dumc,ns,dumc,
c     & r(1,iat,imol),r(2,iat,imol),r(3,iat,imol),
c     & oc,tt,idd,sym(iat)
      end do
      end do  
      close(unit=1)
      open(unit=1,file=fileout)
      do i=1,nhead
      write(1,"(a200)") line(i)
      end do
      do imol=1,nmol
      do iat=1,nat
	  nw=newnum(iat)
      write(1,10) atomt,iat,nomat(nw),dumc,res(nw),dumc,imol,dumc,
     & r(1,nw,imol),r(2,nw,imol),r(3,nw,imol),
     & oc,tt,idd,sym(nw)
      end do
      end do
      stop
      end	  