DIV_2D_ARRAY block
Short summary
Name |
DIV_2D_ARRAY |
→POU type |
|
Category |
|
Conform to →IEC-standard |
not defined in IEC-standard |
Graphical interface |
|
Available since |
|
Functionality
The block performs a bulk division where 2 arrays with 2 dimensions are divided 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 divison. 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 divided |
N |
UINT |
number of columns to divide |
|
Return value: |
– |
ARRAY [*,*] OF REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT or LINT |
array containing the result of the bulk division |
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,
that the size of the arrays for A1 and A2 amounts at least to the rows of M and the columns of N.
that no division by 0 is executed.
In case of an error the output ENO of the block is set to value FALSE (or an equivalent). In case of a division by 0 the corresponding element is set to 0.
Example for usage within ST-editor
FUNCTION_BLOCK ExampleDiv2DArray
VAR
array1 : ARRAY [
1
..
2
, -
1
..
1
] OF LREAL := [
2
( [
10.0
,
20.0
,
30.0
])];
array2 : ARRAY [-
1
..
30
, -
50
..
50
] OF LREAL := [ [
2.0
,
5.0
,
15.0
,
98
(
1.0
)],
31
( [
1.0
,
4.0
,
3.0
,
98
(
1.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 := [ [
5
,
4
,
2
,
17
(
0
)], [
10
,
5
,
10
,
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 := DIV_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 divided. 'enoCheck1' evaluates to 'TRUE'.
// [1][-1] / [-1][-50] = 10.0 / 2.0 = 5.0
// [1][0] / [-1][-49] = 20.0 / 5.0 = 4.0
// [1][1] / [-1][-48] = 30.0 / 15.0 = 2.0
// [2][-1] / [0][-50] = 10.0 / 1.0 = 10.0
// [2][0] / [0][-49] = 20.0 / 4.0 = 5.0
// [2][1] / [0][-48] = 30.0 / 3.0 = 10.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 := DIV_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.