Something I haven’t properly learned yet is all the ways in which Fortran can access files. I gather that there are three access modes - sequential, direct, and stream; and that there are three file structures - formatted, unformatted and binary (with some combination of the aforementioned being illegal). Basically my understanding is as follows, is this roughly correct?
-
Direct access files have a fixed record length so that you can jump straight to a given record.
-
Sequential access files don’t have a fixed record length, which is convenient, but removes the possibility of random access.
-
Stream access is basically doing I/O as raw bytes (most similar to C-style IO)
-
Formatted files are in ASCII. Formatted stream files are rarely used, one normally uses sequential formatted files. Records are basically lines of text (newline and/or carriage return terminated).
-
Unformatted files that aren’t stream-access are in a compiler specific format that includes internal record separators. It’s binary, so quicker to read and write than formatted files, but aren’t human-readable. Stream unformatted files are in practice raw byte views just like C’s fread/fwrite.
I don’t really know anything about “binary” file structure.
Is it still common/recommended to use record based IO at all? Or is stream access preferred in most cases? It seems to me that in particular, formatted sequential access provides a useful way of getting data into and out of human readable / interoperable files, but I’m curious what the modern best practices are.
I apologize if this post is a bit of a mess - I’m trying to wrap my head around the different concepts and only vaguely understand them…