/* nag_dgbbrd (f08lec) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* 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); Vprintf("nag_dgbbrd (f08lec) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%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)) ) { Vprintf("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) Vscanf("%lf", &AB(i,j)); } Vscanf("%*[^\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) { Vprintf("Error from nag_dgbbrd (f08lec).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print bidiagonal form */ Vprintf("\nDiagonal\n"); for (i = 1; i <= MIN(m,n); ++i) Vprintf("%9.4f%s", d[i-1], i%8==0 ?"\n":" "); if (m >= n) Vprintf("\nSuper-diagonal\n"); else Vprintf("\nSub-diagonal\n"); for (i = 1; i <= MIN(m,n) - 1; ++i) Vprintf("%9.4f%s", e[i-1], i%8==0 ?"\n":" "); Vprintf("\n"); END: 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; }