[Fortran] subroutines within the same module

  • Context: Fortran 
  • Thread starter Thread starter mopen
  • Start date Start date
  • Tags Tags
    Fortran module
Click For Summary
SUMMARY

In Fortran 90, subroutines within the same module can access variables without declaring them in the argument list, provided they are defined within the module's scope. The discussion specifically addresses the accessibility of variable "F" in subroutine "m" from subroutine "h" without explicit declaration. This behavior is due to the scoping rules of Fortran, which allow shared access to module-level variables among subroutines. Understanding variable scope is crucial for effective programming in Fortran.

PREREQUISITES
  • Understanding of Fortran 90 programming language
  • Familiarity with module and subroutine structures in Fortran
  • Knowledge of variable scope and lifetime in programming
  • Basic experience with function calls and argument passing
NEXT STEPS
  • Research Fortran 90 variable scope and lifetime
  • Explore best practices for module design in Fortran
  • Learn about the implications of using global variables in Fortran
  • Study examples of subroutine interactions within Fortran modules
USEFUL FOR

Fortran developers, programmers working on scientific computing, and anyone interested in understanding subroutine interactions and variable scope in Fortran 90.

mopen
Messages
2
Reaction score
0
Hi all,

I am working on a Fortran 90 program that has many subroutines within the same module. The question is "are all the variables of a called subroutine are available to the calling subroutine without declaring them in the argument list of the called surboutine"? even though they are within the same module.

for example
****************************************
Module x

Subroutine h
*
*
Call subroutine m (m1,m2,m3)
*
end subroutine h

Subroutine m (m1,m2,m3)
*
*
*
F=*******
end subroutine m

end module x
************************************

so will "F" calculated in subroutine :m" will be available to subroutine "h" without declaring it in the argument list of subroutine "m"?

thanks
 
Technology news on Phys.org
Do you know what is a scope of the variable? (Google if not)
 
Borek said:
Do you know what is a scope of the variable? (Google if not)

Be Nice to people!
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K