```/* nag_fft_multiple_cosine (c06hbc) Example Program.
*
* Copyright 2014 Numerical Algorithms Group.
*
* Mark 2, 1991.
* Mark 8 revised, 2004.
*/

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

#define X(I, J) x[(I) *row_len + (J)]
int main(void)
{
Integer  exit_status = 0, i, j, m, n, row_len;
NagError fail;
double   *trig = 0, *x = 0;

INIT_FAIL(fail);

printf("nag_fft_multiple_cosine (c06hbc) Example Program Results\n");
scanf(" %*[^\n]");    /* Skip heading in data file */
while (scanf("%ld %ld", &m, &n) != EOF)
{
if (m >= 1 && n >= 1)
{
if (!(trig = NAG_ALLOC(2*n, double)) ||
!(x = NAG_ALLOC(m*(n+1), double)))
{
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
}
else
{
printf("Invalid m or n.\n");
exit_status = 1;
return exit_status;
}
row_len = n + 1;
scanf(" %*[^\n]"); /* Skip text in data file */
scanf(" %*[^\n]");
for (i = 0; i < m; ++i)
for (j = 0; j < row_len; ++j)
scanf("%lf", &X(i, j));
printf("\nOriginal data values\n\n");
for (i = 0; i < m; ++i)
{
for (j = 0; j < row_len; ++j)
printf(" %10.4f%s", X(i, j),
(j%7 == 6 && j != row_len-1?"\n":""));
printf("\n");
}

/* nag_fft_init_trig (c06gzc).
* Initialization function for other c06 functions
*/
nag_fft_init_trig(n, trig, &fail);
if (fail.code != NE_NOERROR)
{
printf("Error from nag_fft_init_trig (c06gzc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
/* Initialise trig array */
/* nag_fft_multiple_cosine (c06hbc).
* Discrete cosine transform
*/
nag_fft_multiple_cosine(m, n, x, trig, &fail);
if (fail.code != NE_NOERROR)
{
printf("Error from nag_fft_multiple_cosine (c06hbc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}
/* Compute transform */
printf("\nDiscrete Fourier cosine transforms\n\n");
for (i = 0; i < m; ++i)
{
for (j = 0; j < row_len; ++j)
printf(" %10.4f%s", X(i, j),
(j%7 == 6 && j != row_len-1?"\n":""));
printf("\n");
}
/* Compute inverse transform */
/* nag_fft_multiple_cosine (c06hbc), see above. */
nag_fft_multiple_cosine(m, n, x, trig, &fail);
if (fail.code != NE_NOERROR)
{
printf("Error from nag_fft_multiple_cosine (c06hbc).\n%s\n",
fail.message);
exit_status = 1;
goto END;
}

printf("\nOriginal data as restored by inverse transform\n\n");
for (i = 0; i < m; ++i)
{
for (j = 0; j < row_len; ++j)
printf(" %10.4f%s", X(i, j),
(j%7 == 6 && j != row_len-1?"\n":""));
printf("\n");
}
NAG_FREE(trig);
NAG_FREE(x);
}
END:
NAG_FREE(trig);
NAG_FREE(x);
return exit_status;
}
```