CONST
LIMIT := 7;
END_CONST
VAR_IN_OUT
sortbuffer : ARRAY[0..LIMIT] OF INT;
END_VAR
VAR_OUTPUT
calcbuffer : ARRAY[0..LIMIT] OF
STRUCT
squareroot : INT;
square : INT;
END_STRUCT;
END_VAR
VAR_TEMP
swap : BOOL;
index, aux : INT;
valr, resultr: REAL ;
END_VAR
BEGIN
(********************************************************
Part 1 Sorting : According to the "bubble sort" method: Swap
pairs of values until the measured value buffer is sorted.
**********************************************************)
REPEAT
swap := FALSE;
FOR index := LIMIT TO 1 BY -1 DO
IF sortbuffer[index-1] > sortbuffer[index]
THEN aux :=sortbuffer[index];
sortbuffer[index] := sortbuffer[index-1];
sortbuffer[index-1] := aux;
swap := TRUE;
END_IF;
END_FOR;
UNTIL NOT swap
END_REPEAT;