/* nag_dgb_norm (f16rbc) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * Mark 8, 2005. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ double r_one, r_inf, r_f, r_max; Integer ab_size, exit_status, i, j, kl, ku; Integer m, n, pdab; /* Arrays */ double *ab = 0; /* Nag Types */ NagError fail; Nag_OrderType order; #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 exit_status = 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_dgb_norm (f16rbc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); /* Read the problem dimensions */ fscanf(fpin, "%ld%ld%ld%ld%*[^\n] ", &m, &n, &kl, &ku); pdab = kl + ku + 1; #ifdef NAG_COLUMN_MAJOR ab_size = pdab*n; #else ab_size = pdab*m; #endif if (m > 0 && n > 0) { /* Allocate memory */ if (!(ab = NAG_ALLOC(ab_size, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid m or n\n"); exit_status = 1; return exit_status; } /* Input matrix A. */ 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] "); } /* nag_dgb_norm(f16rbc). * calculates norm of real valued general band matrix. * */ nag_dgb_norm(order, Nag_OneNorm, m, n, kl, ku, ab, pdab, &r_one, &fail); nag_dgb_norm(order, Nag_InfNorm, m, n, kl, ku, ab, pdab, &r_inf, &fail); nag_dgb_norm(order, Nag_FrobeniusNorm, m, n, kl, ku, ab, pdab, &r_f, &fail); nag_dgb_norm(order, Nag_MaxNorm, m, n, kl, ku, ab, pdab, &r_max, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_dgb_norm.\n%s\n", fail.message); exit_status = 1; goto END; } /* Print norms of A. */ fprintf(fpout, " Norms of banded matrix A:\n\n"); fprintf(fpout, " One norm = %7.4f\n", r_one); fprintf(fpout, " Infinity norm = %7.4f\n", r_inf); fprintf(fpout, " Frobenius norm = %7.4f\n", r_f); fprintf(fpout, " Maximum norm = %7.4f\n", r_max); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (ab) NAG_FREE(ab); return exit_status; }