F90_RETURN
FORTRAN Programs Can Return Program Status Value


F90_RETURN is a FORTRAN90 program which demonstrates how a FORTRAN90 program can return a program status value.

C and C++ programs can return an integer value signalling the status of the program's execution. By convention, a return value of 0 indicates that the program executed successfully, while a nonzero value indicates some kind of error.

The return value of such a program can be retrieved and used to make decisions. In particular, if the execution of the program is part of a script, then the failure of the program can be detected, and the script can terminate gracefully.

For an example in the BASH shell, we might have a script that reads:

        ./prog
        if [ $? -ne 0 ]; then
          echo "Errors while running prog."
          exit
        fi
      
Here, $? is a BASH symbol that returns the most recent program status value, and the script exits if that value is not zero.

FORTRAN has always had the option to include a constant integer value as part of the STOP statement. At least some FORTRAN compilers can treat this value as a program status value that is returned to the calling environment, and hence can signal whether certain errors have occurred.

Here, we show a simple example in which the program is guaranteed to fail, and in that case will return the arbitrary but nonzero value 13.

Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Languages:

F90_RETURN is available in a FORTRAN90 version.

Source Code:

You can go up one level to the FORTRAN90 source codes.


Last revised on 25 August 2013.