/* E01DA_P0W_F C++ Header Example Program.
*
* Copyright 2022 Numerical Algorithms Group.
* Mark 28.6, 2022.
*/
#include <dco.hpp>
#include <iostream>
#include <math.h>
#include <nag.h>
#include <nagad.h>
#include <nagx04.h>
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
// Scalars
int exit_status = 0;
cout << "E01DA_P0W_F C++ Header Example Program Results\n\n";
// Skip first line of data file
string mystr;
getline(cin, mystr);
// Read number of x and y data points
Integer mx, my;
cin >> mx;
cin >> my;
// Allocate arrays for data and interpolant
double * x = 0, *lamda = 0, *y = 0, *mu = 0, *f = 0, *c = 0, *wrk = 0;
double * dx = 0, *dy = 0, *df = 0;
Integer *iwrk = 0;
Integer lwrk = (my + 6) * (mx + 6);
x = new double[mx];
y = new double[my];
lamda = new double[mx + 4];
mu = new double[my + 4];
f = new double[my * mx];
c = new double[my * mx];
wrk = new double[lwrk];
dx = new double[mx];
dy = new double[my];
df = new double[my * mx];
iwrk = new Integer[lwrk];
// Read data variables
for (int i = 0; i < mx; i++)
{
double xr;
cin >> xr;
x[i] = xr;
}
for (int i = 0; i < my; i++)
{
double yr;
cin >> yr;
y[i] = yr;
}
for (int i = 0; i < my; i++)
{
double fr;
for (int j = 0; j < mx; j++)
{
Integer k = j * my + i;
cin >> fr;
f[k] = fr;
}
}
// Call the passive routine
Integer px, py;
Integer ifail = 0;
nag::ad::handle_t ad_handle;
nag::ad::e01da(ad_handle, mx, my, x, y, f, px, py, lamda, mu, c, wrk, ifail);
const Integer m = 1;
double tx[m], ty[m], ff[m];
tx[0] = 1.4;
ty[0] = 0.5;
ifail = 0;
nag::ad::e02de(ad_handle, m, px, py, tx, ty, lamda, mu, c, ff, wrk, iwrk,
ifail);
cout << "\n Interpolant evaluated at x = " << tx[0];
cout << " and y = " << ty[0];
cout.precision(5);
cout << "\n Value of interpolant = ";
cout << ff[0] << endl;
delete[] x;
delete[] y;
delete[] lamda;
delete[] mu;
delete[] f;
delete[] c;
delete[] wrk;
delete[] dx;
delete[] dy;
delete[] df;
delete[] iwrk;
return exit_status;
}