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

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

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

int main(void) {
  /* Scalars */
  Integer i, l, n, ndim;
  Integer exit_status = 0;
  NagError fail;
  /* Arrays */
  Complex *x = 0;
  Integer *nd = 0;

  INIT_FAIL(fail);

  printf("nag_sum_fft_complex_multid_1d (c06pfc) Example Program Results\n");
  /* Skip heading in data file */
  scanf("%*[^\n]");
  scanf("%" NAG_IFMT "%" NAG_IFMT "%" NAG_IFMT "", &ndim, &l, &n);
  if (n >= 1) {
    /* Allocate memory */
    if (!(x = NAG_ALLOC(n, Complex)) || !(nd = NAG_ALLOC(ndim, Integer))) {
      printf("Allocation failure\n");
      exit_status = -1;
      goto END;
    }
    for (i = 0; i < ndim; ++i) {
      scanf("%" NAG_IFMT "", &nd[i]);
    }

    /* Read in complex data and print out. */
    scanf("%*[^\n]");
    for (i = 0; i < n; ++i) {
      scanf(" ( %lf, %lf ) ", &x[i].re, &x[i].im);
    }
    scanf("%*[^\n]");
    printf("\n");
    fflush(stdout);
    /* nag_file_print_matrix_complex_gen_comp (x04dbc).
     * Print complex general matrix (comprehensive)
     */
    fflush(stdout);
    nag_file_print_matrix_complex_gen_comp(
        Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, nd[0], n / nd[0], x,
        nd[0], Nag_BracketForm, "%6.3f", "Original data", Nag_NoLabels, 0,
        Nag_NoLabels, 0, 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 = 1;
      goto END;
    }

    /* Compute transform */
    /* nag_sum_fft_complex_multid_1d (c06pfc).
     * One-dimensional complex discrete Fourier transform of
     * multi-dimensional data (using complex data type)
     */
    nag_sum_fft_complex_multid_1d(Nag_ForwardTransform, ndim, l, nd, n, x,
                                  &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_sum_fft_complex_multid_1d (c06pfc).\n%s\n",
             fail.message);
      exit_status = 1;
      goto END;
    }
    printf("\n");
    /* nag_file_print_matrix_complex_gen_comp (x04dbc), see above. */
    fflush(stdout);
    nag_file_print_matrix_complex_gen_comp(
        Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, nd[0], n / nd[0], x,
        nd[0], Nag_BracketForm, "%6.3f",
        "Discrete Fourier transform of variable 2", Nag_NoLabels, 0,
        Nag_NoLabels, 0, 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 = 1;
      goto END;
    }

    /* Compute inverse transform */
    /* nag_sum_fft_complex_multid_1d (c06pfc), see above. */
    nag_sum_fft_complex_multid_1d(Nag_BackwardTransform, ndim, l, nd, n, x,
                                  &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_sum_fft_complex_multid_1d (c06pfc).\n%s\n",
             fail.message);
      exit_status = 1;
      goto END;
    }
    printf("\n");
    /* nag_file_print_matrix_complex_gen_comp (x04dbc), see above. */
    fflush(stdout);
    nag_file_print_matrix_complex_gen_comp(
        Nag_ColMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, nd[0], n / nd[0], x,
        nd[0], Nag_BracketForm, "%6.3f",
        "Original data as restored by inverse"
        " transform",
        Nag_NoLabels, 0, Nag_NoLabels, 0, 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 = 1;
      goto END;
    }
  } else
    printf("\nInvalid value of n.\n");

END:
  NAG_FREE(x);
  NAG_FREE(nd);

  return exit_status;
}