On Oct 22, 2:15 pm, yorua007 <
yoru....@gmail.com> wrote:
> hello everyone,
> I'm curious about what's the difference between fortran intrinsic
> functions and user defined ones.You know, there is a intrinsic
> funtion: SUM(array, dim, mask),here you don't have to tell the
> compiler the shape of the array.But ,in a user-defined function the
> shape of the array must be declared or passed in as arguments.
> ...
You can use 'interface' to create a 'generic' function. For example,
if
you define the following module :
module my_funs
interface mysum
module procedure mysum_vector
module procedure mysum_matrix
end interface
contains
function mysum_vector( array ) result( res )
real :: array(:)
real :: res
! do some job
res = 0.
end function
function mysum_matrix( array ) result( res )
real :: array(:,:)
real :: res
! do some job
res = 1.
end function
end module
then, you may use your 'mysum' function without passing
the shape or dimensions of the 'array', like this :
real :: mat(10,10)
result = mysum(mat)
Hope this help.
Édouard