Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortran 90/95 help

Status
Not open for further replies.

Lukejambo

Programmer
Feb 27, 2015
5
GB
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?
 
You lost me.

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.

 
Sorry about that,

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?
 
I think I understand a bit better what you mean; but, I still don't quite get it.

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
 
Thanks for your help, yes I do want to evaluate all the values before they change.

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?
 
something like:

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]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top