Private function in Fortran

前端 未结 4 1400
感情败类
感情败类 2021-02-07 11:59

How do I declare a private function in Fortran?

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-07 12:35

    If you use modules, here is the syntax:

    PUBLIC  :: subname-1, funname-2, ...
    
    PRIVATE :: subname-1, funname-2, ...
    

    All entities listed in PRIVATE will not be accessible from outside of the module and all entities listed in PUBLIC can be accessed from outside of the module. All the others entities, by default, can be accessed from outside of 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
    

提交回复
热议问题