/* nag_prob_normal (g01eac) Example Program.
 *
 * Copyright 2014 Numerical Algorithms Group.
 *
 * Mark 4, 1996.
 *
 */


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

int main(void)
{
  Integer             exit_status = 0;
  double              prob;
  double              x;
  Integer             i;
  char                nag_enum_arg[40];
  Nag_TailProbability tail;
  NagError            fail;

  INIT_FAIL(fail);

  printf("nag_prob_normal (g01eac) Example Program Results\n");

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

  printf("\n     Tail               X      Probability \n\n");
  for (i = 1; i <= 4; ++i)
    {
      scanf("%39s %lf ", nag_enum_arg, &x);
      /* nag_enum_name_to_value (x04nac).
       * Converts NAG enum member name to value
       */
      tail = (Nag_TailProbability) nag_enum_name_to_value(nag_enum_arg);

      /* nag_prob_normal (g01eac).
       * Probabilities for the standard Normal distribution
       */
      prob = nag_prob_normal(tail, x, &fail);
      if (fail.code != NE_NOERROR)
        {
          printf("Error from nag_prob_normal (g01eac).\n%s\n",
                  fail.message);
          exit_status = 1;
          goto END;
        }
      printf(" %-17s    %4.2f       %6.4f\n", nag_enum_arg, x, prob);
    }


 END:
  return exit_status;
}