NAG Library Manual, Mark 30.1
```/* D01RG_A1W_F C++ Header Example Program.
*
* Copyright 2024 Numerical Algorithms Group.
* Mark 30.1, 2024.
*/

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

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

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

// The example function can raise various exceptions - it contains
// a division by zero and a log singularity - although its integral
// is well behaved.

Integer exmode[3], exmode_old[3];
nag_get_ieee_exception_mode(exmode_old);
// Save the original halting mode.

// Turn exception halting mode off for the three common exceptions.
for (int i = 0; i < 3; i++)
{
exmode[i] = 0;
}
nag_set_ieee_exception_mode(exmode);

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

double ar, br, epsabsr, epsrelr;
cin >> ar;
cin >> br;
cin >> epsabsr;
cin >> epsrelr;

a      = ar;
b      = br;
epsabs = epsabsr;
epsrel = epsrelr;

dco::ga1s<double>::global_tape = dco::ga1s<double>::tape_t::create();

// Create AD configuration data object
Integer           ifail = 0;

// Register variables to differentiate w.r.t.
dco::ga1s<double>::global_tape->register_variable(a);
const Integer &         nx,
Integer &               iflag)
{
// dco/c++ used here to perform AD of the following
for (int i = 0; i < nx; i++)
{
tmp1  = 10.0 * (1.0 - x[i]);
tmp2  = sin(x[i]) / x[i];
fv[i] = tmp2 * log(tmp1);
}
};
Integer           nevals;
double            inc = 1.0;
ifail                 = -1;
if (ifail < 0)
{
cout << "\n ** nag::ad::d01rg failed error exit ifail = " << ifail << endl;
goto END;
}
// Print inputs and primal outputs.
cout << "\n lower limit of integration (a) = " << ar << endl;
cout << " upper limit of integration (b) = " << br << endl;
cout << " absolute accuracy requested    = " << epsabsr << endl;
cout << " relative accuracy requested    = " << epsrelr << endl;
cout.setf(ios::scientific, ios::floatfield);
cout.precision(4);
if (ifail >= 0)
{
cout << "\n approximation to the integral  : " << dco::value(dinest)
<< endl;
cout << " estimate of the absolute error : " << dco::value(errest) << endl;
cout << " number of function evaluations : " << nevals << endl;
}

// Setup evaluation of derivatives via adjoints.
dco::derivative(dinest) += inc;
ifail                                              = 0;
dco::ga1s<double>::global_tape->sparse_interpret() = true;

cout << "\n Derivatives calculated: First order adjoints\n";
cout << " Computational mode    : algorithmic\n";

// Get derivatives

cout << "\n Derivative of solution w.r.t to lower limit:\n";
cout << " d/da(x) = " << dco::derivative(a) << endl;

END:

dco::ga1s<double>::tape_t::remove(dco::ga1s<double>::global_tape);

// Restore the original halting mode
nag_set_ieee_exception_mode(exmode_old);

return exit_status;
}
```