Print

Print




---------- Forwarded message ----------
From: Walt Brainerd <[log in to unmask]>
Date: Mon, Oct 27, 2008 at 4:00 PM
Subject: Re: Passing function as argument in a function inside a module
To: Fortran 90 List <[log in to unmask]>
Cc: [log in to unmask]


On Mon, Oct 27, 2008 at 3:47 PM, <[log in to unmask]> wrote:
 
-------------- Original message from "Tuan, Hoang-Trong" <[log in to unmask]>: --------------


> Any one can help me,
> I define a module to contain a list of functions. These function has one
> arguments f_x which should be a function
>
> MODULE MY_UTILITIES
> IMPLICIT NONE
>
> CONTAINS
> REAL FUNCTION FooFunc1(f_x, a, b)
> ...
> FooFunc1 = f_x(a-b)
> END FUNCTION
>
> REAL FUNCTION FooFunc2 (f_x, a, b)
> ...
> FooFunc2 = FooFunc1 (f_x, a, b) ! error at this point
>
Without seeing all of the declarations, it's hard to say for sure.  But, I
believe you will need an
           EXTERNAL  f_x
 
Even better style might be to specify an interface block for f_x,
allowing the compiler to check that it is called correctly.

statement.  That's consistent with the error message and there is nothing
obvious in FooFunc2 that indicates that the first argument is a function.

As a matter of style, I think it would be a good idea to also put an
EXTERNAL in FooFunc1.  True, the reference to f_x(a,b) marks
it as an external (because it isn't an array), but I think it's better to
explicitly declare all of the interesting attributes.

Dick Hendrickson
> END FUNCTION
> END MODULES
>
> PROGRAM MY_PROGRAM
> USE MY_UTILITIES
> EXTERNAL G_X
> REAL :: a, b
> INTEGER :: errCode
>
> ...
> errCode = FooFunc1(G_X, a,b)
> END PROGRAM MY_PROGRAM
>
> REAL FUNCTION G_X (...)
> END FUNCTION
>
> Ignoring other details of the functions. Eventhough I don't call the
> FooFunc2 function inside main program, when I compile the program, an error
> is popped up:
> error 327 - In the INTERFACE to FooFunc1, the first dummy argument
> (F_X) was of type REAL(KIND=1) FUNCTION, whereas the actual argument is of
> type REAL(KIND=1)
>
> NOTE: I use SilverFrost Plato IDE (Fortran 95 compiler).
>
> Tuan.
> George Mason Univ.



--
Walt Brainerd
[log in to unmask]