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 data from file data.txt

Status
Not open for further replies.

david1983

Programmer
Apr 17, 2012
2
CZ
I do not have a problem with reading data from file if the data are only numbers but if the numbers are mixed with text im not able to do it.
data.txt is filled this way:

probe : scan
frequency: 320Hz

x y
0 1
0.5 3.5
1 4

Question: how do i read data x and y from file without text within the file.

Thank you very much.

D.


 
If you know how many lines contain text, then just skip those lines by reading 'blind' that is without an io-list. Example: if you allways have 5 lines of text (or blanks) then just give five read-statements

Code:
do j = 1, 5
    read (10,*)
enddo
!
!  then start to read your variables
!

If you do not know haow many lines of text are present then read until the desired data are reached and no error occurs any more

Code:
do 
    read (10, *, err = 100, end = 200) iVal1, iVal2
    if (iVal1 .eq. 0) cycle      ! to skip the blank lines
!
!   use your data here
!
100 cycle
200 exit
enddo

Norbert


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