Example description
/* nag_1d_ratnl_eval (e01rbc) Example Program.
 *
 * Copyright 2017 Numerical Algorithms Group.
 *
 * Mark 26.2, 2017.
 */

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

int main(void)
{
  /* Scalars */
  double f, x;
  Integer exit_status, i, m;
  NagError fail;

  /* Arrays */
  double *a = 0, *u = 0;

  exit_status = 0;

  INIT_FAIL(fail);

  printf("nag_1d_ratnl_eval (e01rbc) Example Program Results\n");

  /* Skip heading in data file */
  scanf("%*[^\n] ");
  m = 4;

  /* Allocate memory */
  if (!(a = NAG_ALLOC(m, double)) || !(u = NAG_ALLOC(m, double)))
  {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  for (i = 1; i <= m; ++i)
    scanf("%lf", &a[i - 1]);
  scanf("%*[^\n] ");

  for (i = 1; i <= m - 1; ++i)
    scanf("%lf", &u[i - 1]);
  scanf("%*[^\n] ");
  scanf("%lf%*[^\n] ", &x);

  printf("\n");
  printf("x = %13.4e\n", x);

  /* nag_1d_ratnl_eval (e01rbc).
   * Interpolated values, evaluate rational interpolant
   * computed by nag_1d_ratnl_interp (e01rac), one variable
   */
  nag_1d_ratnl_eval(m, a, u, x, &f, &fail);
  if (fail.code == NE_NOERROR) {
    printf("\n");
    printf("The value of R(x) is %13.4e\n", f);
  }
  else {
    printf("Error from nag_1d_ratnl_eval (e01rbc).\n%s\n", fail.message);
    exit_status = 1;
  }
END:
  NAG_FREE(a);
  NAG_FREE(u);

  return exit_status;
}