Example description
/* F11JC_P0W_F C++ Header Example Program.
 *
 * Copyright 2020 Numerical Algorithms Group.
 * Mark 27.1, 2020.
 */
#include <dco_light.hpp>
#include <nag.h>
#include <nagx04.h>
#include <nagad.h>
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void)
{
  int       exit_status = 0;
  void      *ad_handle = 0;
  Integer   ifail = 0;

  cout << "F11JC_P0W_F C++ Header Example Program Results\n\n";
  // Skip heading in data file
  string mystr;
  getline (cin, mystr);

  // Read order of matrix and number of nonzero entries
  Integer   n, nnz;
  cin >> n;
  cin >> nnz;

  Integer   la = 3*nnz;
  Integer   liwork = 2*la + 7*n + 1;
  Integer   lwork = 6*n + 120;
  double    *a=0, *x=0, *y=0, *work=0;
  Integer   *icol=0, *ipiv=0, *irow=0, *istr=0, *iwork=0;

  a        = new double [la];
  x        = new double [n];
  y        = new double [n];
  work     = new double [lwork];
  icol     = new Integer [la];
  ipiv     = new Integer [n];
  irow     = new Integer [la];
  istr     = new Integer [n+1];
  iwork    = new Integer [liwork];

  double    dtol, dscale, tol;
  Integer   lfill, maxitn;
  cin >> lfill >> dtol;
  cin >> dscale;
  cin >> tol >> maxitn;
  
  // Read the matrix A
  for (int i=0; i<nnz; i++) {
    cin >> a[i] >> irow[i] >> icol[i];
  }
      
  // Read the vector y
  for (int i=0; i<n; i++) {
    cin >> y[i];
  }
  // Read initial vector x
  for (int i=0; i<n; i++) {
    cin >> x[i];
  }
  // Calculate incomplete Cholesky factorization
  Integer           nnzc, npivm;
  ifail = 0;
  f11ja_p0w_f_(ad_handle,n,nnz,a,la,irow,icol,lfill,dtol,"N",dscale,"M",
               ipiv,istr,nnzc,npivm,iwork,liwork,ifail,1,1);

  // Solve Ax = y
  double     rnorm;
  Integer    itn;
  ifail = 0;
  f11jc_p0w_f_(ad_handle,"CG",n,nnz,a,la,irow,icol,ipiv,istr,y,tol,maxitn,
               x,rnorm,itn,work,lwork,ifail,2);
  
  // Output results
  cout << " Converged in " << itn << " iterations" << endl;
  cout << " Final residual norm = " << rnorm << endl;
  cout.setf(ios::scientific,ios::floatfield);
  cout.precision(4);
  cout << endl;
  cout << "  Solution vector" << endl;
  for (int i=0; i<n; ++i) {
    cout.width(12);cout << x[i] << endl;
  }

  delete [] a;
  delete [] x;
  delete [] y;
  delete [] work;
  delete [] icol;
  delete [] ipiv;
  delete [] irow;
  delete [] istr;
  delete [] iwork;

  return exit_status;
}