anchor.diff:         integer(c_int) :: status
        end function objective_gradient_c
   
  +     ! Signature of logging C callback that (optionally) logs
  +     ! information about each iteration in the optimization.
  +     !
  +     ! 'iteration': Number of current iteration.
  +     !
  +     ! 'fg_evals': Number of evaluations in this iteration.  Each
  +     !    evaluation is both a function and a gradient call.
  +     !
  +     ! 'fg_evals_total': Total number of evaluations so far.
  +     !
  +     ! 'step': Length of the step taken towards the minimum in this
  +     !    iteration.
  +     !
  +     ! 'dim': Dimensionality of the optimization space; the size of the
  +     !    arrays used for points, gradients.
  +     !
  +     ! 'x': Current point in optimization space.
  +     !
  +     ! 'f': Current objective function value.
  +     !
  +     ! 'g': Current objective function gradient.
  +     !
  +     ! 'f_delta': Change in objective function value over this
  +     !    iteration.
  +     !
  +     ! 'f_delta_bound': Upper bound on 'f_delta' required for
  +     !    convergence.
  +     !
  +     ! 'g_norm': Infinity norm of the projected gradient.
  +     !
  +     ! 'g_norm_bound': Upper bound on 'g_norm' required for convergence.
  +     !
  +     ! 'error': Returns the error status, one of LBFGSB_STATUS_SUCCESS
  +     !    or LBFGSB_STATUS_INTERNAL_ERROR.  Returning an error will take
  +     !    down the whole optimization, so only return an error if the
  +     !    optimization cannot continue.  Logging issues may or may not
  +     !    be that serious depending on the application.
  +     function log_function_c(iteration, fg_evals, fg_evals_total, step, &
  +          dim, x, f, g, &
  +          f_delta, f_delta_bound, g_norm, g_norm_bound) &
  +          result(error) bind(c)
  +       use, intrinsic :: iso_c_binding
  +       implicit none
  +       integer(c_int), intent(in), value :: iteration, fg_evals, &
  +            fg_evals_total, dim
  +       real(c_double), intent(in), value :: step, f, &
  +            f_delta, f_delta_bound, g_norm, g_norm_bound
  +       real(c_double), intent(in) :: x(dim), g(dim)
  +       integer(c_int) :: error
  +     end function log_function_c
  +
     end interface
   
     ! Private constants
  
positive.code:     ! Fortran versions of arguments
      procedure(objective_function_c), pointer :: func_pointer
      procedure(objective_gradient_c), pointer :: grad_pointer
      real(dp) :: point(dim_c)
      ! Variables and memory for L-BFGS-B
      integer :: print_control
  
negative.code:        initial_point_c, &
         ! Result
         min_x_c, min_f_c, min_g_c, iters_c, evals_c, &
         ! Printing, logging
         print_control_c, log_function, &
         ! Exit status
         status_message_c, status_message_length_c) &
         result(status_c) bind(c)
  
      implicit none
  
      ! Signature
      type(c_funptr), intent(in), value :: func, grad, log_function
      type(c_ptr), intent(in), value :: callback_data
      integer(c_int), intent(in), value :: dim_c, approximation_size_c, &
           print_control_c, status_message_length_c
      real(c_double), intent(in), value :: f_tolerance_c, g_tolerance_c
      integer(c_int), intent(in) :: bounds_control_c(dim_c)
      real(c_double), intent(in) :: lower_bounds_c(dim_c), &
  