Example description
/* nag_lapacklin_zpftrs (f07wsc) Example Program.
 *
 * Copyright 2019 Numerical Algorithms Group.
 *
 * Mark 27.0, 2019.
 */

#include <nag.h>

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

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

  printf("nag_lapacklin_zpftrs (f07wsc) Example Program Results\n\n");
  /* Skip heading in data file */
  scanf("%*[^\n]");
  scanf("%" NAG_IFMT "%" NAG_IFMT "", &n, &nrhs);
  scanf("%39s", nag_enum_arg);
  uplo = (Nag_UploType) nag_enum_name_to_value(nag_enum_arg);
  scanf("%39s%*[^\n]", nag_enum_arg);
  transr = (Nag_RFP_Store) nag_enum_name_to_value(nag_enum_arg);

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

  /* Setup dimensions for RFP array ar and aray b. */
  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;
    pdb = nrhs;
  }
  else {
    pdar = lar1;
    pdb = n;
  }
  /* 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);
    }
  }
  scanf("%*[^\n] ");

  /* Read B */
  for (i = 0; i < n; i++)
    for (j = 0; j < nrhs; j++)
      scanf(" ( %lf , %lf ) ", &B(i, j).re, &B(i, j).im);

  /* Factorize A using nag_lapacklin_zpftrf (f07wrc) which performs a Cholesky
   * factorization of a complex Hermitian positive definite matrix in
   * Rectangular Full Packed format.
   */
  nag_lapacklin_zpftrf(order, transr, uplo, n, ar, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_lapacklin_zpftrf (f07wrc)\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }

  /* Compute solution Ax = B using nag_lapacklin_zpftrs (f07wsc). */
  nag_lapacklin_zpftrs(order, transr, uplo, n, nrhs, ar, b, pdb, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_lapacklin_zpftrs (f07wsc)\n%s\n", fail.message);
    exit_status = 2;
    goto END;
  }

  /* nag_file_print_matrix_complex_gen_comp (x04dbc).
   * Print complex general matrix (comprehensive).
   */
  fflush(stdout);
  nag_file_print_matrix_complex_gen_comp(order, matrix, diag, n, nrhs, b, pdb,
                                Nag_BracketForm, "%7.4f", "Solution(s)",
                                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(b);
  return exit_status;
}