Example description
/* nag_quad_dim1_data (d01gac) Example Program.
 *
 * Copyright 2020 Numerical Algorithms Group.
 *
 * Mark 27.1, 2020.
 */

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

int main(void) {

  Integer exit_status = 0, i, n;
  NagError fail;
  double ans, error, *x = 0, *y = 0;

  INIT_FAIL(fail);

  printf("nag_quad_dim1_data (d01gac) Example Program Results\n");
  scanf("%*[^\n]"); /* Skip heading in data file */
  scanf("%" NAG_IFMT "", &n);
  if (n >= 4) {
    if (!(x = NAG_ALLOC(n, double)) || !(y = 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 (i = 0; i < n; ++i)
    scanf("%lf%lf", &x[i], &y[i]);
  /* nag_quad_dim1_data (d01gac).
   * One-dimensional integration of a function defined by data
   * values only
   */
  nag_quad_dim1_data(n, x, y, &ans, &error, &fail);
  if (fail.code == NE_NOERROR) {
    printf("Integral = %7.4f\n", ans);
    printf("Estimated error = %7.4f\n", error);
  } else {
    printf("Error from nag_quad_dim1_data (d01gac).\n%s\n", fail.message);
    printf("%s\n", fail.message);
    exit_status = 1;
  }
END:
  NAG_FREE(x);
  NAG_FREE(y);
  return exit_status;
}