Advertisement
SepandMeenu

Complicated matrix indices

Jun 19th, 2019
1,177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PROGRAM Matrizen2
  2.   IMPLICIT NONE  ! allow no implicit types
  3.  
  4.   ! constant integers
  5.   INTEGER, PARAMETER :: Ni = 3, Nj = 4, Nk = 100, MAXR = 4
  6.   ! arrays of float64 value, initialized to zero
  7.   DOUBLE PRECISION :: A(Ni, Nk) = 0, B(Ni, Nj) = 0, C(Ni, Nj) = 0
  8.   ! loop counters
  9.   INTEGER :: i, j, k
  10.  
  11.   ! fill in random numbers in interval [0, 1]
  12.   CALL RANDOM_NUMBER(A)
  13.   CALL RANDOM_NUMBER(B)
  14.   ! make random integers
  15.   A = FLOOR(1 + A * MAXR)  ! rand-int [1, 4]
  16.   B = FLOOR(B * Nk)  ! rand-int [0, Nk]
  17.  
  18.   ! NOTE: array index starts from 1
  19.   DO i = 1, Ni
  20.      DO j = 1, Nj
  21.         k = INT(B(i, j))
  22.         C(i, j) = A(i, k)
  23.         PRINT '(A2,I0,A1,I0,A4,F6.3)', 'B[', i, ',', j, '] = ', B(i, j)
  24.         PRINT '(A2,I0,A1,I0,A4,F6.3)', 'A[', i, ',', k, '] = ', A(i, k)
  25.         PRINT '(A2,I0,A1,I0,A4,F6.3)', 'C[', i, ',', j, '] = ', C(i, j)
  26.         PRINT *
  27.      END DO
  28.   END DO
  29.  
  30. END PROGRAM Matrizen2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement