If I have a variable called var which is in a common block named myCB may I use the same name to pass an argument between two other subroutines which are not using the common block myCB?
The code is like below.
Subroutine SR1(Var)
!something here using Var
end Subroutine SR1
Subroutine SR2()
....
Call SR1(B)
....
end Subroutine SR2
Subroutine SR3()
common \myCB\ Var
...
! something using the other Var shared with SR4
......
end Subroutine SR3
Subroutine SR4()
common \myCB\ Var
....
... ! something using the other Var shared with SR3
....
end Subroutine SR4
I do have problem with Var passing between SR1 and SR2, could the problem come from the other named Var in the common block ?
If you don't want to modify the legacy code base too much, I suggest you put the
commonblock in amoduleand import the variables when access is required:or better yet, I suggest you avoid
commonblocks altogether (this requires a full rewrite of the legacy code base) and confine all your subroutines inside amoduleLastly, do the variables in your
commonblock require initialization? If so, this introduces even further complications involvingdatastatements or even theblock dataconstruct.