Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28470 Discussions

How to detect undefined variables in fortran?

Hadi_H_
Beginner
1,821 Views

Hi everybody. I am trying to debug a code containing 33000 lines which has been developed in earlier fortran compilers. Running this code in Visual Studio 2010 reveals a series of problems/errors. For instance, the values of certain variables change when I put a write statement in the code. As soon as I remove (comment) the line the value of the variables changes back. Can anyone help me and tell me what the source of problem would be.

I think there are un-initialized (or undefined) variables in the code which results to this behavior. If this is so, can anyone tell me what the best way is to detect them or force the compiler to give error compilation in these cases.

I appreciate the the helps.

Thanks

0 Kudos
5 Replies
bmchenry
New Contributor II
1,821 Views
Use IMPLICIT NONE in ALL routines. it will start with a mess of errors, but will be well worth the effort to clean them up same goes for common blocks/modules/etc. I expect it has common blocks? since you say 'earlier fortran compilers' which one would that be?
0 Kudos
Anthony_Richards
New Contributor I
1,821 Views
..and also remember that local variables are not automatically SAVEd between calls by the INTEL compiler, so if the code depends on values being saved between calls to a routine, you have to put SAVE at the start of the routine. The Compaq/Digital Fortran compiler automatically SAVEd variables. Module variables retain their values as a matter of course. Remember also that Initialisation of memory locations can differ between DEBUG and RELEASE runs of the same code (as they do with Visual Studio and Intel compiler), so you can get different results for that reason also, if uninitialised variables exist.
0 Kudos
Robert_van_Amerongen
New Contributor III
1,821 Views
Hadi, did you consider the use of the compiler option /check:uninit ? That will cause an error message during runtime if a variable is undefined Robert
0 Kudos
TimP
Honored Contributor III
1,821 Views
I was impressed by Dave Barker's presentation: http://www.nas.nasa.gov/hecc/assets/pdf/training/UnInit_Fix_your_code_2012_10_31.pdf Unfortunately, it's based on linux (does Windows need to be more difficult?) The general idea of causing signaling NaN to trap seems good.
0 Kudos
Steven_L_Intel1
Employee
1,821 Views
If you have Intel Fortran Studio XE, Intel Parallel Studio XE or Intel Cluster Studio XE, you can use the Static Analysis feature to do a whole-program correctness check including for uninitialized variables. The compiler's run-time checking is somewhat limited. Anthony has some good advice above.
0 Kudos
Reply