F276_DMEAN

Total and mean numbers calculation in 32-bit data table

This function calculates the sum and the arithmetic mean of numbers (both with +/- signs) in the specified 32-bit data table.

Parameters

Input

s1_Start (DWORD, DINT, UDINT, DATE, TOD, DT)

starting area of data table

s2_End (DWORD, DINT, UDINT, DATE, TOD, DT)

ending area of data table

Output

Sum (ARRAY [0..1] OF DINT)

sum of all elements in data table area specified

Mean (DINT)

mean of all elements in data table area specified

Remarks

Input s1_Start specifies the starting area of the data table, and s2_End specifies the end. The sum of all elements in the data table is returned at output Sum and the arithmetic mean of all elements in the data table is returned at output Mean. The arithmetic mean is rounded off if it is not a whole number.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the area specified using the index modifier exceeds the limit.

  • if the address of the variable at input s1_Start > s2_End

  • if s1_Start and s2_End belong to different data areas.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the area specified using the index modifier exceeds the limit.

  • if the address of the variable at input s1_Start > s2_End

  • if s1_Start and s2_End belong to different data areas.

sys_bIsCarry (turns to TRUE for one scan)
  • if the total value range overflows or underflows the 32-bit range.

Example

POU header

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 DINT:=[4,7,-32,13,5];
		sum: ARRAY [0..1] OF DINT:=[2(0)];
			(*the sum of all elements of 
data_array; here: -3
[16#FFFFFFFF,FFFFFFFD]*)
		mean: DINT:=0;
			(*the arithmetic mean of all
elements of data_array;
here: 0*)
	END_VAR

POU body

When the variable start is set to TRUE, the function is carried out.

The function calculates the sum of all elements of ARRAY data_field (sum = 2 + 3 + 222222 + (-333333) + 1 = -111105) and transfers the result to the variable sum. In addition, the function calculates the mean (mean = sum/5 = -111105/5 = -22221) and transfers the result to the variable mean.

LD body

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,6,1,8,3,);
B(B_VARIN,,data_field[0],6,2,8,4,);
B(B_VARIN,,data_field[4],6,3,8,5,);
B(B_F,F276_DMEAN,,8,0,17,5,,?DEN?D@'s1'?Ds2?AENO?Csum?Cmean);
B(B_VAROUT,,sum,17,2,19,4,);
B(B_VAROUT,,mean,17,3,19,5,);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF start then
    F276_DMEAN( s1_Start:= data_field[0],
         s2_End:= data_field[4],
         Sum=> sum,
         Mean=> mean);
END_IF;

IL body

Modified on: 2022-10-17Feedback on this pagePanasonic hotline