Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a .txt mixed data file in F77

Status
Not open for further replies.

craigkennedy

Programmer
Mar 16, 2012
1
GB
Hi everyone.

I'm having an issue reading a file. It's basically a text file with a header whose length can change depending on the data input, followed by three columns of numbers which is the data I am interested in. I can open the file alright, but how do I read the file in such a way that I can ignore the header and just access the numeric data?

The file looks like this when opened...


Filename:
C:\Data\2010\290310\earth-moffat-firepla_100329100944.raw

File Created:
March 29, 2010 - 10:09 AM

Specimen Id:
earth sample moffat fireplace

Specimen Name:
earth sample moffat fireplace

Specimen Description:


Comment:
Scan Type: 2Theta Scan
Start Angle: 5 deg.
Stop Angle: 70 deg.
Num Points: 3251
Step Size: 0.02 deg.
Scan Rate: 1.000000
Scan Mode: Continuous
Wavelength: 1.540562
\Kalpha1: 1.540562 \Kalpha2: 1.544390 \Kbeta: 1.392218

Optics:
Detector:
Type: Fixed Slits
Tube:
Type: Fixed Slits


Datas:
Pos [deg] Rate [CPS] ESD [-]

Range 1 ---> Iteration 1
5.000 210.00 15.875
5.020 221.67 16.310
5.040 210.00 15.875
5.060 224.17 16.401
5.080 195.83 15.330
5.100 220.00 16.248

...
...


69.940 29.17 5.916
69.960 25.00 5.477
69.980 30.00 6.000
70.000 28.33 5.831

Everything up to the words "Iteration 1" I would like to ignore, and then read the 3 columns in to three arrays.

Thanks!
 
Try reading the lines you want to ignore as character-strings. Check if the first characters are 'Range 1' and then read your data. This of course depends that 'Range 1' is present in all your inputfiles at the beginning of the last line you want to ignore.

Something like this would do:
Code:
character*7 cWord
open (unit = 10, file = 'your filename')
10 read (10, 20) cWord
20 format (a7)
if (cWord .ne. 'Range 1') goto 10
30 read (10, 40, end = 50) data
40 format (appropriate format)
goto 30
50 ....

hope this is Fortran 77. It's been a long time I last did it ....

The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top