!
!  coefh_intf.f90
!
       subroutine coefh_intf(cell1,cell2,index1r,index2r,index1,index2,& 
                             acoef1,bcoef1,anorm1,massf1,acoef2,bcoef2,& 
                             anorm2,massf2,cbc,cb,ncs1,ncs2,&
                             rz,iz,dz,cz,rzp,izp,czp,ierr)
!
       implicit none
       real :: rzp(*),rz(*)
       integer :: izp(*),iz(*)
       character (len=*) :: czp(*),cz(*)
       real (selected_int_kind (5)) :: dz(*)
       integer :: ncs1,ncs2,ierr 
!
       character (len=*) :: cell1,cell2,cbc
       real :: acoef1(ncs1),bcoef1(ncs1),anorm1(ncs1),massf1(ncs1), &
               acoef2(ncs2),bcoef2(ncs2),anorm2(ncs2),massf2(ncs2),cb
       integer :: index1(ncs1,4),index2(ncs2,4),index1r(6),index2r(6)
!
       character (len=4) :: ctype
       integer :: icvs1,jcvs1,kcvs1,icvs2,jcvs2,kcvs2
       integer :: alength,blength,anlength,mflength
!
! Pointers       
       integer :: pAP1,pAE1,pAW1,pAN1,pAS1,pAT1,pAB1,pB1,pPhi1,pPhi01
       integer :: pRHO01,pTC01,pCP01,pVol1,pAnorm1,pX1,pY1,pZ1,pXC1,pYC1,pZC1,pMf1
       integer :: pAP2,pAE2,pAW2,pAN2,pAS2,pAT2,pAB2,pB2,pPhi2,pPhi02
       integer :: pRHO02,pTC02,pCP02,pVol2,pAnorm2,pX2,pY2,pZ2,pXC2,pYC2,pZC2,pMf2
!     
       if ( cell1(1:8)=='boundary' ) then
         icvs1=0; jcvs1=0 ;kcvs1=0 
         pAP1=0; pB1=0; pPhi1=0; pPhi01=0
         pRHO01=0; pTC01=0; pCP01=0; pVol1=0; pAnorm1=0 ;pMf1=0 
         pX1=0; pY1=0; pZ1=0; pXC1=0; pYC1=0; pZC1=0
       else
!
! Cell dimensions 
         call get_int_value('physics',trim(cell1)//'/icvs',icvs1,izp,ierr)  
         call get_int_value('physics',trim(cell1)//'/jcvs',jcvs1,izp,ierr)      
         call get_int_value('physics',trim(cell1)//'/kcvs',kcvs1,izp,ierr)
!
! Coefficient space
         call get_mem('coef',trim(cell1)//'/ap',ctype,pAP1,alength,ierr)
         call get_mem('coef',trim(cell1)//'/ae',ctype,pAE1,alength,ierr)
         call get_mem('coef',trim(cell1)//'/aw',ctype,pAW1,alength,ierr)
         call get_mem('coef',trim(cell1)//'/an',ctype,pAN1,alength,ierr)
         call get_mem('coef',trim(cell1)//'/as',ctype,pAS1,alength,ierr)
         call get_mem('coef',trim(cell1)//'/at',ctype,pAT1,alength,ierr)
         call get_mem('coef',trim(cell1)//'/ab',ctype,pAB1,alength,ierr)
         call get_mem('coef',trim(cell1)//'/b',ctype,pB1,blength,ierr) 
!
! Geometry
         call get_mem('cell',trim(cell1)//'/mesh/vol',ctype,pVol1,alength,ierr)  
         call get_mem('cell',trim(cell1)//'/mesh/anorm',ctype,pAnorm1,anlength,ierr)
         call get_mem('cell',trim(cell1)//'/mesh/x',ctype,pX1,anlength,ierr)
         call get_mem('cell',trim(cell1)//'/mesh/y',ctype,pY1,anlength,ierr)
         call get_mem('cell',trim(cell1)//'/mesh/z',ctype,pZ1,anlength,ierr) 
!
! Dependent variable and properties
         call get_mem('coef',trim(cell1)//'/energy0',ctype,pPhi01,alength,ierr)
         call get_mem('coef',trim(cell1)//'/props/tc0',ctype,pTC01,alength,ierr)           
         call get_mem('coef',trim(cell1)//'/props/cp0',ctype,pCP01,alength,ierr)          
         call get_mem('coef',trim(cell1)//'/props/rho0',ctype,pRHO01,alength,ierr)
         call get_mem('coef',trim(cell1)//'/energy',ctype,pPhi1,alength,ierr)           
         call get_mem('coef',trim(cell1)//'/mass/massfl',ctype,pMf1,mflength,ierr) 
!
! Get temprary space to hold mesh cv centers
         call get_mem('cell',trim(cell1)//'/mesh/xc',ctype,pXC1,alength,ierr)
         call get_mem('cell',trim(cell1)//'/mesh/yc',ctype,pYC1,alength,ierr)
         call get_mem('cell',trim(cell1)//'/mesh/zc',ctype,pZC1,alength,ierr)       
       endif
!
       if ( cell2(1:8)=='boundary' ) then
         icvs2=0; jcvs2=0 ;kcvs2=0 
         pAP2=0; pB2=0; pPhi2=0; pPhi02=0
         pRHO02=0; pTC02=0; pCP02=0; pVol2=0; pAnorm2=0 ;pMf2=0 
         pX2=0; pY2=0; pZ2=0; pXC2=0; pYC2=0; pZC2=0
       else
!
! Cell dimensions        
         call get_int_value('physics',trim(cell2)//'/icvs',icvs2,izp,ierr)       
         call get_int_value('physics',trim(cell2)//'/jcvs',jcvs2,izp,ierr)      
         call get_int_value('physics',trim(cell2)//'/kcvs',kcvs2,izp,ierr)
!
! Coefficient space
         call get_mem('coef',trim(cell2)//'/ap',ctype,pAP2,alength,ierr)
         call get_mem('coef',trim(cell2)//'/ae',ctype,pAE2,alength,ierr)
         call get_mem('coef',trim(cell2)//'/aw',ctype,pAW2,alength,ierr)
         call get_mem('coef',trim(cell2)//'/an',ctype,pAN2,alength,ierr)
         call get_mem('coef',trim(cell2)//'/as',ctype,pAS2,alength,ierr)
         call get_mem('coef',trim(cell2)//'/at',ctype,pAT2,alength,ierr)
         call get_mem('coef',trim(cell2)//'/ab',ctype,pAB2,alength,ierr)
         call get_mem('coef',trim(cell2)//'/b',ctype,pB2,blength,ierr) 
!
! Geometry
         call get_mem('cell',trim(cell2)//'/mesh/vol',ctype,pVol2,alength,ierr) 
         call get_mem('cell',trim(cell2)//'/mesh/anorm',ctype,pAnorm2,anlength,ierr)
         call get_mem('cell',trim(cell2)//'/mesh/x',ctype,pX2,anlength,ierr)
         call get_mem('cell',trim(cell2)//'/mesh/y',ctype,pY2,anlength,ierr)
         call get_mem('cell',trim(cell2)//'/mesh/z',ctype,pZ2,anlength,ierr)
!
! Dependent variable and properties
         call get_mem('coef',trim(cell2)//'/energy0',ctype,pPhi02,alength,ierr)
         call get_mem('coef',trim(cell2)//'/props/tc0',ctype,pTC02,alength,ierr)           
         call get_mem('coef',trim(cell2)//'/props/cp0',ctype,pCP02,alength,ierr)          
         call get_mem('coef',trim(cell2)//'/props/rho0',ctype,pRHO02,alength,ierr)
         call get_mem('coef',trim(cell2)//'/energy',ctype,pPhi2,alength,ierr)           
         call get_mem('coef',trim(cell2)//'/mass/massfl',ctype,pMf2,mflength,ierr) 
!
! Get temprary space to hold mesh cv centers
         call get_mem('cell',trim(cell2)//'/mesh/xc',ctype,pXC2,alength,ierr)
         call get_mem('cell',trim(cell2)//'/mesh/yc',ctype,pYC2,alength,ierr)
         call get_mem('cell',trim(cell2)//'/mesh/zc',ctype,pZC2,alength,ierr)        
       endif               
!   
       call coefh_intf1(cell1,cell2,rz(pAP1),rz(pAE1),rz(pAW1),rz(pAN1), &
                    rz(pAS1),rz(pAT1),rz(pAB1),rz(pB1), &
                    rz(pPhi01),rz(pPhi1),rz(pXC1),rz(pYC1),rz(pZC1), &
                    rz(pTC01),rz(pCP01),rz(pRHO01),icvs1,jcvs1,kcvs1, & 
                    rz(pAP2),rz(pAE2),rz(pAW2),rz(pAN2), &
                    rz(pAS2),rz(pAT2),rz(pAB2),rz(pB2), &
                    rz(pPhi02),rz(pPhi2),rz(pXC2),rz(pYC2),rz(pZC2), &
                    rz(pTC02),rz(pCP02),rz(pRHO02),icvs2,jcvs2,kcvs2, &
                    index1r,index2r,index1,index2,acoef1,bcoef1,anorm1,massf1, &
                    acoef2,bcoef2,anorm2,massf2,cbc,cb,ncs1,ncs2, &
                    rz,iz,dz,cz,rzp,izp,czp,ierr)
!
       end subroutine coefh_intf        
