/* nag_dgbbrd (f08lec) 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, j, kl, ku, m, n, ncc, pdab, pdc, pdq, pdpt; Integer d_len, e_len; Integer exit_status = 0; NagError fail; Nag_OrderType order; /* Arrays */ double *ab = 0, *c = 0, *d = 0, *e = 0, *pt = 0, *q = 0; #ifdef NAG_COLUMN_MAJOR #define AB(I, J) ab[(J - 1) * pdab + ku + I - J] order = Nag_ColMajor; #else #define AB(I, J) ab[(I - 1) * pdab + kl + J - I] 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); fprintf(fpout, "nag_dgbbrd (f08lec) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%ld%ld%ld%ld%*[^\n] ", &m, &n, &kl, &ku, &ncc); #ifdef NAG_COLUMN_MAJOR pdab = kl + ku + 1; pdq = m; pdpt = n; pdc = m; #else pdab = kl + ku + 1; pdq = m; pdpt = n; pdc = MAX(1, ncc); #endif d_len = MIN(m, n); e_len = MIN(m, n) - 1; /* Allocate memory */ if (!(ab = NAG_ALLOC((kl+ku+1) * m, double)) || !(c = NAG_ALLOC(m * MAX(1, ncc), double)) || !(d = NAG_ALLOC(d_len, double)) || !(e = NAG_ALLOC(e_len, double)) || !(pt = NAG_ALLOC(n * n, double)) || !(q = NAG_ALLOC(m * m, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } /* Read A from data file */ for (i = 1; i <= m; ++i) { for (j = MAX(1, i - kl); j <= MIN(n, i + ku); ++j) fscanf(fpin, "%lf", &AB(i, j)); } fscanf(fpin, "%*[^\n] "); /* Reduce A to bidiagonal form */ /* nag_dgbbrd (f08lec). * Reduction of real rectangular band matrix to upper * bidiagonal form */ nag_dgbbrd(order, Nag_DoNotForm, m, n, ncc, kl, ku, ab, pdab, d, e, q, pdq, pt, pdpt, c, pdc, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_dgbbrd (f08lec).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print bidiagonal form */ fprintf(fpout, "\nDiagonal\n"); for (i = 1; i <= MIN(m, n); ++i) fprintf(fpout, "%9.4f%s", d[i-1], i%8 == 0?"\n":" "); if (m >= n) fprintf(fpout, "\nSuper-diagonal\n"); else fprintf(fpout, "\nSub-diagonal\n"); for (i = 1; i <= MIN(m, n) - 1; ++i) fprintf(fpout, "%9.4f%s", e[i-1], i%8 == 0?"\n":" "); fprintf(fpout, "\n"); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (ab) NAG_FREE(ab); if (c) NAG_FREE(c); if (d) NAG_FREE(d); if (e) NAG_FREE(e); if (pt) NAG_FREE(pt); if (q) NAG_FREE(q); return exit_status; }