Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

BACKSPACE command question

dannycat
Nuevo Colaborador I
1.024 Vistas
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.
0 kudos
1 Solución
Steven_L_Intel1
Empleados
1.024 Vistas
I suggest you use the GETPOS routine from the "Portability library" for this purpose.

Ver la solución en mensaje original publicado

3 Respuestas
Steven_L_Intel1
Empleados
1.025 Vistas
I suggest you use the GETPOS routine from the "Portability library" for this purpose.
jimdempseyatthecove
Colaborador Distinguido III
1.024 Vistas
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
dannycat
Nuevo Colaborador I
1.024 Vistas
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.
Responder