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

Two Independent Modules with a Global Variable with Same Name

ScottBoyce
Novice
1,277 Views

I am not sure if this is possible, but I have two fortran modules that a subroutine I have written needs to access. The problem is the global variable in the modules have the same name. In python you can rename an imported module's global variable to overcome this type of conflict.

My current situation is:

[fortran]

USE MOD1, ONLY: VAR

USE MOD2, ONLY: VAR

[/fortran]

Is it possible to do something like:

[fortran]

USE MOD1, ONLY: VAR as VAR1

USE MOD2, ONLY: VAR as VAR2

[/fortran]

I can not change MOD1 and MOD2. Is the only way to work around this is to create two dummy functions to pull the separate values?

[fortran]

SUBROUTINE A()

VAR1=aMOD1VAR()

VAR2=aMOD2VAR()

END SUBROUTINE

FUNCTION aMOD1VAR()

USE MOD1, ONLY: VAR

aMOD1VAR=VAR

END FUNCTION

FUNCTION aMOD2VAR()

USE MOD2, ONLY: VAR

aMOD2VAR=VAR

END FUNCTION

[/fortran]

Thanks for any comments.

0 Kudos
1 Reply
IanH
Honored Contributor III
1,277 Views

Yes - you can put a rename clause on the USE statement to give a local name to something from a module

[fortran]USE module_name, ONLY: local_name => name_in_module[/fortran]

0 Kudos
Reply