/* nag_incomplete_gamma (s14bac) Example Program.
 *
 * Copyright 2014 Numerical Algorithms Group.
 *
 * Mark 2 revised, 1992.
 */

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

int main(void)
{
  Integer  exit_status = 0;
  double   a, p, q, tol, x;
  NagError fail;

  INIT_FAIL(fail);

  /* Skip heading in data file */
  scanf("%*[^\n]");
  printf("nag_incomplete_gamma (s14bac) Example Program Results\n");
  /* nag_machine_precision (x02ajc).
   * The machine precision
   */
  tol = nag_machine_precision;
  printf("        a           x           p           q\n");
  while (scanf("%lf %lf", &a, &x) != EOF)
    {
      /* nag_incomplete_gamma (s14bac).
       * Incomplete Gamma functions P(ax) and Q(ax)
       */
      nag_incomplete_gamma(a, x, tol, &p, &q, &fail);
      if (fail.code != NE_NOERROR)
        {
          printf("Error from nag_incomplete_gamma (s14bac).\n%s\n",
                  fail.message);
          exit_status = 1;
          goto END;
        }
      printf("%12.4f%12.4f%12.4f%12.4f\n", a, x, p, q);
    }

 END:
  return exit_status;
}