Notice! This document is currently in Archived status.
The content of this document may be incorrect or outdated.

Print this article Edit this article

Debugging your fortran program

Debugging your Fortran program You can minimize your debugging time by following a few specific rules:

  • Declare all variables.
  • Write well documented programs.
  • Use only standard procedures and calls.
  • Use print statements throughout the program to detect errors.
  • Use a subroutine to perform specific functions which are repeated.
  • Keep subroutines shorter than 100 lines.
  • Keep array sizes small during debugging to prevent slower response time.
  • Use simple test data before running actual data.
  • Use dbx for hard-to-find bugs.

Compilation Errors

These errors are usually syntax errors and undefined statement numbers. Please note that compilation does not check your program logic, it only checks syntax. During compilation, error messages are displayed on the terminal. The error messages also specify the line numbers where the problem occurred. A printed copy of these messages can be obtained. Normally, the file has to be recompiled after the errors have been corrected.

Using the -C option will compile code to check that subscripts are within the declared array bounds. This helps catch some causes of the dreaded segmentation fault.

Link Errors

Sometimes the computer is unable to find a library or function referenced by the main program. Error messages such as "undefined:_subr_" will be displayed. Usually this is due to a subroutine name that has been misspelled, a subroutine that was not included, or because the library was not specified by the "f77" command.

Execution Errors

Errors in compilation cause no execute permission:
If a non-fatal error occurs while you are compiling your program, the executable version of the program ('a.out') is created without execute permission. If you attempt to run this program, you will get the error message:
	a.out: Permission denied
You need to fix the errors in your source code and compile it again before attempting to execute the program.

An effective method used to troubleshoot a program for execution errors is to strategically place write statements within the source code. This makes it easier to watch a program as it executes and to focus on problem areas.

A Symbolic Debugger - dbx

A powerful method of troubleshooting execution errors is provided through dbx. dbx is a source level debugging tool which is run after errors have been encountered. It is a symbolic debugger which examines Fortran files and provides a controlled environment for program execution. For more information type:
	 man dbx

Last Modified: Dec 19, 2016 11:12 am US/Eastern
Created: May 31, 2007 1:36 pm GMT-4 by admin
JumpURL: