Maximum value search in real number data table (floating point data)
The function searches for the maximum value and its position in a floating point data table.
Input
Beginning of data table
End of data table
Output
maximum value
position of maximum value
Input s1_Start specifies the starting area of the data table, and s2_End specifies the end. The maximum value is returned at output Max and its position at output Pos.
The position Pos is relative to the position at the beginning of the data table to the first occurrence of the maximum value.
If more than one maximum value is found, the first one found beginning from the starting address specified at s1_Start is stored in Max.
if the address of the variable at input s1_Start > s2_End.
if the address areas of s1_Start and s2_End are different.
if the floating point values exceed the processing range.
if the address of the variable at input s1_Start > s2_End.
if the address areas of s1_Start and s2_End are different.
if the floating point values exceed the processing range.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
start: BOOL:=FALSE;
(*activates the function*)
data_array: ARRAY [0..4] OF REAL:=[4.0,7.0,-32.0,13.0,5.0];
output_max: REAL:=0.0;
(*the maximum value of
data_array; here: -32.0*)
output_pos: INT:=0;
(*the position of the
maximum value; here: 2*)
END_VAR
When the variable start is set to TRUE, the function is carried out.
It then searches the data_field for a maximum value and its position. The result here is: max_value = 5.44 and position = 3.BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_VARIN,,output,8,1,10,3,);
B(B_VARIN,,data field[0],8,2,10,4,);
B(B_VARIN,,data field[4],8,3,10,5,);
B(B_VAROUT,,max_value,19,2,21,4,);
B(B_F,F350_FMAX,,10,0,19,5,,?DEN?D@'s1'?Ds2?AENO?Cmax?Cpos);
B(B_VAROUT,,position,19,3,21,5,);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF start then
F350_FMAX( s1_Start:= data_field[0],
s2_End:= data_field[4],
Max=> max_value,
Pos=> position);
END_IF;