/* nag_normal_scores_exact (g01dac) 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 errest, etol;
  Integer exit_status = 0, i, j, n, nmax;
  NagError fail;
  /* Arrays */
  double *pp = 0;

  INIT_FAIL(fail);

  printf("nag_normal_scores_exact (g01dac) Example Program Results\n");

  etol = 0.001;
  nmax = 15;

  /* Allocate memory */
  if (!(pp = NAG_ALLOC(nmax, double)))
  {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  for (j = 5; j <= nmax; j += 5) {
    n = j;
    /* nag_normal_scores_exact (g01dac).
     * Normal scores, accurate values
     */
    nag_normal_scores_exact(n, pp, etol, &errest, &fail);

    if (fail.code != NE_NOERROR) {
      printf("Error from nag_normal_scores_exact (g01dac).\n%s\n",
             fail.message);
      exit_status = 1;
      goto END;
    }
    printf("\nSet size = %2" NAG_IFMT "\n\n", n);
    printf("Error tolerance (input) = %13.3e\n\n", etol);
    printf("Error estimate (output) = %13.3e\n\n", errest);
    printf("Normal scores\n");
    for (i = 1; i <= n; ++i) {
      printf("%10.3f", pp[i - 1]);
      printf(i % 5 == 0 || i == n ? "\n" : " ");
    }
    printf("\n");
  }

END:
  NAG_FREE(pp);

  return exit_status;
}