- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Everyone
I wonder whether it is possible to assign variable to values in different subroutines. for example,
subroutine a
b=5
a=b+c
call cvalue
end subroutine a
subroutine cvalue
c=2
end subroutine cvalue
Please help.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
module fred implicit none ! always always always use this!!!!! integer :: a, b, c ! the variables are shared by the contained subroutines contains ! module fred contains subroutines a and cvalue subroutine a b=5 a=b+c call cvalue end subroutine a subroutine cvalue integer :: b ! this b is local it is not the same as the module level b!!!!!! b=1 c=2+b end subroutine cvalue end module fred
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wouldn't it be easier to pass the variable c via the argument list? Something aong these lines:
subroutine a implicit none integer :: a, b, c ! Inferred from the value 5 b=5 a=b+c ! Hm, c has no value yet ... call cvalue( c ) end subroutine a subroutine cvalue( c ) implicit none integer, intent(out) :: c c=2 end subroutine cvalue

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page