Re: Simple Input File Parsing Question
- From: "tianyf@xxxxxxxxx" <tianyf@xxxxxxxxx>
- Date: Tue, 24 Jul 2007 21:29:46 -0700
magesing wrote:
Hi,
I am pretty new to programming in Fortran, and I am looking for a good
reference on doing some input parsing tasks.
What I need to do, is to take an input file containing comments (i.e.
anything after the character # to the end of line) and ten columns of
tab-delimited data values.
What I need to do is search through the comments for the number of
rows and columns of data (the comments are actually a header section
describing the data) and feed the first three columns of data into an
array for further calculations/manipulations.
What is a good reference for learning to parse strings in fortran?
An example of the beginning of one of my data-files is below:
# TEM_PIXperUM 1.000000
# x-star 0.399309
# y-star 0.588114
# z-star 0.670835
# WorkingDistance 16.000000
#
# Phase 1
# MaterialName Aluminum
# Formula Al
# Info
# Symmetry 43
# LatticeConstants 4.040 4.040 4.040 90.000 90.000 90.000
# NumberFamilies 4
# hklFamilies 1 1 1 1 0.000000 1
# hklFamilies 2 0 0 1 0.000000 1
# hklFamilies 2 2 0 1 0.000000 1
# hklFamilies 3 1 1 1 0.000000 1
# Categories 0 0 0 0 0
#
# GRID: HexGrid
# XSTEP: 5.000000
# YSTEP: 4.330127
# NCOLS_ODD: 153
# NCOLS_EVEN: 152
# NROWS: 163
#
# OPERATOR: mpl
#
# SAMPLEID:
#
# SCANID:
#
2.81425 0.79224 1.56894 0.00000 0.00000 335.5 0.976 0
12502 0.760
1.23840 1.56899 5.48967 5.00000 0.00000 305.9 0.940 0
15887 1.000
1.23987 1.56937 5.49117 10.00000 0.00000 334.9 0.619 0
13432 1.109
1.24344 1.57048 5.49297 15.00000 0.00000 311.7 0.619 0
15036 1.154
2.81757 0.79262 1.57037 20.00000 0.00000 281.9 0.512 0
15090 1.353
1.24161 1.56819 5.48788 25.00000 0.00000 307.3 0.976 0
13499 0.842
1.24206 1.56873 5.49106 30.00000 0.00000 296.2 0.631 0
15720 0.978
2.81703 0.79813 1.56760 35.00000 0.00000 286.7 0.643 0
12393 1.175
1.24263 1.56745 5.48381 40.00000 0.00000 326.0 0.952 0
14055 0.775
1.24295 1.56957 5.48397 45.00000 0.00000 316.6 0.940 0
12845 0.800
...
Your algorithm could look like this:
1). Define an array (large enough to hold the data section--applicable
to F77).
2). Loop through the header lines (read, goto). When current line
contains NCOLS/NROWS, then assign the part after ':' to variables
(index, if, read).
3). Read real data line by line (read, goto).
Cheers,
Tian
.
- Follow-Ups:
- Re: Simple Input File Parsing Question
- From: Les
- Re: Simple Input File Parsing Question
- References:
- Simple Input File Parsing Question
- From: magesing
- Simple Input File Parsing Question
- Prev by Date: Re: On writing negative zero - with or without sign
- Next by Date: Re: convert f77 code from mixed case to lower case
- Previous by thread: Re: Simple Input File Parsing Question
- Next by thread: Re: Simple Input File Parsing Question
- Index(es):
Relevant Pages
|