# LGF_ShellSort_LReal (FB / 3.0.1)

Overview

Author: Siemens Industry Support

## Short description

This block sorts an array of type `LReal` with any number of elements (max. 1000) in ascending or descending order and returns the sorted version of the array in the same variable.

### Block Interface

| LGF_ShellSort_LReal (FB) |
--- | --- | ---
Bool |  |  | sortDirection |  | error |  |  | Bool
|  |  |  |  | status |  |  | Word
Array[*] of LReal |  |  | array |  |  | Array[*] of LReal

### Input parameter

Identifier | Data type | Default value | Description
--- | --- | --- | ---
sortDirection | Bool | FALSE | FALSE: Sort ascending; TRUE: Sort descending

### Output parameter

Identifier | Data type | Description
--- | --- | ---
error | Bool | FALSE: No error TRUE: An error occurred during the execution of the FB
status | Word | 16#0000-16#7FFF: Status of the FB 16#8000-16#FFFF: Error identification (see following Table)

### In/Out parameter

Identifier | Data type | Description
--- | --- | ---
array | Array[*] of LReal | Array to be sorted

### Status & Error codes

Code / Value | Identifier / Description
--- | ---
16#0000 | STATUS_NO_ERROR Status: Execution finished without errors
16#8200 | ERR_NO_ARRAY Error: Actual parameter at the `array` input has only one element.
16#8201 | ERR_TOO_MANY_ELEMENTS Error: Actual parameter at the `array` input has too many elements (maximum is 1000).

## Functional description

The block sorts according to the shell sort procedure. Note that the execution time of the block depends significantly on how many elements the array to be sorted has. The overview below shows several measured values of the block depending on the number of array elements.

Average steps needed for execution: \mathcal{O}( n \cdot \log (n)^2 )

Table: Execution times of the block `LGF_ShellSort…`

Number of array elements | S7-1212C DC/DC/DC | S7-1516-3 PN/DP
--- | --- | ---
100 | approx. 11-16 ms | approx. 1-2 ms
1000 | approx. 185-205 ms | approx. 10-12 ms

Note
  The block is executed synchronously and is not split over several PLC cycles. Thus the execution time has a direct effect on the PLC cycle time. Note this behavior for your project of the controller used and adjust the monitoring time of the controller if necessary.

## Change log

Version & Date | Change description
--- | ---
| 1.0.0 | Siemens Industry Online Support
| 19.08.2015 | First released version
| 1.1.0 | Siemens Industry Online Support
| 19.05.2016 | New function: reverse sort
| 1.1.1 | Siemens Industry Online Support
| 02.01.2017 | Upgrade: TIA Portal V14 Update 1
| 1.1.2 | Siemens Industry Online Support
| 17.08.2018 | Upgrade: TIA V15 Update 2
| 1.1.3 | Siemens Industry Online Support
| 23.11.2018 | Upgrade: TIA V15.1
| 2.0.0 | Siemens Industry Online Support
| 29.01.2019 | Output "done" removed (not necessary, because only one cycle)
| 2.0.1 | Simatic Systems Support
| 15.10.2019 | Code refactoring, comments added, change data type from Real to LReal
| 3.0.0 | Simatic Systems Support
| 23.04.2020 | Set version to V3.0.0, harmonize the version of the whole library
| 3.0.1 | Simatic Systems Support
| 15.02.2021 | Insert documentation