Welcome to AE Resources
Converted document

3D Arrays

3D arrays are exaclty what they sound like, 3 dimensional sets of data. They can be throught of as several 2D arrays stacked on top of each other like sheets of paper. When declairing 3D arrays, again you must declair the type, dimension and names.

Indexing

Indexing locations in 3D Arrays is again similar to 1D and 2D arrays. To call the value of a specific spot in an array [array A for this example] and assign it to another variable [B] type...
B= A(row#,col#,layer#)
all of these numbers follow the same requirement of having to fall within the user defined indexes created when defining the array. Indexes can be used as a long way to assign the values of an array by...
PROGRAM array_ind_ex
   IMPLICIT NONE
   INTEGER, PARAMETER :: l=1, u=3, d=3
   INTEGER, DIMENSION(l:u,l:u,l:d) :: A
   A(l:u,l:u,1)=1
   A(l:u,l:u,2)=2
   A(l:u,l:u,3)=3
   A(3,2,3)= 55
END PROGRAM array_ind_ex
This would create a 3D array with values of 1, 2, and 3 in the first, second and third layers respectively with an exception at the third row second column and third layer having the value 55.

Reading into 3D Arrays

You can also read values into 3D arrays using DO loops, Implied DOs and the READ function. An example of a DO loop reading the numbers 1-125 into an array is below.
PROGRAM t3DArray
   IMPLICIT NONE
   INTEGER, PARAMETER :: l=1, u=5, d=5
   INTEGER, DIMENSION(l:u,l:u,l:d) :: A
   INTEGER :: val=1, i, j, k, x, y, z
   DO k=l,d,1
      DO j=l,u,1
         DO i=l,u,1
            A(i,j,k)=val
            val= val+1
         END DO
      END DO
   END DO
   READ(*,*) x, y, z !row, column, layer
   WRITE(*,*) A(x,y,z)
END PROGRAM t3DArray
An Implied DO may look like
PROGRAM Implied_DO_3D
   IMPLICIT NONE
   INTEGER :: i,j,k
   INTEGER, PARAMETER :: l=1, u=5
   INTEGER, DIMENSION(l:u,l:u,l:u) :: A
   READ(*,*) ((A(i,j,k), i=l,u),j=l,u),k=l,u)
END PROGRAM
The above program would require entering 125 numbers into the command prompt, as such it would not be very efficient.
Next Page →
Next Page →
← Previous Page
← Previous Page