/* nag_prob_lin_chi_sq (g01jdc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ double c, d, prob; Integer exit_status, i, n; /* Arrays */ char nag_enum_arg[40]; double *rlam = 0; Nag_LCCMethod method; 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); exit_status = 0; fprintf(fpout, "nag_prob_lin_chi_sq (g01jdc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); n = 10; /* Allocate memory */ if (!(rlam = NAG_ALLOC(n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } fscanf(fpin, " %s%lf%lf%*[^\n] ", nag_enum_arg, &d, &c); /* nag_enum_name_to_value(x04nac). * Converts NAG enum member name to value */ method = (Nag_LCCMethod) nag_enum_name_to_value(nag_enum_arg); for (i = 1; i <= n; ++i) fscanf(fpin, "%lf", &rlam[i - 1]); fscanf(fpin, "%*[^\n] "); /* nag_prob_lin_chi_sq (g01jdc). * Computes lower tail probability for a linear combination * of (central) chi^2 variables */ nag_prob_lin_chi_sq(method, n, rlam, d, c, &prob, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_prob_lin_chi_sq (g01jdc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); fprintf(fpout, " Values of lambda "); for (i = 1; i <= n; ++i) { if (i%6 == 0) fprintf(fpout, "%18s", " "); fprintf(fpout, "%6.2f ", rlam[i - 1]); if (i%5 == 0 || i == n) fprintf(fpout, "\n"); } fprintf(fpout, " Value of D %6.2f\n", d); fprintf(fpout, " Value of C %6.2f\n\n", c); fprintf(fpout, " Probability = %11.4f\n", prob); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (rlam) NAG_FREE(rlam); return exit_status; }