title: Error using a read statement
body: <p>I am currently working on a FORTRAN program that is to read an input file. Once reading the input file, the first line of the file contains an integer representing the amount of matrices in the file.  The second line contains how many rows and columns each matrix has.  the rest of the lines contain the matrices themselves.  The program will read in each matrix and write it to an output file as well as calculate the sum of all the matrices.  When reading in the matrix data I keep receiving these two errors</p>
  
  <blockquote>
    <p>Code: READ(1,*,END=99)(DIMENSIONS(I), I=1,2)</p>
    
    <p>Error: Constants and expressions are invalid in read-only I/O lists.</p>
    
    <p>Error2: This label is undefined [99]</p>
  </blockquote>
  
  <p>My code is:</p>
  
  <pre><code>  *START OF CODE
    PROGRAM MAIN
  
    *DECLARATIONS
    INTEGER EXISTS, DONE, NUM, DIMENSIONS*2, USED
    INTEGER I,J, TEMPMAT(10,10), SUM(10,10),OVER
    CHARACTER INNAME*30, OUTNAME*30
    *INITIALIZATIONS
    INNAME='NULL.DOC'
    EXISTS=0
    DONE=0
    I=0
    J=0
    OVER=0
    USED=0
    NUM=1
    *FORMATS
    5     FORMAT(' ','SUM OF 'I2,X,'MATRICIES')
    *MAIN CODE
    *DO (0)
  
    *DO WHILE(1) INPUT NAME !EXIST AND != QUIT
     DO WHILE(EXISTS.EQ.0.OR.INNAME.EQ.'QUIT'.OR.INNAME.EQ.'Q')
    *PROMPT FOR NAME OF FILE AND INPUT
    PRINT *,'PLEASE INPUT A FILE NAME INCLUDING AN EXTENSION'
    PRINT *,'ENTER QUIT OR Q TO EXIT'
    READ (*,*) INNAME
  
    *TEST FOR FILE
    INQUIRE(FILE=INNAME, EXIST=EXISTS)
    PRINT *, 'INPUT FILE EXSISTS'
    *IF EXIST=FALSE, DISPLAY MESSAGE 
    IF(.NOT.EXISTS) THEN
    PRINT *,'FILE DOES NOT EXIST, PLEASE TRY AGAIN'
  
    *ELSE EXIST=TRUE, OPEN (UNIT=1)
    ELSE 
    OPEN(UNIT=1, FILE=INNAME, STATUS='OLD')
    END IF
    *END DO(1)      
    END DO
    *ASK CHOICES FOR OUTPUT
    PRINT *,'PLEASE ENTER A NAME FOR AN OUTPUT FILE W/ EXTENSION'
    PRINT *,'ENTER QUIT OR Q TO EXIT'
    READ(*,*)OUTNAME
  
    IF(OUTNAME.EQ.'Q'.OR.OUTNAME.EQ.'QUIT')THEN
      DONE=1
    END IF
    *CHECK IF DONE (IF 1)
    IF(DONE.EQ.0)THEN
    *OPEN THE OUTPUT FILE DO(2)
          DO WHILE(USED.EQ.0)
              INQUIRE(FILE=OUTNAME,EXIST=EXISTS)
              PRINT *, 'OUTPUT FILE EXSITS'
    *OPEN IF FOR IF FILE ALREADY EXISTS
              IF(EXISTS.EQ.1)THEN
                  DO WHILE(OVER.LT.1.OR.OVER.GT.2)
                  PRINT *,'FILE ALREADY EXISTS. DO YOU WANT TO OVERWRITE?'
                  PRINT *,'SELECT 1 FOR YES OR 2 FOR NO'
                  SELECT CASE(OVER)
                  CASE(1)
                      OPEN(UNIT=2,FILE=OUTNAME,STATUS='OLD')
                      USED=1            
                  CASE(2)
    *DO NOTHING  
                  CASE DEFAULT
                      PRINT *, 'THAT WAS NOT EVEN AN VALID INPUT, TRY AGAIN'
    *END SELECT
                  END SELECT 
    *END IF FOR IF FILE ALREADY EXISTS AMD OPEN IF DID NOT EXIST, END DO(2)
                  END DO
              END IF
              OPEN(UNIT=2,FILE=OUTNAME,STATUS='NEW')                   
    *READ IN 1 INTEGER (MAXIMUM VALUE OF 10) FOR # OF MATRICIES IN FILE
              READ(1,*) NUM
              PRINT *, 'THE NUMBER OF MATRICIES: ', NUM
    *READ IN 2 INTEGERS, 1=ROWS, 2=COLUMNS MAX OF 10 FOR EACH
              READ(1,*,END=99)(DIMENSIONS(I), I=1,2)
    *DO WHILE MORE MATRICIES EXIST DO(3)
              DO WHILE(NUM.GT.0)
    *READ THE MATRIX IN DO(4)
                  DO J=1,DIMENSIONS(1)
                      READ(1,*,END=99)(TEMPMAT(J,I),I=1,DIMENSIONS(2))
    *END DO (4)
                  END DO   
    *ADD MATRIX TO SUM MATRIX
    *DO(5)(6)
                  DO J=1,10
                      DO I=1,10
                          SUM(J,I)=SUM(J,I)+TEMPMAT(J,I)
    *END DO(5)(6) 
                      END DO
                  END DO
    *PRINT CURRENT MATRIX TO FILE W/ HEADER 'MATRIX X'
    *DO(6)
                  DO J=1,DIMENSIONS(1)
                      WRITE(2,*)(TEMPMAT(J,I),I=1,DIMENSIONS(2))
    *END DO(6)
                  END DO  
    *WRITE HEADING 'SUM OF ALL N MATRICES'
                  WRITE(2,*)5,NUM
                  NUM=NUM-1
    *END DO(3)
              END DO
    *END DO(0)
    END DO
    *PRINT SUM OF MATRICES
    *DO(7)
    DO J=1,10
      WRITE(2,*)(SUM(J,I),I=1,10)
    *END DO(7)
    END DO 
    END IF
    *STOP
    STOP
    *END
    END
  </code></pre>