Solved

How to read data in Scentific notation in Fortran90

Posted on 2011-02-13
3
385 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 100
ejb example issues 3 53
Documenting and diagramming code flow within a VBA Excel project 5 52
Java List 4 41
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

733 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