On Wednesday, January 20, 2021 at 8:44:23 AM UTC-8, Ron Shepard wrote:
(snip)
> >> write(*,'(*(1x,g0))') 5, 10, new_line('a')
(snip)
> Just out of curiosity, how portable is this? For example, on MS
> operating systems, new records are delimited with the two-character
> sequence <cr><lf>. What happens if a single <lf> character appears in
> the middle of a record?
That is a good question. The way it works in C, is that programs write
out '\n', which is usually called the newline character, but in any case is
a single character. The I/O library then figures out what to do to make it
work on the given system. It turns out that on Unix and unix-like systems
it just writes out the character. On DOS/Windows and related systems
it converts to the two character termination sequence on output, and
back again on input. Some IBM systems store lines with a length prefix,
so the library has to translate to/from that. (There are some complications
with ftell() and fseek() related to this conversion.)
Since many Fortran libraries now use the C library to do actual I/O,
that naturally happens. As well as I know, the standard is written
to make that obvious, but I never tried to be sure. In any case, it
is my preference not to write them that way.
Reminds me, in Fortran 66 days on IBM systems, I once had a character
constant with a newline character in it. I am not sure now why I
didn't use a hex constant. It was slightly tricky to get the character in.
(EBCDIC is interesting in that there are CR, LF, and NL as three different
characters, but only two in ASCII.)