mollwollfumble
Programmer
I use gfortran with -ffixed-line-length-none
What combination of compiler switch, save statement, static statement or module do I need to transfer data directly between main progran and subsub programs? eg. Sample program below should output 55 55 0 0.
program saver
logical l
dimension a(10)
do i=1,10
a(i)=i
end do
l=.true.
call sub1()
print*,'n=',n
print*,'a(1)=',a(1)
l=.false.
call sub1()
print*,'n=',n
print*,'a(1)=',a(1)
stop
end
subroutine sub1()
call sub2()
return
end
subroutine sub2()
n=f()
return
end
function f()
logical l
dimension a(10)
f=0
do i=1,10
if(l) then
f=f+a(i)
end if
end do
a(1)=f
return
end
What combination of compiler switch, save statement, static statement or module do I need to transfer data directly between main progran and subsub programs? eg. Sample program below should output 55 55 0 0.
program saver
logical l
dimension a(10)
do i=1,10
a(i)=i
end do
l=.true.
call sub1()
print*,'n=',n
print*,'a(1)=',a(1)
l=.false.
call sub1()
print*,'n=',n
print*,'a(1)=',a(1)
stop
end
subroutine sub1()
call sub2()
return
end
subroutine sub2()
n=f()
return
end
function f()
logical l
dimension a(10)
f=0
do i=1,10
if(l) then
f=f+a(i)
end if
end do
a(1)=f
return
end