      MODULE MALHA

      use INPUT


      contains

      subroutine gmesh

c     mesh generator and read eqpt properties
c     March 1, 1998
c
      implicit real *8 (a-h,o-z)
c
c     nelmax must reserve 5 positions for the 5 outside wall temperatures
c
      xl(1,1,1)=0.d0
      xl(1,1,2)=0.d0
      xl(1,1,3)=0.d0
      iel=0
      do k=1,nlz
         if(k.ne.1) then
            xl(iel+1,1,1)=0.d0
            xl(iel+1,1,2)=0.d0
            xl(iel+1,1,3)=xl(iel-nlx*nly+1,1,3)+dz(k-1)
         endif
      do j=1,nly
         if(j.ne.1) then
            xl(iel+1,1,1)=xl(iel-nlx+1,1,1)
            xl(iel+1,1,2)=xl(iel-nlx+1,1,2)+dy(j-1)
            xl(iel+1,1,3)=xl(iel-nlx+1,1,3)
         endif
      do i=1,nlx
         if(i.ne.1) then
            xl(iel+i,1,1)=xl(iel+i-1,2,1)
            xl(iel+i,1,2)=xl(iel+i-1,2,2)
            xl(iel+i,1,3)=xl(iel+i-1,2,3)
         endif
         xl(iel+i,2,1)=xl(iel+i,1,1)+dx(i)
         xl(iel+i,2,2)=xl(iel+i,1,2)
         xl(iel+i,2,3)=xl(iel+i,1,3)
         xl(iel+i,3,1)=xl(iel+i,1,1)+dx(i) 
         xl(iel+i,3,2)=xl(iel+i,1,2)+dy(j) 
         xl(iel+i,3,3)=xl(iel+i,1,3)
         xl(iel+i,4,1)=xl(iel+i,1,1)
         xl(iel+i,4,2)=xl(iel+i,1,2)+dy(j) 
         xl(iel+i,4,3)=xl(iel+i,1,3)
         xl(iel+i,5,1)=xl(iel+i,1,1)
         xl(iel+i,5,2)=xl(iel+i,1,2)
         xl(iel+i,5,3)=xl(iel+i,1,3)+dz(k)
         xl(iel+i,6,1)=xl(iel+i,1,1)+dx(i)
         xl(iel+i,6,2)=xl(iel+i,1,2)
         xl(iel+i,6,3)=xl(iel+i,1,3)+dz(k)
         xl(iel+i,7,1)=xl(iel+i,1,1)+dx(i)
         xl(iel+i,7,2)=xl(iel+i,1,2)+dy(j)
         xl(iel+i,7,3)=xl(iel+i,1,3)+dz(k)
         xl(iel+i,8,1)=xl(iel+i,1,1)
         xl(iel+i,8,2)=xl(iel+i,1,2)+dy(j)
         xl(iel+i,8,3)=xl(iel+i,1,3)+dz(k)
      enddo
         iel=iel+nlx
      enddo
      enddo
      auxa=abs(xl(nel,7,1)-a)
      auxb=abs(xl(nel,7,2)-b)
      auxc=abs(xl(nel,7,3)-c)
      if(auxa.gt.1.d-10.and.auxb.gt.1.d-10
     1     .and.auxc.gt.1.d-10) then
         write(*,*)xl(nel,7,1),xl(nel,7,2),
     1     xl(nel,7,3)
         write(*,*)'mesh is not correct - review input file inpmesh'
         stop
         else
            a=xl(nel,7,1)
            b=xl(nel,7,2)
            c=xl(nel,7,3)
      endif
c
c     reading of equipment properties
c
c     ine is the element number which is equipment
c
c     the equipment density may be evaluated experimentally
c     by weighing the equipment and dividing by its volume
c
c     likewise, the equipment thermal conductivity can be evaluated
c     as an equivalent conductivity, such as
c     rkeqp(ine) = sum_i(k_i*V_i)/V_eqp
c
c     itypel(i) = 0 (air) or 1 (solid)
c
      do ine=1,nel
c
         if ( ihp_i(ine) == 1 ) then
c
               wid=xl(ine,4,2)-xl(ine,1,2)
               hgt=xl(ine,5,3)-xl(ine,1,3)
               rlg=xl(ine,2,1)-xl(ine,1,1)
               afin=wid*hgt
               atc(ine)=2*nfin_i(ine)*afin
               vfin=afin*efin_i(ine)
               vtfin=nfin_i(ine)*vfin
               vol=hgt*wid*rlg
               volair=vol-vtfin
               rhoeqp(ine)=(rhoair*volair+rhofin_i(ine)*vtfin)/vol
               ceqp(ine)=(cvair*volair+cfin_i(ine)*vtfin)/vol
               rkeqp(ine)=(rkair*volair+rkfin_i(ine)*vtfin)/vol
c
          end if
c
      end do
c
      return
c
      end subroutine gmesh
c      
      end module malha