You stated:
I get the file “test.dat” from another program and I do not know, how many and which records are filled (or described) with values.
Then you provide an open statement:
open (20,file='test.dat',access='direct',recl=80)
From this OPEN, you are expecting that the file test.dat contains fixed length records of 80 characters. Is that consistent with 'I do not know, how many and which records are filled (or described) with values' ?
I think the solution would be to open the file “test.dat” in a more flexible way, say access='transparent', and try to see what information you can find, then write it to a new more structured file, that is easier for your program to manage.
Also, I am not a fan of formatted, direct access files, although the default for 'direct' is 'unformatted'.
If I was receiving a direct access file, I would want the file to have a more formal structure and not records that are possibly filled with values'.
Note, if you are creating a fixed length record, direct access file, it is possible to rewrite the first record, with key measures of the file structure after the file has been completed. This initial indexing makes the file a lot easier to use when re-opened. All you need is a well defined record/data structure.
John