Fortran 90/95: Array Help with IF Statement

In summary, the conversation discusses using do loops and if statements in Fortran 90/95 to modify elements in a 10x10 array. It is suggested to use a logical array or the "where" construct instead of loops. The idea of modifying all memory locations at the same time is also mentioned, but it is not possible due to the sequential nature of computer programs.
  • #1
Lukejambo
13
0
Hi,

For fortran 90/95, I've written a 10x10 array of numbers.

2 do loops (n,m) from 1 to 10 indicate the subscript of the elements in this array.

I've applied a generic rule to the array elements where they become 0 if they are above a certain number.

Using an if statement to change the elements they will become 0 or stay the same according to the do loops (ie: so element 1,1 will change first and element 10,10 will change last)

Is it possible to delay or stop the do loop so the if statement does its thing deciding whether an element changes and then change each and every element at the same time?

Any help would be much appreciated.
 
Technology news on Phys.org
  • #2
You can create an array of type logical, which will be true for elements which need to be changed, and then do the modification independently.

In Fortran 90/95, you can also use the where construct instead of loops
Fortran:
real, dimension(10,10) :: a
where (a > x) a = 0
 
  • #3
By nature a computer program is sequential, so it is only modifying one memory location at a time. The only way to modify all of the memory elements at the same time would be to have 100 cores(or threads) in parallel each modifying one of the memory locations. Even then, the memory modifications will probably not all happen at the same time. Why do you want to change all of the memory locations at once?
 

1. What is an array in Fortran 90/95?

An array in Fortran 90/95 is a data structure that allows you to store multiple values of the same data type in a single variable. It is a sequential collection of elements that can be accessed and manipulated using index notation.

2. How do I declare and initialize an array in Fortran 90/95?

To declare an array in Fortran 90/95, you use the DIMENSION statement followed by the name of the array and the number of elements in each dimension. To initialize the array, you can use the DATA statement or assign values to individual elements using the index notation.

3. Can I use an IF statement with arrays in Fortran 90/95?

Yes, you can use an IF statement with arrays in Fortran 90/95. The IF statement allows you to perform conditional operations on array elements based on a logical expression.

4. How do I access and manipulate array elements in Fortran 90/95?

To access array elements in Fortran 90/95, you use the index notation, which includes the name of the array followed by the index values in parentheses. You can manipulate array elements by assigning new values, performing arithmetic operations, or using built-in array functions.

5. Can I use nested IF statements with arrays in Fortran 90/95?

Yes, you can use nested IF statements with arrays in Fortran 90/95. Nested IF statements allow you to perform multiple conditional operations on array elements, making it a powerful tool for data analysis and manipulation.

Similar threads

  • Programming and Computer Science
Replies
4
Views
608
  • Programming and Computer Science
Replies
17
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
7
Views
2K
  • Programming and Computer Science
Replies
19
Views
5K
  • Programming and Computer Science
Replies
5
Views
8K
  • Programming and Computer Science
Replies
1
Views
2K
Back
Top