```/* D01FC_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 <nag_stdlib.h>
#include <iostream>
using namespace std;

extern "C"
{
const Integer& ndim,
Integer iuser[],
}

int main(void)
{
// Scalars
int               exit_status = 0;
Integer           ndim = 4, maxpts = 4000, lenwrk = 100;

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

// Allocate memory
nagad_a1w_w_rtype *a = 0, *b = 0, *work = 0;

if (!(a = NAG_ALLOC(ndim, nagad_a1w_w_rtype)) ||
{
printf("Allocation failure\n");
exit_status = -2;
}

if (exit_status==0) {

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

// Initialize variables
for (int i = 0; i < ndim; i++) {
a[i] = 0.0;
b[i] = 1.0;
}
Integer           minpts = 0;
ruser[0] = 4.0;
ruser[1] = 2.0;
ruser[2] = 1.0;

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

ifail = 0;
Integer           iuser[1];
work,finval,iuser,ruser,ifail);

double inc = 1.0;

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

// Get derivatives
double dr[3];

cout.setf(ios::scientific,ios::floatfield);
cout.setf(ios::right);
cout.precision(4);
cout << "\n Solution, x = ";
cout.width(12); cout << ans_value << endl;
cout << "\n Derivatives:\n";
cout <<  " d/druser[0] = ";
cout.width(12); cout << dr[0] << endl;
cout <<  " d/druser[1] = ";
cout.width(12); cout << dr[1] << endl;
cout <<  " d/druser[2] = ";
cout.width(12); cout << dr[2] << endl;

// Remove computational data object and tape
}

NAG_FREE(a);
NAG_FREE(b);
NAG_FREE(work);

return exit_status;
}

const Integer& ndim,
Integer iuser[],
{