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

Problems exiting subroutines

jjkay
Beginner
693 Views
Hello,

I have been using Fortran software written by a former associate of mine which was written and debugged on a Sun workstation; I am not sure which compiler, but it is likely to be rather old. I have now recompiled them in Linux using Ifort 9.0, and am experiencing some difficulties that seem to be related to system or compiler compatability.

The problem seems to be that upon exiting a subroutine, variables used in that subroutine are somehow "lost" from memory, or subsequently overwritten, and this causes problems when the variables are used again later in the main program. This was apparently not a problem on the Sun workstation, but only occurs when I attempt to compile in Linux using Ifort 9.0. (The code also compiles and runs properly in Windows using the Compaq compiler.) I have heard that in some cases, with the newer versions of Fortran, variables passed to subroutines which are not declared a certain way may be lost when a subroutine closes.

Thus my question: Is there a compiler option which will take care of this (as it was apparently not a problem in other versions of Fortran?), or a simple way of modifying the code to rectify the problem? I am not a programmer myself, merely a consumer of Fortran code, and the programs are enormous :)

Thanks for any advice,

Jeff
0 Kudos
2 Replies
tobias-burnus
Beginner
693 Views
Hi Jeff,
The problem seems to be that upon exiting a subroutine, variables used in that subroutine are somehow "lost" from memory, or subsequently overwritten, and this causes problems when the variables are used again later in the main program.
I'm not completely sure what you mean by that. If you mean that a local variable does not keep the value from the last call to that subroutine, you need to use the SAVE keyword as in
real, save :: myVariable
You could try whether the option -save works for you.

Tobias
0 Kudos
jjkay
Beginner
693 Views
Hi Tobias,

I tried compiling with the "-save" option, and it worked perfectly! Thanks so much for your help!

Jeff
0 Kudos
Reply