Example description
/* G02AA_P0W_F C++ Header Example Program.
 *
 * Copyright 2020 Numerical Algorithms Group.
 * Mark 27.1, 2020.
 */

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

int main(void)
{
  Integer exit_status = 0;

  cout << "G02AA_T1W_F C++ Example Program Results\n\n";

  // Skip heading in data file
  string mystr;
  getline (cin, mystr);
  
  Integer n;
  cin >> n;

  double  *g = 0, *x = 0;
  Integer pdg = n;
  Integer pdx = n;
  g = new double [n * n];
  x = new double [n * n];

  /* Read in the matrix g */
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> g[i+j*n];
    }
  }

  /* Set up method parameters */
  double  errtol = 1.00e-7;
  Integer maxits = 200;
  Integer maxit = 10;

  void    *ad_handle = 0;
  Integer ifail = 0;
  Integer feval, iter;
  double  nrmgrd;
  g02aa_p0w_f_(ad_handle, g, pdg, n, errtol, maxits, maxit, x, pdx,
               iter, feval, nrmgrd, ifail);

  NagError  fail;
  INIT_FAIL(fail);
  x04cac(Nag_ColMajor,Nag_GeneralMatrix,Nag_NonUnitDiag,n,n,x,pdx,
         "     Nearest Correlation Matrix",0,&fail);

  cout << "\n\n Number of Newton steps taken  : " << iter << "\n";
  cout <<     " Number of function evaluations:" << feval << "\n";
  if (nrmgrd > errtol) {
    cout << " Norm of gradient of last Newton step: ";
    cout.width(12); cout << nrmgrd << endl;
  }

  delete [] g;
  delete [] x;

  return exit_status;
}