suggestion for new intrinsic function: CONFORM



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.

.



Relevant Pages

  • Re: CheckedListbox
    ... Dim MyInt(,) - Verschlechterung? ... Das Problem ist ich kann immer nur die letzte Dimension verändern, ... Man kann überhaupt keine Dimension eines Arrays verändern. ... Falls du auf Redim Preserve anspielst: ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Matlab is not a real array oriented language.
    ... For example the language doesnt abstract arrays correctly; to matlab ... Dimension higher than 2 are handled incorrectly; ... Fortran programmers where arrays were column-wise. ... this causes programmers the need to program defensively. ...
    (comp.soft-sys.matlab)
  • Re: Matlab is not a real array oriented language.
    ... For example the language doesnt abstract arrays correctly; to matlab ... Dimension higher than 2 are handled incorrectly; ... Fortran programmers where arrays were column-wise. ...
    (comp.soft-sys.matlab)
  • Re: Extracting 2D array from SAFEARRAY [Was "Passing a 2D array in a property"]
    ... The organization of multi-dimensional safe arrays has not been ... to loop over the second dimension first, ... Microsoft MVP, MCSD ...
    (microsoft.public.vc.atl)
  • Re: DIM vs. Dynamic
    ... Write dynamic, optimize to dimension if/when ... dynamic arrays that got me thinking. ... you're in an optimizing situation. ... 100,000 assignments were finished in the dynamic array case in only ...
    (comp.databases.pick)