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

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

extern "C"
{
static void NAG_CALL f(void * &ad_handle,
const Integer &nx,
Integer &iflag,
Integer iuser[],
const void *&cpuser);
}

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

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

Integer           key = 6;
double            pi = X01AAC;
a = 0.0;
b = 2.0*pi;
epsabs = 0.0;
epsrel = 1.0e-4;

Integer           maxsub = 20;
Integer           lrinfo = 80;
Integer           liinfo = 20;
Integer           *iinfo = 0;

iinfo = new Integer [liinfo];

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

double            inc = 1.0;
Integer           iuser[1];
const void        *cpuser = 0;
iuser[0] = 0;
ruser[0] = 30.0;
ruser[1] = 1.0;

// Register variables to differentiate w.r.t.

ifail = -1;
iuser,ruser,cpuser,ifail);
if (ifail<0) {
cout << "\n ** d01rk_a1w_f_ failed error exit ifail = " << ifail << endl;
goto END;
}
// Print inputs and primal outputs.
cout << "\n lower limit of integration (a) = " << nagad_a1w_get_value(a) << endl;
cout << " upper limit of integration (b) = " << nagad_a1w_get_value(b) << endl;
cout << " choice of Gaussian rule (key)  = " << key << endl;
cout << " absolute accuracy requested    = " << nagad_a1w_get_value(epsabs) << endl;
cout << " relative accuracy requested    = " << nagad_a1w_get_value(epsrel) << endl;
cout << " maximum number of subintervals = " << maxsub << endl;
cout.setf(ios::scientific,ios::floatfield);
cout.precision(4);
if (ifail >= 0) {
cout << "\n approximation to the integral  : " << nagad_a1w_get_value(result) << endl;
cout << " estimate of the absolute error : " << nagad_a1w_get_value(abserr) << endl;
cout << " number of function evaluations : " << iinfo[0] << endl;
}

// Setup evaluation of derivatives via adjoints.
ifail = 0;

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

// Get derivatives
double dr;
cout << "\n Derivative of solution w.r.t to parameter in ruser:\n";
cout << " dI/druser[0] = " << dr << endl;
cout << " dI/druser[1] = " << dr << endl;

END:
// Remove computational data object and tape

delete [] rinfo;
delete [] iinfo;
return exit_status;
}

static void NAG_CALL f(void * &ad_handle,
const Integer &nx,
Integer &iflag,
Integer iuser[],
const void *&cpuser)
{
// dco/c++ used here to perform AD of the following
for (int i=0; i<nx; i++) {
fv[i] = x[i]*sin(ruser[0]*x[i])*cos(ruser[1]*x[i]);
}
return;
}
```