SUB_2D_ARRAY block

Short summary

Name

SUB_2D_ARRAY

→POU type

→function

Category

Standard (non-safe), NumericEnh, block with internal error diagnostic

Conform to →IEC-standard

(plus) not defined in IEC-standard

Graphical interface

Available since

version 1.44.0 (for Neuron Power Engineer) – initial variant

version 2.0.9 (for library Standard) – graphical interface with in-out variables

version 3.8.0 (for library Standard (non-safe)): block moved in this library

Functionality

The block performs a bulk subtraction where 2 arrays with 2 dimensions are subtracted 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 subtraction. 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

→Data type

Description

In-outs
(VAR_IN_OUT):

A1

ARRAY [*,*] OF REALLREALUSINTUINTUDINTULINTSINTINTDINT or LINT
(corresponds to →generic data type ANY_NUM)

variable-length array for the first operands

A2

ARRAY [*,*] OF REALLREALUSINTUINTUDINTULINTSINTINTDINT or LINT
(corresponds to →generic data type ANY_NUM)

variable-length array for the second operands

Inputs:

M

UINT

number of rows to subtract

N

UINT

number of columns to subtract

Return value:

ARRAY [*,*] OF REALLREALUSINTUINTUDINTULINTSINTINTDINT or LINT
(corresponds to →generic data type ANY_NUM)

array containing the result of the bulk subtraction

Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

See:

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 ExampleSub2DArray
    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 := [[-4, -8, -17, 17(0)], [-9,-18,-27, 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 := SUB_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 subtracted. 'enoCheck1' evaluates to 'TRUE'.
    //    [1][-1] - [-1][-50]  = 1.0 - 5.0 =   -4.0
    //    [1][0] - [-1][-49]   = 2.0 - 10.0 =  -8.0
    //    [1][1] - [-1][-48]   = 3.0 - 20.0 = -17.0
    //    [2][-1] - [0][-50]   = 1.0 - 10.0 =  -9.0
    //    [2][0] - [0][-49]    = 2.0 - 20.0 = -18.0
    //    [2][1] - [0][-48]    = 3.0 - 30.0 = -27.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 := SUB_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.