Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_sort_permute_check (m01zb)

## Purpose

nag_sort_permute_check (m01zb) checks the validity of a permutation.

## Syntax

[iperm, ifail] = m01zb(iperm, m1, 'm2', m2)
[iperm, ifail] = nag_sort_permute_check(iperm, m1, 'm2', m2)

## Description

nag_sort_permute_check (m01zb) can be used to check the validity of user-supplied ranks or indices, without the ranks or indices being corrupted.

None.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{iperm}\left({\mathbf{m2}}\right)$int64int32nag_int array
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 function exits with ${\mathbf{ifail}}={\mathbf{0}}$.
2:     $\mathrm{m1}$int64int32nag_int scalar
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}}$.

### Optional Input Parameters

1:     $\mathrm{m2}$int64int32nag_int scalar
Default: the dimension of the array iperm.
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}}$.

### Output Parameters

1:     $\mathrm{iperm}\left({\mathbf{m2}}\right)$int64int32nag_int array
Used as internal workpsace prior to being restored and hence is unchanged.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{m2}}<1$, or ${\mathbf{m1}}<1$, or ${\mathbf{m1}}>{\mathbf{m2}}$.
${\mathbf{ifail}}=2$
Elements m1 to m2 of iperm contain a value outside the range m1 to m2.
${\mathbf{ifail}}=3$
Elements m1 to m2 of iperm contain a repeated value.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
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.

None.

## Example

This example reads in a vector of real numbers, and a vector of ranks; it calls nag_sort_permute_check (m01zb) to check the validity of the ranks before calling nag_sort_realvec_rank_rearrange (m01ea) to rearrange the real numbers into the specified order.
```function m01zb_example

fprintf('m01zb example results\n\n');

rv    = [      5.3  4.6  7.8 1.7 5.3  9.9 3.2 4.3  7.8 4.5 1.2 7.6];
iperm = [int64(7) 6   10   2   8   12   3   4   11   5   1   9];

m1 = int64(1);
[iperm, ifail] = m01zb(iperm, m1);

[rv, iperm, ifail] = m01ea(rv, m1, iperm);

disp('Numbers in rank order');
fprintf('%5.1f%5.1f%5.1f%5.1f%5.1f%5.1f\n',rv);

```
```m01zb example results

Numbers in rank order
1.2  1.7  3.2  4.3  4.5  4.6
5.3  5.3  7.6  7.8  7.8  9.9
```