On Fri, 3 Apr 1998, Dirk Thorsten Vogel wrote:
> I want to pass only one part of a 2d-array to a subroutine.
> How can I handle this?
>
> program ...
> .
> .
> integer :: dim1, dim2, a2, a2, b1, b2, c1, c2
> real :: array(0:Dim1,0:Dim2)
>
> c1=a2-a1
> c2=b2-b1
>
> call sub1 (array (a1:a2, b1:b2), c1, c2)
> .
> end program ...
>
> subroutine sub1 (array, c1, c2)
> real :: array(0:c1, 0:c2)
> .
> end subroutine sub1
>
This should do the trick:
program ...
.
USE SUBMOD
.
integer, PARAMETER :: dim1, dim2
integer :: a2, a2, b1, b2
real :: array(0:Dim1,0:Dim2)
call sub1( array(a1:a2, b1:b2) )
.
end program ...
MODULE SUBMOD
CONTAINS
subroutine sub1 (array)
real :: array(0:, 0:) ! no need for anything else
Integer :: Up1, Up2
Up1 = UBOUND( array, DIM=1 )
Up2 = UBOUND( array, DIM=2 )
! You can also inquire the lower bounds with LBOUND
! then you only need real :: array(:,:)
...
end subroutine sub1
END MODULE SUBMOD
The MODULE version will also make sure that the compiler will
check the interface and alert to errors in CALL sub1.
Cheers,
WWS
-----------------------------------------------------------------------
| Werner W Schulz |
| Dept of Chemistry email: [log in to unmask] |
| University of Cambridge Phone: (+44) (0)1223 336 502 |
| Lensfield Road Secretary: 1223 336 338 |
| Cambridge CB2 1EW Fax: 1223 336 536 |
| United Kingdom WWW: |
-----------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|