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

NAG CL Interface Introduction
Example description
/* nag_nonpar_test_median (g08acc) Example Program.
 *
 * Copyright 2023 Numerical Algorithms Group.
 *
 * Mark 29.1, 2023.
 */

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

int main(void) {
  Integer above, below, exit_status = 0, i, n1, n2;
  NagError fail;
  double p, *x = 0, *y = 0;

  INIT_FAIL(fail);

  printf("nag_nonpar_test_median (g08acc) Example Program Results\n");

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

  n1 = 16;
  n2 = 23;
  if (!(x = NAG_ALLOC(n1, double)) || !(y = NAG_ALLOC(n2, double))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  for (i = 1; i <= n1; ++i)
    scanf("%lf", &x[i - 1]);
  for (i = 1; i <= n2; ++i)
    scanf("%lf", &y[i - 1]);
  printf("\nMedian test\n\n");
  printf("Data values\n\n");
  printf("    Group 1  ");
  for (i = 1; i <= n1; ++i)
    printf("%4.0f%s", x[i - 1], i % 8 ? "" : "\n             ");
  printf("\n");
  printf("    Group 2  ");
  for (i = 1; i <= n2; ++i)
    printf("%4.0f%s", y[i - 1], i % 8 ? "" : "\n             ");
  printf("\n");
  /* nag_nonpar_test_median (g08acc).
   * Median test on two samples of unequal size
   */
  nag_nonpar_test_median(n1, x, n2, y, &above, &below, &p, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_nonpar_test_median (g08acc).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }

  printf("\n");
  printf("%6" NAG_IFMT "%s\n", above, " scores below median in group 1");
  printf("%6" NAG_IFMT "%s\n", below, " scores below median in group 2");
  printf("\n%s%8.5f\n", "     Significance  ", p);
END:
  NAG_FREE(x);
  NAG_FREE(y);
  return exit_status;
}