Help for a relatively inexperienced FORTRAN on a particular problem
Author Message
Help for a relatively inexperienced FORTRAN on a particular problem

I am writing a program in MS 5.1 and I have a particular
problem which hopefully someone can answer...

I am calling a subroutine which performs matrix operations
on an (n x n) array.  However, I need to perform the
calculation i times for an (n x n x i) array.  How can I
create a do loop (do index=1,i) and call the subroutine for
each i and pass just the (n x n) values for each i?

In other words, for an array, say A(n,n,i), I want to do the
following:

do index=1,i
call matrixoperation(A)   !  The values passed from A are
! the n x n for a given index value.

I am calling the subroutine from a library so I cannot
change the subroutine procedure to handle an (n x n x i)
array.

Any help would be appreciated.  Thanks in advance!!

David R. Barrett

Sat, 10 Oct 1998 03:00:00 GMT
Help for a relatively inexperienced FORTRAN on a particular problem

Quote:

> I am calling a subroutine which performs matrix operations
> on an (n x n) array.  However, I need to perform the
> calculation i times for an (n x n x i) array.  How can I
> create a do loop (do index=1,i) and call the subroutine for
> each i and pass just the (n x n) values for each i?

> In other words, for an array, say A(n,n,i), I want to do the
> following:

> do index=1,i
> call matrixoperation(A)   !  The values passed from A are
>                                    ! the n x n for a given index value.

> I am calling the subroutine from a library so I cannot
> change the subroutine procedure to handle an (n x n x i)
> array.

> Any help would be appreciated.  Thanks in advance!!

> David R. Barrett

============================

I believe the code between loop no. 500 below is what you want.
The rest of the code is just for testing.

c----------------------
parameter (N=10)
c
dimension A(N,N,N)
c
sum = 0.0
c
do 100 k = 1, N
do 200 j = 1, N
do 300 i = 1, N
sum = sum + 1.0
A(i,j,k) = sum
300        continue
200     continue
100  continue
c
i = N
c
do 500 indx = 1, i
c
write(*,*)'******** Loop = ',indx,' *********'
c
call matrixoperation(A(1,1,indx))
c
500  continue
c
stop
end
c
c
c
subroutine matrixoperation(A)
dimension A(10,10)
c
do 100 j = 1, 10
do 200 i = 1, 10
write(*,*)i,' x ',j,'  = ', A(i,j)
200     continue
100  continue
c
return
end
c---------------------

--

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\  Sharad M. Shrestha               Department of Civil Engineering  \

\  (217)352-8735 (H)                  at Urbana-Champaign            \
\  (217)333-6957 (O)                Illinois, U.S.A.                 \
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Sat, 10 Oct 1998 03:00:00 GMT
Help for a relatively inexperienced FORTRAN on a particular problem

Quote:
> I am calling a subroutine which performs matrix operations
> on an (n x n) array.  However, I need to perform the
> calculation i times for an (n x n x i) array.  How can I
> create a do loop (do index=1,i) and call the subroutine for
> each i and pass just the (n x n) values for each i?

the only thig you must do is passing a section of the array A. Using your
code, the only modification is:

Quote:
> do index=1,i
> call matrixoperation( A(1,1,i) )           !  The values passed from A are
>                            ! the n x n for a given index value.

In this case you are passing only a section n x n with fixed i.

NP

--
*********************************************************
* _|  _| _| _|
* _| N| _| _|
* _| _| P| _|  Dr. Nuno R. Pinh?o
* _| _| _| _|  Physicist / Gaseous Electronics Group
*                 Instituto Tecnolgico e Nuclear
*                 2685 Sacavm,                PORTUGAL
*

*       fax:    +351-1-994.15.25
*
*********************************************************

Sun, 11 Oct 1998 03:00:00 GMT
Help for a relatively inexperienced FORTRAN on a particular problem
Hi David.  The following works under MS 5.0, but it may not be legal
in general and it may not be standard, but sometimes one has to find out
what his compiler does and make it work.  I don't guarantee that it will
always work, but it always works for me on real arrays.  I haven't
tried it on any other type array.  The propper operation depends on how
arrays are stored in memmory.  I've never tried it with a huge array, only
those that will fit in less than 64K.

Of course, you could copy the relevent coefficients out of your
3d array into a 2d array and pass that for each value of index.  If you
do that you will probably be closer to being legal, portable and standard.
You could even write a subroutine to do this and call the library function,
so it wouldn't be too distracting.

C n1,n2,n3 are constants set by a parameter statement elsewhere

DIMENSION ARRAY(n1,n2,n3)

DO INDEX = 1,I
.
.
CALL SUB(ARRAY(1,1,INDEX),n1,other parameters)
.
.
END DO
END

SUBROUTINE SUB (A,N1, other parameters)
DIMENSION A(N1,*)
.
.
END

Opinions expressed herein are my own and may not represent those of my employer.

Sun, 11 Oct 1998 03:00:00 GMT
Help for a relatively inexperienced FORTRAN on a particular problem

Quote:

>I am writing a program in MS 5.1 and I have a particular
>problem which hopefully someone can answer...

>I am calling a subroutine which performs matrix operations
>on an (n x n) array.  However, I need to perform the
>calculation i times for an (n x n x i) array.  How can I
>create a do loop (do index=1,i) and call the subroutine for
>each i and pass just the (n x n) values for each i?

>In other words, for an array, say A(n,n,i), I want to do the
>following:

>do index=1,i
>call matrixoperation(A)   !  The values passed from A are
>                                    ! the n x n for a given index
value.

>I am calling the subroutine from a library so I cannot
>change the subroutine procedure to handle an (n x n x i)
>array.

>Any help would be appreciated.  Thanks in advance!!

>David R. Barrett

All you need do is this:

do index=1, i
call matrixoperation (A (1,1,index))
end do

The subroutine matrixoperation should declare its dummy argument as a
two dimensional array:   A(N,N), assuming it knows what N is

Be very careful about the order of the subscripts.  Remember, in
fortran, the last subscript varies slowest; that is whyt this works.

Dom Olivastro

Sun, 11 Oct 1998 03:00:00 GMT

 Page 1 of 1 [ 5 post ]

Relevant Pages