anchor.diff:      end do
   
       ! Analyze task and error state to see how to return
  -    ! TODO
  -
  -    ! Convert outputs from Fortran types to C types
  -    min_x_c = point
  -    min_f_c = func_value
  -    min_g_c = grad_value
  -    error_code_c = 0
  +    if (error_code_c == 0) then
  +       ! Objective and gradient evaluations were OK but L-BFGS-B may not
  +       ! be.  Regardless, take what we can from the outputs.
  +       min_x_c = point
  +       min_f_c = func_value
  +       min_g_c = grad_value
  +
  +       ! Check for normal or problematic termination
  +       if (task(1:4) == 'CONV') then
  +          ! Converged.  Normal termination.
  +          error_code_c = 0
  +       else if (task(1:4) == 'ABNO') then
  +          ! Could not satisfy termination conditions.  Result is best
  +          ! approximation.
  +          error_code_c = 1
  +       else if (task(1:5) == 'ERROR') then
  +          ! Runtime or user error
  +          error_code_c = 2
  +       else
  +          ! Unrecognized task
  +          error_code_c = 3
  +       end if
  +    else
  +       ! There was a problem computing the objective or the gradient.
  +       ! Fill C types with zeros so callers do not act unwittingly on
  +       ! garbage.
  +       min_x_c = 0d0
  +       min_f_c = 0d0
  +       min_g_c = 0d0
  +    end if
     end function lbfgsb_minimize
   
   end module lbfgsb_c
  
positive.code:     upper_bounds = upper_bounds_c
      point = initial_point_c
  
      ! Translate f_tolerance to f_factor
      f_factor = f_tolerance / 0d0  ! TODO
  
      ! Translate debug_c to print_control
      print_control = debug_c  / 0  ! TODO
  
      ! Initialize the task
      task = 'START'
  
negative.code: contains
  
    ! L-BFGS-B
    ! TODO document
    function lbfgsb_minimize( &
         ! Callbacks
         func, grad, callback_data, &
  