/* nag_dtrsen (f08qgc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; char *outfile = 0; /* Scalars */ Integer i, j, m, n, pdq, pdt, select_len, w_len; Integer exit_status = 0; double s, sep; NagError fail; Nag_OrderType order; /* Arrays */ double *q = 0, *t = 0, *wi = 0, *wr = 0; char nag_enum_arg[40]; Nag_Boolean *select = 0; #ifdef NAG_COLUMN_MAJOR #define T(I, J) t[(J-1)*pdt + I - 1] #define Q(I, J) q[(J-1)*pdq + I - 1] order = Nag_ColMajor; #else #define T(I, J) t[(I-1)*pdt + J - 1] #define Q(I, J) q[(I-1)*pdq + J - 1] order = Nag_RowMajor; #endif 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); (void) nag_example_file_io(argc, argv, "-nag_write", &outfile); fprintf(fpout, "nag_dtrsen (f08qgc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%*[^\n] ", &n); #ifdef NAG_COLUMN_MAJOR pdq = n; pdt = n; #else pdq = n; pdt = n; #endif w_len = n; select_len = n; /* Allocate memory */ if (!(q = NAG_ALLOC(n * n, double)) || !(wi = NAG_ALLOC(w_len, double)) || !(wr = NAG_ALLOC(w_len, double)) || !(select = NAG_ALLOC(select_len, Nag_Boolean)) || !(t = NAG_ALLOC(n * n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } /* Read T from data file */ for (i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) fscanf(fpin, "%lf", &T(i, j)); } fscanf(fpin, "%*[^\n] "); for (i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) fscanf(fpin, "%lf", &Q(i, j)); } fscanf(fpin, "%*[^\n] "); for (i = 0; i < n; ++i) { fscanf(fpin, "%s", nag_enum_arg); /* nag_enum_name_to_value(x04nac). * Converts NAG enum member name to value */ select[i] = (Nag_Boolean) nag_enum_name_to_value(nag_enum_arg); } fscanf(fpin, "%*[^\n] "); /* Reorder the Schur factorization T */ /* nag_dtrsen (f08qgc). * Reorder Schur factorization of real matrix, form * orthonormal basis of right invariant subspace for * selected eigenvalues, with estimates of sensitivities */ nag_dtrsen(order, Nag_DoBoth, Nag_UpdateSchur, select, n, t, pdt, q, pdq, wr, wi, &m, &s, &sep, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_dtrsen (f08qgc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print reordered Schur form */ /* nag_gen_real_mat_print (x04cac). * Print real general matrix (easy-to-use) */ if (outfile) fclose(fpout); nag_gen_real_mat_print(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, n, t, pdt, "Reordered Schur form", outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print basis of invariant subspace */ /* nag_gen_real_mat_print (x04cac), see above. */ if (outfile) fclose(fpout); nag_gen_real_mat_print(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, m, q, pdq, "Basis of invariant subspace", outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gen_real_mat_print (x04cac).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print condition number estimates */ fprintf(fpout, "\n Condition number estimate of the selected cluster of" " eigenvalues = %11.2e\n", 1.0/s); fprintf(fpout, "\n Condition number estimate of the specified invariant" " subspace = %11.2e\n", 1.0/sep); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (q) NAG_FREE(q); if (t) NAG_FREE(t); if (wi) NAG_FREE(wi); if (wr) NAG_FREE(wr); if (select) NAG_FREE(select); return exit_status; }