OKPEDIA FORTRAN EN

How to create multidimensional arrays in Fortran

To define an array with a dimension (vector) or multiple dimensions (matrix) in the Fortran language we use the DIMENSION statement.

DIMENSION name (dim)

The first argument (name) indicates the name of the array variable while the second argument (dim) defines the size of the array.

Other methods

The dimensioning of an array variable can also be done in the variable declaration.

INTEGER, DIMENSION (dim) :: name

or

INTEGER name (dim)

In the sizing instruction you can add more variables separated by a comma.

A practical example

In this example program written in Fortran, several array declaration techniques are used.

an example of sizing array variables in Fortran

In line 2 of this program the DIMENSION statement defines three matrices a, b, c of integer type with 20 rows and 20 columns.

In line 3 the instruction sizes the variable x in two dimensions without changing the data type.

In line 4 the declaration creates an array variable of integer type with three dimensions (5,5,5) with 5 elements each and 53 total elements.

In the following lines there are some operations to assign to arrays and a print operation.

https://how.okpedia.org/en/fortran/how-to-create-multidimensional-arrays-in-fortran


Report an error or share a suggestion to enhance this page



FacebookTwitterLinkedinLinkedin