anchor.diff:         LocateCandidate, MAX_LOCATE_SUBDIVISIONS, LOCATE_STD_CAP, &
          SQRT_PREC, REDUCE_THRESHOLD, scalar_func, dqagse, &
          specialize_curve_generic, specialize_curve_quadratic, &
  -       subdivide_nodes_generic, split_candidate, projection_error, can_reduce
  +       subdivide_nodes_generic, split_candidate, allocate_candidates, &
  +       update_candidates, projection_error, can_reduce
     public &
          CurveData, LOCATE_MISS, LOCATE_INVALID, evaluate_curve_barycentric, &
          evaluate_multi, specialize_curve, evaluate_hodograph, subdivide_nodes, &
  
positive.code:     ! Compute the s-parameter as the mean of the **start** and
      ! **end** parameters.
      allocate(s_params(2 * num_candidates))
      s_params(:num_candidates) = candidates(:num_candidates)%start
      s_params(num_candidates + 1:) = candidates(:num_candidates)%end_
      s_approx = sum(s_params) / (2 * num_candidates)
  
      std_dev = sqrt(sum((s_params - s_approx)**2) / (2 * num_candidates))
  
negative.code: 
    end subroutine newton_refine
  
    subroutine split_candidate( &
         num_nodes, dimension_, candidate, num_next_candidates, next_candidates)
  
      integer(c_int), intent(in) :: num_nodes, dimension_
      type(LocateCandidate), intent(in) :: candidate
      integer(c_int), intent(in) :: num_next_candidates
      type(LocateCandidate), intent(inout) :: next_candidates(:)
  
      ! Allocate the new nodes and call sub-divide.
      ! NOTE: This **assumes** but does not check that if the nodes are
      !       allocated, they are also the correct shape.
      if (.NOT. allocated(next_candidates(num_next_candidates - 1)%nodes)) then
         allocate(next_candidates(num_next_candidates - 1)%nodes(num_nodes, dimension_))
      end if
      if (.NOT. allocated(next_candidates(num_next_candidates)%nodes)) then
         allocate(next_candidates(num_next_candidates)%nodes(num_nodes, dimension_))
      end if
  
      call subdivide_nodes( &
           num_nodes, dimension_, candidate%nodes, &
           next_candidates(num_next_candidates - 1)%nodes, &
           next_candidates(num_next_candidates)%nodes)
  
      ! Left half.
      next_candidates(num_next_candidates - 1)%start = candidate%start
      next_candidates(num_next_candidates - 1)%end_ = ( &
           0.5_dp * (candidate%start + candidate%end_))
      ! Right half.
      next_candidates(num_next_candidates)%start = ( &
           next_candidates(num_next_candidates - 1)%end_)
      next_candidates(num_next_candidates)%end_ = candidate%end_
  
    end subroutine split_candidate
  
    subroutine allocate_candidates(num_candidates, next_candidates)
      integer(c_int), intent(in) :: num_candidates
      type(LocateCandidate), allocatable, intent(inout) :: next_candidates(:)
  
      if (allocated(next_candidates)) then
         if (size(next_candidates) < 2 * num_candidates) then
            deallocate(next_candidates)
            allocate(next_candidates(2 * num_candidates))
         end if
      else
         allocate(next_candidates(2 * num_candidates))
      end if
  
    end subroutine allocate_candidates
  
    subroutine update_candidates( &
         num_nodes, dimension_, point, num_candidates, candidates, &
         num_next_candidates, next_candidates)
  
      integer(c_int), intent(in) :: num_nodes, dimension_
      real(c_double), intent(in) :: point(1, dimension_)
      integer(c_int), intent(in) :: num_candidates
      type(LocateCandidate), intent(in) :: candidates(:)
      integer(c_int), intent(inout) :: num_next_candidates
      type(LocateCandidate), allocatable, intent(inout) :: next_candidates(:)
      ! Variables outside of signature.
      integer(c_int) :: cand_index
      logical(c_bool) :: predicate
  
      ! Allocate maximum amount of space needed.
      call allocate_candidates(num_candidates, next_candidates)
  
      do cand_index = 1, num_candidates
         call contains_nd( &
              num_nodes, dimension_, candidates(cand_index)%nodes, &
              point(1, :), predicate)
         if (predicate) then
            num_next_candidates = num_next_candidates + 2
            call split_candidate( &
                 num_nodes, dimension_, candidates(cand_index), &
                 num_next_candidates, next_candidates)
         end if
      end do
  
    end subroutine update_candidates
  
    subroutine locate_point( &
         num_nodes, dimension_, nodes, point, s_approx) &
  