/* nag_hermitian_eigenvalues (f02awc) Example Program. * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 8 revised, 2004. */ #include #include #include #include #include #define A(I, J) a[(I) *tda + J] int main(int argc, char *argv[]) { FILE *fpin, *fpout; Complex *a = 0; Integer exit_status = 0, i, j, n, tda; NagError fail; double *r = 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_hermitian_eigenvalues (f02awc) Example Program Results\n"); fscanf(fpin, "%*[^\n]"); /* Skip heading in data file */ fscanf(fpin, "%ld", &n); if (n >= 1) { if (!(r = NAG_ALLOC(n, double)) || !(a = NAG_ALLOC(n*n, Complex))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } tda = n; } else { fprintf(fpout, "Invalid n.\n"); exit_status = 1; return exit_status; } for (i = 0; i < n; i++) for (j = 0; j < n; j++) fscanf(fpin, " ( %lf, %lf ) ", &A(i, j).re, &A(i, j).im); /* nag_hermitian_eigenvalues (f02awc). * All eigenvalues of complex Hermitian matrix */ nag_hermitian_eigenvalues(n, a, tda, r, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_hermitian_eigenvalues (f02awc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "Eigenvalues\n"); for (i = 0; i < n; i++) fprintf(fpout, "%9.4f", r[i]); fprintf(fpout, "\n"); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (r) NAG_FREE(r); if (a) NAG_FREE(a); return exit_status; }