/* nag_prob_1_sample_ks (g01eyc) Example Program.
 *
 * NAGPRODCODE Version.
 *
 * Copyright 2016 Numerical Algorithms Group.
 *
 * Mark 26, 2016.
 */

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

int main(void)
{

  /* Scalars */
  double d__, prob;
  Integer exit_status, n;
  NagError fail;

  INIT_FAIL(fail);

  exit_status = 0;
  printf("nag_prob_1_sample_ks (g01eyc) Example Program Results\n\n");
  printf("%s\n\n", "    d       n    One-sided probability");

  /* Skip heading in data file */
  scanf("%*[^\n] ");
  while (scanf("%" NAG_IFMT " %lf%*[^\n] ", &n, &d__) != EOF)
  {
    /* nag_prob_1_sample_ks (g01eyc).
     * Computes probabilities for the one-sample
     * Kolmogorov-Smirnov distribution
     */
    prob = nag_prob_1_sample_ks(n, d__, &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_prob_1_sample_ks (g01eyc).\n%s\n", fail.message);
      exit_status = 1;
      goto END;
    }
    printf("%7.4f%2s%4" NAG_IFMT "%10s%7.4f\n", d__, "", n, "", prob);
  }
END:
  return exit_status;
}