- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there
Is it possible to read data from a previous line?
For example my program needs to read the third line (30000) first, then the first line (10000) of the following data file:
01.txt:
10000
20000
30000
I can do it by closing and reopening the data file, but there may be a faster solution, e.g. a command for reading data from a specific line number.
INTEGER A,N
OPEN(unit = 1, file = '01.txt')
n = 2
READ (1,11)A
PRINT*, A
CLOSE(unit = 1)
OPEN(unit = 1, file = '01.txt')
n = 1
READ (1,11)A
PRINT*, A
CLOSE(unit = 1)
11 FORMAT(
end
Any comment would be very much appreciated.
Regards
Hamid
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Look at BACKSPACE for getting the previous record,
and REWIND to go back to the begining of the file without needing to close and re-open it.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Les Neilson
Look at BACKSPACE for getting the previous record,
and REWIND to go back to the begining of the file without needing to close and re-open it.
Les
Many thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Also consider
A2 = A1
A1 = A
READ(fmt) A
Then when A is your trigger (30000 in example) use A2
Use an array of prior results when the go-back is larger than a few.
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i would suggest tryinginternal reads into a character array and then simply setting the counter back 2 when special situations are encounteredto read prior records.
depending on how large your input dataset is, and how many times you need to check a prior value, you can save valuable time by simply inputting input in arrays (groups of 3) or more?
whenever you doing multiple open/close/rewind you are slowing things down.
memory is cheap and fast there's lots of it out there.
brian
depending on how large your input dataset is, and how many times you need to check a prior value, you can save valuable time by simply inputting input in arrays (groups of 3) or more?
whenever you doing multiple open/close/rewind you are slowing things down.
memory is cheap and fast there's lots of it out there.
brian

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page