- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
0 Replies

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page