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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

to READ ASCII FILES

Status
Not open for further replies.

ilvecchio

Technical User
Jan 18, 2010
5
IT
Hello!
I'm trying to read files (ASCII output from commercial software) containing data as follow (coordinates, title, values):

1 -27.500 -70.500 -94.500
2 -27.500 -69.500 -94.500
3 -27.500 -68.500 -94.500
4 -27.500 -67.500 -94.500
5 -27.500 -66.500 -94.500
6 -27.500 -65.500 -94.500
7 -27.500 -64.500 -94.500
8 -27.500 -63.500 -94.500
9 -27.500 -62.500 -94.500
10 -27.500 -61.500 -94.500
primo.kout HEADER CMPD 1
0.000
-0.003
-0.005
-0.003
-0.004
-0.005
-0.005
-0.004
-0.003
-0.003

In order to read only the values (0.000, -0.003, ect.) I'm using this approach

...
REAL:: data
...
300 FORMAT(T2, F8.3) !is the same if I use default (2,*)
...
DO l=1,(number of row in the file)
IF ((11<l).AND.(l<21)) THEN
READ(2,300) data !is the same when (2,*)
WRITE(*,*) data
END If
ENDDO
...

Surprising, the result is ALWAYS something like the subsequent, instead of a list of values!
1.000000
2.000000
3.000000
etc...
The mail poin is:
=>if I try to read the coordinates set (like -27.500 -70.500 -94.500) is quite easy.
=> I'm not able to read the values, because each appempt to do this give a set of increasing integer values!!!

But.... if I delete the reports of coordinates and title the program work wery well!!!!

Do you have some ideas to solve the problem or understand better?

Thank you

Marck
 
You should also place a "READ(2,*)" outside the IF..THEN, if not, the cursor doesn't pass over to the next line.

The result is that you're reading the first column of integers as reals, because all the time the IF wasn't true, you didn't pass over to the next line


 
...I'm stupid!!!!
I forgot to copy the line "read..." outside the IF statement.
There is a bug in my brain!!!
For the second time...Thank you GerriGroot!
Since, this is the second post regarding "to read a specific line in a text file", I have a question:
There is some kind of command to jump on a specific record of the file? Whit files containing 11000000 of reports, to read all lines will be more time consuming!
 
Eeehm, I asked something similar myself on this forum some time ago. I got the answer from xwb telling me that you can do so if you open the file as a binary and then jump to a certain record (using ACCESS='DIRECT').


To do so, the part that you change must have the same amount of characters as the original text, for all 11,000,000 files!! (In my case, I fulfilled this exceptional condition by coincidence)

If all these files are ascii, and if you never worked with binaries before, I wouldn't bother doing the binary stuff. Apart form the time you lose programming it, there's quite some chance it won't work from scratch, because some of the 11000000 files may be different, have longer comments or whatsoever.

I'd just detect the line I wanted to change, reading all the lines in ascii and let it run overnight in batch.

Maybe you can also use "sed" as Mikrom stated in a recent post:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top