/* nag_polygamma_deriv (s14adc) Example Program.
 *
 * Copyright 2017 Numerical Algorithms Group.
 *
 * Mark 26.1, 2017.
 */

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

int main(void)
{
  Integer exit_status = 0;
  double x, w[4];
  int n, m;
  NagError fail;

  INIT_FAIL(fail);

  /* Skip heading in data file */
  scanf("%*[^\n]");
  printf("nag_polygamma_deriv (s14adc) Example Program Results\n");
  printf("%9s%14s%14s%14s%14s\n", "x", "w(0,x)", "w(1,x)", "w(2,x)",
         "w(3,x)");
  while (scanf("%lf", &x) != EOF)
  {
    n = 0;
    m = 4;
    /* nag_polygamma_deriv (s14adc).
     * Scaled derivatives of psi(x)
     */
    nag_polygamma_deriv(x, n, m, w, &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_polygamma_deriv (s14adc).\n%s\n", fail.message);
      exit_status = 1;
      goto END;
    }
    printf("%13.4e %13.4e %13.4e %13.4e %13.4e\n", x, w[0], w[1], w[2], w[3]);
  }

END:
  return exit_status;
}