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

NAG CL Interface Introduction
Example description
/* nag_sum_fft_qtrsine (c06rgc) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.3, 2024.
 */

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

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

  INIT_FAIL(fail);

  printf("nag_sum_fft_qtrsine (c06rgc) Example Program Results\n");
  fflush(stdout);

  /* Read dimensions of array from data file. */
  scanf("%*[^\n] %" NAG_IFMT "%" NAG_IFMT "%*[^\n]", &m, &n);
  if (!(x = NAG_ALLOC((m * n), double))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  /* Read array values from data file and print out. */
  for (j = 0; j < m * n; j++)
    scanf("%lf", &x[j]);
  sprintf(title, "\n Original data values\n");
  nag_file_print_matrix_real_gen_comp(
      Nag_RowMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, m, n, x, n, "%9.4f",
      title, Nag_NoLabels, 0, Nag_NoLabels, 0, 80, 0, NULL, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_file_print_matrix_real_gen_comp (x04cbc).\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  /* nag_sum_fft_qtrsine (c06rgc).
   * Discrete quarter-wave sine transforms
   */
  nag_sum_fft_qtrsine(Nag_ForwardTransform, m, n, x, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_sum_fft_qtrsine (c06rgc).\n%s\n", fail.message);
    exit_status = 2;
    goto END;
  }
  sprintf(title, "\n Discrete quarter-wave Fourier sine transforms\n");
  nag_file_print_matrix_real_gen_comp(
      Nag_RowMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, m, n, x, n, "%9.4f",
      title, Nag_NoLabels, 0, Nag_NoLabels, 0, 80, 0, NULL, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_file_print_matrix_real_gen_comp (x04cbc).\n%s\n",
           fail.message);
    exit_status = 3;
    goto END;
  }

  /* Call backward transform to restore the original data. */
  nag_sum_fft_qtrsine(Nag_BackwardTransform, m, n, x, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_sum_fft_qtrsine (c06rgc).\n%s\n", fail.message);
    exit_status = 4;
    goto END;
  }
  sprintf(title, "\n Original data as restored by inverse transform\n");
  nag_file_print_matrix_real_gen_comp(
      Nag_RowMajor, Nag_GeneralMatrix, Nag_NonUnitDiag, m, n, x, n, "%9.4f",
      title, Nag_NoLabels, 0, Nag_NoLabels, 0, 80, 0, NULL, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_file_print_matrix_real_gen_comp (x04cbc).\n%s\n",
           fail.message);
    exit_status = 5;
    goto END;
  }

END:
  NAG_FREE(x);
  return exit_status;
}