NAG Library Manual, Mark 27.3
Interfaces:  FL   CL   CPP   AD 

NAG AD Library Introduction
Example description
/* nag::ad::e01bf Passive Example Program.
 */

#include <dco.hpp>
#include <iostream>
#include <nagad.h>

// Function which calls NAG AD routines.
//  Evaluates a piecewise cubic Hermite interpolant and computes function value
//  at point xint.
template <typename T> void func(const T &xint, T &fint);

int main()
{
  std::cout << "nag::ad::e01bf Passive Example Program Results\n\n";

  // Point to interpolate at
  double xint = 8.4;
  // Interpolated function value
  double fint;

  // Call NAG Lib
  func(xint, fint);

  // Print outputs
  std::cout.setf(std::ios::scientific, std::ios::floatfield);
  std::cout.precision(6);
  std::cout << " fint = " << fint << std::endl;
  std::cout << std::endl;

  return 0;
}

// Function which calls NAG AD Library routines
template <typename T> void func(const T &xint, T &fint)
{

  // Create AD configuration data object
  Integer           ifail = 0;
  nag::ad::handle_t ad_handle;

  // Initialize abscissa and ordinate data
  std::vector<T> x{7.99, 8.09, 8.19, 8.70, 9.20, 10.00, 12.00, 15.00, 20.00};
  std::vector<T> f{0.00000E+0, 0.27643E-4, 0.43750E-1, 0.16918E+0, 0.46943E+0,
                   0.94374E+0, 0.99864E+0, 0.99992E+0, 0.99999E+0};

  // Local output of e01be; approximation of derivatives at points x
  std::vector<T> d(x.size());
  ifail = 0;
  nag::ad::e01be(ad_handle, x.size(), x.data(), f.data(), d.data(), ifail);

  // Interpolate at point x
  ifail = 0;
  nag::ad::e01bf(ad_handle, x.size(), x.data(), f.data(), d.data(), 1, &xint,
                 &fint, ifail);

  ifail = 0;
}