NAG Library Manual, Mark 27.2
```/* D02PS_A1W_F C++ Header Example Program.
*
* Copyright 2021 Numerical Algorithms Group.
*
* Mark 27.2, 2021.
*/

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

#ifdef __cplusplus
extern "C"
{
#endif
static void NAG_CALL f(void *&                  ad_handle,
const Integer &          n,
Integer                  iuser[],
#ifdef __cplusplus
}
#endif

int main(void)
{
const Integer n = 2, npts = 16, nwant = 1;
const Integer liwsav = 130;
const Integer lrwsav = 350 + 32 * n;
const Integer lwcomm = n + 5 * nwant;

Integer exit_status = 0;

nagad_a1w_w_rtype *rwsav = 0, *thresh = 0, *ynow = 0, *wcomm = 0;
nagad_a1w_w_rtype *ypnow = 0, *y = 0, *ywant = 0, *ypwant = 0, ruser[2];
Integer *          iwsav = 0, iuser[1];

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

iwsav  = new Integer[liwsav];

// Set initial conditions for ODE and parameters for the integrator.
Integer           method = -1;
tstart = 0.0;
tol    = 1.0e-4;
tend   = 2.0 * nag_math_pi;
hstart = 0.0;
for (int k = 0; k < n; k++)
{
thresh[k] = 1.0e-8;
}
ruser[0] = 1.0;
ruser[1] = 1.0;
y[0]     = 0.0;
y[1]     = 1.0;

{
double tolr = dco::value(tol);
cout << "\n  Calculation with tol = " << tolr << endl;
}
cout.setf(ios::fixed);
cout.setf(ios::right);
cout.precision(3);
{
double t = dco::value(tstart);
cout << "\n    t         y1        y2" << endl;
cout.width(6);
cout << t;
}

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

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

dco::ga1s<double>::global_tape->register_variable(ruser[0]);
dco::ga1s<double>::global_tape->register_variable(ruser[1]);

for (int k = 0; k < n; k++)
{
double yr = dco::value(y[k]);
cout.width(10);
cout << yr;
}
cout << endl;

// Initialize Runge-Kutta method for integrating ODE
ifail = 0;
iwsav, rwsav, ifail);

tinc  = (tend - tstart) / ((double)npts);
twant = tstart + tinc;
tnow  = tstart;
while (tnow < tend)
{
ifail = 0;
iwsav, rwsav, ifail);
while (twant <= tnow)
{
Integer ideriv = 2;
ifail          = 0;
wcomm, lwcomm, -1, iuser, -1, ruser, iwsav, rwsav,
ifail);

cout.width(6);
cout << dco::value(twant);
cout.width(10);
cout << dco::value(ywant[0]);
cout.width(10);
cout << dco::value(ypwant[0]);
cout << endl;

twant = twant + tinc;
}
}

Integer           fevals, stepcost, stepsok;
ifail = 0;
rwsav, ifail);
cout << "\n Cost of the integration in evaluations of f is " << fevals;
cout << endl;

// Setup evaluation of derivatives via adjoints.
double inc = 1.0;
dco::derivative(ywant[0]) += 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 Derivatives: (solution w.r.t. function parameters)\n";

cout.setf(ios::scientific, ios::floatfield);
cout.precision(5);
double dr;
dr = dco::derivative(ruser[0]);
cout << " dy(t)/druser[0] = ";
cout.width(12);
cout << dr << endl;
dr = dco::derivative(ruser[1]);
cout << " dy(t)/druser[1] = ";
cout.width(12);
cout << dr << endl;

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

delete[] thresh;
delete[] ynow;
delete[] y;
delete[] ywant;
delete[] ypnow;
delete[] ypwant;
delete[] iwsav;
delete[] rwsav;
delete[] wcomm;
return exit_status;
}

static void NAG_CALL f(void *&                  ad_handle,