local - Pass a common variable to a subroutine in Fortran -


i'm customizing commercial code uses common block define global variables.

what pass 1 of variable subroutine, not making include, because don't need other several variables defined common.

the way found has been define new local variable, assign value of global variable, , pass new variable subroutine, don't way of proceed..

is there solution tell fortran convert variable local when passing subroutine?

here 1 example:

main program:

integer :: real :: y(20) common /vars/ y, integer :: res, transfer_var transfer_var = call sub_test(transfer_var, res) ... 

subroutine:

subroutine sub_test(var1, var2) integer, intent(in) :: var1 integer, intent(out) :: var2 var2 = 1 + var1 return end 

this minimal working example of code does not exhibit behavior describe. a assigned in main, passed common sub_one, used directly subroutine argument.

 implicit none  integer :: a,res  common /vars/  a=41  call sub_one()  end    subroutine sub_one()  integer :: a,res  common /vars/  call sub_test(a,res)  write(*,*)res  end   subroutine sub_test(var1, var2)  integer, intent(in) :: var1  integer, intent(out) :: var2  var2 = 1 + var1  return  end 

this compiles without issue , returns result 42.

can provide example code shows issue?


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -