Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to read data in Scentific notation in Fortran90

Posted on 2011-02-13
3
Medium Priority
?
389 Views
Last Modified: 2013-11-25
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.
0
Comment
Question by:jl66
  • 2
3 Comments
 
LVL 5

Expert Comment

by:dcesari
ID: 34886692
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.
0
 
LVL 5

Accepted Solution

by:
dcesari earned 2000 total points
ID: 34886727
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
INTEGER :: id
REAL :: val1, val2

OPEN(10,file='prova.txt')
DO WHILE(.TRUE.)
read(10, '(A3, I3, E12.0, E6.0)', END=25) NAME, ID, VAL1, VAL2
PRINT*,name,id,val1,val2
ENDDO

25 CLOSE(10)

END PROGRAM prova

Open in new window

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

Open in new window

0
 

Author Closing Comment

by:jl66
ID: 34887996
Excellent!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Starting up a Project
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question