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

Global variables across project workspace

jayaraj_ind001yahoo_
516 Views
Hi,

I have 4 fortran projects and right now theyall are statically linked.
A function in one of the fortran project is called by a C++ COM,out ofwhich i want one of the function argument (string) to be made available for all theremaining 3 fortran projects. I dont want to pass it as a function argument to all the functions and subroutines across all the projects. Instead I want to declare it as a global variable that can be consumed across all thethree projects. I dont have any clue about usingglobal variables in Fortran.

Please explain with a small arithmetic example (calculator), wherein one project does addition, second one does multiplication and third one does division. Fouth project calls the other three projects. The variables for arithmetic calculation should be decalred as global in fourth project and i want to consume those variables in the other three projects.

Please help me with your valuable suggestion and more valuable time.

Regards,
Jayaraj
0 Kudos
2 Replies
ZlamalJakub
New Contributor III
516 Views
You can use FileMapping to share memory between processes in windows.

Look at example http://support.microsoft.com/kb/188535

It is written in VisualFoxPro but it is easily rewritable to fortran because all API functions interfaces are already defined. Look at help to used functions.

Jakub
0 Kudos
jimdempseyatthecove
Honored Contributor III
516 Views

Create a common module file used by all programs

! yourGlobalData.f90
module yourGlobalData
real :: sharedReal
end module yourGlobalData

------
! yourProgram.f90
program yourProgram
use yourGlobalData
sharedReal = 1234.5678
call fileInOtherProject
end program yourProgram

------
! fileInOtherProject.f90
subroutine fileInOtherProject
use yourGlobalData
write(*,*) sharedReal
end subroutine fileInOtherProject

Jim Dempsey


0 Kudos
Reply