Many hard-to-find errors in our FORTRAN models come from out-of-range array references. Here is I usually find them:

Recompile your program with debugging options. This is the line in my makefile that defines the compiler options:

FOPTFLAGS = -g -qarch=auto -qtune=auto -C -qinitauto=FF -qextchk -qsigtrap -qspillsize=1024 -qzerosize

Explanation of the flags:

-gGenerates debugging information so the executable machine code can be traced to the corresponding source code line number.
-qarch=autoDetects the architecture of the compiling machine
-qtune=autoDetects processor type of the compiling machine
-CChecks each reference to an array element, array section, or character substring for correctness.
-qextchkDoes type-checking for subroutine and function calls
-qinitauto=FFInitializes word or byte values to hexadecimal FF, which makes unitialized REALS into NaNQ's - helps to find unitialized variables
-qsigtrapCompiling with this option and -g flag allows the program to generate a trace when it encounters a problem. This will let you find the line in your source code which the program was executing when it had the problem.
-qspillsize=1024Only needed on the p690 to get it to compile in debug mode
-qzerosizeAllows zero-size character strings

When you run your program which has been compiled in debug mode, it will run much slower than usual, because it is not optimized and because it is checking all array references. When it encounters an out-of-range array reference, it will stop with a message something like this:

  Signal received: SIGTRAP - Trace trap
    Fortran language trap: subscript out of bounds

  Traceback:
    Offset 0x000022cc in procedure beam_with_reg_densities, near line 2405 in file Xmicrolib.f
    Offset 0x00000a08 in procedure pp1, near line 3126 in file Xmicro.f
    Offset 0x000103b8 in procedure microfem, near line 2545 in file Xmicro.f
    --- End of call chain ---

The first line after "Traceback" shows the line in the source code where it encountered the out-of-range array reference. The next lines show the call path, i.e. the subroutines that called the procedure with the out of bounds problem.


This page was last modified on Tuesday, 17-Aug-2010 23:39:12 ADT
Comments to geodynam at dal dot ca