ADD_2D_ARRAY block
Short summary
Name |
ADD_2D_ARRAY |
→POU type |
|
Category |
|
Conform to →IEC-standard |
not defined in IEC-standard |
Graphical interface |
|
Available since |
|
Functionality
The block performs a bulk addition where 2 arrays with 2 dimensions are added element by element until a specified column and row.
Enter the first array at the in-out A1 and the second array at the in-out A2. The arrays may have different sizes and index ranges (e.g. A1 =
[1..2, 1..3], A2 = [3..4, 4..8]
). However, the arrays must contain at least those columns and rows that are entered at the inputs M and N.
The block returns an array where the first M rows and N columns contain the result of the bulk addition. The size of this array is determined by the "target array" to which the result of the block is assigned. If the target array contains more elements than M * N , the excess elements are left unchanged.
Inputs, return value
|
Identifier |
Description |
|
In-outs |
A1 |
ARRAY [*,*] OF REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT or LINT |
variable-length array for the first operands |
A2 |
ARRAY [*,*] OF REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT or LINT |
variable-length array for the second operands |
|
Inputs: |
M |
UINT |
number of rows to add |
N |
UINT |
number of columns to add |
|
Return value: |
– |
ARRAY [*,*] OF REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT or LINT |
array containing the result of the bulk addition |
Input EN and output ENO are available when →calling
the block. See "Execution control: EN, ENO" for information on input EN and output ENO.
Internal error diagnostic for block
The block checks whether the size of the arrays for A1 and A2 amounts at least to the rows of M and the columns of N. If this is not the case, the output ENO of the block is set to value FALSE (or an equivalent).
Example for usage within ST-editor
FUNCTION_BLOCK ExampleAdd2DArray
VAR
array1 : ARRAY [
1
..
2
, -
1
..
1
] OF LREAL := [
2
( [
1.0
,
2.0
,
3.0
])];
array2 : ARRAY [-
1
..
30
, -
50
..
50
] OF LREAL := [ [
5.0
,
10.0
,
20.0
,
98
(
30.0
)],
31
( [
10.0
,
20.0
,
30.0
,
98
(
40.0
)])];
arrayResult1 : ARRAY [
1
..
20
,
1
..
20
] OF LREAL;
arrayResult2 : ARRAY [
1
..
20
,
1
..
20
] OF LREAL;
arrayExpected1 : ARRAY [
1
..
20
,
1
..
20
] OF LREAL := [[
6
,
12
,
23
,
17
(
0
)], [
11
,
22
,
33
,
17
(
0
)],
18
([
20
(
0
)])];
arrayExpected2 : ARRAY [
1
..
20
,
1
..
20
] OF LREAL;
enoCheck1, enoCheck2 : BOOL;
arrayEqual : BOOL := TRUE;
indexFirstDimension, indexSecondDimension : INT;
END_VAR
arrayResult1 := ADD_2D_ARRAY(A1 := array1, A2 := array2, M :=
2
, N :=
3
, ENO => enoCheck1);
// The following elements of 'array1' and 'array2', i.e. the following values, are added. 'enoCheck1' evaluates to 'TRUE'.
// [1][-1] + [-1][-50] = 1.0 + 5.0 = 6.0
// [1][0] + [-1][-49] = 2.0 + 10.0 = 12.0
// [1][1] + [-1][-48] = 3.0 + 20.0 = 23.0
// [2][-1] + [0][-50] = 1.0 + 10.0 = 11.0
// [2][0] + [0][-49] = 2.0 + 20.0 = 22.0
// [2][1] + [0][-48] = 3.0 + 30.0 = 33.0
// check the results
FOR indexFirstDimension :=
1
TO
20
DO
FOR indexSecondDimension :=
1
TO
20
DO
arrayEqual := AND(arrayEqual, arrayResult1[indexFirstDimension, indexSecondDimension] = arrayExpected1[indexFirstDimension, indexSecondDimension]);
END_FOR;
END_FOR;
ENO := AND(arrayEqual, enoCheck1);
arrayResult2 := ADD_2D_ARRAY(A1 := array1, A2 := array2, M :=
3
, N :=
2
, ENO => enoCheck2);
// 'enoCheck2' evaluates to 'FALSE' because 'array1' has only 2 rows.
// All elements of arrayResult2 remain unchanged.
// check the results
FOR indexFirstDimension :=
1
TO
20
DO
FOR indexSecondDimension :=
1
TO
20
DO
arrayEqual := AND(arrayEqual, arrayResult2[indexFirstDimension, indexSecondDimension] = arrayExpected2[indexFirstDimension, indexSecondDimension]);
END_FOR;
END_FOR;
ENO := AND(ENO, arrayEqual, NOT(enoCheck2));
END_FUNCTION_BLOCK
When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.