Example description
/* nag_fit_dim1_cheb_eval (e02aec) Example Program.
 *
 * Copyright 2019 Numerical Algorithms Group.
 *
 * Mark 27.0, 2019.
 *
 */

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

int main(void)
{
  Integer exit_status = 0, i, m, n, r;
  NagError fail;
  double *a = 0, p, xcap;

  INIT_FAIL(fail);

  printf("nag_fit_dim1_cheb_eval (e02aec) Example Program Results \n");

  /* Skip heading in data file */
  scanf("%*[^\n]");
  while ((scanf("%" NAG_IFMT "", &m) != EOF))
  {
    if (m > 0) {
      scanf("%" NAG_IFMT "", &n);
      if (n >= 0) {
        if (!(a = NAG_ALLOC(n + 1, double)))
        {
          printf("Allocation failure\n");
          exit_status = -1;
          goto END;
        }
      }
      else {
        printf("Invalid n.\n");
        exit_status = 1;
        return exit_status;
      }
      for (i = 0; i < n + 1; ++i)
        scanf("%lf", &a[i]);
      printf("\n   R       Argument       Value of polynomial \n");
      for (r = 1; r <= m; ++r) {
        xcap = (double) (2 * r - m - 1) / (double) (m - 1);
        /* nag_fit_dim1_cheb_eval (e02aec).
         * Evaluates the coefficients of a Chebyshev series
         * polynomial
         */
        nag_fit_dim1_cheb_eval(n + 1, a, xcap, &p, &fail);
        if (fail.code != NE_NOERROR) {
          printf("Error from nag_fit_dim1_cheb_eval (e02aec).\n%s\n", fail.message);
          exit_status = 1;
          goto END;
        }
        printf(" %3" NAG_IFMT "%14.4f    %14.4f\n", r, xcap, p);
      }
    }
  END:
    NAG_FREE(a);
  }
  return exit_status;
}