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

NAG CL Interface Introduction
Example description
/* nag_blast_zgb_norm (f16ubc) Example Program.
 *
 * Copyright 2021 Numerical Algorithms Group.
 *
 * Mark 27.3, 2021.
 */

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

int main(void) {

  /* Scalars */
  double r_one, r_inf, r_f, r_max;
  Integer ab_size, exit_status, i, j, kl, ku;
  Integer m, n, pdab;

  /* Arrays */
  Complex *ab = 0;

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

#ifdef NAG_COLUMN_MAJOR
#define AB(I, J) ab[(J - 1) * pdab + ku + I - J]
  order = Nag_ColMajor;
#else
#define AB(I, J) ab[(I - 1) * pdab + kl + J - I]
  order = Nag_RowMajor;
#endif

  exit_status = 0;
  INIT_FAIL(fail);

  printf("nag_blast_zgb_norm (f16ubc) Example Program Results\n\n");

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

  /* Read the problem dimensions */
  scanf("%" NAG_IFMT "%" NAG_IFMT "%" NAG_IFMT "%" NAG_IFMT "%*[^\n] ", &m, &n,
        &kl, &ku);

  pdab = kl + ku + 1;
#ifdef NAG_COLUMN_MAJOR
  ab_size = pdab * n;
#else
  ab_size = pdab * m;
#endif

  if (m > 0 && n > 0) {
    /* Allocate memory */
    if (!(ab = NAG_ALLOC(ab_size, Complex))) {
      printf("Allocation failure\n");
      exit_status = -1;
      goto END;
    }
  } else {
    printf("Invalid m or n\n");
    exit_status = 1;
    return exit_status;
  }

  /* Input matrix A. */

  for (i = 1; i <= m; ++i) {
    for (j = MAX(1, i - kl); j <= MIN(n, i + ku); ++j)
      scanf(" ( %lf , %lf )", &AB(i, j).re, &AB(i, j).im);
    scanf("%*[^\n] ");
  }

  /* nag_blast_zgb_norm (f16ubc).
   * calculates norm of Complex valued general band matrix.
   *
   */
  nag_blast_zgb_norm(order, Nag_OneNorm, m, n, kl, ku, ab, pdab, &r_one, &fail);

  if (fail.code != NE_NOERROR)
    goto GB_FAIL;

  nag_blast_zgb_norm(order, Nag_InfNorm, m, n, kl, ku, ab, pdab, &r_inf, &fail);

  if (fail.code != NE_NOERROR)
    goto GB_FAIL;

  nag_blast_zgb_norm(order, Nag_FrobeniusNorm, m, n, kl, ku, ab, pdab, &r_f,
                     &fail);

  if (fail.code != NE_NOERROR)
    goto GB_FAIL;

  nag_blast_zgb_norm(order, Nag_MaxNorm, m, n, kl, ku, ab, pdab, &r_max, &fail);

  if (fail.code != NE_NOERROR)
    goto GB_FAIL;

  /* Print norms of A. */
  printf(" Norms of banded matrix A:\n\n");
  printf(" One norm       = %7.4f\n", r_one);
  printf(" Infinity norm  = %7.4f\n", r_inf);
  printf(" Frobenius norm = %7.4f\n", r_f);
  printf(" Maximum norm   = %7.4f\n", r_max);
  goto END;

GB_FAIL:
  printf("Error from nag_blast_zgb_norm.\n%s\n", fail.message);
  exit_status = 1;

END:
  NAG_FREE(ab);

  return exit_status;
}