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

how to read the data on the same line

Status
Not open for further replies.

matthewkmk

Programmer
Nov 18, 2002
19
MO
how to read the data on the same line
e.g.

if i want to read the number after Mary once I have found Mary in the data file. Because it will read the next line after it found Mary if I want to read the number after Mary.


open(13,FILE='ff.dat')

1010 continue
read(13,1001,end=1011) ee

if (ee(1:4) .eq. 'Mary') then
read(13,1002,advance='no',end=1011) a
endif
goto 1010


1011 close(13)


Data:


Mary 100
John 200
David 400
Mary 300


Thx very much.
 
I'd suggest reading the entire line as character, then doing an internal read on the character variable. If the format of the line is fixed, this should work. For instance, if the data is as follows:

Mary 100
John 200
David 400
Mary 300

The code would be:

character*80 full_line
integer the_number

open(13,FILE='ff.dat')

1010 continue
read(13,1001,end=1011) full_line
1001 format(A80)

if (full_line(1:4).eq.'Mary') then
read(full_line,1002) the_number
1002 format(7X,I3)
end if
goto 1010

1011 close(13)

Hope this helps.
 
Sorry, got the variable declarations backwards. Should be:

full_line character*80
the_number integer
 
i think it doesnt work because once u read
Mary at that line , after u use "READ" again, it will automatically change to the next line.

can anybody help me to solve this? thx
 
It should work. Vecjjk reads the line number from the character variable full_line, not from the file.
To read the same line twice from the file, use BACKSPACE (13) before the 2. read.
 
I can solve it now, Thx very much.

Do anybody know something about how to write visual fortran dll?

Thx!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top