Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29377 Discussions

How to read values with unknown format from text file?

jirina
New Contributor I
1,465 Views
I would like to read real values from a text file, not knowing in advance their format (width and position of the decimal point).

E.g., a user specifies

0.915
1000
12.300

and I would like to read these values into real variables. Is there any way of opening and reading the text file so that I would not have to force the user to specify values in a certain format?
0 Kudos
2 Replies
jirina
New Contributor I
1,465 Views
It is Murphy's law - I think I found a solution right after posting my questions. It seems that
[cpp]OPEN ( unit, FILE='...', FORM='FORMATTED', ACCESS='SEQUENTIAL', ACTION='READ' )

READ ( unit, * ) value[/cpp]
could do the job; I just hope there is nothing wrong about it.
0 Kudos
TimP
Honored Contributor III
1,465 Views
For your example, list-directed is fine. F12.0 would work too.
0 Kudos
Reply