Elem_OfArray3D

Number of elements in an array

This function yields the number of elements of the 1st, 2nd and 3rd dimension of an array.

Parameters

Input

Array3D (ANY_IN_UNITS_OF_WORDS)

Input variable (array dimension 1,2 or 3) whose number of elements is to be determined

Output

NrOfElem1 (INT, DINT, UINT, UDINT)

Yields number of elements in the first dimension

NrOfElem2 (INT, DINT, UINT, UDINT)

Yields number of elements in the second dimension

NrOfElem3 (INT, DINT, UINT, UDINT)

Yields number of elements in the third dimension

Remarks

If input Array3D is an one dimensional array:

  • The number of elements in the array at input Array3D is yielded at output NrOfElem1.

  • Value 1 is returned at output NrOfElem2.

  • Value 1 is returned at output NrOfElem3.

If input Array3D is a two dimensional array:

  • From the array at input Array3D, the number of elements in the first dimension is yielded at output NrOfElem1 and the number of elements in the second dimension at output NrOfElem2.

  • Value 1 is returned at output NrOfElem3.

If input Array3D is a three dimensional array:

  • At outputs NrOfElem1, NrOfElem2 and NrOfElem3 the number of elements in the first, second, and third dimensions of the array at input Array3D are yielded.

Hence, functions and function blocks can be written that process arrays of various lengths (also in conjunction with the functions (GetPointer, AreaOffs_ToVar,Var_ToAreaOffs).

NOTE

The product NrOfElem1 * NrOfElem2 * NrOfElem3 always equals the total number of the elements in the array.

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
		ArrayOfInt: ARRAY [2..15,3..20,4..25] OF INT:=[5544(0)];
		NumberOfDim1: INT:=0;
		NumberOfDim2: INT:=0;
		NumberOfDim3: INT:=0;
	END_VAR

POU body

In this case the function Elem_OfArray3D is executed in each CPU cycle (no EN input). It determines the number of elements of the variable ArrayOfInt. The result here is: NumberOfDim1 = 14, NumberOfDim2 = 18 and NumberOfDim3 = 22.

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,,ArrayOfInt,6,2,8,4,);
B(B_VAROUT,,NumberOfDim1,19,2,21,4,);
B(B_F,Elem_OfArray3D!,Instance,8,1,19,6,,?DArray3D?CNrOfElem1?CNrOfElem2?CNrOfElem3);
B(B_VAROUT,,,19,3,21,5,);
B(B_VAROUT,,,19,4,21,6,);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

Further example projects (directory "Samples" of FPWIN Pro installation):Calculate the trace of a three-dimensional array (FB)

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