/* nag_dsterf (f08jfc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ Integer i, n, d_len, e_len; Integer exit_status = 0; NagError fail; /* Arrays */ double *d = 0, *e = 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_dsterf (f08jfc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%*[^\n] ", &n); d_len = n; e_len = n - 1; /* Allocate memory */ if (!(d = NAG_ALLOC(d_len, double)) || !(e = NAG_ALLOC(e_len, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } /* Read T from data file */ for (i = 0; i < d_len; ++i) fscanf(fpin, "%lf", &d[i]); for (i = 0; i < e_len; ++i) fscanf(fpin, "%lf", &e[i]); /* Calculate all the eigenvalues of T*/ /* nag_dsterf (f08jfc). * All eigenvalues of real symmetric tridiagonal matrix, * root-free variant of QL or QR */ nag_dsterf(n, d, e, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_dsterf (f08jfc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print eigenvalues */ fprintf(fpout, " Eigenvalues\n"); for (i = 0; i < n; ++i) fprintf(fpout, " %7.4lf", d[i]); fprintf(fpout, "\n"); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (d) NAG_FREE(d); if (e) NAG_FREE(e); return exit_status; }