TheIsingGuy
08-11-2009, 05:46 AM
Hi, I have written a piece of code with some subroutine and a module, and I am having problem passing some variables between the main program and the subroutines that I have. I have included below part of my program to which this is concerned.
!-------------------------------------------------------------------
Program MonteCarlo
use vars
..
..
Call Distribute_Velocity
write(10,*)TCP !Failed to output from subroutine
..
End Program
Subroutine Distribute_Velocity
use vars
..
..
..
A loop to modify a real variable TCP
write(20,*)TCP This gives a value out.
..
..
End Subroutine Distribute_Velocity
!-------------------------------------------------------------------------
and the Module call vars, which is included by the subroutine and the main program:
Module vars
..
Real :: TCP
..
..
End Module
!-----------------------------------------------------------------------
As you can see, TCP is global, after calling the subroutine from the main program, its value should be allocated, but apparently there is no output, it doesn't even give me anything, just an empty file.
Sorry if I'm being silly at all, but do I HAVE to put the subroutine inside the main program with a CONTAINS statement for it work?
Thanks
Ising
!-------------------------------------------------------------------
Program MonteCarlo
use vars
..
..
Call Distribute_Velocity
write(10,*)TCP !Failed to output from subroutine
..
End Program
Subroutine Distribute_Velocity
use vars
..
..
..
A loop to modify a real variable TCP
write(20,*)TCP This gives a value out.
..
..
End Subroutine Distribute_Velocity
!-------------------------------------------------------------------------
and the Module call vars, which is included by the subroutine and the main program:
Module vars
..
Real :: TCP
..
..
End Module
!-----------------------------------------------------------------------
As you can see, TCP is global, after calling the subroutine from the main program, its value should be allocated, but apparently there is no output, it doesn't even give me anything, just an empty file.
Sorry if I'm being silly at all, but do I HAVE to put the subroutine inside the main program with a CONTAINS statement for it work?
Thanks
Ising