STOP(7) - [STATEMENT] initiates termination of execution
stop [ stop-code ]
error stop [ stop-code ]
o STOP-CODE is a constant scalar _character_or integer expression, of default kind.
A STOP statement will cause the program to terminate normally.
It may provide additional information in the form of output or a system status code, depending on the system.
Any messages generated appear on the ERROR_UNIT file, as identified in the intrinsic module ISO_FORTRAN_ENV. This unit is often referred to as "stderr".
It is recommended that systems write the value of the stop code whether numeric or a string.
Note that although STOP causes a "normal" termination, system status codes or "exit codes" are often used for error processing in many scripting languages. This code may be detectable by EXECUTE_SYSTEM_COMMAND(3f).
Execution of an ERROR STOP statement initiates error termination of an execution, which on several systems includes the output from a traceback.
So when an image is terminated by a STOP or ERROR STOP statement, its stop code, if any, is made available in a processor-dependent manner.
If any exception is signaling on a stopped image, the processor issues a warning indicating which exceptions are signaling;
When normal termination occurs on more than one image, it is expected that a processor-dependent summary of any stop codes and signaling exceptions will be made available.
If an integer STOP-CODE is used as the process exit status, the processor might be able to interpret only values within a limited range, OR only a limited portion of the integer value (for example, only the least-significant 8 bits).
If the STOP-CODE is of type character or does not appear, OR if an END PROGRAM statement is executed, it is recommended that the value zero be supplied as the process exit status, if the processor supports that concept.
Sample:
program demo_stop ! select which STOP call to make from command line use, intrinsic :: iso_fortran_env, only : stderr=>ERROR_UNIT implicit none integer :: i, istat, argument_length, stopcode character(len=:),allocatable :: which, message ! allocate string array big enough to hold command line call get_command_argument(number=1,length=argument_length) ! argument strings and related information if(allocated(which))deallocate(which) allocate(character(len=argument_length) :: which) call get_command_argument(1, which,status=istat) if(istat.ne.0)which= select case(which) ! normal terminations: ! A STOP with no non-zero numeric parameter is a normal ! termination and generally returns a zero status value if the ! system supports return statuses case(basic); stop ! usually displays nothing case(zero); stop 0 ! sometimes displays "STOP 0" or "0" case(text); stop That is all, folks! ! ! All other stops are generally used to indicate an error or ! special exit type case(nonzero); stop 10 case(variable); stopcode=11; stop stopcode case(expression); stopcode=11; stop 110/stopcode case(string); message=oops; stop ERROR:[//message//] ! Error terminations: ! ERROR STOP is always an error stop, even without a stop-code ! ERROR STOP often displays a traceback but that is not required case(error) error stop case(errornum) stopcode=10 error stop stopcode+3 case(errorstring) message=That is all, folks! error stop ERROR://message case default write(*,(a))enter a stop type:, & & {basic, text, zero, nonzero, variable, expression}, & & {error, errornum, errorstring} write(*,*)try again ... end select end program demo_stop
FORTRAN 77, ERROR STOP introduced in Fortran f2018
Fortran statement descriptions (license: MIT) @urbanjost
Nemo Release 3.1 | stop (7fortran) | November 02, 2024 |