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

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

#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_row (c06ppc) "
         "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[j * m + p]);
      printf("%10.4f%s", x[j * m + p],
             (j % 6 == 5 && j != n - 1 ? "\n     " : ""));
    }
    printf("\n");
  }

  /* Calculate transforms */
  /* nag_sum_fft_realherm_1d_multi_row (c06ppc).
   * Multiple one-dimensional real discrete Fourier transforms
   */
  nag_sum_fft_realherm_1d_multi_row(Nag_ForwardTransform, m, n, x, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_sum_fft_realherm_1d_multi_row (c06ppc).\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[2 * j * m + p]);
    printf("\nImag ");
    for (j = 0; j <= n / 2; ++j)
      printf("%10.4f", x[(2 * j + 1) * m + p]);
    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[2 * j * m + p]);
    for (j = n / 2 + 1; j < n; ++j)
      printf("%10.4f", x[2 * (n - j) * m + p]);
    printf("\nImag ");
    for (j = 0; j <= n / 2; ++j)
      printf("%10.4f", x[(2 * j + 1) * m + p]);
    for (j = n / 2 + 1; j < n; ++j)
      printf("%10.4f", x[(2 * (n - j) + 1) * m + p]);
    printf("\n");
  }

  /* Transform back to original data */
  nag_sum_fft_realherm_1d_multi_row(Nag_BackwardTransform, m, n, 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[j * m + p],
             (j % 6 == 5 && j != n - 1 ? "\n     " : ""));
    printf("\n");
  }
END:
  NAG_FREE(x);

  return exit_status;
}