I'm trying to output a trivial error message in Fortran90, like so:
error: failed to read '<file>'
But I cannot figure out how to produce the single quotes, escaping them leads to compilation errors. I have tried the following:
write(*, fmt="('error: failed to read: \'', a, '\'')") arg
Also, if I print the message without them:
write(*, fmt="('error: failed to read: ', a)") file
an extra newline (i.e. two in total) is produced on the command line. I obtain arg
by executing call getarg(1, arg)
, maybe that has something to do with it.
Here is a minimal working example which demonstrates the newline problem:
program foo
character(len=100) :: arg
call getarg(1, arg)
write(*, fmt="('error: failed to read: ', a)") arg
end program foo
I find formatted output in fortran to be very unintuitive, if someone could additionally direct me to a resource that explains this in more detail that would be great.