LGF_ShellSort_LReal (FB / V3.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

IdentifierData type Default value Description
sortDirectionBool FALSE FALSE: Sort ascending; TRUE: Sort descending

Output parameter

IdentifierData type Description
errorBool FALSE: No error
TRUE: An error occurred during the execution of the FB
statusWord 16#0000-16#7FFF: Status of the FB
16#8000-16#FFFF: Error identification (see following Table)

In/Out parameter

IdentifierData type Description
arrayArray[*] of LReal Array to be sorted

Status & Error codes

Code / ValueIdentifier / Description
16#0000STATUS_NO_ERROR
Status: Execution finished without errors
16#8200ERR_NO_ARRAY
Error: Actual parameter at the `array` input has only one element.
16#8201ERR_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 & DateChange description
01.00.00Siemens Industry Online Support
19.08.2015First released version
01.01.00Siemens Industry Online Support
19.05.2016New function: reverse sort
01.01.01Siemens Industry Online Support
02.01.2017Upgrade: TIA Portal V14 Update 1
01.01.02Siemens Industry Online Support
17.08.2018Upgrade: TIA V15 Update 2
01.01.03Siemens Industry Online Support
23.11.2018Upgrade: TIA V15.1
02.00.00Siemens Industry Online Support
29.01.2019Output "done" removed (not necessary, because only one cycle)
02.00.01Simatic Systems Support
15.10.2019Code refactoring, comments added,
change data type from Real to LReal
03.00.00Simatic Systems Support
23.04.2020Set version to V3.0.0, harmonize the version of the whole library
03.00.01Simatic Systems Support
15.02.2021Insert documentation