- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear All,
Suppose I have a module like the following.
module test
use global, only : ndim
real(8), dimension(ndim) :: y
contains
...
end module
Is it possible to limit the scope of variables which appear in the specification part of the module? In particular, is it possible to restrict the scope of ndim so it is only used to define the dimension of y, and is not visible in the subroutines that the module contains?
Thanks, T.
Suppose I have a module like the following.
module test
use global, only : ndim
real(8), dimension(ndim) :: y
contains
...
end module
Is it possible to limit the scope of variables which appear in the specification part of the module? In particular, is it possible to restrict the scope of ndim so it is only used to define the dimension of y, and is not visible in the subroutines that the module contains?
Thanks, T.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use the PRIVATE and PUBLIC attributes as needed. For example, with the following source codes:
1. glob.f90:
1. glob.f90:
[fortran]module global integer,parameter :: ndim=10,mdim=5 end module global[/fortran]2. ugl.f90:
[fortran]module test use global, only : ndim implicit none private :: ndim real, dimension(ndim),public :: y end module test[/fortran]3. prg.f90:
[fortran]program testprg use test implicit none write(*,10)lbound(y),ubound(y),size(y) write(*,10)ndim 10 format(1x,3i6) end program testprg[/fortran]an attempt to compile prg.f90 would give you the compiler error message:
[bash]prg.f90(5) : Error: This name does not have a type, and must have an explicit type. [NDIM] write(*,10)ndim -------------^ compilation aborted for prg.f90 (code 1)[/bash]If you then remove the second WRITE statement, the program should compile and run fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The original question seems to be asking if there is a way to restrict host-association i.e. the "contained" procedure does not see entities defined in the host. I don't know if it is possible... {The well-known exception to host-association being the interface blocks i.e. use of IMPORT statement.}
Abhi
Abhi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That was the second part of the original question, and I see that did not address this part.
Metcalf, Reid & Cohen's Fortran 95/2003 Explained states in Sec. 5.6: "An internal subprogram automatically has access to all the host's entities...".
Although access to host variables cannot be hidden, one could use local variables with the same names as the host variables, but this,too, has obvious drawbacks.
Metcalf, Reid & Cohen's Fortran 95/2003 Explained states in Sec. 5.6: "An internal subprogram automatically has access to all the host's entities...".
Although access to host variables cannot be hidden, one could use local variables with the same names as the host variables, but this,too, has obvious drawbacks.

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