IonicWind Software

IWBasic => General Questions => Topic started by: John S on January 03, 2007, 10:22:10 AM

Title: Possible problem passing arrays
Post by: John S on January 03, 2007, 10:22:10 AM
Paul,
there may be a problem with passing arrays. 
In the example below, when compiled, the vector B seems to pass o.k. to the sub, but the matrix A doesn't.


DIM A[5, 5], B[5] as double

N = 4

databegin MatrixElements
'      System matrix    Constant vector
'      ---------------  ---------------
  DATA  2,  1,   5, -8,        0
  DATA  7,  6,   2,  2,       17
  DATA -1, -3, -10,  4,      -10
  DATA  2,  2,   2,  1,        7
dataend

restore MatrixElements

FOR I = 1 TO N
  FOR J = 1 TO N
    getdata MatrixElements, A[I, J]
    print A[I,J],"   ",
  NEXT J
  getdata MatrixElements, B[I]
  print
NEXT I
print
FOR I = 1 TO N
  print B[I]
NEXT I
print

PrintMatrix( "Matrix A", A)
PrintVector( "Vector B", B)

DO
UNTIL INKEY$ <> ""

END

SUB PrintMatrix( Title AS STRING, A[] AS DOUBLE )
' ------------------------------------------------------------------
' Print matrix
' ------------------------------------------------------------------
  int I, J
  PRINT : PRINT Title : PRINT
  FOR I = 1 TO 4
    FOR J = 1 TO 4
      PRINT A[I, J], "   ",
    NEXT J
    PRINT
  NEXT I
ENDSUB

SUB PrintVector( Title AS STRING, B[] AS DOUBLE )
' ------------------------------------------------------------------
' Print vector
' ------------------------------------------------------------------
  int I
  PRINT : PRINT Title : PRINT   
  FOR I = 1 TO 4
    PRINT B[I]
  NEXT I
ENDSUB
Title: Re: Possible problem passing arrays
Post by: Ionic Wind Support Team on January 03, 2007, 12:27:03 PM
You have to tell it the size of the array.

SUB PrintVector( Title AS STRING, B[5,5] AS DOUBLE )

Paul.
Title: Re: Possible problem passing arrays
Post by: John S on January 03, 2007, 10:54:43 PM
thanks Paul,
I missed that in the docs (probably need more sleep)