anchor.diff:  
   ! === Helper function.
   ! Given a point, look for a better one nearby, one coord at a time.
  -double precision function best_nearby(delta, point, prevbest, nvars)
  -    use proto__, only: VARS, f
  +real(DP) function best_nearby(delta, point, prevbest, nvars)
  +    use proto__, only: DP, VARS, f
   
       implicit none
   
       ! Returns: The objective function value at a nearby.
   
       ! Arg. The delta between prevbest and point.
  -    double precision, intent(inout) :: delta(:)
  +    real(DP), intent(inout) :: delta(:)
   
       ! Arg. The coordinate from where to begin.
  -    double precision, intent(inout) :: point(:)
  +    real(DP), intent(inout) :: point(:)
   
       ! Arg. The previous best-valued coordinate.
  -    double precision, intent(in) :: prevbest
  +    real(DP), intent(in) :: prevbest
   
       ! Arg. The number of variables.
       integer, intent(in) :: nvars
   
  -    double precision :: minf
  -    double precision :: z(VARS)
  -    double precision :: ftmp
  +    real(DP) :: minf
  +    real(DP) :: z(VARS)
  +    real(DP) :: ftmp
   
       integer :: i
   
  
positive.code:     ! Function prototypes.
      interface
          ! The objective function f(x,n).
          double precision function f(x, n)
              double precision, intent(in)     :: x(:)
              integer, intent(inout), optional :: n
          end function f
  
          ! The helper function best_nearby(...).
          double precision function best_nearby(delta, point, prevbest, nvars)
              double precision, intent(inout) :: delta(:)
              double precision, intent(inout) :: point(:)
              double precision, intent(in)    :: prevbest
              integer, intent(in)             :: nvars
          end function best_nearby
  
          ! The main optimization function hooke(...).
          integer function hooke(nvars, startpt, endpt, rho, epsilon, itermax)
              integer, intent(in)           :: nvars
              double precision, intent(in)  :: startpt(:)
              double precision, intent(out) :: endpt(:)
              double precision, intent(in)  :: rho
              double precision, intent(in)  :: epsilon
              integer, intent(in)           :: itermax
          end function hooke
      end interface
  end module proto__
  
  ! === The user-supplied objective function f(x,n).
  double precision function f(x, n)
      use proto__, only: funevals
  
      implicit none
  
      ! Returns: The objective function value.
  
      ! Arg. The point at which f(x) should be evaluated.
      double precision, intent(in) :: x(:)
  
      ! Arg. The number of coordinates of x.
      integer, intent(inout), optional :: n
  
  #ifndef WOODS
  ! Rosenbrock's classic parabolic valley ("banana") function.
      double precision :: a
      double precision :: b
      double precision :: c
  
      funevals = funevals + 1
  
  
negative.code: module proto__
      implicit none
  
      ! Constant. The double precision kind for real type values.
      integer, parameter :: DP = kind(1.d0)
  
      ! Constant. The maximum number of variables.
      integer, parameter :: VARS = 250
  
      ! Constant. The stepsize geometric shrink.
      real(DP), parameter :: RHO_BEGIN = 0.5
  
      ! The Hooke & Jeeves algorithm works reasonably well on Rosenbrock's
      ! function, but can fare worse on some standard test functions,
      ! depending on rho. Here is an example that works well when rho = 0.5,
      ! but fares poorly with rho = 0.6, and better again with rho = 0.8.
      real(DP), parameter :: RHO_WOODS = 0.6
  
      ! Constant. The ending value of stepsize.
      real(DP), parameter :: EPSMIN = 1e-6
  
      ! Constant. The maximum number of iterations.
      integer, parameter :: IMAX = 5000
  