/* nag_ranks_and_scores (g01dhc) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * Mark 8 revised, 2004. * */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, i, n; NagError fail; double *r = 0, *x = 0; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_ranks_and_scores (g01dhc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld ", &n); if (n >= 1) { if (!(r = NAG_ALLOC(n, double)) || !(x = NAG_ALLOC(n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid n.\n"); exit_status = 1; return exit_status; } for (i = 1; i <= n; ++i) fscanf(fpin, "%lf ", &x[i - 1]); /* nag_ranks_and_scores (g01dhc). * Ranks, Normal scores, approximate Normal scores or * exponential (Savage) scores */ nag_ranks_and_scores(Nag_SavageScores, Nag_AverageTies, n, x, r, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_ranks_and_scores (g01dhc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "The Savage Scores : \n"); fprintf(fpout, " (Average scores are used for tied observations)\n\n"); for (i = 1; i <= n; ++i) fprintf(fpout, "%10.4f\n", r[i - 1]); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (r) NAG_FREE(r); if (x) NAG_FREE(x); return exit_status; }