[ACCEPTED]-Private function in Fortran-fortran
This will only work with a Fortran 90 module. In 11 your module declaration, you can specify 10 the access limits for a list of variables 9 and routines using the "public" and "private" keywords. I 8 usually find it helpful to use the private 7 keyword by itself initially, which specifies 6 that everything within the module is private 5 unless explicitly marked public.
In the code 4 sample below, subroutine_1() and function_1() are 3 accessible from outside the module via the 2 requisite "use" statement, but any other 1 variable/subroutine/function will be private.
module so_example
implicit none
private
public :: subroutine_1
public :: function_1
contains
! Implementation of subroutines and functions goes here
end module so_example
If you use modules, here is the syntax:
PUBLIC :: subname-1, funname-2, ...
PRIVATE :: subname-1, funname-2, ...
All 6 entities listed in PRIVATE will not be accessible 5 from outside of the module and all entities 4 listed in PUBLIC can be accessed from outside 3 of the module. All the others entities, by 2 default, can be accessed from outside of 1 the module.
MODULE Field
IMPLICIT NONE
Integer :: Dimen
PUBLIC :: Gravity
PRIVATE :: Electric, Magnetic
CONTAINS
INTEGER FUNCTION Gravity()
..........
END FUNCTION Gravity
REAL FUNCTION Electric()
..........
END FUNCTION
REAL FUNCTION Magnetic()
..........
END FUNCTION
..........
END MODULE Field
I've never written a line of FORTRAN, but 5 this thread about "Private module procedures" seems to be topical, at least I hope so. Seems 4 to contain answers, at least.
jaredor summary:
The 3 public/private attribute exists within modules 2 in Fortran 90 and later. Fortran 77 and 1 earlier--you're out of luck.
Private xxx, yyy, zzz
real function xxx (v)
...
end function xxx
integer function yyy()
...
end function yyy
subroutine zzz ( a,b,c )
...
end subroutine zzz
...
other stuff that calls them
...
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.