David Leal wrote
> Hi,
>
> I give you also another example: It is not possible tu put the
> interface block with an use. You have to use in this case an include
> statement. The following example gives an error.
>
> !=================================
>
> module fun_name_mod
>
> implicit none
>
> contains
>
> function fun_name(x) result(f)
> real,intent(in) :: x
> real :: f
>
> f=x*x
> return
> end function fun_name
>
> end module fun_name_mod
>
> module fun_interface_mod
>
> interface
> function fun_name(x) result(f)
> real,intent(in) :: x
> real :: f
> end function fun_name
> end interface
>
> end module fun_interface_mod
>
> !=========================================
>
> module sub_name_mod
>
> implicit none
>
> contains
>
> subroutine sub_name(fun_name,x)
>
> use fun_interface_mod
>
> real,intent(in) :: x
>
> interface
> function fun_name(x) result(f)
> real,intent(in) :: x
> real :: f
> end function fun_name
> end interface
>
>
> print*, fun_name(x)
> return
> end subroutine sub_name
>
> end module sub_name_mod
>
> !===================================
>
> program Sinter_prog
>
> use sub_name_mod
> use fun_name_mod
>
> implicit none
>
> call sub_name(fun_name,2.0)
>
> stop 'End of Sinter_prog'
>
> end program Sinter_prog
I think the code can be simplified (corrected?). I have
(a) eliminated fun_interface_mod,
(b) changed the name of fun_name in sub_name into fun,
this to emphasize that fun is a dummy function.
Here is the code
!=========================================
module fun_name_mod
implicit none
contains
function fun_name(x) result(f)
real,intent(in) :: x
real :: f
f=x*x
return
end function fun_name
end module fun_name_mod
!=========================================
module sub_name_mod
implicit none
contains
subroutine sub_name(fun,x)
interface
function fun(x) result(f)
real,intent(in) :: x
real :: f
end function fun
end interface
real,intent(in) :: x
print*, fun(x)
return
end subroutine sub_name
end module sub_name_mod
!===================================
program Sinter_prog
use sub_name_mod
use fun_name_mod
implicit none
call sub_name(fun_name,2.0)
stop 'End of Sinter_prog'
end program Sinter_prog
!===================================
Cheers, hasta luego, Vittorio
-------------------------------------------------
Dr. Vittorio G. Caffa Tel.: (089) 6088-2054
IABG, Abt. AF 11 Fax: (089) 6088-3990
Einsteinstr. 20 E-Mail: [log in to unmask]
D-85521 Ottobrunn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|