Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
intrinsic functions and user-defined functions
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
yorua007  
View profile  
 More options Oct 22, 8:15 am
From: yorua007 <yoru....@gmail.com>
Date: Thu, 22 Oct 2009 05:15:26 -0700 (PDT)
Local: Thurs, Oct 22 2009 8:15 am
Subject: intrinsic functions and user-defined functions
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?

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Edouard  
View profile  
 More options Oct 23, 6:57 am
From: Edouard <Edouard.Ca...@irisa.fr>
Date: Fri, 23 Oct 2009 03:57:45 -0700 (PDT)
Local: Fri, Oct 23 2009 6:57 am
Subject: Re: intrinsic functions and user-defined functions

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


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
yorua007  
View profile  
 More options Oct 23, 7:13 am
From: yorua007 <yoru....@gmail.com>
Date: Fri, 23 Oct 2009 04:13:21 -0700 (PDT)
Local: Fri, Oct 23 2009 7:13 am
Subject: Re: intrinsic functions and user-defined functions
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:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Edouard  
View profile  
 More options Oct 26, 3:30 am
From: Edouard <Edouard.Ca...@irisa.fr>
Date: Mon, 26 Oct 2009 00:30:38 -0700 (PDT)
Local: Mon, Oct 26 2009 3:30 am
Subject: Re: intrinsic functions and user-defined functions
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'.

Regards,
Édouard


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google