c
c *** Convert the original element data to data with Vp, Vs, and density 
c     for a 2 flat-layered model ***
c     Note that the original orders for n1 and n2 of elements are changed
c     to those for n2 and n1 to get positive volume values
c
      parameter(mnode=300000)
      dimension x(mnode),y(mnode),z(mnode),nf(mnode)

      vp1= 2.0
      vs1= 1.0
      dn1= 2.0
      vp2= 5.0
      vs2= 3.0
      dn2= 2.5
      d  =-1.0
      Xbnd = 9.0

      open(9,file='try.2.fi',status='unknown')
      write(9,900)
 900  format('NODES'/'ELEMENTS')
      close(9)

      open(10,file='try.1.ele',status='old')
      open(11,file='try.2.ele',status='unknown')
      open(12,file='try.1.node',status='old')
      open(13,file='try.2.node',status='unknown')

      read(12,*)nnode,ntet,ninfo,nflag
      write(13,1000)nnode,ntet,ninfo,nflag
 1000 format(4i9)
      if(nnode.ge.mnode)then
        write(*,*)'nnode>mnode !!!'
        stop
      end if

      do i=1,nnode
        read(12,*)n,x(i),y(i),z(i),nf(i)
        write(13,1100)n,x(i),y(i),z(i),nf(i)
      end do
 1100 format(i9,3f9.3,i9)

      read(10,*)nele,ntet,nflag
      write(11,1200)nele,ntet,3
 1200 format(4i9)
      do i=1,nele
        read(10,*)n,n1,n2,n3,n4
        xc=(x(n1)+x(n2)+x(n3)+x(n4))/4.0
        zc=(z(n1)+z(n2)+z(n3)+z(n4))/4.0
        if((zc.gt.d).and.(xc.gt.xbnd))then
          write(11,1300)n,n2,n1,n3,n4,vp1,vs1,dn1
        else
          write(11,1300)n,n2,n1,n3,n4,vp2,vs2,dn2
        end if
      end do
 1300 format(5i9,3f9.3)

      close(10)
      close(11)
      close(12)
      close(13)

      stop
      end




