!----------------------------------------------------------------------------------------------------------------------------------!
SUBROUTINE cbem_lap_input(InfParams, InfData)
!----------------------------------------------------------------------------------------------------------------------------------!

!===purpose===! 

!**********************************************************************************************************************************!
!********************************  COLLOCATION BEM for 3D LAPLACE EQUATION: SINGULAR FORMULATION  *********************************!
!***************************************  3-NODED TRIANGULAR ELEMENT: ANALYTIC INTEGRATION  ***************************************!
!***********************************************  PIECEWISE CONSTANT APPROXIMATION  ***********************************************!
!**********************************************  Data input for 3D Laplace Equation  **********************************************!
!**********************************************************************************************************************************!

!*** Developer: Sylvain Nintcheu Fata, Oak Ridge National Laboratory
!*** Version:   V.1.1
!*** Released:  Mar 21, 2011

 
USE KINDS
USE PARAMS,   ONLY: gm_eps,f_eps ! gm_eps == Tolerance on the geometry
                                 ! f_eps == Tolerance on the argument of a function
USE SRF_GEOM, ONLY: mx_nd_elt    ! mx_nd_elt == Maximum number of nodes per element
USE SRF_GEOM, ONLY: nbnd,nbelt   ! nbnd == Total number of boundary nodes
                                 ! nbelt == Total number of boundary elements
USE SRF_GEOM, ONLY: belt         ! belt(:,i) == Global indices of boundary nodes on the i-th element
USE SRF_COND, ONLY: eltbc	 ! eltbc(i) = {0,1} ==> {Dirichlet,Neunamm} boundary condition is prescribed on belt(:,i)
USE SRF_GEOM, ONLY: bnd          ! bnd(:,i) == Cartesian coordinates of the i-th boundary node
USE POTFLUX,  ONLY: pbv          ! pbv(i) == Prescribed Boundary Value at the centroid of the i-th boundary element


IMPLICIT NONE

 character(len=72) :: InfParams,InfData 
 integer(kind=k9) :: i,alloc_st,alloc_st1,alloc_st2



    open (unit=54, file=InfParams, action='read')

!*** Read parameters
     read(54,*)gm_eps  ! gm_eps == Tolerance on the geometry
     read(54,*)f_eps   ! f_eps == Tolerance on the argument of a function
    close(54)

    open (unit=55, file=InfData, action='read')

    read(55,*) nbnd  ! nbnd == Total number of boundary nodes
    read(55,*) nbelt ! nbelt == Total number of boundary elements

    allocate(bnd(3,nbnd),STAT=alloc_st)
    if ( alloc_st == 0 ) then  ! If bnd is successfully allocated 
!*** Read the Cartesian coordinates of boundary nodes
          loop0: do i=1,nbnd    ! Loop over all boundary nodes
             read(55,*) bnd(1,i), bnd(2,i), bnd(3,i)  ! bnd(:,i) = Cartesian coordinates of the i-th boundary node
          enddo loop0
    else
          write(*,*)'cbem_lap_input: Allocate array "bnd" failed with Status=',alloc_st
	  stop
    endif


   allocate(pbv(nbelt),STAT=alloc_st) 
   allocate(belt(mx_nd_elt,nbelt),STAT=alloc_st1)
   allocate(eltbc(nbelt),STAT=alloc_st2)
    if ( (alloc_st == 0) .and. (alloc_st1 == 0) .and. (alloc_st2 == 0) ) then  ! If pbv, belt, eltbc are successfully allocated 
!*** Read the characteristics of each boundary element
          loop1: do i=1,nbelt     ! Loop over all boundary elements
             read(55,*) belt(1,i),belt(2,i),belt(3,i),pbv(i),eltbc(i)
          enddo loop1
    else
          if ( alloc_st .ne. 0 ) then  ! If pbv is not successfully allocated 
                write(*,*)'cbem_lap_input: Allocate array "pbv" failed with Status=',alloc_st
	        stop
          endif

          if ( alloc_st1 .ne. 0 ) then  ! If belt is not successfully allocated 
                write(*,*)'cbem_lap_input: Allocate array "belt" failed with Status=',alloc_st1
	        stop
          endif

          if ( alloc_st2 .ne. 0 ) then  ! If eltbc is not successfully allocated 
                write(*,*)'cbem_lap_input: Allocate array "eltbc" failed with Status=',alloc_st2
	        stop
          endif
    endif

close (unit=55, status='keep')

!----------------------------------------------------------------------------------------------------------------------------------!
END SUBROUTINE cbem_lap_input
!----------------------------------------------------------------------------------------------------------------------------------!
