next up previous contents
Next: Modules Up: Survey of the New Previous: New Source Form

Array Processing

 

Array processing features are the most significant of the language enhancements offered by the new standard. Popular Fortran 77 extensions, such as whole array operations, masked assignment, array sections, and vector subscripting that are common in Cray Fortran and CM (Connection Machine) Fortran, are now part of the Fortran 90 standard. These types of constructs are important for parallel and vector computers.

Arithmetic and logical operations work elementally on arrays, so that, for example, C = A + B calculates the sum of two matrices, element-by-element, storing the result in C. The statement Z = ( A > 0 ) creates a logical array with elements whose entries are .true. where the elements of A are greater than 0 and .false. elsewhere. Logical expressions of this kind may be used in a masked assignment statement, performing the specified assignment only where the mask is true.

To accompany this new notational convenience, most of the intrinsic functions act elementally on arrays, so that an expression such as log(A) applies the scalar log function to each element in A (in an unspecified order).

Arrays may now be dynamically allocated at run-time using pointers or allocatable arrays.

program AllocatableMatrices
   real, allocatable :: A( :, : )
   integer n
   print *, 'Enter an integer for the array dimension: '
   read *, n
   
   ! Dynamically allocate an n x n matrix.
   allocate( A( n, n ) )
   call random_number( A )   ! Fill A with [0,1) random reals.

   ! Masked assignment.
   where ( A /= 0.0 )
      A = 1.0 / A
   elsewhere
      A = -1.0
   end where

   print *, 'A = '
   print *, A
end program AllocatableMatrices

Automatic arrays are also properly handled and are created on entry to a subprogram and destroyed upon exit. Lack of this feature in Fortran 77 was a severe limitation and often required that scratch variables be passed in the argument list. Functions may also be array-valued, as can be seen from such assignments as A = log(B).



next up previous contents
Next: Modules Up: Survey of the New Previous: New Source Form