Re: why doesn't this compile ?
- From: beliavsky@xxxxxxx
- Date: 27 Apr 2005 14:29:28 -0700
Ken Fairfield wrote:
<snip>
> I looks to me like your attempt to define a generic function
interface
> within the main program is running afoul of the contained
proccedures.
>
> This would have worked pretty transparently if the interface and
> the contained procedures were in a separate module, but the attempt
> to put them altogether in a single procedure isn't working so well...
The following code demonstrates Ken Fairfield's suggestion of putting
the functions in a separate module.
module f_mod
implicit none
public :: f
private :: f_1,f_2
interface f
module procedure f_1,f_2
end interface f
contains
! The function that takes a rank 2
! array as its argument.
function f_2(x) result (y)
integer, intent(in), dimension(:,:) :: x
integer, dimension(size(x,2)) :: y
y = sum(x, dim=1)
end function f_2
! The function that takes a rank 1
! array as its argument.
function f_1(x) result (y)
integer, intent(in), dimension(:) :: x
integer :: y
y = sum(x)
end function f_1
end module f_mod
!
program test_array_arguments
use f_mod, only: f
implicit none
integer, dimension(2,3) :: x
! Create a 3x2 array
x(:,1) = (/ 1, 1 /)
x(:,2) = (/ 2, 2 /)
x(:,3) = (/ 3, 3 /)
! Call f on an array argument
print *, f(x)
! Call f on a vector argument
print *, f(x(:,1))
end program test_array_arguments
.
- Follow-Ups:
- Re: why doesn't this compile ?
- From: Bart Vandewoestyne
- Re: why doesn't this compile ?
- References:
- why doesn't this compile ?
- From: Bart Vandewoestyne
- Re: why doesn't this compile ?
- From: Ken Fairfield
- why doesn't this compile ?
- Prev by Date: Re: why doesn't this compile ?
- Next by Date: Re: why doesn't this compile ?
- Previous by thread: Re: why doesn't this compile ?
- Next by thread: Re: why doesn't this compile ?
- Index(es):
Relevant Pages
|