Welcome to AE Resources
Converted document
DEBUGGING A COMPILER ERROR
It can be frustrating to write a code and get many compilation errors. However, this is very common, and most errors can be avoided through good programming practices. Most compilers will have a FAQ (Frequently Asked Questions) or common problems/known issues pages on the web or in their documentation. Those should be consulted.
Errors will provide some information, such as line number and the type of problem. Those should be used to help guide debugging. Learning how to debug is the most important part of programming, and various best practices (and pitfalls) will be pointed out on the appropriate pages.
HOW TO RUN A FORTRAN PROGRAM
Running Fortran programs is most easily done with a command prompt. Depending on the compiler the code may need to be saved with a specific extension. Once the compiler is installed, a command prompt (a linux terminal) is opened. At the command prompt , the run command is used. A good compiler will help the programmer debug the code if there are errors in the code. Once it is compiled it will be able to be run and the outputs will be produced in the way specified in the program. How these steps are carried out will depend on the compiler’s specific instructions.
When running interactively, in the same directory where the executable (and any inputs) resides, the code can be run by the command:
>> ./<executablefilename> 
Basic Linux commands can be used to run from different directories. How to deal with input and output files is discussed under the Input/Output section.
DEBUGGING A RUNTIME ERROR
Runtime errors typically fall under several topics. First, the code may not be doing the mathematical operations and illegal numbers (NaN - not a number) may occur from underflow or overflow operations, typically indicating an infinite number. In this case, hand-checking the computations using the code can be helpful, or printing out intermediate values of the computation to understand what is actually being computed.
The second most common error is that of exceeding array bounds. This can occur if a larger array is read in than is defined, or if a computed array is incorrectly defined. In the former case, check the defined maximum array size and increase it to be larger than needed. It is possible to program a code to adjust automatically to input array sizes in many cases. For the latter, one can invoke the compiler option to check the array bounds (Table 2↑).
For complex problems or for long codes, it may be beneficial to invoke a debugger code that runs with the compiler. This option and its usefulness varies with compiler and computer platform. For the gnu fortran compilers, the option -fsyntax-only can be used on the command line to check syntax. The gnu debugger, gdb, can be invoked to help find errors. The gdb debugger can be found at http://www.gnu.org/software/gdb/.
← Previous Page
← Previous Page