Fortran/structures

< Fortran

Structures or structured types were first introduced in Fortran 90[1]. Structures allow the user to create data types that hold multiple different variables

Example

As an example, we can define a new structure type, 'Fruit' which stores some basic fruit variables:

TYPE fruit
  REAL diameter      ! in mm
  REAL length        ! in mm
  CHARACTER colour
end type fruit

We can declare two 'fruit' variables, and assign them values:

TYPE(fruit) apple, banana
apple = fruit(50,45,"red")
banana%diameter = 40
banana%length = 200
banana%colour= "yellow"

And we can then use the fruit variables and their child values in normal Fortran operations.

References

  1. A Look at Fortran 90 - Lahey computer systems
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.