Array Basics in FORTRAN 95

Subscripted Variables

In algebra and in FORTRAN 95

Xi , Yj, Zk X (i), Y (j), Z (k)

REAL , DIMENSION(10) :: X, Y ,Z, W

Operations :

1. Summation

x_ sum = S Xi x_ sum = SUM (X)

2. Product

y_ prd = ? Yj y_ prd =PRODUCT (Y)
Arrays * Operations

Using FORTRAN 95 library functions

1. Maximum value x_ max=MAXVAL (X)

2. Minimum value y_ min=MINVAL (Y)

3. Assigning values Z = -2.5 ! For all!

4. Changing a value X(3) = 4.8 ! Just one!

5. Changing values Y (1:5:2) = 1.52 Which?

6. Applying DO loops (See: s10_adn.F)
Array Features in FORTRAN 95

Library function: MAXVAL

z_max = MAXVAL(Z, MASK=Z>0)

Library function: MATMUL

d_mult = MATMUL(X,Y)

Adding matrices : W = X + Z

Note: See Appendix in the text book!

Are you ready for a bonus point quiz?
Two -dimensional Arrays

REAL , DIMENSION(6,6) :: AA, BB, CC

INTEGER :: j, k, n =6

DO j = 1, n

DO k = 1, n

AA(j,k) = j**k + k/j

BB(j,k) = (k+j)**2 – k*j

END DO

END DO

Sketch the flow chart , please!
Flow Chart for Nested Do Loops

Let Us See The Solution !

How Much Time Was Used?

Getting Some Fresh Air

Prev Next