Debugging:Common Problems

Two classes of programming errors

Compile time errors
syntax errors, undeclared variables, declaring variables twice (potentially more of a problem with F90 modules)

Run time errors
Segementation Fault / Bus Error - the program trys to access memory that it does not have access to.
Problems with formatted I/O

Common bugs and pitfalls

Oversteping array bounds
symptoms: Other variables have wildly incorrect values, segementation fault
solution: dbx is useful here to print out loop variables upon crashing

Variables not initialized (particularly to zero)
DO NOT assume variables are automatically set to zero. This was a fairly safe assumption in older compilers, but not anymore.

Line length exceeding 72 characters (F77)
symptoms: usually results in a compile time error. May also result in mismatched subroutine parameters or incorrect arithmetic results .

Mismatched parameters between a subroutine call and its declaration
symptoms:parameters at end of list not set correctly
solution:use ftnck, use F90 modules

Variable declared incorrectly, or variable name mistyped
symptoms: some variable not getting set right
solution: use implicit none at the beginning of the program or subroutine. Then the compiler will return an error if a variable is not explicitly typed.

Mixing single and double precision
symptoms: real variables having extremely large or small values.
solution: may result from using 1.0 instead of 1.0d0, parameter mismatch in a subroutine.

Return to main debugging page