This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
question about elemental subroutines
- From: dominiq at lps dot ens dot fr (Dominique Dhumieres)
- To: fortran at gcc dot gnu dot org
- Date: Mon, 24 Apr 2006 18:15:48 +0200
- Subject: question about elemental subroutines
How am I supposed to understand:
> 12.7.3 Elemental subroutine actual arguments
>
> ... . In the case that the actual arguments associated with INTENT (OUT)
> and INTENT (INOUT) dummy arguments are arrays, the values of the
> elements, if any, of the results are the same as would be obtained if the
> subroutine had been applied separately, in any order, to corresponding
> elements of each array actual argument.
> ...
in the following case:
module elem_assign
implicit none
type mytype
integer x
end type mytype
end module elem_assign
program test
use elem_assign
implicit none
type(mytype) :: x(6) = (/mytype(1),mytype(2),mytype(3), &
mytype(4),mytype(5), mytype(6)/), y(6)
y = x
print *, x
call nonassign (x(2:3), x(1:2))
print *, x
x = y
call nonassign (x(2), x(1))
call nonassign (x(3), x(2))
print *, x
x = y
call nonassign (x(3), x(2))
call nonassign (x(2), x(1))
print *, x
contains
elemental subroutine nonassign(x,y)
type(mytype), intent(INout) :: x
type(mytype), intent(in) :: y
! Change the sign according to the input, to verify that INOUT is working.
if (x%x > 2) then
x%x = y%x*3
else
x%x = -y%x*3
end if
end subroutine nonassign
end program test
which returns
1 2 3 4 5 6
1 -3 6 4 5 6
1 -3 -9 4 5 6
1 -3 6 4 5 6
where the result of 'nonassign' depends on the order of the calls?
TIA
Dominique