# NAG FL Interfacem01zbf (permute_​check)

## 1Purpose

m01zbf checks the validity of a permutation.

## 2Specification

Fortran Interface
 Subroutine m01zbf ( m1, m2,
 Integer, Intent (In) :: m1, m2 Integer, Intent (Inout) :: iperm(m2), ifail
#include <nag.h>
 void m01zbf_ (Integer iperm[], const Integer *m1, const Integer *m2, Integer *ifail)
The routine may be called by the names m01zbf or nagf_sort_permute_check.

## 3Description

m01zbf can be used to check the validity of user-supplied ranks or indices, without the ranks or indices being corrupted.

None.

## 5Arguments

1: $\mathbf{iperm}\left({\mathbf{m2}}\right)$Integer array Input/Output
On entry: elements m1 to m2 of iperm must be set to values which are supposed to be a permutation of the integers m1 to m2. If they are a valid permutation, the routine exits with ${\mathbf{ifail}}={\mathbf{0}}$.
On exit: used as internal workpsace prior to being restored and hence is unchanged.
2: $\mathbf{m1}$Integer Input
3: $\mathbf{m2}$Integer Input
On entry: the range of elements used in the array iperm and the range of values in the permutation, as specified under iperm.
Constraint: $0<{\mathbf{m1}}\le {\mathbf{m2}}$.
4: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, . If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value 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{m1}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m1}}\ge 1$.
On entry, ${\mathbf{m1}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m2}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m1}}\le {\mathbf{m2}}$.
On entry, ${\mathbf{m2}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m2}}\ge 1$.
${\mathbf{ifail}}=2$
${\mathbf{iperm}}\left({\mathbf{m1}}:{\mathbf{m2}}\right)$ does not contain a permutation of the integers m1 to m2. ${\mathbf{iperm}}\left(I\right)$ contains an out-of-range value: $I=〈\mathit{\text{value}}〉$, ${\mathbf{iperm}}\left(I\right)=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=3$
${\mathbf{iperm}}\left({\mathbf{m1}}:{\mathbf{m2}}\right)$ does not contain a permutation of the integers m1 to m2. iperm contains a repeated value: $〈\mathit{\text{value}}〉$.
${\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.
If ${\mathbf{ifail}}={\mathbf{2}}$ or ${\mathbf{3}}$, elements m1 to m2 of iperm do not contain a permutation of the integers m1 to m2.

Not applicable.

## 8Parallelism and Performance

m01zbf is not threaded in any implementation.

None.

## 10Example

This example reads in a vector of real numbers, and a vector of ranks; it calls m01zbf to check the validity of the ranks before calling m01eaf to rearrange the real numbers into the specified order.

### 10.1Program Text

Program Text (m01zbfe.f90)

### 10.2Program Data

Program Data (m01zbfe.d)

### 10.3Program Results

Program Results (m01zbfe.r)