How to read data in Scentific notation in Fortran90

Have data set as follows
ABC  1  4.2023E-02 100.1
AAA 10 1.2345E-03  200.2
How to read the data into the variables in FORTRAN 90?? I tried the following, but it did not work.
read(UNIT=1, '(A3, I3, E7.4, F6.1)', END=25) NAME, ID, VAL1, VAL2

Gurus, please advise.
Who is Participating?
dcesariConnect With a Mentor Commented:
A little update: the right format for your lines (provided that they are pasted with the correct number of spaces) is:

read(10, '(A3, I3, E12.0, E6.0)', END=25) NAME, ID, VAL1, VAL2

i.e. the third field is 12 characters wide, not 7, I show what I used as input text in the attached code (there seems to be some misalignment, however. The other attachment shows the code giving the correct result.
ROGRAM prova
CHARACTER(len=3) :: name
REAL :: val1, val2

read(10, '(A3, I3, E12.0, E6.0)', END=25) NAME, ID, VAL1, VAL2

25 CLOSE(10)


Open in new window

ABC  1  4.2023E-02 100.1
AAA 10 1.2345E-03  200.2

Open in new window

Hi, when reading floating point data with fixed format in Fortran, it is better to use a format like *.0, otherwise strange data scaling will happen, and the difference between E and F descriptors is not so important in reading, so, try to use the following:

read(UNIT=1, '(A3, I3, F7.0, F6.0)', END=25) NAME, ID, VAL1, VAL2

this should work correctly regardless of the number of digits you have after the decimal point in your floating point numbers, and regardless of having exponential notation or not, the only constraint is that the length of each field (including possible blanks) is fixed, so 7 and 6 characters respectively for the two real numbers.
jl66Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.