/* nag_gamma_pdf (g01kfc) Example Program. * * Copyright 2009, Numerical Algorithms Group. * * Mark 9, 2009. */ /* Pre-processor includes */ #include #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /*Integer scalar and array declarations */ Integer exit_status = 0; Integer i, ndata; /*Double scalar and array declarations */ double a, b, f, x; /*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); fprintf(fpout, "nag_gamma_pdf (g01kfc) Example Program Results\n\n"); fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%*[^\n] ", &ndata); fprintf(fpout, "%14s%16s%16s%16s\n\n", "X", "A", "B", "RESULT"); for (i = 0; i < ndata; i++) { fscanf(fpin, "%lf%lf%lf%*[^\n] ", &x, &a, &b); /* * nag_gamma_pdf (g01kfc) * Calculates the value for the probability density function of * the gamma distribution at a chosen point. */ f = nag_gamma_pdf(x, a, b, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gamma_pdf (g01kfc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "%18.4e%16.4e%16.4e%16.4e\n", x, a, b, f); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); return exit_status; }