```/* D02PU_T1W_F C++ Header Example Program.
*
* Copyright 2020 Numerical Algorithms Group.
*
* Mark 27.1, 2020.
*/

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

#ifdef __cplusplus
extern "C"
{
#endif
const Integer &n, const nagad_t1w_w_rtype y[],
#ifdef __cplusplus
}
#endif

int main(void)
{
const Integer     n = 4;
const Integer     liwsav = 130;
const Integer     lrwsav = 350 + 32 * n;

Integer           exit_status = 0;

nagad_t1w_w_rtype *rwsav = 0, *thresh = 0, *ygot = 0, *ymax = 0;
nagad_t1w_w_rtype *ypgot = 0, *y = 0, ruser[1];
Integer           *iwsav = 0, iuser[1];

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

iwsav  = new Integer [liwsav];

// Set initial conditions for ODE and parameters for the integrator.
Integer           method = 3;
nagad_t1w_w_rtype tol, hstart, tend, tstart, eps;
eps       = 0.7;
tstart    = 0.0;
tol       = 1.0e-6;
tend      = 3.0*nag_math_pi;
hstart    = 0.0;
for (int i = 0; i < n; ++i) {
thresh[i] = 1.0e-10;
}

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

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

double inc = 1.0;

y[0] = 1.0 - eps;
y[1] = 0.0;
y[2] = 0.0;
y[3] = sqrt((1.0+eps)/(1.0-eps));
for (int k = 0; k < n; k++) {
cout.width(11); cout << yr;
}
cout << endl;

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

twant = tend;

ifail = 2;
while (ifail>1 && ifail<5) {
ifail = -1;
iwsav,rwsav,ifail);
}

if (ifail==0) {
for (int k = 0; k < n; ++k) {
}
cout << endl;

// Get Error estimates
ifail = 0;

cout.setf(ios::scientific,ios::floatfield);
cout.precision(2);
cout << "\n Componentwise error assessment\n        ";
for (int k = 0; k < n; ++k) {
}
cout << endl;
cout.precision(3);
cout << "\n Worst global error observed was ";
cout.width(9); cout << nagad_t1w_get_value(errmax) << endl;
cout << "              it occurred at T = ";
cout.width(8); cout << nagad_t1w_get_value(terrmx) << endl;

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

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

// Get derivatives
cout << "\n Derivatives: (solution w.r.t. eps)\n";

cout.setf(ios::scientific,ios::floatfield);
cout.precision(4);
double deps;
cout << " dy(t)/deps = ";
cout.width(12); cout << deps << endl;
}

delete [] thresh;
delete [] ygot;
delete [] y;
delete [] ypgot;
delete [] ymax;
delete [] iwsav;
delete [] rwsav;
delete [] rmserr;
return exit_status;
}