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

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

extern "C"
{
  static void (NAG_CALL f)(void* &ad_handle,
                           const nagad_t1w_w_rtype &x,
                           nagad_t1w_w_rtype &z,
                           Integer iuser[],
                           nagad_t1w_w_rtype ruser[]);
}

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

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

  // Skip first line of data file
  string mystr;
  getline (cin, mystr);

  // Read problem parameters
  double            ar, br, epsr, etar, ruserr;
  cin >> ar;
  cin >> br;
  cin >> epsr;
  cin >> etar;
  cin >> ruserr;

  // Create AD configuration data object
  Integer ifail = 0;
  void    *ad_handle = 0;
  x10aa_t1w_f_(ad_handle,ifail);

  nagad_t1w_w_rtype a, b, eps, eta, ruser[1];
  a = ar;
  b = br;
  eps = epsr;
  eta = etar;
  ruser[0] = ruserr;

  // Call AD routine
  nagad_t1w_w_rtype x;
  Integer           iuser[1];

  dco::derivative(ruser[0]) = 1.0;
  ifail = 0;
  c05ay_t1w_f_(ad_handle,a,b,eps,eta,f,x,iuser,ruser,ifail);

  cout.setf(ios::scientific,ios::floatfield);
  cout.precision(5);

  cout << " Solution, x = " << dco::value(x) << endl;
  cout << " d/druser(x) = " << dco::derivative(x) << endl;

  // Remove computational data object
  x10ab_t1w_f_(ad_handle,ifail);

  return exit_status;
}

static void (NAG_CALL f)(void* &ad_handle,
                         const nagad_t1w_w_rtype &x,
                         nagad_t1w_w_rtype &z,
                         Integer iuser[],
                         nagad_t1w_w_rtype ruser[])
{
  z = exp(-x) - x*ruser[0];
  return;
}