/* nag_prob_non_central_students_t (g01gbc) Example Program.
 *
 * Copyright 2017 Numerical Algorithms Group.
 *
 * Mark 26.1, 2017.
 */

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

int main(void)
{
  Integer exit_status = 0, max_iter;
  NagError fail;
  double delta, df, prob, t, tol;

  INIT_FAIL(fail);

  printf("nag_prob_non_central_students_t (g01gbc) Example Program Results"
         "\n\n");

  /* Skip heading in data file */
  scanf("%*[^\n]");

  printf("      t       df    delta    prob\n\n");
  tol = 5e-6;
  max_iter = 50;
  while ((scanf("%lf %lf %lf %*[^\n]", &t, &df, &delta)) != EOF)
  {
    /* nag_prob_non_central_students_t (g01gbc).
     * Computes probabilities for the non-central Student's
     * t-distribution
     */
    prob = nag_prob_non_central_students_t(t, df, delta, tol, max_iter,
                                           &fail);
    if (fail.code == NE_NOERROR)
      printf(" %8.3f%8.3f%8.3f%8.4f\n", t, df, delta, prob);
    else {
      printf("Error from nag_prob_non_central_students_t (g01gbc).\n%s\n",
             fail.message);
      exit_status = 1;
      goto END;
    }
  }
END:
  return exit_status;
}