Matrix IO

There are two formats for matrix files used in this program: ASCII and binary. Each format have read and write functions. Reada() reads ASCII matrices, and Writea() writes them. The format for an ASCII file is reasonably simple:
  1. Line 1: The first line is the matrix name. It may include blanks, may be no longer than 80 columns, and is terminated by a carriage return.
  2. Line 2: Two integers, the first is the number of rows and the second is the number of columns.
  3. Lines 3...r+2 : The next r rows are the rows of the matrix. Columns are separated by spaces.
There is no facility for missing data. The data is written to the file using "width" characters, and "dec" decimal places, so some accuracy may be lost if you do not set the width and decimal places before writing the matrix in ASCII format. The argument to Reada() is a file name character string. The file is opened and read. Reada() returns a VMatrix reference. The arguments to Writea() are a file name character string, and the VMatrix to be written.

Readb() and Writeb() read and write binary matrices. Writeb() creates a binary file storing the matrix. There is no loss in accuracy when using a binary matrix since the binary form of the elements is written. The file format for a binary file is:

  1. Bytes 1-4: An integer counting the number of characters in the matrix name. This is called strlen.
  2. Bytes 5...strlen+5: The matrix name string.
  3. The next two fields are integers containing the numbers of rows and columns of the matrix.
  4. The remaining fields: The matrix elements stored in row major order.
The arguments for Readb() and Writeb() are the same as their ASCII counterparts. Note however that Writeb() is a member function of the VMatrix class. This is required so that Writeb() may be more efficient. It needs access to the hdr pointer in its vdoub parent class. Writeb() sends data out in blocks of size BLK_SIZE bytes. This simplifies the paging of the matrix blocks in vmm storage. A block is read from the vmm and written. However, Readb() is not as efficient. It reads elements one at a time. To use Writeb(), you must use it as a member functions, eg. a.Writeb("junk.bin",a) where a is a VMatrix.

Another function for loading a matrix is LoadMat(). LoadMat() is another member function of VMatrix. It lets you enter matrix elements interactively.