Example description
/* F08KE_P0W_F C++ Header Example Program.
 *
 * Copyright 2019 Numerical Algorithms Group.
 * Mark 27, 2019.
 */

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

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

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

  // Read matrix dimensions
  Integer m, n;
  cin >> m >> n;

  // Allocate arrays containing A and its factorized form, B
  // and the solution X.
  Integer lda = m, lwork=64*(m+n);
  double  *a=0, *d=0, *e=0, *taup=0, *tauq, *work=0;
  a     = new double [m*n];
  d     = new double [n];
  e     = new double [n-1];
  taup  = new double [n];
  tauq  = new double [n];
  work  = new double [lwork];

  // Read the matrix A, register and copy
  double ddd;
  for (int i = 0; i<m; i++) {
    for (int j = 0; j<n; j++) {
      Integer k = i + j*m;
      cin >> a[k];
    }
  }

  // reduce A to bidiagonal form
  ifail = 0;
  f08ke_p0w_f_(ad_handle,m,n,a,lda,d,e,tauq,taup,work,lwork,ifail);

  // Print bidiagonal form
  cout.precision(4);
  cout << " Diagonal:" << endl;
  cout.width(12); cout << " ";
  for (int i=0; i<n; i++) {
    cout.width(11); cout << d[i];
  }
  cout << endl;
  if (m>n) {
    cout << " Superdiagonal:" << endl;
  } else {
    cout << " Subdiagonal:" << endl;
  }
  cout.width(12); cout << " ";
  for (int i=0; i<n-1; i++) {
    cout.width(11); cout << e[i];
  }
  cout << endl;
  
  delete [] a;
  delete [] d;
  delete [] e;
  delete [] taup;
  delete [] tauq;
  delete [] work;
  return exit_status;
}