Fortran 90 question about reading files with text

Click For Summary
SUMMARY

This discussion focuses on reading numerical data from text files using Fortran 90. The user seeks to extract numbers from a file containing text and adjacent numerical values, specifically addressing two formats of data. The solution involves utilizing DO loops to process each format separately, leveraging the identification of specific string patterns to delineate the start of the second data set. A relevant tutorial with source code is provided for further guidance.

PREREQUISITES
  • Understanding of Fortran 90 syntax and file I/O operations
  • Familiarity with DO loops and conditional statements in Fortran
  • Basic knowledge of data formatting and parsing techniques
  • Experience with numerical data representation in text files
NEXT STEPS
  • Study Fortran 90 file reading techniques and best practices
  • Learn about string manipulation functions in Fortran 90
  • Explore advanced data parsing methods for mixed-format files
  • Review the tutorial on class averages provided in the discussion for practical examples
USEFUL FOR

This discussion is beneficial for Fortran developers, data scientists working with numerical data, and anyone involved in file processing and data extraction tasks in Fortran 90.

dealove
Messages
3
Reaction score
0
I have a file with text and adjacent to it, the number i want to read. Below is the format. I was wondering how to read just the numbers without touching the text.

trhy 30.0
difje 30.0
sdjk 66.5
xmb 15.0
dcos 15.0
fjvm 2.573e-4
srht 9.05e-3
art3 0.0
19.954
39.499
43.852
48.713
51.660
53.801
54.715
55.602

another format is:

is...o2. mw2 31.998 htf2 0.0
is...n2. mw3 28.014 htf3 0.0
is..co2. mw4 44.009 htf4 -93.965
is..h2o. mw5 18.015 htf5 -57.103

if above two formats are in the same file, can I use DO loops for first format and second format individually by counting the number of lines?
 
Technology news on Phys.org
if the second set always starts with 'is' then once you are able to identify strings you can use this as a starting point to start your second do loop.
I have found a tutorial with source code online. This should help you out:
http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap05/class-avg.html"
 
Last edited by a moderator:

Similar threads

  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 33 ·
2
Replies
33
Views
6K
  • · Replies 12 ·
Replies
12
Views
16K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 19 ·
Replies
19
Views
7K