Porting Adventure - reading Free Format Numbers

In the PDP-10 version code like this:
	READ (1, 1000) LOC, NEWLOC, (TK (I), I = 1, 20)
1000    FORMAT (99G)
Is used to read data like this:
1       2       2       44      29
1       3       3       12      19      43
1       4       5       13      14      46      30
1       5       6       45      43
1       8       63
2       1       2       12      7       43      30
2       5       6       45      46
(Where the numbers are seperated by TAB characters). Each read is supposed to read one line, setting the unused members of TK to zero.

A naïve translation into ICL Fortran would fail because the ICL free format input "G0" (or "I0") would skip over the line boundaries.

In order to work around this we allocate an I/O unit number for "in-core" I/O:

        INPUT 4 = /ARRAY
Then read each line as text, examine the line to see how many fields it contains then read only as many fields as there are using the ICL "in-core I/O" facility.

C  ICL1900 - READ RECORD WITH VARIABLE NUMBER OF INTEGER FIELDS.
C  NECESSARY BECAUSE ICL FORTRAN FREE FORMAT INPUT (I0, G0) SKIPS
C  RECORD BOUNDARIES.

        SUBROUTINE FIELDS (UNIT, TK)
        IMPLICIT INTEGER (A-Z)
        LOGICAL EQUAL
        DIMENSION TK (20)
        DIMENSION TEMP (10)
        DATA WD1 /' '/

1030    READ(UNIT,10311) TEMP
10311   FORMAT (10A8)
        LOC = 0
        K = 0
        DO 10312 I = 1, 80
        CALL COPY (1, WD1, 1, TEMP(1), I)
        IF (EQUAL(WD1, ' ')) GOTO 10314
        IF (LOC.NE.0) GOTO 10312
C       FIRST NONSPACE OF NEW FIELD
        LOC = 1
        K = K + 1
        GOTO 10312
10314   LOC = 0
10312   CONTINUE
        IF (K .EQ. 0) GOTO 1030
        IF (K .GT. 20) CALL BUG (0)
        CALL DEFBUF (4, 80, TEMP)
10315   READ(4,1031)(TK(L), L = 1, K)
1031    FORMAT(99I0)
        IF (K .EQ. 20) GOTO 1034
        DO 1033 L = K + 1, 20
        TK(L) = 0
1033    CONTINUE
1034    RETURN
	END
The read from unit "4" actualy reads from the array passed to the DEFBUF routine.

Now the READ in the main routine can be replaced by a call to FIELDS.


All questions to john@AtlanTech.com