NAG Library Manual, Mark 30.1
Interfaces:  FL   CL   CPP   AD 

NAG CL Interface Introduction
Example description
/* nag_nonpar_gofstat_anddar_exp (g08clc) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.1, 2024.
 */
#include <math.h>
#include <nag.h>
#include <stdio.h>
#include <string.h>

int main(void) {
  /* Scalars */
  Integer exit_status = 0, i, n;
  double a2, aa2, p, ybar;
  /* Array */
  double *y = 0;
  /* NAG types */
  Nag_Boolean issort;
  NagError fail;

  printf("%s\n\n",
         "nag_nonpar_gofstat_anddar_exp (g08clc) Example Program Results");

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

  /* Read number of observations */
  scanf("%" NAG_IFMT "", &n);
  scanf("%*[^\n] ");

  /* Memory allocation */
  if (!(y = NAG_ALLOC(n, double))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  /* Read observations */
  for (i = 0; i < n; i++) {
    scanf("%lf", y + i);
  }
  scanf("%*[^\n]");

  /* Let nag_nonpar_gofstat_anddar_exp (g08clc) sort the data */
  issort = Nag_FALSE;

  /* Calculate the Anderson-Darling goodness-of-fit test statistic and its
     probability for the case of an unspecified exponential distribution */
  INIT_FAIL(fail);
  /* nag_nonpar_gofstat_anddar_exp (g08clc) */
  nag_nonpar_gofstat_anddar_exp(n, issort, (const double *)y, &ybar, &a2, &aa2,
                                &p, &fail);

  /* Results */
  printf("%s ", "H0: data from exponential distribution with mean");
  printf("%6g\n", ybar);
  printf("%s", " Test statistic, A-squared: ");
  printf("%6g\n", a2);
  printf("%s", " Adjusted A-squared:        ");
  printf("%6g\n", aa2);
  printf("%s", " Upper tail probability:    ");
  printf("%6g\n", p);

END:
  NAG_FREE(y);

  return exit_status;
}