TTT
TTT

Reputation: 1205

Fortran reading mixed string and numeric data

I'm having trouble with a read statement. I'd prefer Fortran90, though other versions might be possible if it helps. I have a bunch of lines of data in a file that can be described as:

Here's an example:

maxele/OS1_HC_LF_A_0001_004_maxele.63    4.22E-03        9.00E-01        1.00E-06        1       -999    -999    -999
maxele/OS1_Inl_A_0001_005_maxele.63     2.11E-03        9.00E-01        1.00E-06        3       -999    -999    -999
maxele/OS1_HC_LF_C_0001_009_maxele.63  1.56E-03        9.00E-01        1.00E-06        2       58.77   -82.82  28.91
maxele/OS1_TS_B_0001_006_maxele.63   3.90E-03        9.00E-01        1.00E-06        1       -999    -999    -999  

I've learned that Fortran will stop a read statement if it encounters a slash (/) character for unformatted reads, so I have to use format specifiers. And because the string length is unknown, I'm not sure how to make sure the string read stops at the first space. I believe it's possible to read in the whole line, then parse afterwards, but this seems convoluted. Is there no way to force it to treat the data as space-delimited? Thanks in advance.

Upvotes: 3

Views: 2907

Answers (1)

agentp
agentp

Reputation: 6999

you do need to read the whole line and parse, in this case its not so bad because you only need to parse the first string and can internal list read the rest.

read(unit,'(a)')string !declared long enough for a whole line
iblnk=index(string,' ')
read(string(iblnk:),*)seven_reals

Upvotes: 5

Related Questions