Nested dummy procedures
- From: "Stanislaus" <FedorovStanislav@xxxxxxx>
- Date: 29 Jan 2006 10:03:37 -0800
Hello,
Does any body know how make code below more smart? Do not look whta
functions do -- it's example.
Code:
module Parameters
implicit none
integer, parameter :: K = 10, L = 10
end module Parameters
Code:
program DummyProcedures
use Parameters
implicit none
real(8) X(L)
X = Newton( MyFunc, X )
contains
function Newton( Func, Xi ) result(X)
real(8) :: X(L)
interface
function Func( V )
use Parameters
real(8), intent(in) :: V(L)
real(8) Func(K)
end
end interface
real(8), intent(in) :: Xi(L)
real(8) M(K, L)
M = DiffVectorByVector( Func, Xi )
X = M(1, :)
end function Newton
function DiffVectorByVector( Func, V ) result(M)
interface
function Func( V )
use Parameters
real(8), intent(in) :: V(L)
real(8) Func(K)
end
end interface
real(8), intent(in) :: V(L)
real(8) :: M(K, L)
M(1:K, 1) = Func( V )
end function DiffVectorByVector
function MyFunc( V )
real(8), intent(in) :: V(L)
real(8) MyFunc(K)
MyFunc = V(1:Min( K, L ))
end function MyFunc
end program DummyProcedures
I mean, when dummy function returns scalar all looking good.
Code:
program DummyScalarProcedure
implicit none
integer, parameter :: K = 10, L = 10
real(8) X(L)
X = Newton( MyFunc, X )
contains
function Newton( Func, Xi ) result(X)
real(8) :: X(L)
real(8) Func
real(8), intent(in) :: Xi(L)
real(8) M(K, L)
M = DiffVectorByVector( Func, Xi )
X = M(1, :)
end function Newton
function DiffVectorByVector( Func, V ) result(M)
real(8) Func
real(8), intent(in) :: V(L)
real(8) :: M(K, L)
M(K, 1) = Func( V )
end function DiffVectorByVector
function MyFunc( V )
real(8), intent(in) :: V(L)
real(8) MyFunc
MyFunc = V(Min( K, L ))
end function MyFunc
end program DummyScalarProcedure
It seems that when I declare dummy function as real(8) Func(K) compiler
thinks that it can be only array, but not a function which returns
array of length K! But real(8) Func -- can be function wich returns
scalar. So I had to use interfaces => module or triple declaration of K
and L. May be there is a way of writing more smart code in this case.
I'll be glad any help.
Stanislaus
.
- Follow-Ups:
- Re: Nested dummy procedures
- From: Jugoslav Dujic
- Re: Nested dummy procedures
- Prev by Date: Re: How to pass a string to/from a function in 77
- Next by Date: warning #266: function declared implicitly
- Previous by thread: How to pass a string to/from a function in 77
- Next by thread: Re: Nested dummy procedures
- Index(es):