# NAG FL Interfacec09ezf (dim2_​coeff_​ins)

## 1Purpose

c09ezf inserts a selected set of two-dimensional discrete wavelet transform (DWT) coefficients into the full set of coefficients stored in compact form, which may be later used as input to the multi-level reconstruction routine c09edf.

## 2Specification

Fortran Interface
 Subroutine c09ezf ( ilev, lenc, c, d, ldd,
 Integer, Intent (In) :: ilev, cindex, lenc, ldd Integer, Intent (Inout) :: icomm(180), ifail Real (Kind=nag_wp), Intent (In) :: d(ldd,*) Real (Kind=nag_wp), Intent (Inout) :: c(lenc)
#include <nag.h>
 void c09ezf_ (const Integer *ilev, const Integer *cindex, const Integer *lenc, double c[], const double d[], const Integer *ldd, Integer icomm[], Integer *ifail)
The routine may be called by the names c09ezf or nagf_wav_dim2_coeff_ins.

## 3Description

c09ezf inserts a selected set of two-dimensional DWT coefficients into the full set of coefficients stored in compact form in a one-dimensional array c. It is required that c09ezf is preceded by a call to the initialization routine c09abf and the forward multi-level transform routine c09ecf.
Given an initial two-dimensional data set $A$, a prior call to c09ecf computes the approximation coefficients (at the highest requested level) and three sets of detail coeficients at all levels and stores these in compact form in a one-dimensional array c. c09eyf can then extract either the approximation coefficients or one of the sets of detail coefficients at one of the levels into a two-dimensional array, d. Following some calculation on this set of coefficients (for example, denoising), the updated coefficients in d are inserted back into the full set c using c09ezf. Several extractions and insertions may be performed at different levels. c09edf can then be used to reconstruct a manipulated data set $\stackrel{~}{A}$. The dimensions of d depend on the level extracted and are available from the arrays dwtlvm and dwtlvn as returned by c09ecf which contain the first and second dimensions respectively. See Section 2.1 in the C09 Chapter Introduction for a discussion of the multi-level two-dimensional DWT.

None.

## 5Arguments

Note: the following notation is used in this section:
• ${n}_{\mathrm{cm}}$ is the number of wavelet coefficients in the first dimension, which, at level ilev, is equal to ${\mathbf{dwtlvm}}\left({\mathbf{nwl}}-{\mathbf{ilev}}+1\right)$ as returned by a call to c09ecf transforming nwl levels.
• ${n}_{\mathrm{cn}}$ is the number of wavelet coefficients in the second dimension, which, at level ilev, is equal to ${\mathbf{dwtlvn}}\left({\mathbf{nwl}}-{\mathbf{ilev}}+1\right)$ as returned by a call to c09ecf transforming nwl levels
1: $\mathbf{ilev}$Integer Input
On entry: the level at which coefficients are to be inserted.
Constraints:
• $1\le {\mathbf{ilev}}\le {\mathbf{nwl}}$, where nwl is as used in a preceding call to c09ecf;
• if ${\mathbf{cindex}}=0$, ${\mathbf{ilev}}={\mathbf{nwl}}$.
2: $\mathbf{cindex}$Integer Input
On entry: identifies which coefficients to insert. The coefficients are identified as follows:
${\mathbf{cindex}}=0$
The approximation coefficients, produced by application of the low pass filter over columns and rows of the original matrix ($\mathrm{LL}$). The approximation coefficients are present only for ${\mathbf{ilev}}={\mathbf{nwl}}$, where nwl is the value used in a preceding call to c09ecf.
${\mathbf{cindex}}=1$
The vertical detail coefficients produced by applying the low pass filter over columns of the original matrix and the high pass filter over rows ($\mathrm{LH}$).
${\mathbf{cindex}}=2$
The horizontal detail coefficients produced by applying the high pass filter over columns of the original matrix and the low pass filter over rows ($\mathrm{HL}$).
${\mathbf{cindex}}=3$
The diagonal detail coefficients produced by applying the high pass filter over columns and rows of the original matrix ($\mathrm{HH}$).
Constraint: $0\le {\mathbf{cindex}}\le 3$ when ${\mathbf{ilev}}={\mathbf{nwl}}$ as used in c09ecf, otherwise $1\le {\mathbf{cindex}}\le 3$.
3: $\mathbf{lenc}$Integer Input
On entry: the dimension of the array c as declared in the (sub)program from which c09ezf is called.
Constraint: lenc must be unchanged from the value used in the preceding call to c09ecf.
4: $\mathbf{c}\left({\mathbf{lenc}}\right)$Real (Kind=nag_wp) array Input/Output
On entry: contains the DWT coefficients inserted by previous calls to c09ezf, or computed by a previous call to c09ecf.
On exit: contains the same DWT coefficients provided on entry except for those identified by ilev and cindex, which are updated with the values supplied in d, inserted into the correct locations as expected by the reconstruction routine c09edf.
5: $\mathbf{d}\left({\mathbf{ldd}},*\right)$Real (Kind=nag_wp) array Input
Note: the second dimension of the array d must be at least ${n}_{\mathrm{cn}}$.
On entry: the coefficients to be inserted.
If ${\mathbf{ilev}}={\mathbf{nwl}}$ (as used in c09ecf) and ${\mathbf{cindex}}=0$, the ${n}_{\mathrm{cm}}$ by ${n}_{\mathrm{cn}}$ manipulated approximation coefficients ${a}_{\mathit{i}\mathit{j}}$ must be stored in ${\mathbf{d}}\left(\mathit{i},\mathit{j}\right)$, for $\mathit{i}=1,2,\dots ,{n}_{\mathrm{cm}}$ and $\mathit{i}=1,2,\dots ,{n}_{\mathrm{cn}}$.
Otherwise the ${n}_{\mathrm{cm}}$ by ${n}_{\mathrm{cn}}$ manipulated level ilev detail coefficients (of type specified by cindex) ${d}_{\mathit{i}\mathit{j}}$ must be stored in ${\mathbf{d}}\left(\mathit{i},\mathit{j}\right)$, for $\mathit{i}=1,2,\dots ,{n}_{\mathrm{cm}}$ and $\mathit{j}=1,2,\dots ,{n}_{\mathrm{cn}}$.
6: $\mathbf{ldd}$Integer Input
On entry: the first dimension of the array d as declared in the (sub)program from which c09ezf is called.
Constraint: ${\mathbf{ldd}}\ge {n}_{\mathrm{cm}}$.
7: $\mathbf{icomm}\left(180\right)$Integer array Communication Array
On entry: contains details of the discrete wavelet transform and the problem dimension as setup in the call to the initialization routine c09abf.
8: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{ilev}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ilev}}\ge 1$.
On entry, ${\mathbf{ilev}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nwl}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ilev}}\le {\mathbf{nwl}}$, where ${\mathbf{nwl}}$ is the number of levels used in the call to c09ecf.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{cindex}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{cindex}}\le 3$.
On entry, ${\mathbf{cindex}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{cindex}}\ge 0$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{lenc}}=〈\mathit{\text{value}}〉$ and ${n}_{\mathrm{ct}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lenc}}\ge {n}_{\mathrm{ct}}$, where ${n}_{\mathrm{ct}}$ is the number of DWT coefficients computed in a previous call to c09ecf.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{ldd}}=〈\mathit{\text{value}}〉$ and ${n}_{\mathrm{cm}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldd}}\ge {n}_{\mathrm{cm}}$, where ${n}_{\mathrm{cm}}$ is the number of DWT coefficients in the first dimension at the selected level ilev.
${\mathbf{ifail}}=5$
On entry, ${\mathbf{ilev}}=〈\mathit{\text{value}}〉$ and ${\mathbf{nwl}}=〈\mathit{\text{value}}〉$, but ${\mathbf{cindex}}=0$.
Constraint: ${\mathbf{cindex}}>0$ when ${\mathbf{ilev}}<{\mathbf{nwl}}$ in the preceding call to c09ecf.
${\mathbf{ifail}}=6$
Either the initialization routine has not been called first or icomm has been corrupted.
Either the initialization routine was called with ${\mathbf{wtrans}}=\text{'S'}$ or icomm has been corrupted.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

Not applicable.

## 8Parallelism and Performance

c09ezf is not threaded in any implementation.

None.

## 10Example

The following example demonstrates using the coefficient extraction and insertion routines in order to apply denoising using a thresholding operation. The original input data, which is horizontally striped, has artificial noise introduced to it, taken from a normal random number distribution. Reconstruction then takes place on both the noisy data and denoised data. The Mean Square Errors (MSE) of the two reconstructions are printed along with the reconstruction of the denoised data. The MSE of the denoised reconstruction is less than that of the noisy reconstruction.

### 10.1Program Text

Program Text (c09ezfe.f90)

### 10.2Program Data

Program Data (c09ezfe.d)

### 10.3Program Results

Program Results (c09ezfe.r)