NAG Library Manual, Mark 30.3
Interfaces:  FL   CL   CPP   AD 

NAG AD Library Introduction
Example description
/* F08AH_P0W_F C++ Header Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 * Mark 30.3, 2024.
 */

#include <iostream>
#include <dco.hpp>
#include <math.h>
#include <nag.h>
#include <nagad.h>
#include <stdio.h>
#include <string>
using namespace std;

int main()
{
  /* Scalars */
  Integer exit_status = 0;

  cout << "F08AH_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];
  work = new double[lwork];
  tau  = new double[tau_len];

  // Read A from data file
  for (int i = 0; i < m; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      cin >> a[i + j * m];
    }
  }

  ifail = 0;
  nag::ad::f08ah(ad_handle, m, n, a, pda, tau, work, lwork, ifail);

  NagError fail;
  INIT_FAIL(fail);
  x04cac(Nag_ColMajor, Nag_LowerMatrix, Nag_NonUnitDiag, m, m, a, m,
         "L from Q factorization of A", 0, &fail);

  delete[] a;
  delete[] tau;
  delete[] work;

  return exit_status;
}