> The solution I prefer the most was sent to me by Phillip Helbig, and is
> a variation on a suggestion by Nils Smeds. In my case it appears to be
> the simplest to implement. The idea is to store the number of records at
> the end of the file rather than the beginning, and to open the file for
> reading with the position set to append (ie; positioned at the end of
> the file before the end of file marker), to backspace by one to read the
> number of records, and then rewind go back to the beginning of the file
> and read all the records in.
>
> An example program is appended.
>
> This compiles and works fine with CVF and g95 on windows. However,
> Phillip Helbig has gets a runtime error with this program using
> DEC/Compaq/HP Fortran95 on VMS/Alpha,
I hasten to add that I might not have the latest version of my compiler.
Can anyone else on VMS run the code below? (I can compile and link
fine, but get a runtime error.) With the code as it stands, I get:
%FOR-F-INCOPECLO, inconsistent OPEN/CLOSE parameters
if I replace READ with READWRITE for the ACTION in the second OPEN
statement, I get
%FOR-F-BACERR, BACKSPACE error
If the code below is standard, then I suppose that I have a bug in my
compiler.
> and both his compiler and PGI on
> linux will only compile it if the file is opened for reading with
> ACTION='READWRITE' rather than 'READ' even though there are no WRITE
> statements.
>
> Any ideas why?
My suspicion here is that POSITION="APPEND" is normally used to WRITE
records at the end of a file which already exists, so some compilers
might (wrongly) assume that if POSITION="APPEND" is specified, then
ACTION must be either WRITE or READWRITE. As the code below
demonstrates, there are times when one wants POSITION to be APPEND but
doesn't need WRITE (or READWRITE), just READ for ACTION.
|