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

NAG CL Interface Introduction
Example description
/* nag_fit_dim1_spline_integ (e02bdc) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.0, 2024.
 */

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

int main(void) {
  Integer exit_status = 0, j;
  NagError fail;
  Nag_Spline spline;
  double integral;

  INIT_FAIL(fail);

  /* Initialize spline */
  spline.lamda = 0;
  spline.c = 0;

  printf("nag_fit_dim1_spline_integ (e02bdc) Example Program Results\n");
  scanf("%*[^\n]"); /* Skip heading in data file */
  while (scanf("%" NAG_IFMT "", &(spline.n)) != EOF)
  {
    if (spline.n > 0) {
      if (!(spline.c = NAG_ALLOC(spline.n, double)) ||
          !(spline.lamda = NAG_ALLOC(spline.n, double))) {
        printf("Storage allocation failed. Reduce the "
               "size of spline.n\n");
        exit_status = 1;
        goto END;
      }
    } else {
      printf("spline.n is out of range : spline.n = %" NAG_IFMT "\n", spline.n);
      exit_status = 1;
      goto END;
    }
    for (j = 0; j < spline.n; j++)
      scanf("%lf", &(spline.lamda[j]));
    for (j = 0; j < spline.n - 3; j++)
      scanf("%lf", &(spline.c[j]));
    /* nag_fit_dim1_spline_integ (e02bdc).
     * Evaluation of fitted cubic spline, definite integral
     */
    nag_fit_dim1_spline_integ(&spline, &integral, &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_fit_dim1_spline_integ (e02bdc).\n%s\n",
             fail.message);
      exit_status = 1;
      goto END;
    }
    printf("Definite integral = %12.3e\n", integral);
    NAG_FREE(spline.c);
    NAG_FREE(spline.lamda);
  }
END:
  return exit_status;
}