/* S18DE_A1W_F C++ Header Example Program.
*
* Copyright 2019 Numerical Algorithms Group.
* Mark 27, 2019.
*/
#include <nag.h>
#include <dco.hpp>
#include <nagad.h>
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
int exit_status = 0;
// Input and output variables
cout << "S18DE_A1W_F C++ Header Example Program Results\n\n";
// Create AD tape
nagad_a1w_ir_create();
// Create AD configuration data object
Integer ifail = 0;
void *ad_handle = 0;
x10aa_a1w_f_(ad_handle,ifail);
cout << " nu z scal";
cout << " cy[0] dy/dnu\n";
cout.setf(ios::scientific,ios::floatfield);
cout.setf(ios::right);
cout.precision(2);
const Integer n = 1;
nagad_a1w_w_rtype fnu, x, zr, zi;
nagad_a1w_w_ctype z, cy[n];
Integer nz;
fnu = 5.5;
zr = -6.1;
zi = 9.8;
z.real(zr);
z.imag(zi);
// Register x, i.e. differentiate w.r.t. x
nagad_a1w_ir_register_variable(&fnu);
// Call NAG AD Routine
ifail = 0;
s18de_a1w_f_(ad_handle,fnu,z,n,"S",cy,nz,ifail,1);
nagad_a1w_w_rtype cyr;
cyr = real(cy[0]);
double inc = 1.0;
nagad_a1w_inc_derivative(&cyr,inc);
ifail = 0;
nagad_a1w_ir_interpret_adjoint(ifail);
double dyrdnu;
dyrdnu = nagad_a1w_get_derivative(fnu);
nagad_a1w_ir_zero_adjoints();
nagad_a1w_w_rtype cyi;
cyi = imag(cy[0]);
nagad_a1w_inc_derivative(&cyi,inc);
ifail = 0;
nagad_a1w_ir_interpret_adjoint(ifail);
double dyidnu;
dyidnu = nagad_a1w_get_derivative(fnu);
cout.width(10); cout << nagad_a1w_get_value(fnu) << " (";
cout.width(9); cout << nagad_a1w_get_value(real(z)) << ",";
cout.width(10); cout << nagad_a1w_get_value(imag(z)) << ") S (";
cout.width(9); cout << nagad_a1w_get_value(cyr) << ",";
cout.width(10); cout << nagad_a1w_get_value(cyi) << ") (";
cout.width(9); cout << dyrdnu << ",";
cout.width(10); cout << dyidnu << ")" << endl;
// Remove computational data object and tape
x10ab_a1w_f_(ad_handle,ifail);
nagad_a1w_ir_remove();
return exit_status;
}