- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello-
I have a block of code WITHIN a routine that I execute fromseveral different places.
Rather than have a messy setup of assigned GOTO statements, is there a way to call it internally
from somewhere else in the same routine?
Example: (this doesn't work, but it illustrates what I'm talking about).
Subroutine SUB1
call sub2
return
subroutine sub2
la-di-da-di dah
return
end ! sub1
end ! sub2
Notice that here I don't give any arguments, but sometimes it might be nice to do this with a calling sequnece.
I don't want sub2 to be accessable from anywhere else
Is this where a MODULE would be used?
I have a block of code WITHIN a routine that I execute fromseveral different places.
Rather than have a messy setup of assigned GOTO statements, is there a way to call it internally
from somewhere else in the same routine?
Example: (this doesn't work, but it illustrates what I'm talking about).
Subroutine SUB1
call sub2
return
subroutine sub2
la-di-da-di dah
return
end ! sub1
end ! sub2
Notice that here I don't give any arguments, but sometimes it might be nice to do this with a calling sequnece.
I don't want sub2 to be accessable from anywhere else
Is this where a MODULE would be used?
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Any Fortran textbook of the last 20 years, including those on line, will help. Both module and internal procedures appear even on wikipedia
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is where you would use an "internal subprogram", a feature of Fortran 90. The general syntax is:
subroutine SUB1
call sub2
return
contains
subroutine sub2
...
return
end subroutine sub2
end
The key points here are the line "contains", following which are your internal subprograms. The internal subprograms can see variables in the parent. You are also required to use end subroutine (or end function) and not just end, to end an internal subprogram.
I don't think a module is right for what you want.
subroutine SUB1
call sub2
return
contains
subroutine sub2
...
return
end subroutine sub2
end
The key points here are the line "contains", following which are your internal subprograms. The internal subprograms can see variables in the parent. You are also required to use end subroutine (or end function) and not just end, to end an internal subprogram.
I don't think a module is right for what you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the example ! !
It clarifies things a LOT better.
It clarifies things a LOT better.
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