anchor.diff:  !     the square of this function.
   !
           curv = zero
  -        do 160 k = 1, npt
  +        do k = 1, npt
               temp = zero
  -            do 150 j = 1, n
  -150         temp = temp + xpt (k, j) * w (j)
  -160     curv = curv + hcol (k) * temp * temp
  +            do j = 1, n
  +                temp = temp + xpt (k, j) * w (j) 
  +            end do
  +            curv = curv + hcol (k) * temp * temp
  +        end do
           if (iflag == 1) curv = - curv
           if (curv >-gw .and. curv <-const*gw) then
               scale = - gw / curv
  -            do 170 i = 1, n
  +            do i = 1, n
                   temp = xopt (i) + scale * w (i)
  -170         xalt (i) = max (sl(i), min(su(i), temp))
  +                xalt (i) = max (sl(i), min(su(i), temp))
  +            end do
               cauchy = (half*gw*scale) ** 2
           else
               cauchy = (gw+half*curv) ** 2
  
positive.code:                 bmat (jp, j) = one / ptsaux (1, j)
                  bmat (j+npt, j) = - half * ptsaux (1, j) ** 2
              end if
  60      continue
  !
  !     Set any remaining identifiers with their nonzero elements of ZMAT.
  !
          if (npt >= n+np) then
              do 70 k = 2 * np, npt
                  iw = (real(k-np, wp)-half) / real (n, wp)
                  ip = k - np - iw * n
                  iq = ip + iw
  
negative.code: !
  210     call altmov (n, npt, xpt, xopt, bmat, zmat, ndim, sl, su, kopt, knew, adelt, &
         & xnew, xalt, alpha, cauchy, w, w(np), w(ndim+1))
          do i = 1, n
              d (i) = xnew (i) - xopt (i)
          end do
  !
  !     Calculate VLAG and BETA for the current choice of D. The scalar
  !     product of D with XPT(K,.) is going to be held in W(NPT+K) for
  !     use when VQUAD is calculated.
  !
  230     do k = 1, npt
              suma = zero
              sumb = zero
              sum = zero
              do j = 1, n
                  suma = suma + xpt (k, j) * d (j)
                  sumb = sumb + xpt (k, j) * xopt (j)
                  sum = sum + bmat (k, j) * d (j)
              end do
              w (k) = suma * (half*suma+sumb)
              vlag (k) = sum
              w (npt+k) = suma
          end do
          beta = zero
          do jj = 1, nptm
              sum = zero
              do k = 1, npt
                  sum = sum + zmat (k, jj) * w (k)
              end do
              beta = beta - sum * sum
              do k = 1, npt
                  vlag (k) = vlag (k) + sum * zmat (k, jj)
              end do
          end do
          dsq = zero
          bsum = zero
          dx = zero
          do j = 1, n
              dsq = dsq + d (j) ** 2
              sum = zero
              do k = 1, npt
                  sum = sum + w (k) * bmat (k, j)
              end do
              bsum = bsum + sum * d (j)
              jp = npt + j
              do i = 1, n
                  sum = sum + bmat (jp, i) * d (i)
              end do
              vlag (jp) = sum
              bsum = bsum + sum * d (j)
              dx = dx + d (j) * xopt (j)
          end do
          beta = dx * dx + dsq * (xoptsq+dx+dx+half*dsq) + beta - bsum
          vlag (kopt) = vlag (kopt) + one
  !
  