/* nag_double_quantiles (g01amc) Example Program. * * Copyright 2006 Numerical Algorithms Group. * * Mark 9, 2009. */ #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ Integer exit_status = 0, i, n, nq; /* Arrays */ double *vec = 0, *quants = 0, *quant_vec = 0; /* Nag Types */ NagError fail; 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); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fprintf(fpout, "nag_double_quantiles (g01amc) Example Program Results\n"); fscanf(fpin, "%ld", &n); fscanf(fpin, "%ld", &nq); if (n >= 1 && nq >= 1) { if (!(vec = NAG_ALLOC(n, double)) || !(quants = NAG_ALLOC(nq, double)) || !(quant_vec = NAG_ALLOC(nq, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { if (n < 1) { fprintf(fpout, "Invalid n.\n"); } else { fprintf(fpout, "Invalid nq.\n"); } exit_status = 1; goto END; } for (i = 0; i < n; ++i) fscanf(fpin, "%lf", &vec[i]); for (i = 0; i < nq; ++i) fscanf(fpin, "%lf", &quants[i]); /* nag_double_quantiles (g01amc). * Find quantiles of set of values of data type double */ nag_double_quantiles((size_t) n, vec, (size_t) nq, quants, quant_vec, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_double_quantiles (g01amc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, " Quantile Result\n\n"); for (i = 0; i < nq; ++i) { fprintf(fpout, " %7.4f %7.4f\n", quants[i], quant_vec[i]); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (vec) NAG_FREE(vec); if (quants) NAG_FREE(quants); if (quant_vec) NAG_FREE(quant_vec); return exit_status; }