Lahey Support
08-15-2003, 01:23 AM
Egon,
In that case you use an array section like this
allocate (a(2*n,2*n))
allocate (b(n,n))
...fill a
b = a(1:n,1:n)
call matinv(b)
...process inverted b
b = a(n+1:2*n,n+1:2*n)
call matinv(b)
...process inverted b
(matinv does not need the dimension of b, it can get it from the SIZE
function)
Tom Laub
Sandia National Laboratories
(505)844-9142 FAX (505)844-6729
-----Original Message-----
From: Szondi Egon Janos [address removed]
Sent: February 09, 2000 1:44 AM
To: [address removed]
Cc: [address removed]
Subject: Re: [LF] [LF digest] Adjustable dimensions
Dear Robin,
you have illustrated a SIDE EFFECT writing this program:
>We used this style:
>DIMENSION A(500, 500)
>CALL MATRINV (A, 75)
>
>SUBROUTINE MATRINV (ARRAY, LIMIT)
> DIMENSION ARRAY (LIMIT, LIMIT)
> DO I = 1, LIMIT
The sequence of the array elements in the memory is described
among others in the Lahey Fortran 90 Language Reference, on
pages 10-11. The merit is, that "the subscript of the leftmost
dimension changes most rapidly as one goes from first elemt to
last in array element order".
The sequence of the elements of array A declared in your main
program will be:
(1,1),(2,1)...(75,1),(76,1)...(150,1),(151,1)...(5 00,1),(1,2)...
The subroutine MATRINV gets the address of A(1,1), and treates
the SAME SEQUENCE OF MEMORY WORDS as they would be the elements
of the array specified as first argument of the subroutine:
(1,1),(2,1)...(75,1),(1,2)...(75,2),(1,3)...(50,7) ,(51,7)...
It means, that this program inverts a matrix build up of the
first columns of the array A, instead of the elements of the
top-left (square) submatrix of A.
This situation is mentioned by my words: "otherwise anything
could happen".
That's why both the size of the whole matrix and the size of
the submatrix are required as arguments of the subroutine, if
they had to be processed simultaneously.
Best regards,
E. J. Szondi
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
SZONDI, Egon Janos [address removed]
Institute of Nuclear Techniques http://www.reak.bme.hu/~szondi
Technical University of Budapest
H-1521 Budapest, Hungary Tel: ++36-1 463-1563
Muegyetem rkp. 9. Fax: ++36-1 463-1954
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
--------------------------------------------------------------------------
To unsubscribe from Fortran Forum, send a message to [address removed]
with the following command as the first and only line of the message body:
unsubscribe fortran
--------------------------------------------------------------------------
--------------------------------------------------------------------------
To unsubscribe from Fortran Forum, send a message to [address removed]
with the following command as the first and only line of the message body:
unsubscribe fortran
--------------------------------------------------------------------------
In that case you use an array section like this
allocate (a(2*n,2*n))
allocate (b(n,n))
...fill a
b = a(1:n,1:n)
call matinv(b)
...process inverted b
b = a(n+1:2*n,n+1:2*n)
call matinv(b)
...process inverted b
(matinv does not need the dimension of b, it can get it from the SIZE
function)
Tom Laub
Sandia National Laboratories
(505)844-9142 FAX (505)844-6729
-----Original Message-----
From: Szondi Egon Janos [address removed]
Sent: February 09, 2000 1:44 AM
To: [address removed]
Cc: [address removed]
Subject: Re: [LF] [LF digest] Adjustable dimensions
Dear Robin,
you have illustrated a SIDE EFFECT writing this program:
>We used this style:
>DIMENSION A(500, 500)
>CALL MATRINV (A, 75)
>
>SUBROUTINE MATRINV (ARRAY, LIMIT)
> DIMENSION ARRAY (LIMIT, LIMIT)
> DO I = 1, LIMIT
The sequence of the array elements in the memory is described
among others in the Lahey Fortran 90 Language Reference, on
pages 10-11. The merit is, that "the subscript of the leftmost
dimension changes most rapidly as one goes from first elemt to
last in array element order".
The sequence of the elements of array A declared in your main
program will be:
(1,1),(2,1)...(75,1),(76,1)...(150,1),(151,1)...(5 00,1),(1,2)...
The subroutine MATRINV gets the address of A(1,1), and treates
the SAME SEQUENCE OF MEMORY WORDS as they would be the elements
of the array specified as first argument of the subroutine:
(1,1),(2,1)...(75,1),(1,2)...(75,2),(1,3)...(50,7) ,(51,7)...
It means, that this program inverts a matrix build up of the
first columns of the array A, instead of the elements of the
top-left (square) submatrix of A.
This situation is mentioned by my words: "otherwise anything
could happen".
That's why both the size of the whole matrix and the size of
the submatrix are required as arguments of the subroutine, if
they had to be processed simultaneously.
Best regards,
E. J. Szondi
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
SZONDI, Egon Janos [address removed]
Institute of Nuclear Techniques http://www.reak.bme.hu/~szondi
Technical University of Budapest
H-1521 Budapest, Hungary Tel: ++36-1 463-1563
Muegyetem rkp. 9. Fax: ++36-1 463-1954
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
--------------------------------------------------------------------------
To unsubscribe from Fortran Forum, send a message to [address removed]
with the following command as the first and only line of the message body:
unsubscribe fortran
--------------------------------------------------------------------------
--------------------------------------------------------------------------
To unsubscribe from Fortran Forum, send a message to [address removed]
with the following command as the first and only line of the message body:
unsubscribe fortran
--------------------------------------------------------------------------