Vahid
Vahid

Reputation: 125

Reading strings from file separated by space in Fortran

I am reading large files in Fortran that contain mixed string/numeric data such as:

114 MIDSIDE 0 0 O0002        436        437        584        438
115 SURFACE M00002 0 0        359        561        560        356
412236 SOLID   M00002 O00001 0      86157      82419      82418      79009

Currently, each line is read as a string and then post-processed to identify the proper terms. I was wondering if there is any way to read each line as an integer followed by four strings separated by space, and then some more integers; i.e. similar to '(I10,4(A6,X),4I10)' format, but without any information on the size of each string.

Does not work (charr is empty, iarr(2:5)=0):

INTEGER IARR(5)
CHARACTER*30 CHARR(4)
C open the file with ID=1
READ(1,*)IARR(1),(CHARR(I),I=1,4),(IARR(I),I=2,5)

Works (only for the last line in the data example):

INTEGER IARR(5)
CHARACTER*30 CHARR(4)
C open the file with ID=1
READ(1,'(I10,4(A7,X),4I10)')IARR(1),(CHARR(I),I=1,4),(IARR(I),I=2,5)

The issue is I don't know a-priori what would be the size of each string.

Upvotes: 1

Views: 2189

Answers (1)

Vahid
Vahid

Reputation: 125

I actually found out the f77rtl flag was used to compile the project, and when I removed the flag, the issue was resolved. So the list-directed input format works just fine.

Upvotes: 1

Related Questions