[Fortran] 纯文本查看 复制代码
module matmul_int
INTERFACE OPERATOR(.mm.)
module procedure fc
END INTERFACE
contains
function fc(a,b)
real , intent( IN ) :: a(:,:) , b(:,:)
real :: fc(size(a,dim=1),size(b,dim=2))
fc = matmul(a,b)
end function fc
end module matmul_int
program main
use matmul_int
real :: x(3,2) , y(2,4)
x = 1 ; y = 2
write(*,*) x .mm. y
end
[Fortran] 纯文本查看 复制代码
Module S
Interface Operator (.U.)
Module Procedure Addy
End Interface Operator (.U.)
Contains
Function Addy(C1, C2)
Implicit None
Integer, Intent (In) :: C1(:), C2(:)
Integer :: Addy(20)
Integer :: Arry1(20), Arry2(20)
Integer I, Len
Logical :: Flg(20)
Len = Size(C1)
Arry1 = -1
Do I = 1, Len
Arry1(C1(I)) = C1(I)
End Do
Len = Size(C2)
Arry2 = -2
Do I = 1, Len
Arry2(C2(I)) = C2(I)
End Do
Addy = -3
Flg = All(Arry1.Eq.Arry2)
Print *, Flg
Addy = Merge(Arry1, Addy, Flg)
End Function Addy
End Module S
Program Main
Use S
Implicit None
Interface
Subroutine Random_arr(A)
Implicit None
Integer (Kind=4), Intent (Out), Allocatable :: A(:)
End Subroutine Random_arr
End Interface
Integer, Allocatable :: A(:)
Integer, Allocatable :: B(:)
Integer Lena, Lenb
Call Init_random_seed()
Call Random_arr(A)
Call Random_arr(B)
Lena = Size(A)
Lenb = Size(B)
Print *, 'A'
Write (*, 10) A
Print *, 'B'
Write (*, 10) B
10 Format (20I3)
End Program Main