suggestion for new intrinsic function: CONFORM
- From: "Beliavsky" <beliavsky@xxxxxxx>
- Date: 27 Feb 2007 13:33:53 -0800
When passing assumed shape arrays to procedures, typically the first
thing I do is check that the dimension are what I expect, in
particular that certain pairs of arguments conform, for example
subroutine foo(imat,y,z)
integer, intent(in) :: imat(:,:) ! (n1,n2)
real, intent(in) :: x(:,:) ! (n1,n2)
real, intent(out) :: z(:,:) ! (n1,n2)
if (size(imat,1) /= size(x,1) .or. size(imat,2) /= size(x,2) .or.
size(x,1) /= size(z,1) .or. size(x,2) /= size(z,2)) then
stop "unexpected dimenions in foo"
end if
! some code
end subroutine foo
(There is of course no requirement in Fortran 90 or 95 that the
dimensions of array arguments passed to procedures have any
relationship to each other -- it just typically makes sense for my
codes).
It would be convenient to have a CONFORM intrinsic function such that
conform(x,y)
would be .true. if x and y had the same shape. Arrays x and y could be
of different (intrinsic) types and would have to have the same rank
(that would be checked at compile time).
Then the if statement above could be written
if (conform(imat,y) .and. conform(imat,z)) then
which is shorter and more expressive. Usually I am checking the
conformance of 1, 2, or 3D arrays, and I can write an overloaded
CONFORM myself, but I think the need to check that arrays conform is
so common that it be convenient to have it in the language.
One way to avoid having to check that arrays conform is to use arrays
of derived types:
type foo_dt
integer :: i
real :: y,z
end type foo_dt
subroutine foo(z)
type(foo_dt) :: z(:,:)
end subroutine foo
but this is not always convenient.
.
- Follow-Ups:
- Re: suggestion for new intrinsic function: CONFORM
- From: James Giles
- Re: suggestion for new intrinsic function: CONFORM
- From: Beliavsky
- Re: suggestion for new intrinsic function: CONFORM
- Prev by Date: Re: character string assumed length
- Next by Date: Re: suggestion for new intrinsic function: CONFORM
- Previous by thread: character string assumed length
- Next by thread: Re: suggestion for new intrinsic function: CONFORM
- Index(es):
Relevant Pages
|
|