Tutorial by Examples

Any type can be declared as an array using either the dimension attribute or by just indicating directly the dimension(s) of the array: ! One dimensional array with 4 elements integer, dimension(4) :: foo ! Two dimensional array with 4 rows and 2 columns real, dimension(4, 2) :: bar ! Three...
Arrays can have the allocatable attribute: ! One dimensional allocatable array integer, dimension(:), allocatable :: foo ! Two dimensional allocatable array real, dimension(:,:), allocatable :: bar This declares the variable but does not allocate any space for it. ! We can specify the bounds...
A rank-1 array value can be created using an array constructor, with the syntax (/ ... /) [ ... ] The form [...] was introduced in Fortran 2003 and is generally regarded as clearer to read, especially in complex expressions. This form is used exclusively in this example. The values featuring ...
The dimension attribute on an object specifies that that object is an array. There are, in Fortran 2008, five array natures:1 explicit shape assumed shape assumed size deferred shape implied shape Take the three rank-1 arrays2 integer a, b, c dimension(5) a ! Explicit shape (default ...
Consider the array declared as real x(10) Then we have three aspects of interest: The whole array x; Array elements, like x(1); Array sections, like x(2:6). Whole arrays In most cases the whole array x refers to all of the elements of the array as a single entity. It may appear in exec...
Due to its computational goals, mathematical operations on arrays are straight forward in Fortran. Addition and subtraction Operations on arrays of the same shape and size are very similar to matrix algebra. Instead of running through all the indices with loops, one can write addition (and subtra...
As mentioned in another example a subset of the elements of an array, called an array section, may be referenced. From that example we may have real x(10) x(:) = 0. x(2:6) = 1. x(3:4) = [3., 5.] Array sections may be more general than this, though. They may take the form of subscript trip...

Page 1 of 1