ccccccccccccccccccccccccc     Program 2.9     cccccccccccccccccccccccccc
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c                                                                      c
c Please Note:                                                         c
c                                                                      c
c (1) This computer program is part of the book, "An Introduction to   c
c     Computational Physics," written by Tao Pang and published and    c
c     copyrighted by Cambridge University Press in 1997.               c
c                                                                      c
c (2) No warranties, express or implied, are made for this program.    c
c                                                                      c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
      PROGRAM BOND
C
C Main program to calculate the bond length of NaCl.
C
      COMMON /CSTNT/ E2,A0,R0
      DL = 1.0E-06
      A0 = 1090.0
      R0 = 0.33
      E2 = 14.4
      X0 = 2.0
      DX = 0.1
      CALL M_SECANT (DL,X0,DX,ISTEP)
      WRITE (6,999) ISTEP,X0,DX
      STOP
  999 FORMAT (I4,2F16.8)
      END
C
      SUBROUTINE M_SECANT (DL,X0,DX,ISTEP)
C
C Subroutine for the root of f(x) = dg(x)/dx = 0 with the
C secant method with the search toward the maximum of g(x).
C
      ISTEP = 0
      G0 = G(X0)
      X1 = X0+DX
      G1 = G(X1)
      IF(G1.LT.G0) X1 = X0-DX
      DO    100  WHILE (ABS(DX).GT.DL)
        D  = F(X1)-F(X0)
        DX = -(X1-X0)*F(X1)/D
        X2 = X1+DX
        G2 = G(X2)
        IF(G2.LT.G1) X2 = X1-DX
        X0 = X1
        X1 = X2
        G1 = G2
        ISTEP = ISTEP+1
  100 END DO
      X0 = X2
      RETURN
      END
C
      FUNCTION G(X)
      COMMON /CSTNT/ E2,A0,R0
        G  = E2/X-A0*EXP(-X/R0)
      RETURN
      END
C
      FUNCTION F(X)
      COMMON /CSTNT/ E2,A0,R0
        F  = E2/(X*X)-A0*EXP(-X/R0)/R0
      RETURN
      END
