Minimum value search in real number data table (floating point data)
The function searches for the minimum value and its position in a floating point data table.
Input
Beginning of data table
End of data table
Output
minimum value
position of minimum value
Input s1_Start specifies the starting area of the data table, and s2_:End specifies the end. The minimum value is returned at output Min and its position at output Pos.
If more than one minimum value is found, the first one found beginning from the starting address specified at s1_Start is stored in Min.
The address of the minimum value at output Pos is relative to the beginning address in the data table as specified at input s1_Start.
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];
sum: REAL:=0.0;
(*the sum of all elements of
data_array; here: -3.0*)
mean: REAL:=0.0;
(*the arithmetic mean of all
elements of data_array;
here: -0.6*)
END_VAR
When the variable start is set to TRUE, the function is carried out.
It then searches the data_field for a minimum value and its position. The result here is: min_value = 6.91 and position = 2.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,7,1,9,3,);
B(B_VARIN,,data field[0],7,2,9,4,);
B(B_VARIN,,data field[4],7,3,9,5,);
B(B_VAROUT,,min_value,18,2,20,4,);
B(B_F,F351_FMIN,,9,0,18,5,,?DEN?D@'s1'?Ds2?AENO?Cmin?Cpos);
B(B_VAROUT,,position,18,3,20,5,);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF start then
F351_FMIN( s1_Start:= data_field[0],
s2_End:= data_field[4],
Min=> min_value ,
Pos=> position );
END_IF;