MAL.VectorLength

Previous  Next

 

ref_arr_out = MAL.VectorLength( [BYREF arr_out      AS ARRAY],

                                 BYREF arr_in       AS ARRAY,

                                [BYVAL nPoint       AS INTEGER=ML_ALL],

                                [BYVAL nFrameOffset AS INTEGER=0] ) AS REFERENCE

 


 

Returns the vector length for each sample in a 2D or 3D array.  The output array must be a 1D array.  The input array can be either 2D or 3D (first dimenson 2, 3 or 5)

 

Example:

 

OPTION EXPLICIT ON

OPTION BASE 1

 

' Include C3D Support

$INCLUDE "MyBASIC2_C3DFile"

$LIBRARY "MyBASIC2_C3DFileLib"

 

' Include the MaxMAL Library

$INCLUDE "MyBASIC2_MaxMAL"

$LIBRARY "MyBASIC2_MaxMALLib"

 

' Forward Declare PrintArray

DECLARE SUB PrintArray

 

' Declare variables and arrays

DIM nPoints AS INTEGER

DIM nFrames AS INTEGER

DIM hFile   AS INTEGER

DIM fid     AS HANDLE

 

' Open the Test File

hFile = C3DFile.Open( "e:\walk8.c3d" )

 

IF NOT hFile > 0 THEN

  PRINT "Error Opening File ";cFileName,

  STOP

ENDIF

 

' Get the no of points and frames

nFrames = C3DFile.GetNoOfFrames( hFile )

nPoints = C3DFile.GetNoOfPoints( hFile )

 

' Dimension the arrays

DIM arrPoints(nFrames,nPoints,3) AS REAL

 

IF C3DFile.GetPoints( hFile, arrPoints ) <> nFrames THEN

  C3DFile.Close( hFile )

  PRINT "Error Reading ";nPoints;" from file ";cFileName,

  STOP

ENDIF

 

' Array to receive the calculated Vector Length

DIM arrVLen(nFrames,nPoints,1) AS REAL

 

' Calculate Vector Length of Point 2 and 3

MAL.VectorLength( arrVLen, arrPoints, PTS( 2, 3 ) )

CALL PrintArray( REF( arrVLen ) )

 

' Close Test File

C3DFile.Close( hFile )

 

END

 

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Print an array with up to 3 dimensions.  Array is passed as a reference

'

SUB PrintArray( arr AS REFERENCE )

  DIM i AS INTEGER  ' Frames

  DIM j AS INTEGER  ' Dimensions

  DIM n AS INTEGER  ' Points

 

  PRINT "-----------------------------------------------------",

  PRINT FORMAT( "%-12s|", VARNAME( arr ) )

 

  FOR n = 1 TO LEN( arr, 2 )

     PRINT " Point ";n;" |";

  ENDFOR

  PRINT ,"-----------------------------------------------------",

  FOR i = 1 TO LEN( arr, 3 )

     IF i < 10 THEN

        PRINT "Frame[";i;"]   = | ";

     ELSE IF i < 100 THEN

        PRINT "Frame[";i;"]  = | ";

     ELSE

        PRINT "Frame[";i;"] = | ";

     ENDIF

 

     FOR n = 1 TO LEN( arr, 2 )

        FOR j = 1 TO LEN( arr, 1 )

           PRINT arr( i, n, j )

           IF j < LEN( arr, 1 ) THEN

              PRINT ", "

           ENDIF

        ENDFOR

        PRINT " | "

     ENDFOR

     PRINT ,

  ENDFOR

  PRINT "-----------------------------------------------------",

END SUB