*dk fphi
      function fphi(phi)
c
c   $RCSfile: fphi.f,v $ $Revision: 1.4 $
c   $Date: 89/08/04 14:22:13 $
c   $State: Stable $
c
c   fh2 new surface no. 5
c   ab,ac sato parameters are z(1)=z(3) for deg.le.deg1.
c   deg1 must be set in prepot.
c   z0 is set equal to z(1)=z(3) in prepot.
      implicit real*8 (a-h,o-z)
      common /phicom/ deg1,z0,fder,deg
      common /z3com/ z(3),lchi
      common /fh2pot/r(3),e,dedr(3)
      common/derivs/ds1dr1,ds1dr2,ds1dr3
      deg=57.29577951d0*phi
      tdeg = 57.29577951d0
      dist = r(1)**2 + r(2)**2 - r(3)**2
      ctang = dist/(2.0d0*r(1)*r(2))
      arg2 = (r(1)**2 + (r(2)/2.0d0)**2 - r(1)*r(2)*ctang)
      if(arg2 .lt. 0.0d0) arg2 = 1.0d-28
      rfh2 = sqrt(arg2)
      rfh22 = rfh2**2
      g = .2d0
      g2 = g**2
      rat = rfh22/(g2+rfh22)
      dem = g2 + rfh22
      drat = 2.0d0*rfh2*(g2/dem**2)
c    these are various terms for evaluating deriv.
      dctdr1 = 1.0d0/r(2) - dist/(2.0d0*r(2)*r(1)**2)
      dctdr2 = 1.0d0/r(1) - dist/(2.0d0*r(1)*r(2)**2)
      dctdr3 = -r(3)/(r(1)*r(2))
      tem = .5d0/sqrt(rfh2)
      drhfr1 = (2.0d0*r(1) - r(2)*ctang - r(1)*r(2)*dctdr1)*tem
      drhfr2 = (r(2) - r(1)*ctang - r(1)*r(2)*dctdr2)*tem
      drhfr3 = (-r(1)*r(2)*dctdr3)*tem
      if (lchi.ne.0) write (6,100) deg
  100 format (74x,f10.4)
      if (deg.gt.180.0d0)deg=deg-180.0d0
      if (deg.lt.0.0d0)  deg=-deg
      if (deg.gt.90.0d0) deg=180.0d0-deg
      if (deg.lt.0.0d0) stop 89
c     write (6,9998) phi,deg
c9998 format (1x,'phi,deg',1p2d20.10)
      if (deg.gt.deg1) go to 200
      if (lchi.ne.0) write (6,100) deg
      fphi=z0
      fder=0.0d0
      ds1dr1 = 0.0d0
      ds1dr2 = 0.0d0
      ds1dr3 = 0.0d0
      return
  200 if (deg.gt.20.0d0) go to 300
      degdif=deg-10.0d0
      dd2=degdif*degdif
      dd3 = degdif*dd2
      fphi=z0 +rat*(1.15d-4*dd2    -6.0d-6*dd3)
      fder=         2.30d-4*degdif -1.8d-5*dd2
      fder = fder*tdeg*rat
      ds1dr1 = ((fphi - z0)/rat)*drat*drhfr1
      ds1dr2 = ((fphi - z0)/rat)*drat*drhfr2
      ds1dr3 = ((fphi - z0)/rat)*drat*drhfr3
      return
  300 if (deg.gt.60.0d0) go to 400
      degdif=deg-41.0d0
      fphi=z0 + rat*(0.016d0+0.0005d0*degdif)
      fder=         0.0005d0
      fder = fder*tdeg*rat
      ds1dr1 = ((fphi - z0)/rat)*drat*drhfr1
      ds1dr2 = ((fphi - z0)/rat)*drat*drhfr2
      ds1dr3 = ((fphi - z0)/rat)*drat*drhfr3
      return
  400 if (deg.gt.90.0d0) go to 500
      sindeg=sin(phi)
      s2=sindeg*sindeg
      fphi=z0 + rat*(0.00069d0+3.308d-2*s2)
      cosdeg=cos(phi)
      fder=           tdeg*6.616d-2*sindeg*cosdeg
      fder = fder *  rat
      ds1dr1 = ((fphi - z0)/rat)*drat*drhfr1
      ds1dr2 = ((fphi - z0)/rat)*drat*drhfr2
      ds1dr3 = ((fphi - z0)/rat)*drat*drhfr3
      return
  500 stop 90
      end
