Searching for this question I found this SO thread, and the suggestion is to use stop N. Is that a standard way to do it? Seems from the discussion that sometimes the number gets printed, or not, depending on the OS or the compiler.
What I want is a flag to allow easier handling of errors from the output of a Fortran program, using an upper level script.
If the stop-code is an integer, it is recommended that the value be used as the process exit status, if the processor supports that concept.
If QUIET= is omitted or the scalar-logical-expr has the value false:
• …
• if a stop code is specified, it is recommended that it be made available by formatted output to the same unit.
(ERROR_UNIT, I think)
Note there is also the ERROR STOP statement:
Execution of a STOP statement initiates normal termination of execution. Execution of an ERROR STOP statement initiates error termination of execution.
A process exit code has not always been a thing, and thus the Fortran standard cannot mandate anything about it. I will note that I have had fairly good luck with stop n passing n as the exit code on all platforms and compilers that I care about. I will note that detecting it on Windows is occasionally a bit finicky, I suspect more due to the idiosyncrasies of the cmd and/or batch shells than problems in the Fortran compilers or run-time systems.