Calculate total and mean numbers in data table of INT numbers
This FP instruction calculates the sum and the arithmetic mean of positive and negative INT numbers in the data table specified by s1_Start and s2_End. The sum of all elements in the data table is returned at output d1_Sum and the arithmetic mean of all elements in the data table is returned at output d2_Mean. The arithmetic mean is rounded off if it is not a whole number.
Input
Beginning of data table
End of data table
Output
Sum of all elements in data table area specified
Mean of all elements in data table area specified
if the area specified using the index modifier exceeds the limit.
if s1_Start>s2_End
if s1_Start and s2_End belong to different data areas.
if the area specified using the index modifier exceeds the limit.
if s1_Start>s2_End
if s1_Start and s2_End belong to different data areas.
Corresponding F instructions: F275_MEAN, F276_DMEAN, F352_FMEAN
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
bStart: BOOL:=FALSE;
(*activates the function*)
aiDataField: ARRAY [0..4] OF INT:=[2,3,6,-3,1];
diSum: DINT:=0;
(*the sum of all elements of
data_array; here: 9*)
iMean: INT:=0;
(*the arithmetic mean of all
elements of data_array;
here: 1*)
END_VAR
When the variable bStart is set to TRUE, the function is carried out.
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_CONTACT,,bStart,6,2,8,4,);
B(B_VARIN,,aiDataField[0],10,3,12,5,);
B(B_VARIN,,aiDataField[4],10,4,12,6,);
B(B_VAROUT,,diSum,25,3,27,5,);
B(B_VAROUT,,iMean,25,4,27,6,);
B(B_F,FP_DATA_MEAN_SUM_INT!,,12,1,25,6,,?DEN?Ds1_Start?Ds2_End?AENO?Cd1_Sum?Cd2_Mean);
L(8,3,12,3);
L(1,3,6,3);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF bStart then
FP_DATA_MEAN_SUM_INT(s1_Start := aiDataField[0],
s2_End := aiDataField[4],
d1_Sum => diSum,
d2_Mean => iMean);
END_IF;