How to detect undefined variables in fortran?

How to detect undefined variables in fortran?

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

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
bmchenry's picture

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?

..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.

Robert van Amerongen's picture

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

I was impressed by Dave Barker's presentation:
http://www.nas.nasa.gov/hecc/assets/pdf/training/UnInit_Fix_your_code_20...

Unfortunately, it's based on linux (does Windows need to be more difficult?)
The general idea of causing signaling NaN to trap seems good.

Steve Lionel (Intel)'s picture

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.

Steve

Login to leave a comment.