Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transfer data directly between main and subsubsub program?

Status
Not open for further replies.

mollwollfumble

Programmer
May 11, 2021
1
AU
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
 
You could use a common block or named common block or pass it as a parameter all the way down.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top