; MATRIX
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; Functions to manipulate bidimensional matrices.
FUNCTION MatNew(row, col)
; Create a new matrix of size row by col
hmat = VECNEW(row)
FOR r = 1 TO row
VECSET(hmat, r, VECNEW(col))
NEXT
RETURN hmat
FUNCTION MatLen(hmat)
; Return the number of items in the matrix, assuming
; that each row has the same length
RETURN MUL(VECLEN(hmat), VECLEN(VECGET(hmat, 1)))
FUNCTION MatGet(hmat, row, col)
; Returns item row, col in matrix hmat
RETURN VECGET(VECGET(hmat, row), col)
FUNCTION MatSet(hmat, row, col, val)
; Sets to val item (row, col) in matrix hmat
RETURN VECSET(VECGET(hmat, row), col, val)
FUNCTION MatFree(hmat)
; Frees memory reserved to matrix hmat
limit = VECLEN(hmat)
FOR row = 1 TO limit
VECFREE(VECGET(hmat, row))
NEXT
RETURN VECFREE(hmat)