MODULE port_test10a_gm2; FROM ChanConsts IMPORT OpenResults, old, read, write; FROM IOChan IMPORT ChanId; FROM StdChans IMPORT StdOutChan; IMPORT StreamFile; FROM TextIO IMPORT SkipLine, WriteLn, WriteString; FROM WholeIO IMPORT ReadCard, ReadInt, WriteCard, WriteInt; PROCEDURE ReadNumbersTest(); CONST arr_len= 128; TYPE arr_type= ARRAY[0..arr_len-1] OF CHAR; VAR cid_file: ChanId; cid_out: ChanId; file_name: arr_type; res: OpenResults; c1: CARDINAL; ival: INTEGER; cval: CARDINAL; BEGIN (* PROCEDURE ReadNumbersTest *) cid_out:=StdOutChan(); file_name:='test_data'; (* create file and write (INTEGER) numbers to it *) WriteString(cid_out, 'write (INTEGER) numbers to file...'); WriteLn(cid_out); StreamFile.Open(cid_file, file_name, write+old, res); IF res=opened THEN WriteString(cid_file, ' 123'); WriteLn(cid_file); WriteString(cid_file, '234'); WriteLn(cid_file); StreamFile.Close(cid_file); END; (* IF res=opened *) (* (re-)open file and read numbers with ReadCard *) WriteString(cid_out, 'read numbers with ReadCard...'); WriteLn(cid_out); StreamFile.Open(cid_file, file_name, read, res); IF res=opened THEN FOR c1:=1 TO 2 DO ReadCard(cid_file, cval); WriteCard(cid_out, cval, 1); WriteLn(cid_out); SkipLine(cid_file); END; (* FOR c1 *) StreamFile.Close(cid_file); END; (* IF res=opened *) WriteLn(cid_out); (* (re-)open file and read numbers with ReadInt *) WriteString(cid_out, 'read numbers with ReadInt...'); WriteLn(cid_out); StreamFile.Open(cid_file, file_name, read, res); IF res=opened THEN FOR c1:=1 TO 2 DO ReadInt(cid_file, ival); WriteInt(cid_out, ival, 1); WriteLn(cid_out); SkipLine(cid_file); END; (* FOR c1 *) StreamFile.Close(cid_file); END; (* IF res=opened *) WriteLn(cid_out); END ReadNumbersTest; BEGIN (* MODULE port_test10a_gm2 *) ReadNumbersTest(); END port_test10a_gm2. (* 12.05.2023 Tests for reading INTEGERs and CARDINALs from (text) file. *)