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.I tried
to figure out this by reading the G95 source code, but the referrence
relationship in the project is some what complicated for me to get
through.Could anyone help me get out of this question or show me the
control flow in the G95 source code?
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 :
Does it mean that if the array, I want to pass into the function, has
a rank of 3, then I have to implement another function just like
mysum_3D in the interface?
function mysum_3D( array ) result(res)
real::array(:,:,:)
real:: res
......
end function
On 10月23日, 下午6时57分, Edouard <Edouard.Ca...@irisa.fr> wrote:
> 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 :
On Oct 23, 1:13 pm, yorua007 <yoru....@gmail.com> wrote:
> Does it mean that if the array, I want to pass into the function, has
> a rank of 3, then I have to implement another function just like
> mysum_3D in the interface?
> function mysum_3D( array ) result(res)
> real::array(:,:,:)
> real:: res
> ......
> end function
Yes, of course. And you must also add the new line :
module procedure mysum_3D
in the 'interface' block for the generic function, 'mysum'.