array valued functions 
Author Message
 array valued functions


Date: Sat, 28 Jun 2003 15:52:36 GMT

Quote:

>> You'll need an expicit interface and a change to the declarations
>> of the dummy arguments:--
> Yes, the explicit intgerface is needed, as mentioned in other replies
> in this thread (at least in mine - though I didn't show code to do so).
> However, changing the dummy arguments to assumed shape is not needed,
> and I wouldn't even think of doing it the way robin shows here.

I am certainly not going to illustrate an obsolete and error-prone method
of passing arguments.

Nor an I going to illustrate an inflexible (hard-wired) dummy.
This example illustrates generally how the dummy is linked.
        In any case, dummy arguments that are not assumed shape
are not supported in some of the subset compilers.

Quote:
> I generally do prefer assumed shape dummy arguments, but certainly not
> like this
>> FUNCTION VECP(A, B)
>>    IMPLICIT NONE
>>    REAL, INTENT (IN) :: A(:), B(:)
>>    REAL, DIMENSION(3) :: VECP

>>    VECP(1) = A(1)+B(1)
>>    VECP(2) = A(2)+B(2)
>>    VECP(3) = A(3)+B(3)
>>    RETURN
>> END FUNCTION VECP
> Here the dummies are declared assumed shape, but the function result
> and the body of the code are hard-wired to specific sizes.

Please do credit the originator with sufficient nous to
change this code to something general (a loop) when he gets the
basic material to work.

Quote:
>  Nothing
> good can come of this.  Make declarations agree with the actual usage.
> In this case, the actual usage is hard-wired to a size of 3.

Ugh!

The originator was
(a) having trouble with interfacing to the function
(b) experimenting with the arguments & dummies, getting it down to
    the basics, to try to get something to work, which is a good approach.
I have made minimum changes to his code to show how the interface is done.
No-one else did that (show how the interface is done)

Quote:
> If you want to use assumed shape, that's fine, but in that case,
> make the function return shape depend on that of the arguments
> and make the body loop also do so.

No doubt the originator will do that once he has the interface
working with the general case, which would be, of course, non-"hard-wired"
array sizes.
Quote:
> --
> Richard Maine



Sat, 17 Dec 2005 20:44:15 GMT  
 array valued functions

Date: Fri, 27 Jun 2003 15:06:23 GMT

Quote:






>> > > > i am trying to write a simple function that takes two arrays
>> > > > and returns me their sum vector. i want to do it using a function
>> > > > and not a subroutine. I tried the following

>> > > > FUNCTION VECP(A, B)

>> > > You need a RESULT clause in order to pass back the sum to
>> > > the invoking statement.
>> > > e,g, FUNCTION VECP (A, B) RESULT (VECP)

>> Oops, hadn't noticed that VECP is name of function.

>> > > > IMPLICIT DOUBLE PRECISION (A - Z)

>> > > > DIMENSION A(3), B(3)
>> > > > DOUBLE PRECISION, DIMENSION(3) :: VECP

>> > > > VECP(1) = A(1)+B(1)
>> > > > VECP(2) = A(2)+B(2)
>> > > > VECP(3) = A(3)+B(3)

>> > > > RETURN
>> > > > END

>> > Above is wrong..

>> > I'm surprised you didnt tell him to just use
>> > C = A + B  without the use of a function,

>> Someone had already done that, and after all,
>> he wanted a function that returned an array result.
>> RTQ. See the Subject heading.
> A nice try implying you have corrected the poster's function, but when
> you remove your erroneous result clause, we are left with poster's
> ORIGINAL function, which was and is correct..

It won't work with his calling statement!
which was the reason for the request for assistance.

The requester's function did not use assumed size dummy arguments,
which are needed for making this procedure general.



Sat, 17 Dec 2005 20:46:28 GMT  
 array valued functions
Hi All,

Thanks for all your replies, but looks like my basic fortran
knowledge is not good enough for this, i am having a tough time
understanding concepts of modules, interfaces etc using the manual
i have, Cd someone please suggest me a good book that explains these
concepts in detail.

Sai Vaddi
--
Direct access to this group with http://web2news.com
http://web2news.com/?comp.lang.fortran



Sun, 18 Dec 2005 02:08:03 GMT  
 array valued functions

Quote:

> Hi All,

> Thanks for all your replies, but looks like my basic fortran
> knowledge is not good enough for this, i am having a tough time
> understanding concepts of modules, interfaces etc using the manual
> i have, Cd someone please suggest me a good book that explains these
> concepts in detail.

> Sai Vaddi
> --
> Direct access to this group with http://web2news.com
> http://web2news.com/?comp.lang.fortran

Metcalf and Reid "Fortran 90/95 Explained". This book is the bible.

Otherwise, see "Fortran Resources" http://www.fortran.com/fortran/metcalf.htm



Sun, 18 Dec 2005 18:10:27 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Passing array valued functions as argument to function.

2. array valued functions

3. array valued functions

4. Memory leaks with array-valued functions

5. Array valued function and memory

6. rank-reduced array-valued function (like SUM)

7. Array-valued functions possible?

8. Array-valued function

9. A question regarding array-valued functions in fortran 90

10. Passing Array-valued functions TO procedures

11. array-valued function as dummy argument

12. array valued function ?

 

 
Powered by phpBB® Forum Software