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

NAG CL Interface Introduction
Example description
/* nag_matop_complex_gen_matrix_log (f01fjc) Example Program.
 *
 * Copyright 2022 Numerical Algorithms Group.
 *
 * Mark 28.3, 2022.
 */

#include <nag.h>

int main(void) {

  /* Scalars */
  Integer exit_status = 0;
  Integer i, j, n, pda;

  /* Arrays */
  Complex *a = 0;

  /* Nag Types */
  Nag_OrderType order;
  NagError fail;

  INIT_FAIL(fail);

#ifdef NAG_COLUMN_MAJOR
#define A(I, J) a[(J - 1) * pda + I - 1]
  order = Nag_ColMajor;
#else
#define A(I, J) a[(I - 1) * pda + J - 1]
  order = Nag_RowMajor;
#endif

  /* Output preamble */
  printf("nag_matop_complex_gen_matrix_log (f01fjc) ");
  printf("Example Program Results\n\n");
  fflush(stdout);

  /* Skip heading in data file */
  scanf("%*[^\n]");

  /* Read in the problem size */
  scanf("%" NAG_IFMT "%*[^\n]", &n);

  pda = n;

  if (!(a = NAG_ALLOC((pda) * (n), Complex))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  /* Read in the matrix a from data file */
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      scanf(" ( %lf , %lf ) ", &A(i, j).re, &A(i, j).im);
  scanf("%*[^\n]");

  /* Find log(A) using
   * nag_matop_complex_gen_matrix_log (f01fjc)
   * Complex matrix logarithm
   */
  nag_matop_complex_gen_matrix_log(order, n, a, pda, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_matop_complex_gen_matrix_log (f01fjc)\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  /* Print solution using
   * nag_file_print_matrix_complex_gen (x04dac)
   * Print complex general matrix (easy to use)
   */
  nag_file_print_matrix_complex_gen(order, Nag_GeneralMatrix, Nag_NonUnitDiag,
                                    n, n, a, n, "log(A)", NULL, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_file_print_matrix_complex_gen (x04dac)\n%s\n",
           fail.message);
    exit_status = 2;
    goto END;
  }

END:
  NAG_FREE(a);
  return exit_status;
}