- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does anyone know of a simple way, within the FORTRAN language,of establishing if theBACKSPACE command has hit the beginning of a sequential file? I use backspace to look for comments within an engineering analysis input deck. If a line corresponds to a recognised fieldI need to backspace two lines to check for a comment on thepreceeding linefrom which a descriptive text string can be obtained. The comments are not mandatory in these input files so a problem occurs if the first line of the file is not a comment. In this case backspacing once will hit the beginning of the file and the second BACKSPACE will do nothing (IOSTAT is still returned as 0) so there seems to be no way of knowing where you are.Normally after checking for a preceding comment there willfollow two read statements to get you back to where you would have been if you were reading sequentially through the file. This works fine if the first line of the file is a comment (or any line further down the file) but when it is not thetwo reads will cause the second line of the file to be bypassed.
Ideally the BACKSPACE could return a Start_of_File code in a similar way to aREAD statement returning an end of file code when you reach that point. I don't dsee anything in the function references to provide the functionality I am after. The Inquire statement looked a possiblity but the Position returns the settings used to open the file rather than its current position.
Ideally the BACKSPACE could return a Start_of_File code in a similar way to aREAD statement returning an end of file code when you reach that point. I don't dsee anything in the function references to provide the functionality I am after. The Inquire statement looked a possiblity but the Position returns the settings used to open the file rather than its current position.
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suggest you use the GETPOS routine from the "Portability library" for this purpose.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suggest you use the GETPOS routine from the "Portability library" for this purpose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Prior to backspacing try issuing INQUIRE to obtain POS.
I am not sure if POS is 0-based or 1-based, you can easily determine this.
If/when the inquire indicates the last record read, was the first record of the file, then assume that there is no comment (as it would have to preceed the beginning of the file).
Jim Dempsey
I am not sure if POS is 0-based or 1-based, you can easily determine this.
If/when the inquire indicates the last record read, was the first record of the file, then assume that there is no comment (as it would have to preceed the beginning of the file).
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve,
GetPos is just what I was after.
I think the INQUIRE POS idea only works on files opened with ACCESS='STREAMED' according to documentation.
Thanks again.
GetPos is just what I was after.
I think the INQUIRE POS idea only works on files opened with ACCESS='STREAMED' according to documentation.
Thanks again.

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