anchor.diff:      end if
     end function lbfgsb_minimize
   
  +  ! Interprets the various task strings coming out of L-BFGS-B.  Maps
  +  ! them to concrete, disjoint states which are easier and less
  +  ! ambiguous to handle.  Also extracts the message, if any.
  +  !
  +  ! The concrete, disjoint states are START, EVAL_FG, NEW_X,
  +  ! CONVERGENCE, ABNORMAL, WARNING, ERROR_USAGE, ERROR_INTERNAL
  +  ! padded to 'state_size' characters.
  +  subroutine interpret_task(task, state, message)
  +    character(len=*), intent(in) :: task
  +    character(len=state_size), intent(out) :: state
  +    character(len=*), intent(out) :: message
  +
  +    ! Fill the state and message with spaces
  +    state = ' '
  +    message = ' '
  +
  +    ! Discriminate the tasks based on the initial characters
  +    select case (task(1:5))
  +    case ('START')
  +       state = 'START'
  +    case ('FG', 'FG_LN', 'FG_ST')
  +       state = 'EVAL_FG'
  +    case ('NEW_X')
  +       state = 'NEW_X'
  +    case ('CONVE')
  +       state = 'CONVERGENCE'
  +       message = task(14:)
  +    case ('ABNOR')
  +       state = 'ABNORMAL'
  +       message = task
  +    case ('WARNI')
  +       ! All the warnings appear to relate only to the line search code
  +       ! and so may not get back to here
  +       state = 'WARNING'
  +       message = task(10:)
  +    case ('ERROR')
  +       ! It appears all the reported errors are usage errors, rather
  +       ! than, say division by zero
  +       state = 'ERROR_USAGE'
  +       message = task(8:)
  +    case default
  +       ! Unrecognized task
  +       state = 'ERROR_INTERNAL'
  +       message = 'Error: Unrecognized task: '//task
  +    end select
  +
  +    ! Assigned task values
  +    ! 'FG_START'
  +    ! 'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'
  +    ! 'ABNORMAL_TERMINATION_IN_LNSRCH'
  +    ! 'RESTART_FROM_LNSRCH'
  +    ! 'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'
  +    ! 'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'
  +    ! 'ERROR: N .LE. 0'
  +    ! 'ERROR: M .LE. 0'
  +    ! 'ERROR: FACTR .LT. 0'
  +    ! 'ERROR: INVALID NBD'
  +    ! 'ERROR: NO FEASIBLE SOLUTION'
  +    ! 'FG_LNSRCH'
  +    ! 'NEW_X'
  +    ! Line search
  +    ! 'ERROR: STP .LT. STPMIN'
  +    ! 'ERROR: STP .GT. STPMAX'
  +    ! 'ERROR: INITIAL G .GE. ZERO'
  +    ! 'ERROR: FTOL .LT. ZERO'
  +    ! 'ERROR: GTOL .LT. ZERO'
  +    ! 'ERROR: XTOL .LT. ZERO'
  +    ! 'ERROR: STPMIN .LT. ZERO'
  +    ! 'ERROR: STPMAX .LT. STPMIN'
  +    ! 'FG'
  +    ! 'WARNING: ROUNDING ERRORS PREVENT PROGRESS'
  +    ! 'WARNING: XTOL TEST SATISFIED'
  +    ! 'WARNING: STP = STPMAX'
  +    ! 'WARNING: STP = STPMIN'
  +    ! 'CONVERGENCE'
  +    !
  +    ! Compared task values
  +    ! 'START'
  +    ! 'ERROR'
  +    ! 'FG_LN'
  +    ! 'NEW_X'
  +    ! 'FG_ST'
  +    ! 'STOP'
  +    ! 'CPU'
  +  end subroutine interpret_task
  +
     ! Converts Fortran strings to C strings ensuring length bounds, null
     ! chars, and all that.
     subroutine convert_f_c_string(string_f, string_c_length, string_c)
  
positive.code:      !
       ! 'callback_data': Arbitrary data to be used by the callback.
       !
       ! 'error_message_length': Usable length of 'error_message_c'
       !    buffer.  Recommend at least 100.
       !
       ! 'error_message': Returns a message explaining the exit status.
       !
       ! 'error_code': Returns the exit status code, one of the
       !    LBFGSB_STATUS_* constants defined in enumeration above.
       function objective_gradient_c(dim, point, objective_function_gradient, &
            callback_data, error_message_length, error_message) &
            result(error_code) bind(c)
         use, intrinsic :: iso_c_binding
         implicit none
         integer(c_int), intent(in), value :: dim
         real(c_double), intent(in) :: point(dim)
         real(c_double), intent(out) :: objective_function_gradient(dim)
         type(c_ptr), intent(in), value :: callback_data
         integer(c_int), intent(in), value :: error_message_length
         character(c_char), intent(out) :: &
              error_message(error_message_length)
         integer(c_int) :: error_code
       end function objective_gradient_c
  
    end interface
  
  contains
  
  
negative.code:     ! certain values)
      print_control = debug_c - 1
  
      ! Initialize the state and task
      state = 'START'
      task = state
  
      ! Loop to do tasks and coordinate the optimization
      do while ( &
           state(1:7) == 'EVAL_FG' .or. &
           state(1:5) == 'NEW_X' .or. &
           state(1:7) == 'WARNING' .or. &
           state(1:5) == 'START')
  
         ! Call L-BFGS-B code
         call setulb(dim_c, approximation_size_c, point, &
  