Dear Dr. Wang:
Xiaogang Wang wrote:
>Hi,
>
> Is there a command in F90 that can skip some records when reading a
>SEQUENTIAL and UNFORMATTED file?
>
No, not directly. As Malcolm cohen suggested, you can do this with
a READ statement with no I/O list.
>Not able to find such a command, I have to
>settle with reading and discarding the records I want to skip. But why there
>isn't such a command in F90 that goes directly to where the wanted record is.
>Is this problem more acute when each record is very long (say, a million
>element)?
>
<snip>
Why? Because different records in the same sequential-access file
can, and usually do, have different lengths. Almost all operating
systems and files systems in use today do **NOT** keep an index of the
starting location of each sequential record within the whole file.
Without this information, it is impossible to skip the intervening
records directly, as you appear to be suggesting.
In fact, I can't think of any that do, not even the RMS file system
of the OpenVMS operating system. At best, a sequential file of
variable-length records will have the record length at the start of each
record and possibly at the end as well (for backspacing). Some
operating systems and/or file systems do not permit even this amount of
information about each record.
Are all of your records of the same length? If so, you should
create the file as a direct-access file (use ACCESS="DIRECT" on the OPEN
statement). Some operating systems and/or file systems require that the
file be created as direct-access in order to use direct-access READ and
WRITE statements.
One of the difficulties of answering questions about I/O issues is
that they are highly specific to the host operating system and file
system. There are major design differences in file and record
structures between different operating systems and file systems, and ISO
standard Fortran has to work reasonably well with all of them.
Another problem is that people tend to be highly centric toward the
operating system and/or file system that they use on a daily basis in
their work:
* "The whole world is Unix, and if it's not, then it damn well ought to be!"
* Ditto for Windows.
* Ditto for everything else.
Yes, I sometimes feel that way about VMS, my own personal favorite, but
in my saner moments I try to be a little more grown-up about such things.
--
Sincerely,
Craig T. Dedo
17130 W. Burleigh Place E-mail: [log in to unmask]
Brookfield, WI 53005-2759 Voice Phone: (262) 783-5869
USA Fax Phone: (262) 783-5928
"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety." -- Benjamin Franklin
(1759)
|