Reading formatted input in fortran

Click For Summary
SUMMARY

The discussion focuses on reading formatted input in Fortran, specifically using the E format for scientific notation. The E format syntax is defined as Ew.d, where W is the total width and D is the number of decimal places in the mantissa. A practical example provided demonstrates how to read a line of exponential data using a default format statement. The user is guided to use the READ statement with a specified unit and file to successfully capture the data in variables.

PREREQUISITES
  • Understanding Fortran syntax and structure
  • Familiarity with scientific notation and its representation
  • Knowledge of Fortran I/O operations
  • Basic programming concepts related to data types and variable declaration
NEXT STEPS
  • Learn about Fortran E format specifications in detail
  • Explore advanced Fortran I/O operations for formatted data
  • Investigate the differences between READ and WRITE statements in Fortran
  • Study examples of reading and writing various data types in Fortran
USEFUL FOR

This discussion is beneficial for Fortran programmers, data scientists working with scientific data, and students learning numerical methods in programming.

agalya
Messages
9
Reaction score
0
format statement to read input in fortran

hello everyone,
I've to read this following line in fortran,
I don't know to read the exponential form
please help me

3.49E+03 2.73E+01 2.01E-01 9.16E-02 5.94E-02 5.11E-02 3.27E+04 3.27E+04

can somebody help me to write the format statement to read the whole line
or can please tell me how should I read the exponential data eg 3.49E+01 and 9.44E-09

thank you,
agalya
 
Last edited:
Technology news on Phys.org
Taken from this site: http://elsa.berkeley.edu/sst/fmttop.html

The E format allows the user to enter data stored in scientific notation. The syntax of the E format is the same as the F format:

Ew.d

Here W is the total width of the variable, including exponent, while D indicates the number of implied decimal places in the mantissa. The data field should contain the mantissa and the letter E followed by an integer indicating the power of ten to which the mantissa is to be raised. For example, E6.0 would read `1234E2' as `123400' (1234.0 x 10^2), while E6.1 would read `1234E2' as `12340' (123.4 x 10^2). As before, any decimal actually coded overrides the format specification, so that both E6.0 and E6.1 would read `123.4E2' as `12340'. "

Try also this site, for more details: http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap05/format.html
 
If the data is separated by spaces as you have here, you can use the default format (*):

Code:
      real a, b, c, d, e, f, g, h
      open (unit=10, file='agalya.txt')
      read (10, *) a, b, c, d, e, f, g, h
      write (*, *) a, b, c, d, e, f, g, h
      end

This "write" statement doesn't give you the numbers in the same format in which you read them; it uses its own default format. You can of course specify your own output format as needed.
 
Last edited:

Similar threads

  • · Replies 8 ·
Replies
8
Views
5K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 17 ·
Replies
17
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
8K
  • · Replies 4 ·
Replies
4
Views
3K