/* nag_wfilt_2d (c09abc) Example Program. * * Copyright 2011, Numerical Algorithms Group. * * Mark 23, 2011. */ #include #include #include #include #include #include #include int main(void) { /* Scalars */ Integer exit_status = 0; Integer i, j, lenc, m, n, nf, nwcn, nwct, nwl, pda, pdb; /* Arrays */ char mode[24], wavnam[20], title[27]; double *a = 0, *b = 0, *c = 0; Integer *dwtlevm = 0, *dwtlevn = 0; Integer icomm[180]; /* Nag Types */ Nag_Wavelet wavnamenum; Nag_WaveletMode modenum; Nag_MatrixType matrix = Nag_GeneralMatrix; Nag_OrderType order = Nag_ColMajor; Nag_DiagType diag = Nag_NonUnitDiag; NagError fail; INIT_FAIL(fail); printf("nag_wfilt_2d (c09abc) Example Program Results\n\n"); /* Skip heading in data file and read problem parameters */ scanf("%*[^\n] %"NAG_IFMT "%"NAG_IFMT "%*[^\n] ",&m,&n); pda = m; pdb = m; scanf("%s%s%*[^\n] ", wavnam,mode); if ( !(a = NAG_ALLOC((pda)*(n), double)) || !(b = NAG_ALLOC((pdb)*(n), double)) ) { printf("Allocation failure\n"); exit_status = -1; goto END; } printf(" Parameters read from file :: \n"); printf(" MLDWT :: Wavelet : %s\n", wavnam); printf(" End mode : %s\n", mode); printf(" m : %" NAG_IFMT "\n", m); printf(" n : %" NAG_IFMT "\n\n", n); /* * nag_enum_name_to_value (x04nac). * Converts NAG enum member name to value */ wavnamenum = (Nag_Wavelet) nag_enum_name_to_value(wavnam); modenum = (Nag_WaveletMode) nag_enum_name_to_value(mode); /* Read data array and write it out*/ #define A(I, J) a[(J-1)*pda + I-1] for (i = 1; i <= m; i++) for (j = 1; j <= n; j++) scanf("%lf", &A(i, j)); nag_gen_real_mat_print_comp(order, matrix, diag, m, n, a, pda, "%8.4f", "Input Data A :", Nag_NoLabels, 0, Nag_NoLabels, 0, 80, 0, 0, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_gen_real_mat_print_comp (x04cbc).\n%s\n", fail.message); exit_status = 1; goto END; } /* * nag_wfilt_2d (c09abc). * Two-dimensional wavelet filter initialization */ nag_wfilt_2d(wavnamenum, Nag_MultiLevel, modenum, m, n, &nwl, &nf, &nwct, &nwcn, icomm, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_wfilt_2d (c09abc).\n%s\n", fail.message); exit_status = 2; goto END; } lenc = nwct; if ( !(c = NAG_ALLOC((lenc), double)) || !(dwtlevm = NAG_ALLOC((nwl), Integer)) || !(dwtlevn = NAG_ALLOC((nwl), Integer)) ) { printf("Allocation failure\n"); exit_status = -2; goto END; } /* * nag_mldwt_2d (c09ecc). * Two-dimensional multi-level discrete wavelet transform */ nag_mldwt_2d(m, n, a, pda, lenc, c, nwl, dwtlevm, dwtlevn, icomm, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_mldwt_2d (c09ecc).\n%s\n", fail.message); exit_status = 3; goto END; } /* Print decomposition */ printf("\n Length of wavelet filter : %12s%"NAG_IFMT " \n", "", nf); printf("\n\n Number of Levels : %ld\n", nwl); printf(" Number of coefficients in 1st dimension for each level :\n"); for (j = 0; j < nwl; j++) printf("%8ld%s", dwtlevm[j], (j+1)%8?" ":"\n"); printf("\n Number of coefficients in 2nd dimension for each level :\n"); for (j = 0; j < nwl; j++) printf("%8ld%s", dwtlevn[j], (j+1)%8?" ":"\n"); printf("\n Total number of wavelet coefficients : "); printf("%10"NAG_IFMT " \n\n", nwct); printf(" Wavelet coefficients c : \n"); for (j = 0; j < nwct; j++) printf("%8.4f%s", c[j], (j+1)%8?" ":"\n"); printf("\n"); /* nag_imldwt_2d (c09edc). Two-dimensional inverse multi-level discrete wavelet transform */ nag_imldwt_2d(nwl, lenc, c, m, n, b, pdb, icomm, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_imldwt_2d (c09edc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Print reconstruction */ printf("\n"); strcpy(title, "Reconstruction B :"); nag_gen_real_mat_print_comp(order, matrix, diag, m, n, b, pdb, "%8.4f", title, Nag_NoLabels, 0, Nag_NoLabels, 0, 80, 0, 0, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_gen_real_mat_print_comp (x04cbc).\n%s\n", fail.message); exit_status = 6; goto END; } END: if (a) NAG_FREE(a); if (b) NAG_FREE(b); if (c) NAG_FREE(c); if (dwtlevm) NAG_FREE(dwtlevm); if (dwtlevn) NAG_FREE(dwtlevn); return exit_status; }