Think about using Mod(i+M,M) for your second index.
Gene Wheeler
Herff Professor of Structural Mechanics
Civil Engineering Department
The University of Memphis
[log in to unmask]
----- Original Message -----
From: Tim Prince <[log in to unmask]>
To: <[log in to unmask]>
Sent: Tuesday, January 30, 2001 8:02 AM
Subject: Re: "Averaging" an array in F9x
----- Original Message -----
From: "José Luis Gómez Dans"
<[log in to unmask]>
To: <[log in to unmask]>
Sent: Tuesday, January 30, 2001 5:17 AM
Subject: "Averaging" an array in F9x
Hi,
This should be an easy question. I am trying to average out
an
N-dimensional array, A. Let us assume for simplicity that A
is a 1D
array, A(:). I want to find x=sum(n)/(2*M+1), where n
"slides" through
the
array. So for element i, n=i-M:i+M.
At present, I am doing all this using F77 constructs
with
do-loops and the such. This is not optimal (and very messy
to
debug!). As an added feature, you need to think what happens
at the
"edges" of the array. In principle, I want to "wrap round".
That is
(and going back to the same symbols exposed on the previous
paragraph), if the array has K elements, and starts at 1,
if (i<M+1) then
[complete the average with the last elements of the
array]
else if (i>M+1) then
[complete the averaging with the first elements]
else then
[normal behaviour]
endif
Thanks for your time,
José
Does CSHIFT do what you are looking for? It's probably not
implemented
efficiently, but it may express your ideas more clearly.
|