# NAG FL Interfacec09eaf (dim2_​sngl_​fwd)

## 1Purpose

c09eaf computes the two-dimensional discrete wavelet transform (DWT) at a single level. The initialization routine c09abf must be called first to set up the DWT options.

## 2Specification

Fortran Interface
 Subroutine c09eaf ( m, n, a, lda, ca, ldca, ch, ldch, cv, ldcv, cd, ldcd,
 Integer, Intent (In) :: m, n, lda, ldca, ldch, ldcv, ldcd Integer, Intent (Inout) :: icomm(180), ifail Real (Kind=nag_wp), Intent (In) :: a(lda,n) Real (Kind=nag_wp), Intent (Inout) :: ca(ldca,*), ch(ldch,*), cv(ldcv,*), cd(ldcd,*)
#include <nag.h>
 void c09eaf_ (const Integer *m, const Integer *n, const double a[], const Integer *lda, double ca[], const Integer *ldca, double ch[], const Integer *ldch, double cv[], const Integer *ldcv, double cd[], const Integer *ldcd, Integer icomm[], Integer *ifail)
The routine may be called by the names c09eaf or nagf_wav_dim2_sngl_fwd.

## 3Description

c09eaf computes the two-dimensional DWT of a given input data array, considered as a matrix $A$, at a single level. For a chosen wavelet filter pair, the output coefficients are obtained by applying convolution and downsampling by two to the input, $A$, first over columns and then to the result over rows. The matrix of approximation (or smooth) coefficients, ${C}_{a}$, is produced by the low pass filter over columns and rows; the matrix of horizontal coefficients, ${C}_{h}$, is produced by the high pass filter over columns and the low pass filter over rows; the matrix of vertical coefficients, ${C}_{v}$, is produced by the low pass filter over columns and the high pass filter over rows; and the matrix of diagonal coefficients, ${C}_{d}$, is produced by the high pass filter over columns and rows. To reduce distortion effects at the ends of the data array, several end extension methods are commonly used. Those provided are: periodic or circular convolution end extension, half-point symmetric end extension, whole-point symmetric end extension and zero end extension. The total number, ${n}_{\mathrm{ct}}$, of coefficients computed for ${C}_{a}$, ${C}_{h}$, ${C}_{v}$, and ${C}_{d}$ together and the number of columns of each coefficients matrix, ${n}_{\mathrm{cn}}$, are returned by the initialization routine c09abf. These values can be used to calculate the number of rows of each coefficients matrix, ${n}_{\mathrm{cm}}$, using the formula ${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$.

## 4References

Daubechies I (1992) Ten Lectures on Wavelets SIAM, Philadelphia

## 5Arguments

1: $\mathbf{m}$Integer Input
On entry: number of rows, $m$, of data matrix $A$.
Constraint: this must be the same as the value m passed to the initialization routine c09abf.
2: $\mathbf{n}$Integer Input
On entry: number of columns, $n$, of data matrix $A$.
Constraint: this must be the same as the value n passed to the initialization routine c09abf.
3: $\mathbf{a}\left({\mathbf{lda}},{\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the $m$ by $n$ data matrix $A$.
4: $\mathbf{lda}$Integer Input
On entry: the first dimension of the array a as declared in the (sub)program from which c09eaf is called.
Constraint: ${\mathbf{lda}}\ge {\mathbf{m}}$.
5: $\mathbf{ca}\left({\mathbf{ldca}},*\right)$Real (Kind=nag_wp) array Output
Note: the second dimension of the array ca must be at least ${n}_{\mathrm{cn}}$ where ${n}_{\mathrm{cn}}$ is the argument nwcn returned by routine c09abf.
On exit: contains the ${n}_{\mathrm{cm}}$ by ${n}_{\mathrm{cn}}$ matrix of approximation coefficients, ${C}_{a}$.
6: $\mathbf{ldca}$Integer Input
On entry: the first dimension of the array ca as declared in the (sub)program from which c09eaf is called.
Constraint: ${\mathbf{ldca}}\ge {n}_{\mathrm{cm}}$ where ${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ${n}_{\mathrm{cn}}$, ${n}_{\mathrm{ct}}$ are returned by the initialization routine c09abf.
7: $\mathbf{ch}\left({\mathbf{ldch}},*\right)$Real (Kind=nag_wp) array Output
Note: the second dimension of the array ch must be at least ${n}_{\mathrm{cn}}$ where ${n}_{\mathrm{cn}}$ is the argument nwcn returned by routine c09abf.
On exit: contains the ${n}_{\mathrm{cm}}$ by ${n}_{\mathrm{cn}}$ matrix of horizontal coefficients, ${C}_{h}$.
8: $\mathbf{ldch}$Integer Input
On entry: the first dimension of the array ch as declared in the (sub)program from which c09eaf is called.
Constraint: ${\mathbf{ldch}}\ge {n}_{\mathrm{cm}}$ where ${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ${n}_{\mathrm{cn}}$, ${n}_{\mathrm{ct}}$ are returned by the initialization routine c09abf.
9: $\mathbf{cv}\left({\mathbf{ldcv}},*\right)$Real (Kind=nag_wp) array Output
Note: the second dimension of the array cv must be at least ${n}_{\mathrm{cn}}$ where ${n}_{\mathrm{cn}}$ is the argument nwcn returned by routine c09abf.
On exit: contains the ${n}_{\mathrm{cm}}$ by ${n}_{\mathrm{cn}}$ matrix of vertical coefficients, ${C}_{v}$.
10: $\mathbf{ldcv}$Integer Input
On entry: the first dimension of the array cv as declared in the (sub)program from which c09eaf is called.
Constraint: ${\mathbf{ldcv}}\ge {n}_{\mathrm{cm}}$ where ${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ${n}_{\mathrm{cn}}$, ${n}_{\mathrm{ct}}$ are returned by the initialization routine c09abf.
11: $\mathbf{cd}\left({\mathbf{ldcd}},*\right)$Real (Kind=nag_wp) array Output
Note: the second dimension of the array cd must be at least ${n}_{\mathrm{cn}}$ where ${n}_{\mathrm{cn}}$ is the argument nwcn returned by routine c09abf.
On exit: contains the ${n}_{\mathrm{cm}}$ by ${n}_{\mathrm{cn}}$ matrix of diagonal coefficients, ${C}_{d}$.
12: $\mathbf{ldcd}$Integer Input
On entry: the first dimension of the array cd as declared in the (sub)program from which c09eaf is called.
Constraint: ${\mathbf{ldcd}}\ge {n}_{\mathrm{cm}}$ where ${n}_{\mathrm{cm}}={n}_{\mathrm{ct}}/\left(4{n}_{\mathrm{cn}}\right)$ and ${n}_{\mathrm{cn}}$, ${n}_{\mathrm{ct}}$ are returned by the initialization routine c09abf.
13: $\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.
14: $\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{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}=〈\mathit{\text{value}}〉$, the value of m on initialization (see c09abf).
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}=〈\mathit{\text{value}}〉$, the value of n on initialization (see c09abf).
${\mathbf{ifail}}=2$
On entry, ${\mathbf{lda}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lda}}\ge {\mathbf{m}}$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{ldca}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldca}}\ge 〈\mathit{\text{value}}〉$, the number of wavelet coefficients in the first dimension.
On entry, ${\mathbf{ldcd}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldcd}}\ge 〈\mathit{\text{value}}〉$, the number of wavelet coefficients in the first dimension.
On entry, ${\mathbf{ldch}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldch}}\ge 〈\mathit{\text{value}}〉$, the number of wavelet coefficients in the first dimension.
On entry, ${\mathbf{ldcv}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldcv}}\ge 〈\mathit{\text{value}}〉$, the number of wavelet coefficients in the first dimension.
${\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{'M'}$ or icomm has been corrupted.
${\mathbf{ifail}}=-99$
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.

## 7Accuracy

The accuracy of the wavelet transform depends only on the floating-point operations used in the convolution and downsampling and should thus be close to machine precision.

## 8Parallelism and Performance

c09eaf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

## 10Example

This example computes the two-dimensional discrete wavelet decomposition for a $6×6$ input matrix using the Daubechies wavelet, ${\mathbf{wavnam}}=\text{'DB4'}$, with half point symmetric end extension.

### 10.1Program Text

Program Text (c09eafe.f90)

### 10.2Program Data

Program Data (c09eafe.d)

### 10.3Program Results

Program Results (c09eafe.r)