/* nag_deviates_students_t (g01fbc) Example Program.
 *
 * Copyright 2014 Numerical Algorithms Group.
 *
 * Mark 4, 1996.
 * Mark 5 revised, 1998.
 * Mark 7 revised, 2001.
 *
 */

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

int main(void)
{
  Integer                    exit_status=0;
  double                     df, p, t;
  int                        i;
  static Nag_TailProbability tail[] = { Nag_LowerTail, Nag_UpperTail,
                                        Nag_TwoTailSignif, Nag_TwoTailConfid };
  static const char          *tailmess[] = { "Nag_LowerTail", "Nag_UpperTail",
                                             "Nag_TwoTailSignif",
                                             "Nag_TwoTailConfid" };
  NagError                   fail;

  INIT_FAIL(fail);

  printf(
          "nag_deviates_students_t (g01fbc) Example Program Results\n\n");
  /* Skip heading in data file */
  scanf("%*[^\n]");
  printf("    p      df          tail                  t\n\n");
  while (scanf("%lf %lf %d", &p, &df, &i) != EOF)
    {
      /* nag_deviates_students_t (g01fbc).
       * Deviates for Student's t-distribution
       */
      t = nag_deviates_students_t(tail[i], p, df, &fail);
      if (fail.code != NE_NOERROR)
        {
          printf("Error from nag_deviates_students_t (g01fbc).\n%s\n",
                  fail.message);
          exit_status = 1;
          goto END;
        }
      printf("%8.3f%8.3f   %-19s  %8.3f\n", p, df, tailmess[i], t);
    }

 END:
  return exit_status;
}