How to read a text file written by a MAT PRINT statement

In Full BASIC, (MAT)PRINT is discord with (MAT)INPUT.
We open a file as an internal file and write data using (MAT) WRITE statements, and later we read data using (MAT) READ statements.

However, when the array written by a MAT PRINT statement is numeric, we can modify it so as to read using a MAT INPUT statement. The essential is that commas should be written between every two numerals.
We modify a file, assuming its name comma.txt, such as
 1   2   3   4
 5   6   7   8
 9  10 11 12
into such as
 1,   2,   3,   4,
 5,   6,   7,   8,
 9,  10, 11, 12
and then we read the file using a MAT INPUT statement as follows.
DIM A(3,4)
OPEN #1:NAME "a:comma.txt"
MAT INPUT #1: A
CLOSE #1

The following is an example of a program that performs this conversion.
100 OPEN #1: NAME "a:space.txt"   ! input file
110 OPEN #2: NAME "a:comma.txt"   ! output file
120 ERASE #2
130 LINE INPUT #1:s$
140 DO WHILE s$<>""
150    WHEN EXCEPTION IN
160       LINE INPUT #1 : t$    ! t$ is the next line
170    USE
180       LET  t$=""
190    END WHEN
200    LET s$=RTRIM$(s$)        ! Eliminate blank characters at the right end.
210    LET p=1
220    DO WHILE s$(p:p)<>""
230       DO UNTIL s$(p:p)<>" "
240          LET p=p+1          ! Find the first non-blank
250       LOOP
260       DO UNTIL s$(p:p)=" " OR s$(p:p)=""
270          LET p=p+1          ! Find the next blank or end of the line
280       LOOP
290       IF (t$<>"") OR s$(p:p)=" " THEN  ! If the position is not the end of the line or there is a next line,
300          LET  s$(p:p-1)="," ! insert a comma.
310          LET p=p+1
320       END IF
330    LOOP
340    PRINT #2:s$
350    LET s$=t$
360 LOOP
370 CLOSE #1
380 CLOSE #2
390 END


Back