FORTRAN 90+: WHERE EXAMPLE
It is recommended to look at the numerical methods codes where the use of the WHERE statement is demonstrated. An additional example is included here.
PROGRAM whereq IMPLICIT NONE REAL, DIMENSION(1:3,1:3) :: a,b,c LOGICAL, DIMENSION(1:3,1:3) :: d INTEGER :: i,j,num=1 a(1,1:3)=0 a(2:3,1:3)=2 b(1,:)=(/1,2,3/) b(2,:)=(/4,5,6/) b(3,:)=(/7,8,9/) WHERE (a .EQ. 0) b=9 END WHERE WHERE (a .NE. 0) c= b/a END WHERE d=a .NE. 0 WRITE(*,"(3(3(3(2X,F4.2),/)/))") TRANSPOSE(a), & TRANSPOSE(b),& &TRANSPOSE(c) !Reason for TRANSPOSE discussed on formatting page WRITE(*,"(3(3(2X,L1)/)))") TRANSPOSE(d) END PROGRAM whereq
Which will output four 3x3 arrays:
0.00 | 0.00 | 0.00 |
2.00 | 2.00 | 2.00 |
2.00 | 2.00 | 2.00 |
9.00 | 9.00 | 9.00 |
4.00 | 5.00 | 6.00 |
7.00 | 8.00 | 9.00 |
0.00 | 0.00 | 0.50 |
2.00 | 2.50 | 3.00 |
3.50 | 4.00 | 4.50 |
F | F | F |
T | T | T |
T | T | T |