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

NAG CL Interface Introduction
Example description
/* nag_interp_dim1_monotonic_intg (e01bhc) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.2, 2024.
 */

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

int main(void) {
  Integer exit_status = 0, n, r;
  NagError fail;
  double a, b, *d = 0, *f = 0, integral, *x = 0;

  INIT_FAIL(fail);

  printf("nag_interp_dim1_monotonic_intg (e01bhc) Example Program Results\n");
  scanf("%*[^\n]"); /* Skip heading in data file */
  scanf("%" NAG_IFMT "", &n);
  if (n >= 2) {
    if (!(d = NAG_ALLOC(n, double)) || !(f = NAG_ALLOC(n, double)) ||
        !(x = NAG_ALLOC(n, double))) {
      printf("Allocation failure\n");
      exit_status = -1;
      goto END;
    }
  } else {
    printf("Invalid n.\n");
    exit_status = 1;
    return exit_status;
  }
  for (r = 0; r < n; r++)
    scanf("%lf%lf%lf", &x[r], &f[r], &d[r]);
  printf("                                          Integral\n");
  printf("          a                  b            over (a,b)\n");
  /* Read a, b pairs until end of file and compute
   * definite integrals.
   */
  while (scanf("%lf%lf", &a, &b) != EOF)
  {
    /* nag_interp_dim1_monotonic_intg (e01bhc).
     * Evaluation of interpolant computed by
     * nag_interp_dim1_monotonic (e01bec), definite integral
     */
    nag_interp_dim1_monotonic_intg(n, x, f, d, a, b, &integral, &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_interp_dim1_monotonic_intg (e01bhc).\n%s\n",
             fail.message);
      exit_status = 1;
      goto END;
    }
    printf("%13.4f      %13.4f      %13.4f\n", a, b, integral);
  }
END:
  NAG_FREE(d);
  NAG_FREE(f);
  NAG_FREE(x);
  return exit_status;
}