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

NAG CL Interface Introduction
Example description
/* nag_interp_dim1_monconv_eval (e01cfc) Example Program.
 *
 * Copyright 2023 Numerical Algorithms Group.
 *
 * Mark 29.1, 2023.
 */

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

int main(void) {

  /* Logicals */
  Nag_Boolean negfor;
  Nag_Boolean yfor;

  /* Scalars */
  Integer i, n, m;
  Integer exit_status = 0;
  double lambda = 0;

  /* Arrays */
  double *comm = 0, *fwd = 0, *val = 0, *x = 0, *xi = 0, *y = 0;
  char cnegfor[40], cyfor[40];

  /* Nag Types */
  NagError fail;

  INIT_FAIL(fail);

  printf("nag_interp_dim1_monconv_eval (e01cfc) Example Program Results\n");
  printf("\n");

  /* Read dimensions of arrays from data file */
  scanf("%*[^\n] ");
  scanf("%" NAG_IFMT "%" NAG_IFMT "%*[^\n]", &n, &m);

  /* Allocate arrays accordingly */
  if (!(x = NAG_ALLOC((n), double)) || !(y = NAG_ALLOC((n), double)) ||
      !(comm = NAG_ALLOC((4 * n + 10), double)) ||
      !(xi = NAG_ALLOC((m), double)) || !(val = NAG_ALLOC((m), double)) ||
      !(fwd = NAG_ALLOC((m), double))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  /* Input whether negative forward differences are allowed, and whether */
  /* supplied values are forward differences */
  scanf("%39s", cnegfor);
  scanf("%39s", cyfor);
  scanf("%*[^\n] ");

  negfor = (Nag_Boolean)nag_enum_name_to_value(cnegfor);
  yfor = (Nag_Boolean)nag_enum_name_to_value(cyfor);

  /* Read amelioration parameter value */
  scanf("%lf%*[^\n]", &lambda);

  /* Read x and y array values from data file */
  for (i = 0; i < n; i++) {
    scanf("%lf%lf%*[^\n]", &x[i], &y[i]);
  }

  /* Interpolation setup */
  nag_interp_dim1_monconv_disc(n, lambda, negfor, yfor, x, y, comm, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_interp_dim1_monconv_disc (e01cec).\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  /* Interpolate at values in range [0:x(n)+0.2] in steps of 0.1 */
  printf("i     x       Rate    Forward\n");
  for (i = 0; i < m; i++) {
    xi[i] = ((double)i * 0.1);
  }
  nag_interp_dim1_monconv_eval(m, xi, val, fwd, comm, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_interp_dim1_monconv_eval (e01cfc).\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }
  for (i = 0; i < m; i++) {
    printf("%3.3" NAG_IFMT " %7.2f %7.3f %7.3f\n", i, xi[i], val[i], fwd[i]);
  }

END:
  NAG_FREE(x);
  NAG_FREE(y);
  NAG_FREE(comm);
  NAG_FREE(xi);
  NAG_FREE(val);
  NAG_FREE(fwd);

  return exit_status;
}