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

NAG CL Interface Introduction
Example description
/* nag_matop_ztrttf (f01vfc) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.2, 2024.
 */

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

int main(void) {
  /* Scalars */
  Integer exit_status = 0, indent = 0, ncols = 80;
  Integer i, j, k, pda, pdar, q, lar1, lar2, lenar, n;
  /* Arrays */
  Complex *a = 0, *ar = 0;
  char nag_enum_transr[40], nag_enum_uplo[40], form[] = "%5.2f";
  /* Nag Types */
  Nag_MatrixType matrix;
  Nag_OrderType order;
  Nag_RFP_Store transr;
  Nag_UploType uplo;
  NagError fail;

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

  INIT_FAIL(fail);

  printf("nag_matop_ztrttf (f01vfc) Example Program Results\n\n");
  /* Skip heading in data file */
  scanf("%*[^\n] ");
  scanf("%" NAG_IFMT "%*[^\n] ", &n);
  scanf("%39s ", nag_enum_transr);
  scanf("%39s  %*[^\n] ", nag_enum_uplo);
  pda = n;
  lenar = (n * (n + 1)) / 2;
  if (!(a = NAG_ALLOC(pda * n, Complex)) || !(ar = NAG_ALLOC(lenar, Complex))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }
  /* Nag_RFP_Store */
  transr = (Nag_RFP_Store)nag_enum_name_to_value(nag_enum_transr);
  uplo = (Nag_UploType)nag_enum_name_to_value(nag_enum_uplo);
  /* Read a triangular matrix of order n. */
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++)
      scanf(" ( %lf , %lf ) ", &A(i, j).re, &A(i, j).im);
  }

  /* Print the unpacked array. */
  matrix = (uplo == Nag_Upper ? Nag_UpperMatrix : Nag_LowerMatrix);

  fflush(stdout);
  /* nag_file_print_matrix_complex_gen_comp (x04dbc).
   * Print complex general matrix (comprehensive).
   */
  nag_file_print_matrix_complex_gen_comp(
      order, matrix, Nag_NonUnitDiag, n, n, a, pda, Nag_BracketForm, form,
      "Unpacked Matrix A:", Nag_IntegerLabels, NULL, Nag_IntegerLabels, NULL,
      ncols, indent, NULL, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_file_print_matrix_complex_gen_comp (x04dbc).\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }
  printf("\n");

  /* Convert complex triangular matrix from full format, a, to
   * Rectangular Full Packed form, ar, using nag_matop_ztrttf (f01vfc).
   */
  nag_matop_ztrttf(order, transr, uplo, n, a, pda, ar, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from  nag_matop_ztrttf (f01vfc).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }

  /* Print the Rectangular Full Packed array
   * showing how the elements are arranged.
   */
  k = n / 2;
  q = n - k;
  if (transr == Nag_RFP_Normal) {
    lar1 = 2 * k + 1;
    lar2 = q;
  } else {
    lar1 = q;
    lar2 = 2 * k + 1;
  }
  if (order == Nag_RowMajor) {
    pdar = lar2;
  } else {
    pdar = lar1;
  }

  /* nag_file_print_matrix_complex_gen_comp (x04dbc).
   * Print complex general matrix (comprehensive).
   */
  fflush(stdout);
  nag_file_print_matrix_complex_gen_comp(
      order, Nag_GeneralMatrix, Nag_NonUnitDiag, lar1, lar2, ar, pdar,
      Nag_BracketForm, form,
      "RFP Packed Array AR "
      "(graphical representation):",
      Nag_IntegerLabels, NULL, Nag_IntegerLabels, NULL, ncols, indent, NULL,
      &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_file_print_matrix_complex_gen_comp (x04dbc).\n%s\n",
           fail.message);
    exit_status = 1;
  }

END:
  NAG_FREE(a);
  NAG_FREE(ar);
  return exit_status;
}