While reading through a rather large text file (~46 Gb), a little less than halfway through the snippet of code shown below crashes. The variable IFTLFMT is a flag for indicating if the file being read is binary (IFTLFMT=0) or formatted text (IFTLFMT=1). For debugging, IFTLFMT is currently equal to 1, though the code seems to crash when reading the binary equivalent as well. With IFTLFMT = 1, the BACKSPACE command is called with each loop and I'm suspicious this is where the problem is.
The behavior leading up to the crash is that as the Fortran shown below is looping, it reads the middle line of example text shown below (shown after the fortran code) and on the next loop, instead of reading the next line of text:
SFR REJ 1 32 16 1 3 0.108565
It reads LABEL,TEXT which appear to be read in OK based on the values they are filled with, but then runs BACKSPACE(INUF) followed by the next READ statement which is where it crashes. All of the values in the READ statement are filled with 0.00, which clearly are not in the text file. Thus, I'm wondering if there is a limit on the number of time BACKSPACE can be used? I would venture a ballpark guess that BACKSPACE has been called somewhere in the neighborhood of 51.3 million times by the time the crash occurs.
I've also tried removing the BACKSPACE command, but my limited understanding of READ is that it reads an entire line when reading formatted text. Thus, the code won't continue reading part way through a line, but this is exactly what I need because the second read statement depends on the value of the first entry on the line.
Code that crashes:
C--READ CONNECTIONS INFORMATION DO I=1,NCON IF(IFTLFMT.EQ.0) THEN READ(INUF) LABEL,TEXT ELSEIF(IFTLFMT.EQ.1) THEN READ(INUF,*) LABEL,TEXT BACKSPACE(INUF) ENDIF C C--LOOP THROUGH EACH CONNECTION C C--IF UZF -> SFR, READ 8 VALUES IF(LABEL.EQ.'SFR ') THEN IF(IFTLFMT.EQ.0) THEN READ(INUF) KK,II,JJ,ISTSG,NREACH,Q ELSEIF(IFTLFMT.EQ.1) THEN READ(INUF,2) LABEL,TEXT,KK,II,JJ,ISTSG,NREACH,Q 2 FORMAT(2X,A4,2X,A4,5I6,F) ENDIF IROUTE(1,I)=1 !1:SFR, 2:LAK, 3:SNK IROUTE(2,I)=KK IROUTE(3,I)=II IROUTE(4,I)=JJ IROUTE(5,I)=ISTSG IROUTE(6,I)=NREACH C Do some more stuff... ELSEIF(LABEL.EQ.'LAK ') THEN C ... ELSEIF(LABEL.EQ.'SNK ') THEN C ... ENDIF ENDDO
Example of text that is being read:
... SFR GRW 1 32 16 1 2 0.064677 SFR REJ 1 32 16 1 2 0.130278 SFR GRW 1 32 16 1 3 0.053897 !After this line, the code crashes SFR REJ 1 32 16 1 3 0.108565 SFR GRW 1 32 16 1 4 0.053897
...