***********************************************************************
      program Eos9Eos3
***********************************************************************
c
c Converts EOS9 INCON file to EOS3 INCON file
c S. Finsterle, May 1999
c
      implicit double precision (a-h,o-z)

      character*80 line
      character*40 filein,fileout

      write(*,*)
      write(*,*) ' Convert INCON from EOS9 to EOS3'
      write(*,*) ' *******************************'
      write(*,*)
      write(*,*) ' Input EOS9 INCON file              : ?  '
      read(*,'(a)')filein
      open(1,file=filein, status='old')
      write(*,*) ' Output EOS3 INCON file             : ?  '
      read(*,'(a)')fileout
      open(2,file=fileout,status='unknown')
      write(*,*) ' Reference pressure [Pa]            : ?  '
      read(*,*) refpres
      write(*,*) ' Reference temperature              : ?  '
      read(*,*) reftemp
      write(*,*)
      iel=0
 2000 continue
      read(1,7000,end=9000) line
 7000 format(a)
      call lenos(line,ll)
      if (line(1:5).eq.'INCON') then
         call lenos(filein,lfi)
         write(2,7001) filein(:lfi)
 7001 format('INCON -- Initial conditions converted from EOS9 file ',a)
      else
         write(2,7000) line(:ll)
         goto 2000
      endif
 2001 continue
c
c --- elements
      iel=iel+1
      if (mod(iel,1000).eq.1)
     &    write(*,*) ' Working on element ',max(1,iel-1)
      read(1,7000) line
      write(2,7000) line(:40)
      if (line(:5).eq.'    '.or.line(:3).eq.'+++') goto 2002
      read(1,7002,err=2002) x1
 7002 format(3e20.12)
      if (x1.lt.1.5) then
         pres=refpres
         x2=min(11.0-x1,10.9999999)
      else 
         pres=x1
         x2=0.0
      endif
      write(2,7002) pres,x2,reftemp
      goto 2001
 2002 continue
c
c --- copy rest of file
      read(1,7000,end=9000) line
      call lenos(line,ll)
      write(2,7000) line(:ll)
      goto 2002
 9000 continue
      close(1)
      close(2)
      end

c --- end of Eos9Eos3


***********************************************************************
      subroutine lenos(string,lstr)
***********************************************************************
      character string*(*)

      lstr=1
      ilenstr=len(string)
      if (ilenstr.eq.0) return
      do 1000 i=ilenstr,1,-1
        if (string(i:i).ne.char(9).and.string(i:i).ne.' ') then
          lstr=i
          return
        endif
1000  continue
      end

c --- end of lenos
