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

NAG CL Interface Introduction
Example description
/* nag_stat_ranks_and_scores (g01dhc) Example Program.
 *
 * Copyright 2023 Numerical Algorithms Group.
 *
 * Mark 29.2, 2023.
 *
 */

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

int main(void) {

  Integer exit_status = 0, i, n;
  NagError fail;
  double *r = 0, *x = 0;

  INIT_FAIL(fail);

  printf("nag_stat_ranks_and_scores (g01dhc) Example Program Results\n\n");

  /* Skip heading in data file */
  scanf("%*[^\n] ");
  scanf("%" NAG_IFMT " ", &n);
  if (n >= 1) {
    if (!(r = NAG_ALLOC(n, double)) || !(x = NAG_ALLOC(n, double))) {
      printf("Allocation failure\n");
      exit_status = -1;
      goto END;
    }
  } else {
    printf("Invalid n.\n");
    exit_status = 1;
    return exit_status;
  }
  for (i = 1; i <= n; ++i)
    scanf("%lf ", &x[i - 1]);

  /* nag_stat_ranks_and_scores (g01dhc).
   * Ranks, Normal scores, approximate Normal scores or
   * exponential (Savage) scores
   */
  nag_stat_ranks_and_scores(Nag_SavageScores, Nag_AverageTies, n, x, r, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_stat_ranks_and_scores (g01dhc).\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  printf("The Savage Scores : \n");
  printf("  (Average scores are used for tied observations)\n\n");
  for (i = 1; i <= n; ++i)
    printf("%10.4f\n", r[i - 1]);
END:
  NAG_FREE(r);
  NAG_FREE(x);
  return exit_status;
}