## Fortran 90/95 help

## Fortran 90/95 help

(OP)

Hi,

Is it possible to write an array (say 10x10) with 2 do loops (1,10) calculating each element of the array and then change each element all at the same time rather than changing each element individually as the do loop runs?

Is it possible to write an array (say 10x10) with 2 do loops (1,10) calculating each element of the array and then change each element all at the same time rather than changing each element individually as the do loop runs?

## RE: Fortran 90/95 help

Why don't you write what you would like to see ideally happen and then we can look at how exactly it should be to become proper Fortran.

## RE: Fortran 90/95 help

For a 10x10 array, each element is either a 1 or a 0.

Using 2 do loops (n,m) from 1,10 for the subscripts of each element in the array, I've used a select case function to find the sum of each of the element's neighbours (8 in total for each element).

Then depending on the sum of the neighbours of each element, the element will become change (from 0 to 1 and vice versa) using an if statement, however at the moment this change occurs when the do loop reaches that element (so element 100 will change last and element 1 will change first).

Is it possible to delay the if statement from occurring until the sums of all the neighbours have been found and then allowing the if statement to change all elements at once?

Or can I store the original array to a file, to then be called upon where the if statement shall be used?

## RE: Fortran 90/95 help

Do you really want to evaluate all values before you change them? if so, how about using two copies of the matrix?

Let's say you have matrix A

You go into the double-loop

evaluate entry, but instead of changing the entry in A, you assign it to the same entry in another matrix B

once outside the loops, you can assign B back to A

## RE: Fortran 90/95 help

So declare matrix a before the do loops.

During the do loops, let a=b?

Apply the evaluations to matrix b and then after the do loop change back to a?

## RE: Fortran 90/95 help

declare both matrices: A and B

matrix of interest A

[code]

B = A

do i = 1, 10

do j = 1, 10

if this and that and the surrounding elements of the A(i,j)

add up to whatever, then do something, but do it on B:

B(i,j) = some function/algorithm on A

end do

end do

A = B

[/ccode]