tags:

views:

1067

answers:

4

How to declare a private function in Fortran?

+1  A: 

I've never written a line of FORTRAN, but this thread about "Private module procedures" seems to be topical, at least I hope so. Seems to contain answers, at least.

unwind
Your understandable modesty does you credit, but you can be more definitive: The answer is in that thread. The public/private attribute exists within modules in Fortran 90 and later. Fortran 77 and earlier--you're out of luck.
jaredor
+1  A: 
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
...
SumoRunner
+3  A: 

This will only work with a Fortran 90 module. In your module declaration, you can specify the access limits for a list of variables and routines using the "public" and "private" keywords. I usually find it helpful to use the private keyword by itself initially, which specifies that everything within the module is private unless explicitly marked public.

In the code sample below, subroutine_1() and function_1() are accessible from outside the module via the requisite "use" statement, but any other 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
Tim Whitcomb
A: 

Ed Akin's book, Object-Oriented Programming via Fortran 90/95 explores this. The book isn't "five star" but it does its job.

(Sorry, I would have left this in my comment but I can't seem to riddle out the syntax for leaving non-ugly links in comments.)

jaredor