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

NAG CL Interface Introduction
Example description
/* nag_eigen_complex_gen_eigsys (f02gcc) Example Program.
 *
 * Copyright 2022 Numerical Algorithms Group.
 *
 * Mark 28.4, 2022.
 *
 */

#include <nag.h>
#include <stdio.h>

#define MMAX 3

#define A(I, J) a[(I)*tda + J]
#define V(I, J) v[(I)*tdv + J]

int main(void) {

  Complex *a = 0, *v = 0, *w = 0;
  Integer exit_status = 0, i, j, m, mest = MMAX, n, tda, tdv;
  NagError fail;
  double wl, wu;

  INIT_FAIL(fail);

  printf("nag_eigen_complex_gen_eigsys (f02gcc) Example Program Results\n");

  /* Skip heading in data file */
  scanf("%*[^\n]");
  scanf("%" NAG_IFMT "%lf%lf%*[^\n] ", &n, &wl, &wu);
  if (n >= 0) {
    if (!(a = NAG_ALLOC(n * n, Complex)) ||
        !(v = NAG_ALLOC(n * mest, Complex)) || !(w = NAG_ALLOC(n, Complex))) {
      printf("Allocation failure\n");
      exit_status = -1;
      goto END;
    }
    tda = n;
    tdv = mest;
  } else {
    printf("Invalid n.\n");
    exit_status = 1;
    return exit_status;
  }

  /* Read a from data file */
  for (i = 0; i < n; ++i)
    for (j = 0; j < n; ++j)
      scanf(" ( %lf, %lf ) ", &A(i, j).re, &A(i, j).im);

  /* Compute selected eigenvalues and eigenvectors of A */

  /* nag_eigen_complex_gen_eigsys (f02gcc).
   * Computes selected eigenvalues and eigenvectors of a
   * complex general matrix
   */
  nag_eigen_complex_gen_eigsys(Nag_Select_Modulus, n, a, tda, wl, wu, mest, &m,
                               w, v, tdv, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_eigen_complex_gen_eigsys (f02gcc).\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  printf("\n\nEigenvalues\n\n");
  for (i = 0; i < m; ++i)
    printf("(%7.4f, %7.4f)%s", w[i].re, w[i].im, (i + 1) % 2 == 0 ? "\n" : " ");

  printf("\nEigenvectors\n");
  for (i = 1; i <= m; i++)
    printf("%15" NAG_IFMT "%s", i, i % m == 0 ? "\n" : "");

  for (i = 0; i < n; i++) {
    printf("%" NAG_IFMT "  ", i + 1);
    for (j = 0; j < m; j++)
      printf("(%8.4f, %8.4f)%s", V(i, j).re, V(i, j).im,
             (j + 1) % m == 0 ? "\n" : "  ");
  }
END:
  NAG_FREE(a);
  NAG_FREE(v);
  NAG_FREE(w);
  return exit_status;
}