Example description
/* E01AA_T1W_F C++ Header Example Program.
 *
 * Copyright 2019 Numerical Algorithms Group.
 * Mark 27, 2019.
 */

// #define USE_DCO

#include "dco_light.hpp"

#include <nag.h>
#include <nagad.h>
#include <stdio.h>
#include <math.h>
#include <string>
#include <iostream>
using namespace std;

int main(void)
{
  // Scalars
  int               exit_status = 0;

  cout << "E01AA_T1W_F C++ Header Example Program Results\n\n";

  // Skip first line of data file
  string mystr;
  getline (cin, mystr);
  // Read number of data points
  Integer n;
  cin >> n;

  // Allocate arrays for data and interpolant
  nagad_t1w_w_rtype x,  *a = 0, *b = 0, *c = 0;
  double            xr, fx, *ar = 0, *br = 0, *dx = 0;
  Integer           n1, n2;
  n1 = n + 1;
  n2 = n*(n+1)/2;
  ar = new double [n1];
  br = new double [n1];
  dx = new double [n1];
  a  = new nagad_t1w_w_rtype [n1];
  b  = new nagad_t1w_w_rtype [n1];
  c  = new nagad_t1w_w_rtype [n2];

  cin >> xr;

  for (int i= 0; i < n1; i++) {
    cin >> ar[i];
  }
  for (int i= 0; i < n1; i++) {
    cin >> br[i];
  }
  
  // Create AD configuration data object
  Integer ifail = 0;
  void    *ad_handle = 0;
  x10aa_t1w_f_(ad_handle,ifail);

  for (int i=0; i<n1; ++i) {
    x = xr;
    for (int j= 0; j < n1; j++) {
      a[j] = ar[j];
      b[j] = br[j];
    }
    
    double inc = 1.0;
    nagad_t1w_inc_derivative(&a[i],inc);

    // Call the AD routine
    ifail = 0;
    e01aa_t1w_f_(ad_handle,a,b,c,n,x,ifail);
    
    if (i==0) {
      fx = nagad_t1w_get_value(c[n2-1]);
    }

    double zero = 0.0;
    nagad_t1w_set_derivative(&a[i],zero);
      
    dx[i] = nagad_t1w_get_derivative(c[n2-1]);
  }

  cout.setf(ios::scientific,ios::floatfield);
  cout.precision(5);
  cout << "\n Interpolation point = ";
  cout.width(12);cout << xr << endl;
  cout << "\n Function value at interpolation point = ";
  cout.width(12);cout << fx << endl;
  
  cout << "\n Derivatives calculated: First order tangents\n";
  cout << " Computational mode    : algorithmic\n";
  
  // Get derivatives
  cout << "\n Derivatives of fitted value w.r.t. x values:\n";
  cout << "  j         d/da(j)\n";
  for (int j=0; j < n1; j++) {
    cout.width(3); cout << j+1 << "     ";
    cout.width(12); cout << dx[j] << endl;
  }
    
  // Remove computational data object
  x10ab_t1w_f_(ad_handle,ifail);

  delete [] ar;
  delete [] br;
  delete [] dx;
  delete [] a;
  delete [] b;
  delete [] c;
  return exit_status;
}