/* nag_legendre_p (s22aac) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * NAG C Library * * Mark 6, 2000. * Mark 7, revised, 2001. * Mark 8 revised, 2004. * */ #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, m, mode, n, nl; NagError fail; char *str = 0; double *p = 0, x; 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_legendre_p (s22aac) Example Program Results\n"); fscanf(fpin, "%ld %lf %ld %ld", &mode, &x, &m, &nl); if (!(p = NAG_ALLOC(nl+1, double)) || !(str = NAG_ALLOC(80, char))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } if (mode == 1) { if (m == 0) Vstrcpy(str, "Unnormalized Legendre function values\n"); else Vstrcpy(str, "Unnormalized associated Legendre function values\n"); } else if (mode == 2) { if (m == 0) Vstrcpy(str, "Normalized Legendre function values\n"); else Vstrcpy(str, "Normalized associated Legendre function values\n"); } /* nag_legendre_p (s22aac). * Legendre and associated Legendre functions of the first * kind with real arguments */ nag_legendre_p(mode, x, m, nl, p, &fail); fprintf(fpout, "mode x m nl\n"); fprintf(fpout, "%3ld %5.1f%6ld%6ld\n\n", mode, x, m, nl); if (fail.code == NE_NOERROR) { fprintf(fpout, str); fprintf(fpout, "\n"); fprintf(fpout, " n P(n)\n"); for (n = 0; n <= nl; ++n) fprintf(fpout, "%2ld %13.4e\n", n, p[n]); } else { fprintf(fpout, "Error from nag_legendre_p (s22aac).\n%s\n", fail.message); exit_status = 1; goto END; } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (p) NAG_FREE(p); if (str) NAG_FREE(str); return exit_status; }