/* nag_ztrsen (f08quc) 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 */ Complex *q = 0, *t = 0, *w = 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_ztrsen (f08quc) 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, Complex)) || !(w = NAG_ALLOC(w_len, Complex)) || !(select = NAG_ALLOC(select_len, Nag_Boolean)) || !(t = NAG_ALLOC(n * n, Complex))) { 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 , %lf ) ", &T(i, j).re, &T(i, j).im); } fscanf(fpin, "%*[^\n] "); for (i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) fscanf(fpin, " ( %lf , %lf ) ", &Q(i, j).re, &Q(i, j).im); } 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_ztrsen (f08quc). * Reorder Schur factorization of complex matrix, form * orthonormal basis of right invariant subspace for * selected eigenvalues, with estimates of sensitivities */ nag_ztrsen(order, Nag_DoBoth, Nag_UpdateSchur, select, n, t, pdt, q, pdq, w, &m, &s, &sep, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_ztrsen (f08quc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print reordered Schur form */ /* nag_gen_complx_mat_print_comp (x04dbc). * Print complex general matrix (comprehensive) */ if (outfile) fclose(fpout); nag_gen_complx_mat_print_comp(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, n, t, pdt, Nag_BracketForm, "%7.4f", "Reordered Schur form", Nag_IntegerLabels, 0, Nag_IntegerLabels, 0, 80, 0, outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gen_complx_mat_print_comp (x04dbc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print basis of invariant subspace */ /* nag_gen_complx_mat_print_comp (x04dbc), see above. */ if (outfile) fclose(fpout); nag_gen_complx_mat_print_comp(order, Nag_GeneralMatrix, Nag_NonUnitDiag, n, m, q, pdq, Nag_BracketForm, "%7.4f", "Basis of invariant subspace", Nag_IntegerLabels, 0, Nag_IntegerLabels, 0, 80, 0, outfile, &fail); if (outfile && !(fpout = fopen(outfile, "a"))) { exit_status = 2; goto END; } if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_gen_complx_mat_print_comp (x04dbc).\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 (w) NAG_FREE(w); if (select) NAG_FREE(select); return exit_status; }