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

NAG CL Interface Introduction
Example description
/* nag_interp_dim1_everett (e01abc) 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;
  Integer i, n, r;
  double p;

  /* Local Arrays */
  double *a = 0, *g = 0;

  /* Nag Types */
  NagError fail;

  INIT_FAIL(fail);

  printf("nag_interp_dim1_everett (e01abc) Example Program Results\n");

  /* Skip heading in data file */
  scanf("%*[^\n] ");
  scanf("%" NAG_IFMT "", &n);
  scanf("%lf", &p);
  scanf("%*[^\n] ");

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

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

  /* nag_interp_dim1_everett (e01abc).
   * Interpolated values, Everett's formula, equally spaced data, one variable.
   */
  nag_interp_dim1_everett(n, p, a, g, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_interp_dim1_everett (e01abc).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }

  printf("\n");
  for (r = 0; r <= n - 1; r++) {
    printf("Central differences order %" NAG_IFMT "  of Y0 = %12.5f\n", r,
           g[2 * r]);
    printf("                                Y1 = %12.5f\n", g[2 * r + 1]);
  }
  printf("\n");
  printf("Function value at interpolation point = %12.5f\n", g[2 * n]);

END:
  NAG_FREE(a);
  NAG_FREE(g);

  return exit_status;
}