anchor.diff:            ! Call objective function
             status_c = func_pointer(dim_c, point, func_value, &
                  callback_data, status_message_c, status_message_length_c)
  +          ! Terminate optimization on any error
             if (status_c /= LBFGSB_STATUS_SUCCESS) exit
   
             ! Call objective function gradient
             status_c = grad_pointer(dim_c, point, grad_value, &
                  callback_data, status_message_c, status_message_length_c)
  +          ! Terminate optimization on any error
             if (status_c /= LBFGSB_STATUS_SUCCESS) exit
          case ('WARNING')
             ! TODO handle warnings
          case ('NEW_X')
  -          ! TODO handle logging
  +          ! Call the logging function if one was given
  +          if (c_associated(log_function)) then
  +             ! Compute some of the values not otherwise available
  +             step_length = real_state(4) * real_state(14)
  +             f_delta = abs(real_state(2) - func_value) / &
  +                  max(abs(real_state(2)), abs(func_value), 1d0)
  +             ! Log the information
  +             status_c = log_pointer( &
  +                  int_state(30), int_state(36), int_state(34), step_length, &
  +                  dim_c, point, func_value, grad_value, &
  +                  f_delta, real_state(3), real_state(13), g_tolerance_c &
  +                  )
  +             ! Terminate optimization on any error
  +             if (status_c /= LBFGSB_STATUS_SUCCESS) exit
  +          end if
          end select
       end do
       ! End optimization
  
positive.code:   public objective_function_c, objective_gradient_c
    abstract interface
  
       ! Signature of objective function C callback.
       !
       ! 'dim': Dimensionality of the optimization space; the size of the
       !    arrays used for points, gradients.
  
negative.code:          2 * approximation_size_c * dim_c + 5 * dim_c + &
           11 * approximation_size_c ** 2 + 8 * approximation_size_c &
           )
      ! Other locals
      real(dp) :: step_length, f_delta
  
      ! Convert inputs from C types to Fortran types
      call c_f_procpointer(func, func_pointer)
      call c_f_procpointer(grad, grad_pointer)
      if (c_associated(log_function)) &
           call c_f_procpointer(log_function, log_pointer)
      ! Copy initial_point_c to point because point is written to
      point = initial_point_c
      ! Other arrays do not need to be copied because their binary
      ! representations are compatible (but I'm not sure if this will
      ! always be the case).  Plus the other arrays are only read, not
      ! written.
  