REAL, DIMENSION(10) :: A, B INTEGER, DIMENSION(0:9) :: C
Here, the three arrays A, B, and C have each been dimensioned with 10 storage slots. The index of the real arrays A and B start at 1 while the index for the integer array C starts at 0.
A = (/ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 /)
or,
A = (/ (I, I = 1, 10) /)
B = A
assigns the previously determined values of the elements of the A array to the array B.
A = A + B C = 2*C
assigns the ith element of A the value of the sum of the ith elements of arrays A and B. Similarly, the ith element of C is assigned the value equal to the ith element of itself multiplied by 2.
WHERE (logical argument) sequence of array assignments ELSEWHERE sequence of array assignments END WHERE
For example, if A is assigned the values
A = (/ (I, I = 1,10) /)
then, we may consider assigning the elements of the array B as
WHERE (A > 5) B = 1. ELSEWHERE B = 0. END WHERE
This assigns to B the values 0, 0, 0, 0, 0, 1, 1, 1, 1, 1.
DOT_PRODUCT(A, B): returns the dot product of A and B MAXVAL(A): returns the maximum value in array A MAXLOC(A): returns a one-element 1D array whose value is the location of the first occurrence of the maximum value in A PRODUCT(A): returns the product of the elements of A SUM(A): returns the sum of the elements of A
REAL, DIMENSION(:), ALLOCATABLE :: A
At run time, the actual bounds for the array A may be determined by the statement
ALLOCATE ( A(N) )
where N is an integer variable that has been previously assigned. To ensure that enough memory is available to allocate space for your array, make use of the STAT option of the ALLOCATE command:
ALLOCATE ( A(N), STAT = AllocateStatus) IF (AllocateStatus /= 0) STOP "*** Not enough memory ***"
Here, AllocateStatus is an integer variable. AllocateStatus takes the value 0 if allocation is successful or some other machine dependent value of there is insufficient memory.
An array can be released from memory by using the DEALLOCATE command
DEALLOCATE (A, STAT = DeAllocateStatus)
Again, DeAllocateStatus is an integer variable whose value is 0 if the deallocation was successful.
REAL, DIMENSION(2,3) :: A REAL, DIMENSION(0:1,0:2) :: B INTEGER, DIMENSION(10,20,3) :: I
The maximum limit on the rank (the number of dimensions) of an array is 7.
A = (/ 1, 2, 3, 4, 5, 6 /)
This assigns the values of the A array in column order similar to the rules of Fortran 77.
B = A
assigns the previously determined values of the elements of the A array to the array B.
WHERE (logical argument) sequence of array assignments ELSEWHERE sequence of array assignments END WHERE
MAXVAL(A, D): returns an array of one less dimension than A containing the maximum values of A along dimension D (if D is omitted, returns the maximum value in the entire array) MAXLOC(A): returns a one-element 1D array whose value is the location of the first occurrence of the maximum value in A SUM(A, D): returns an array of one less dimension than A containing the sums of the elements of A along dimension D (if D is omitted, returns sum of the elements in the entire array) MATMUL(A, B): returns the matrix product of A and B TRANSPOSE(A): returns the transpose of the 2D array A
REAL, DIMENSION(:, :), ALLOCATABLE :: A
At run time, the actual bounds for the array A may be determined by the statements
ALLOCATE ( A(N, N), STAT = AllocateStatus) IF (AllocateStatus /= 0) STOP "*** Not enough memory ***"
Here, N and AllocateStatus are integer variables. AllocateStatus takes the value 0 if allocation is successful or some other machine dependent value of there is insufficient memory.
An array can be released from memory by using the DEALLOCATE command
DEALLOCATE (A, STAT = DeAllocateStatus)
Again, DeAllocateStatus is an integer variable whose value is 0 if the deallocation was successful.
Copyright © 1996-7 by Stanford University. All rights reserved.