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

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

#include <nag.h>

int main(void) {
  /* Scalars */
  Integer exit_status = 0;
  Integer i, j, k, lar1, lar2, lenar, n, pdar, pda, q;
  /* Arrays */
  Complex *ar = 0, *a = 0;
  char nag_enum_arg[40];
  /* NAG types */
  Nag_RFP_Store transr;
  Nag_UploType uplo;
  Nag_DiagType diag;
  Nag_OrderType order;
  Nag_MatrixType matrix;
  NagError fail;

#ifdef NAG_COLUMN_MAJOR
  order = Nag_ColMajor;
#define AR(I, J) ar[J * pdar + I]
#else
  order = Nag_RowMajor;
#define AR(I, J) ar[I * pdar + J]
#endif

  INIT_FAIL(fail);
  printf("nag_lapacklin_ztftri (f07wxc) Example Program Results\n\n");

  /* Skip heading in data file */
  scanf("%*[^\n] ");
  scanf("%" NAG_IFMT "", &n);
  scanf("%39s", nag_enum_arg);
  uplo = (Nag_UploType)nag_enum_name_to_value(nag_enum_arg);
  scanf("%39s", nag_enum_arg);
  transr = (Nag_RFP_Store)nag_enum_name_to_value(nag_enum_arg);
  scanf("%39s%*[^\n] ", nag_enum_arg);
  diag = (Nag_DiagType)nag_enum_name_to_value(nag_enum_arg);

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

  /* Setup dimensions for RFP array ar. */
  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;
  }
  /* Read matrix into RFP array ar. */
  for (i = 0; i < lar1; i++) {
    for (j = 0; j < lar2; j++) {
      scanf(" ( %lf , %lf ) ", &AR(i, j).re, &AR(i, j).im);
    }
  }

  /* Compute inverse of A using nag_lapacklin_ztftri (f07wxc). */
  nag_lapacklin_ztftri(order, transr, uplo, diag, n, ar, &fail);
  if (fail.code != NE_NOERROR) {
    printf("%s\n", fail.message);
    exit_status = 1;
    goto END;
  }
  /* Convert inverse to full matrix format using  nag_matop_ztfttr (f01vhc). */
  nag_matop_ztfttr(order, transr, uplo, n, ar, a, pda, &fail);
  if (fail.code != NE_NOERROR) {
    printf("%s\n", fail.message);
    exit_status = 2;
    goto END;
  }

  /* nag_file_print_matrix_complex_gen_comp (x04dbc).
   * Print complex general matrix (comprehensive)
   */
  if (uplo == Nag_Lower)
    matrix = Nag_LowerMatrix;
  else
    matrix = Nag_UpperMatrix;
  fflush(stdout);
  nag_file_print_matrix_complex_gen_comp(
      order, matrix, diag, n, n, a, pda, Nag_BracketForm, "%7.4f", "Inverse",
      Nag_IntegerLabels, NULL, Nag_IntegerLabels, NULL, 80, 0, 0, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_file_print_matrix_complex_gen_comp (x04dbc)\n%s\n",
           fail.message);
    exit_status = 3;
  }

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