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_realvec_rank_rearrange (m01ea)

## Purpose

nag_sort_realvec_rank_rearrange (m01ea) rearranges a vector of real numbers into the order specified by a vector of ranks.

## Syntax

[rv, irank, ifail] = m01ea(rv, m1, irank, 'm2', m2)
[rv, irank, ifail] = nag_sort_realvec_rank_rearrange(rv, m1, irank, 'm2', m2)

## Description

nag_sort_realvec_rank_rearrange (m01ea) is designed to be used typically in conjunction with the M01D ranking functions. After one of the M01D functions has been called to determine a vector of ranks, nag_sort_realvec_rank_rearrange (m01ea) can be called to rearrange a vector of real numbers into the rank order. If the vector of ranks has been generated in some other way, then nag_sort_permute_check (m01zb) should be called to check its validity before nag_sort_realvec_rank_rearrange (m01ea) is called.

None.

## Parameters

### Compulsory Input Parameters

1:     rv(m2) – double array
m2, the dimension of the array, must satisfy the constraint 0 < m1m2$0<{\mathbf{m1}}\le {\mathbf{m2}}$.
Elements m1 to m2 of rv must contain real values to be rearranged.
2:     m1 – int64int32nag_int scalar
m1 and m2 must specify the range of the ranks supplied in irank and the elements of rv to be rearranged.
Constraint: 0 < m1m2$0<{\mathbf{m1}}\le {\mathbf{m2}}$.
3:     irank(m2) – int64int32nag_int array
m2, the dimension of the array, must satisfy the constraint 0 < m1m2$0<{\mathbf{m1}}\le {\mathbf{m2}}$.
Elements m1 to m2 of irank must contain a permutation of the integers m1 to m2, which are interpreted as a vector of ranks.

### Optional Input Parameters

1:     m2 – int64int32nag_int scalar
Default: The dimension of the arrays irank, rv. (An error is raised if these dimensions are not equal.)
m1 and m2 must specify the range of the ranks supplied in irank and the elements of rv to be rearranged.
Constraint: 0 < m1m2$0<{\mathbf{m1}}\le {\mathbf{m2}}$.

None.

### Output Parameters

1:     rv(m2) – double array
These values are rearranged into rank order. For example, if irank(i) = m1${\mathbf{irank}}\left(i\right)={\mathbf{m1}}$, then the initial value of rv(i)${\mathbf{rv}}\left(i\right)$ is moved to rv(m1)${\mathbf{rv}}\left({\mathbf{m1}}\right)$.
2:     irank(m2) – int64int32nag_int array
Used as internal workspace prior to being restored and hence is unchanged.
3:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
 On entry, m2 < 1${\mathbf{m2}}<1$, or m1 < 1${\mathbf{m1}}<1$, or m1 > m2${\mathbf{m1}}>{\mathbf{m2}}$.
ifail = 2${\mathbf{ifail}}=2$
Elements m1 to m2 of irank contain a value outside the range m1 to m2.
ifail = 3${\mathbf{ifail}}=3$
Elements m1 to m2 of irank contain a repeated value.
If ${\mathbf{ifail}}={\mathbf{2}}$ or 3${\mathbf{3}}$, elements m1 to m2 of irank do not contain a permutation of the integers m1 to m2. On exit, the contents of rv may be corrupted. To check the validity of irank without the risk of corrupting rv, use nag_sort_permute_check (m01zb).

## Accuracy

Not applicable.

The average time taken by the function is approximately proportional to n$n$, where n = m2m1 + 1$n={\mathbf{m2}}-{\mathbf{m1}}+1$.

## Example

```function nag_sort_realvec_rank_rearrange_example
rv = [6;
5;
2;
4;
4;
4;
3;
2;
1;
9;
6;
4];
m1 = int64(1);
irank = [int64(10);9;2;5;6;7;4;3;1;12;11;8];
[rvOut, irankOut, ifail] = nag_sort_realvec_rank_rearrange(rv, m1, irank)
```
```

rvOut =

1
2
2
3
4
4
4
4
5
6
6
9

irankOut =

10
9
2
5
6
7
4
3
1
12
11
8

ifail =

0

```
```function m01ea_example
rv = [6;
5;
2;
4;
4;
4;
3;
2;
1;
9;
6;
4];
m1 = int64(1);
irank = [int64(10);9;2;5;6;7;4;3;1;12;11;8];
[rvOut, irankOut, ifail] = m01ea(rv, m1, irank)
```
```

rvOut =

1
2
2
3
4
4
4
4
5
6
6
9

irankOut =

10
9
2
5
6
7
4
3
1
12
11
8

ifail =

0

```