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

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

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

int main(void) {
  /* Scalars */
  Integer exit_status = 0, j, m, n, p;
  /* Arrays */
  double *x = 0;
  /* Nag Types */
  NagError fail;

  INIT_FAIL(fail);

  printf("nag_sum_fft_realherm_1d_multi_col (c06pqc) "
         "Example Program Results\n\n");

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

  /* read number of sequences and sequence length */
  scanf("%" NAG_IFMT "%" NAG_IFMT "", &m, &n);
  if (m < 1 || n < 1) {
    printf("Invalid m or n.\n");
    exit_status = 1;
    return exit_status;
  }
  if (!(x = NAG_ALLOC(m * n + 2 * m, double))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  printf("m = %2" NAG_IFMT "  n = %2" NAG_IFMT "\n", m, n);
  /* Read in data and print out. */
  for (p = 0; p < m; ++p) {
    printf("    ");
    for (j = 0; j < n; ++j) {
      scanf("%lf", &x[p * (n + 2) + j]);
      printf("%10.4f%s", x[p * (n + 2) + j],
             (j % 6 == 5 && j != n - 1 ? "\n     " : ""));
    }
    printf("\n");
  }

  /* Calculate transforms */
  /* nag_sum_fft_realherm_1d_multi_col (c06pqc).
   * Multiple one-dimensional real discrete Fourier transforms
   */
  nag_sum_fft_realherm_1d_multi_col(Nag_ForwardTransform, n, m, x, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_sum_fft_realherm_1d_multi_col (c06pqc).\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }
  printf("\nDiscrete Fourier transforms in complex Hermitian format\n");
  for (p = 0; p < m; ++p) {
    printf("\nReal ");
    for (j = 0; j <= n / 2; ++j)
      printf("%10.4f", x[p * (n + 2) + 2 * j]);
    printf("\nImag ");
    for (j = 0; j <= n / 2; ++j)
      printf("%10.4f", x[p * (n + 2) + 2 * j + 1]);
    printf("\n");
  }
  printf("\nFourier transforms in full Hermitian form\n");
  for (p = 0; p < m; ++p) {
    printf("\nReal ");
    for (j = 0; j <= n / 2; ++j)
      printf("%10.4f", x[p * (n + 2) + 2 * j]);
    for (j = n / 2 + 1; j < n; ++j)
      printf("%10.4f", x[p * (n + 2) + 2 * (n - j)]);
    printf("\nImag ");
    for (j = 0; j <= n / 2; ++j)
      printf("%10.4f", x[p * (n + 2) + 2 * j + 1]);
    for (j = n / 2 + 1; j < n; ++j)
      printf("%10.4f", x[p * (n + 2) + 2 * (n - j) + 1]);
    printf("\n");
  }

  /* Transform back to original data */
  nag_sum_fft_realherm_1d_multi_col(Nag_BackwardTransform, n, m, x, &fail);
  printf("\nOriginal data as restored by inverse transform\n\n");
  for (p = 0; p < m; ++p) {
    printf("    ");
    for (j = 0; j < n; ++j)
      printf("%10.4f%s", x[p * (n + 2) + j],
             (j % 6 == 5 && j != n - 1 ? "\n     " : ""));
    printf("\n");
  }
END:
  NAG_FREE(x);

  return exit_status;
}