F352_FMEAN

Total and mean numbers calculation in floating point data table

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

Parameters

Input

s1_Start (REAL)

starting area of data table

s2_End (REAL)

ending area of data table

Output

Sum (REAL)

sum of all elements in data table area specified

Mean (REAL)

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.

Instead of using this F instruction, we recommend using the corresponding FP7 instruction:

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the address of the variable at input s1_Start > s2_End.

  • if the address areas are different.

  • if the floating point values exceed the processing range.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the address of the variable at input s1_Start > s2_End.

  • if the address areas are different.

  • if the floating point values exceed the processing range.

sys_bIsCarry (turns to TRUE for one scan)
  • if the total value range overflows or an underflow.

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 REAL:=[4.0,7.0,-32.0,13.0,5.0];
			(*result after a 0->1 leading
edge from start: 
[-32.0,4.0,5.0,7.0,13.0]*)
		asc_order: INT:=0;
			(*which way to sort:
0 means ascending order
1 means descending order*)
	END_VAR

POU body

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

It calculates the sum = 2.0 + 3.45 + (-6.91) + 5.44 + 1.3 = 5.28 and the mean = Sum/5 = 5.28/5 = 1.056 of the elements of the data_field.

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,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,,sum,19,2,21,4,);
B(B_F,F352_FMEAN,,10,0,19,5,,?DEN?D@'s1'?Ds2?AENO?Csum?Cmean);
B(B_VAROUT,,mean,19,3,21,5,);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

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

IL body

Modified on: 2019-01-25Feedback on this pagePanasonic hotline