      subroutine intglcha(x1,y1,z1,x2,y2,z2,x3,y3,z3,x,y,z,f,area)
c******************************************************************
c
c  purpose: to evaluate the second term of the scalar potential
c           integral.
c
c******************************************************************
c
      common /poten/f1

      real x1, y1, z1, x2, y2, z2, x3, y3, z3, x, y, z
      real f, area
      integer is(3,2), ng(3)
      integer i, j, n, k
      real al, d, d2, r0, rg, e, ae, sg, ro2, r02, ro
      real snden, sn, ft, f1
      real vr(4,3),r(4),ul(3,3),un(3),rl(3,2),ue(3,3)
c
      vr(1,1)=x1-x
      vr(1,2)=y1-y
      vr(1,3)=z1-z
      vr(2,1)=x2-x
      vr(2,2)=y2-y
      vr(2,3)=z2-z
      vr(3,1)=x3-x
      vr(3,2)=y3-y
      vr(3,3)=z3-z
      do 1 i=1,3
 1    vr(4,i)=vr(1,i)
      do 3 i=1,3
      r(i)=0.
      do 2 j=1,3
2     r(i)=r(i)+vr(i,j)**2
3     r(i)=sqrt(r(i))
      r(4)=r(1)
      do 4 i=1,3
      ng(i)=i
4     if(r(i+1).gt.r(i)) ng(i)=i+1
      do 7 i=1,3
      al=0.
      do 5 j=1,3
      ul(i,j)=vr(i+1,j)-vr(i,j)
5     al=al+ul(i,j)**2
      al=sqrt(al)
      do 6 j=1,3
6     ul(i,j)=ul(i,j)/al
7     continue
      un(1)=ul(1,2)*ul(2,3)-ul(1,3)*ul(2,2)
      un(2)=ul(1,3)*ul(2,1)-ul(1,1)*ul(2,3)
      un(3)=ul(1,1)*ul(2,2)-ul(1,2)*ul(2,1)
      al=sqrt(un(1)**2+un(2)**2+un(3)**2)
      do 8 i=1,3
8     un(i)=un(i)/al
      d=0.
      do 9 i=1,3
      n=ng(1)
9     d=d+vr(n,i)*un(i)
      d=abs(d)
      d2=d*d
      do 11 i=1,3
      do 11 j=1,2
      rl(i,j)=0.
      n=i+j-1
      do 10 k=1,3
10    rl(i,j)=rl(i,j)+vr(n,k)*ul(i,k)
      is(i,j)=1
      if(rl(i,j).lt.0.) is(i,j)=-1
11    rl(i,j)=abs(rl(i,j))
      do 12 i=1,3
      ue(i,1)=un(2)*ul(i,3)-un(3)*ul(i,2)
      ue(i,2)=un(3)*ul(i,1)-un(1)*ul(i,3)
12    ue(i,3)=un(1)*ul(i,2)-un(2)*ul(i,1)
      f=0.
      do 15 i=1,3
      ro=0.
      n=ng(i)
      do 13 j=1,3
13    ro=ro+vr(i,j)*ue(i,j)
      rg=sqrt(r(n)**2-d2)
	if(rg.lt.(sqrt(area)/1000.)) go to 15
      e=ro/rg
      ae=abs(e)
      if(ae.lt.1.e-4)go to 15
      sg=-e/ae
      ro2=ro*ro
      ro=sqrt(ro2)
      r02=ro2+d2
      r0=sqrt(r02)
      do 14 j=1,2
      n=i+j-1
	snden=sqrt(r(n)**2-d2)
	if(snden.lt.(sqrt(area)/1000.)) go to 14
      sn=rl(i,j)/snden
      rg=sqrt(r(n)**2-d2)
      ae=abs(rl(i,j)-rg)
      rg=rg*.0001
      if(ae.lt.rg) sn=1.
	if(sn.gt.1.00) sn=1.0
c
c
      ft=sg*is(i,j)*(ro*alog((r(n)+rl(i,j))/r0)+d*(asin((d/r0)*
     $sn)-asin(sn)))
      ft=(-1)**j*ft
      f=f+ft
 14	continue
c
 15    continue
      f1=f
      return
      end
