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

NAG CL Interface Introduction
Example description
/* nag_sum_withdraw_fft_hermitian_1d_multi_rfmt (c06fqc) Example Program.
 *
 * Copyright 2023 Numerical Algorithms Group.
 *
 * Mark 29.1, 2023.
 */

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

int main(void) {
  Integer exit_status = 0, i, j, m, n;
  NagError fail;
  double *trig = 0, *u = 0, *v = 0, *x = 0;

  INIT_FAIL(fail);

  printf(
      "nag_sum_withdraw_fft_hermitian_1d_multi_rfmt (c06fqc) Example Program Results\n");
  /* Skip heading in data file */
  scanf("%*[^\n]");
  while (scanf("%" NAG_IFMT "%" NAG_IFMT "", &m, &n) != EOF)
  {
    if (m >= 1 && n >= 1) {
      printf("\n\nm = %2" NAG_IFMT "  n = %2" NAG_IFMT "\n", m, n);
      if (!(trig = NAG_ALLOC(2 * n, double)) ||
          !(u = NAG_ALLOC(m * n, double)) || !(v = NAG_ALLOC(m * n, double)) ||
          !(x = NAG_ALLOC(m * n, double))) {
        printf("Allocation failure\n");
        exit_status = -1;
        goto END;
      }
    } else {
      printf("Invalid m or n.\n");
      exit_status = 1;
      return exit_status;
    }

    /* Read in data and print out. */
    for (j = 0; j < m; ++j)
      for (i = 0; i < n; ++i)
        scanf("%lf", &x[j * n + i]);
    printf("\nOriginal data values\n\n");
    for (j = 0; j < m; ++j) {
      printf("    ");
      for (i = 0; i < n; ++i)
        printf("%10.4f%s", x[j * n + i],
               (i % 6 == 5 && i != n - 1 ? "\n     " : ""));
      printf("\n");
    }
    /* Calculate full complex form of Hermitian data sequences */
    /* nag_sum_withdraw_convert_herm2complex_sep (c06gsc).
     * Convert Hermitian sequences to general complex sequences
     */
    nag_sum_withdraw_convert_herm2complex_sep(m, n, x, u, v, &fail);
    if (fail.code != NE_NOERROR) {
      exit_status = 1;
      goto END;
    }
    printf("\nOriginal data written in full complex form\n\n");
    for (j = 0; j < m; ++j) {
      printf("Real");
      for (i = 0; i < n; ++i)
        printf("%10.4f%s", u[j * n + i],
               (i % 6 == 5 && i != n - 1 ? "\n     " : ""));
      printf("\nImag");
      for (i = 0; i < n; ++i)
        printf("%10.4f%s", v[j * n + i],
               (i % 6 == 5 && i != n - 1 ? "\n     " : ""));
      printf("\n\n");
    }
    /* Initialize trig array */
    /* nag_sum_init_trig (c06gzc).
     * Initialization function for other c06 functions
     */
    nag_sum_init_trig(n, trig, &fail);
    if (fail.code != NE_NOERROR) {
      exit_status = 1;
      goto END;
    }
    /* Calculate transforms */
    /* nag_sum_withdraw_fft_hermitian_1d_multi_rfmt (c06fqc).
     * Multiple one-dimensional Hermitian discrete Fourier
     * transforms
     */
    nag_sum_withdraw_fft_hermitian_1d_multi_rfmt(m, n, x, trig, &fail);
    if (fail.code != NE_NOERROR) {
      exit_status = 1;
      goto END;
    }
    printf("\nDiscrete Fourier transforms (real values)\n\n");
    for (j = 0; j < m; ++j) {
      printf("    ");
      for (i = 0; i < n; ++i)
        printf("%10.4f%s", x[j * n + i],
               (i % 6 == 5 && i != n - 1 ? "\n     " : ""));
      printf("\n");
    }
    /* Calculate inverse transforms */
    /* nag_sum_withdraw_fft_real_1d_multi_rfmt (c06fpc).
     * Multiple one-dimensional real discrete Fourier transforms
     */
    nag_sum_withdraw_fft_real_1d_multi_rfmt(m, n, x, trig, &fail);
    if (fail.code != NE_NOERROR) {
      exit_status = 1;
      goto END;
    }
    /* nag_sum_withdraw_conjugate_hermitian_mult_rfmt (c06gqc).
     * Complex conjugate of multiple Hermitian sequences
     */
    nag_sum_withdraw_conjugate_hermitian_mult_rfmt(m, n, x, &fail);
    if (fail.code != NE_NOERROR) {
      exit_status = 1;
      goto END;
    }
    printf("\nOriginal data as restored by inverse transform\n\n");
    for (j = 0; j < m; ++j) {
      printf("    ");
      for (i = 0; i < n; ++i)
        printf("%10.4f%s", x[j * n + i],
               (i % 6 == 5 && i != n - 1 ? "\n     " : ""));
      printf("\n");
    }
  END:
    NAG_FREE(trig);
    NAG_FREE(u);
    NAG_FREE(v);
    NAG_FREE(x);
  }
  return exit_status;
}