/* G01GC_T1W_F C++ Header Example Program.
*
* Copyright 2020 Numerical Algorithms Group.
* Mark 27.1, 2020.
*/
#include <dco_light.hpp>
#include <nag.h>
#include <nagad.h>
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
int exit_status = 0;
cout << "G01GC_T1W_F C++ Header Example Program Results\n\n";
// Skip heading in data file
string mystr;
getline (cin, mystr);
// Read number of x values
Integer n;
cin >> n;
cout << " x df rlamda p";
cout << " p' df' rlamda'\n";
cout.setf(ios::scientific,ios::floatfield);
cout.setf(ios::right);
cout.precision(2);
Integer maxit = 100;
nagad_t1w_w_rtype p, x, df, rlamda, tol;
tol = 0.0;
// Create AD configuration data object
Integer ifail = 0;
void *ad_handle = 0;
x10aa_t1w_f_(ad_handle,ifail);
// Loop over x values
for (Integer i = 0; i < n; ++i) {
// Read next x, df, rlamda
double xr, dfr, rr;
cin >> xr >> dfr >> rr;
x = xr;
df = dfr;
rlamda = rr;
double inc = 1.0;
nagad_t1w_inc_derivative(&x,inc);
// Call NAG AD Routine
p = 0.0;
ifail = 0;
g01gc_t1w_f_(ad_handle,x,df,rlamda,tol,maxit,p,ifail);
// Get derivatives
double dpdx;
dpdx = nagad_t1w_get_derivative(p);
x = xr;
df = dfr;
rlamda = rr;
nagad_t1w_inc_derivative(&df,inc);
// Call NAG AD Routine
p = 0.0;
ifail = 0;
g01gc_t1w_f_(ad_handle,x,df,rlamda,tol,maxit,p,ifail);
double dpdd;
dpdd = nagad_t1w_get_derivative(p);
x = xr;
df = dfr;
rlamda = rr;
nagad_t1w_inc_derivative(&rlamda,inc);
// Call NAG AD Routine
p = 0.0;
ifail = 0;
g01gc_t1w_f_(ad_handle,x,df,rlamda,tol,maxit,p,ifail);
double dpdr;
dpdr = nagad_t1w_get_derivative(p);
// Output results
cout.width(9); cout << nagad_t1w_get_value(x);
cout.width(9); cout << nagad_t1w_get_value(df);
cout.width(9); cout << nagad_t1w_get_value(rlamda);
cout.width(9); cout << nagad_t1w_get_value(p);
cout.width(11); cout << dpdx;
cout.width(11); cout << dpdd;
cout.width(11); cout << dpdr << endl;
// Remove computational data object
}
x10ab_t1w_f_(ad_handle,ifail);
return exit_status;
}