Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem reading blank variables

Status
Not open for further replies.

cyberix1

Technical User
Mar 28, 2008
3
CA
Program is reading direct formatted text file. Each record consist of two character variables and two integer variables. The first record has text in both character variables but the second record has only blanks in the first character variable.

These are the relevant statements used:

OPEN(LUN, FILE=FILNAM, ACCESS='DIRECT', RECL=78,FORM=FORMATTED, STATUS='OLD', IOSTAT=IOST)

I = 0
15 I = I + 1
KREC = IREC + I - 1
READ (LUN, 1001, REC=KREC) MESS, TEXT, NBL, NL
IF (I .EQ. 1) NLINES = NL
IF (NBL .EQ. 0) GO TO 14
DO 8 J=1,NBL
8 WRITE (IWR, 2002)
14 WRITE (IWR, 2001) TEXT
WRITE (IWR, 1002) MESS, TEXT, NBL, NL, I
IF (I .LT. NLINES) GO TO 15
GO TO 19

1001 FORMAT(A5, 1X, A67, I3, I2)
1002 FORMAT(A5, 5X, A67, 5X, I2, 2X, I2, 2X, I3)
2001 FORMAT(1X, A67)
2002 FORMAT(1X)

The first 2 lines (78 characters) of the text file are:

Initz Welcome to the TROP standard table handling module Version 1.0 115
(July 1985). There are four tables of standard data in TROP, for: 0 0

(Note: the ( in the second record starts in the 7th column; the first 0 is in the 76th column)

The first line prints out OK but the second record does not and I assume it is because the first character variable of the second line has only blanks in it. I am using the gnu Fortran77 compiler.

Any help would be greatly appreciated.
 
Thanks for the reply. I shortened the program to limit it to the problem area:
PROGRAM TEST
CHARACTER*5 MESS
CHARACTER*20 FNAME
CHARACTER*67 TEXT
ITX1 = 14
IWR = 13
FNAME = 'TEST.TXT'
OPEN (ITX1, FILE=FNAME, ACCESS='DIRECT', RECL=78,
1FORM='FORMATTED', STATUS='OLD', IOSTAT=IOST)
I = 0
15 I = I + 1
READ (ITX1, 3001, REC=I) MESS, TEXT, NBL, NL
IF (I .EQ. 1) NLINES = NL
WRITE (IWR, 4001) TEXT
IF (I .LT. NLINES) GO TO 15
CLOSE (ITX1)
STOP
3001 FORMAT(A5, 1X, A67, I3, I2)
4001 FORMAT(1X, A67)
END

The text file Test.txt is:
Initz Welcome to the TROP standard table handling module Version 1.0 1 6
(July 1985). There are four tables of standard data in TROP, for: 0 0

There are 2 records each 78 characters long. Compiling is Ok. When executing the character string TEXT of the first record prints OK. But nothing prints of the second record.
Messages upon execution are:

fmt: read unexpected character
apparent state: unit 14 named TEST.TXT
last format: (A5, 1X, A67, I3, I2)
lately reading direct formatted external IO

abnormal program termination

This got me baffled, any help very appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top