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

NAG CL Interface Introduction
Example description
/* nag_file_print_matrix_complex_gen (x04dac) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.1, 2024.
 */

#include <nag.h>

int main(void) {
  Integer exit_status = 0, n = 5;
  Integer i, j, pda;
  double aa;
  Complex *a = 0;
  /* Nag Types */
  Nag_OrderType order;
  NagError 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

  INIT_FAIL(fail);

  printf(
      "nag_file_print_matrix_complex_gen (x04dac) Example Program Results\n\n");

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

  /* Generate a full-format symmetric array of data. */
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      aa = (double)(10 * i + j);
      A(i, j) = nag_complex_create(aa, -aa);
    }
  }

  /* Print n by (n-1) rectangular matrix
   * using nag_geb_complx_mat_print (x04dac).
   */
  fflush(stdout);
  nag_file_print_matrix_complex_gen(order, Nag_GeneralMatrix, Nag_NonUnitDiag,
                                    n, n - 1, a, pda, "Example 1:", NULL,
                                    &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_file_print_matrix_complex_gen (x04dac).\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }
  printf("\n");

  /* Print the order-n upper-triangular matrix with Unit diagonal
   * using nag_file_print_matrix_complex_gen (x04dac).
   */
  fflush(stdout);
  nag_file_print_matrix_complex_gen(order, Nag_UpperMatrix, Nag_UnitDiag, n, n,
                                    a, pda, "Example 2:", 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;
  }
  printf("\n");

END:
  NAG_FREE(a);

  return exit_status;
}