在Fortran中,interface通常定义在模块(module)中,模块是Fortran中用于封装程序模块的结构,可以将具有相关功能的函数和变量封装在一起。在interface内部,使用MODULE PROCEDURE关键字列出所有可能的具体函数。 3. 展示一个具体的Fortran interface示例,包含xxx_0d函数 以下是一个包含零维函数xxx_0d
fortran interface myFunction module procedure myFunction_int, myFunction_real end interface function myFunction_int(x) integer, intent(in) :: x integer :: myFunction_int ! Implementation end function myFunction_int function myFunction_real(x) real, intent(in) :: x real :: myFunction_real ...
module my_module implicit noneinterfacemaxvalmodule procedure maxval_int,maxval_real endinterfacemaxvalcontainsfunctionmaxval_int(a)result(m)integer,intent(in)::a(:)integer::m m=maxval(a)endfunctionmaxval_intfunctionmaxval_real(a)result(m)real,intent(in)::a(:)real::m m=maxval(a)endfunctionmax...
! 主模块 module main_module implicit none interface my_interface module procedure my_subroutine, my_function end interface my_interface contains ! 子程序 subroutine my_subroutine(a) integer, intent(in) :: a ! 实现具体功能 print *, "This is my_subroutine. Input: ", a end subroutine my_...
MODULE m INTERFACE MODULE SUBROUTINE sub(arg) INTEGER :: arg END SUBROUTINE END INTERFACE END MODULE SUBMODULE (m) n CONTAINS MODULE PROCEDURE sub ! MODULE PROCEDURE statement arg = 1 END PROCEDURE END SUBMODULE Related information Separate module procedures (Fortran 2008) Separate module subprograms...
end subroutine add_real_real end module total 3. 自定义操作符 一般用来定义派生数据类型的两两运算。 module time_util implicit none type :: time integer :: hour, minute end type time interface operator(+) module procedure add end interface contains function add(a, b) implicit none type(time...
The following example shows how aMODULE PROCEDUREstatement is used as the first statement of a separate module subprogram. MODULE m INTERFACE MODULE SUBROUTINE sub(arg) INTEGER :: arg END SUBROUTINE END INTERFACE END MODULE SUBMODULE (m) n CONTAINS MODULE PROCEDURE sub ! MODULE PROCEDURE statement...
15 public swap ! 但是,需要将泛型接口公开16 ! 泛型接口Generic interface 17 interface swap18! 对于不在本模块的过程,需要显式接口19subroutine swapReal( a, b )20real, intent(inout) :: a, b21end subroutine swapReal22 ! 23 ! 但是,对于模块里的过程,则是通过加上'module procedure'声明24module pr...
interface function add(a, b) real, intent(in) :: a, b real :: add end function add end interface end module MathOperations program InterfaceExample use MathOperations implicit none real :: x, y, result x = 5.0 y = 3.0 result = add(x, y) ...
module procedure实现对实型、浮点数、字符串的三元操作符(52:44) 10.自定义操作符 Interface 与 Module 的结合 自定义操作符通过函数实现,函数中的参数必须为intent(in)属性(58:04) 通过使用自定义操作符可简化数据处理的过程 第十讲 文件读写(上)