In this example, the CIN accepts two two-dimensional arrays and computes the cross product of the arrays. The CIN returns the cross product in a third parameter and a Boolean value as a fourth parameter. The Boolean parameter is TRUE if the number of columns in the first matrix is not equal to the number of rows in the second matrix. This example shows only the front panel, block diagram, and source code.
Complete the following steps to create the CIN.
![]() |
Note LabVIEW must be installed on the computer you use to create the CIN. |

The following illustration shows the block diagram for this VI.

#include "extcode.h"
#define ReturnParamNum 2 // The return array is the 2nd (0 based) parameter
// in the exported CIN routine, CINRun.
typedef struct {
int32 dimSizes[2];
float64 arg1[1];
} TD1;
typedef TD1 **TD1Hdl;
CIN MgErr CINRun( TD1Hdl ppA, TD1Hdl ppB, TD1Hdl ppAxB, LVBoolean* pError );
CIN MgErr CINRun( TD1Hdl ppA, TD1Hdl ppB, TD1Hdl ppAxB, LVBoolean* pError ){
MgErr mgErr = noErr;
float64* pAElem; // Pointer to walk through values in the "A" array
float64* pBElem; // Pointer to walk through values in the "B" array
float64* pResultElem; // Pointer to walk and fill in values in the "AxB" array
int32 iRow, iCol, iLoop;
int32 nResultRows = ( *ppA )->dimSizes[ 0 ];
int32 nResultCols = ( *ppB )->dimSizes[ 1 ];
int32 nNumberOfElem = nResultRows * nResultCols;
// Verify the number of columns in the "A" array equals the number of
// rows in the "B" array.
int32 nACols = ( *ppA )->dimSizes[ 1 ];
int32 nBRows = ( *ppB )->dimSizes[ 0 ];
if ( nACols != nBRows ) {
// This is invalid so set the parameter error. The CIN return value
// will still be noErr which will allow the VI to continue execution.
*pError = LVTRUE;
goto out;
}
// Allocate space for the return array.
mgErr = SetCINArraySize(( UHandle )ppAxB, ReturnParamNum, nNumberOfElem );
if ( mgErr ) {
// Here the CIN returns an error so the VI will stop anyway so
// don't worry about setting outputs.
goto out;
}
*pError = LVFALSE;
// Start setting up the result array..
( *ppAxB )->dimSizes[ 0 ] = nResultRows;
( *ppAxB )->dimSizes[ 1 ] = nResultCols;
// Initialize the pointers to their respective places in each array.
pAElem = ( *ppA )->arg1;
pBElem = ( *ppB )->arg1;
pResultElem = ( *ppAxB )->arg1;
// Now, let's start going through and calculating.
for ( iRow = 0; iRow < nResultRows; iRow++ ) {
for ( iCol = 0; iCol < nResultCols; iCol++ ) {
*pResultElem = 0;
for ( iLoop = 0; iLoop < nACols; iLoop++ ) {
*pResultElem += pAElem[ iRow * nACols + iLoop ] *
pBElem[ iLoop * nResultCols + iCol ];
}
pResultElem++;
}
}
out:
return mgErr;
}
In this example, CINRun is the only routine performing substantial operations. CINRun cross-multiplies the two-dimensional arrays A and B. LabVIEW stores the resulting array in ppAxB. If the number of columns in A is not equal to the number of rows in B, CINRun sets *pError to LVTRUE to inform the calling diagram of invalid data.
SetCINArraySize, the LabVIEW routine that accounts for alignment and padding requirements, resizes the array. The two-dimensional array data structure is the same as the one-dimensional array data structure, except the 2D array has two dimension fields instead of one. The two dimensions indicate the number of rows and the number of columns in the array, respectively. The data is declared as a one-dimensional C-style array. LabVIEW stores data row by row, as shown in the following illustration.
For an array with r rows and c columns, you can access the element at row i and column j, as shown in the following code:
value = (*arrayh)–>arg1[i*c + j];Refer to the Calculate the cross product VI in the labview\examples\cins\cross directory for an example of a CIN that computes the cross product of two arrays.