/* F08AE_P0W_F C++ Header Example Program.
*
* Copyright 2022 Numerical Algorithms Group.
* Mark 28.3, 2022.
*/
#include <iostream>
#include <math.h>
#include <nag.h>
#include <nagad.h>
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
/* Scalars */
Integer exit_status = 0;
#ifdef NAG_LOAD_FP
/* The following line is needed to force the Microsoft linker
to load floating point support */
float force_loading_of_ms_float_support = 0;
#endif /* NAG_LOAD_FP */
cout << "F08AE_P0W_F C++ Header Example Program Results\n\n";
nag::ad::handle_t ad_handle;
Integer ifail = 0;
// Skip heading in data file
string mystr;
getline(cin, mystr);
Integer m, n;
cin >> m;
cin >> n;
Integer pda = m;
Integer lwork = 64 * n;
Integer tau_len;
if (m < n)
{
tau_len = m;
}
else
{
tau_len = n;
}
// Allocate arrays
double *a = 0, *tau = 0, *work = 0;
a = new double[m * n];
tau = new double[tau_len];
work = new double[lwork];
// Read A from data file
double tmp;
for (int i = 0; i < m; ++i)
{
for (int j = 0; j < n; ++j)
{
cin >> tmp;
a[i + j * m] = tmp;
}
}
ifail = 0;
nag::ad::f08ae(ad_handle, m, n, a, pda, tau, work, lwork, ifail);
NagError fail;
INIT_FAIL(fail);
x04cac(Nag_ColMajor, Nag_UpperMatrix, Nag_NonUnitDiag, n, n, a, pda,
"R from Q factorization of A", 0, &fail);
delete[] a;
delete[] work;
delete[] tau;
return exit_status;
}