19. Debugging hints

It has been estimated that about 90% of the time it takes to develope commercial software is spent debugging and testing. This shows how important it is to write good code in the first place.

Still, we all discover from time to time. Here are some hints for how to track them down.

Useful compiler options

Most Fortran compilers will have a set of options you can turn on if you like. The following compiler options are specific to the BC-FORTRAN77 compiler, but most compilers will have similar options (although the letters may be different).
You can use /Option instead of -Option.

    -D Debug:      equivalent to -BVL
    -B deBugcode:  implies -H and also produces debugger calls for 
                   examination of field borders and substrings. 
    -H parcHeck:   produces code for examination of parameter lists 
                   and checks of stack overruns 
    -V Varlist:    List of variables for debugger
    -L Lineslist:  Line number list for debugger
    -U Uppercase:  Changes lower-case into upper case characters (even 
                   in character constants and formats).  Without this 
                   option xy, XY, Xy and xY are four different 
                   variables! 
    -F Free input: Source program is not in FORTRAN format.  Non-standard!
    -P Protocol:   registry of the compiled lines.
    -S Short protocol:  One line per module with the size of the stack 
                   frame and code in bytes. 
    -O One:        produces one output file with name of the first 
                   input file. 

Some common errors

Here are some common errors to watch out for:

Debugging tools

If you have a bug, you have to try to locate it. Syntax errors are easy to find. The problem is when you have run-time errors. The old-fashioned way to find errors is to add write statements in your code and try to track the values of your variables. This is a bit tedious since you have to recompile your source code every time you change the program slightly. BC-FORTRAN77 has a debugger which is a convient tool. You can step through a program line by line , you can display the values of the variables you want to monitor, and much more. When the program has been compiled with the -D option, a run time error will give an error message and wait for a command. The debugger can also be activated by a key-stroke interrupting the program's execution if the program was created with the B option. The following keys are recognized by the debugger as commands:
T
(Traceback) Look back through the subroutine call stack and find the next higher module with line number if the program was compiled with the -L option.
U
(Untrace) Cancel all trace back actions. This happens automatically when the program is restarted.
V
Display Variables of the current subroutine with their current contents if the program was compiled with the -V option. Move into the last displayed program module when T is pressed.
Z
Terminate program.
(space)
Resume program execution, unless there was a run-time error encountered.
S
Step program until next label, subprogram ELSE, ENDIF or DO.
C
Step subroutine until next CALL or RETURN

Note on Error Messages

Since the BC-FORTRAN77 compiler outputs error messages in German, here are some of the more common error messages:

 #      Description
---     -----------
200     Unrecognized statement
201     Declaration not allowed here
203     Multiply defined label
252     Illegal expression
253     Equals sign expected
282     Undefined label
The format of the compiler error messages is the error number followed by the error description (in German). On the next line is the string which was being scanned when the error was encountered, followed by the line number where the error was noticed.

A special case are thr Input/Output (I/O) errors. They take the form:
IO-Error: Number
Input/output errors may be intercepted by placing the IOSTAT= parameter in the IO statement. The number has the same value as is returned in the IOSTAT variable.

	Number:

    -1   End of File
    -2   End of File in middle of record.
    1    File number already in use (OPEN)
    2    Too many files (OPEN). Max. is 32
    3    File name too long (OPEN).  Max is 32 characters.
    5    File number not opened.  Only file numbers 5 and 6 can be 
           used with being OPENed 
    6    formatted/unformatted contradiction
    7    REC parameter for file with ACCESS='SEQUENTIAL'
    8    BACKSPACE, REWIND, ENDFILE are not possible for files AUX: and PRN:
    10   Internal I/O is formatted only
    20   INTEGER overflow
    21   Data error by the listing generator input, e.g. missing 
           apostrophe for a symbol link
    22   unexpected end of data
    23   record too long
    24   UNFORMATTED SEQUENTIAL read error
    30   IO list element doesn't match format element.
           INTEGER needs I format
           REAL, DOUBLE PRECISION (COMPLEX) need one or two F, G, E or 
           D format elements 
    31   Format element L:  T or F expected (input)
    32   format element I: unexpected characters (input). Null 
           characters, signs and numerics allowed. 
    33   format element E, F or D unexpected characters (input
           null characters, signs, numerics, decimal point, E, e, D or 
           d (for the exponent) allowed. 
    34   too many ( in format
    35   too many ) in format
    36   numeric character in a disallowed place in format
    37   illegal format element
    38   decimal point error in F, E, G, or D format element
    39   4Htext or 'text' in format for READ.  In FORTRAN66 this was 
           allowed as a way to read in text but in FORTRAN77 this is 
           no longer allowed. 
    40   exponent too large for the given format.
    42   format element too long.  Must be less than the internal 
           record buffer size (80 characters). 
    43   Internal I/O, record too long.
    44   TL, record too long.  
    45   zero field length in I, L, F, E, G, D format

    1000+n MS-DOS Error n
    1002   File not found
    1003   Path not found
    1004   Too many open files
    1005   Access denied
    1008   Not enough free RAM
    1012   Invalid access code
    1015   Invalid disk drive

Have Fun.


[Next] [Previous] [Fortran Tutorial Home]