Tutorial by Examples

Fortran 2003 introduced support for object oriented programming. This feature allows to take advantage of modern programming techniques. Derived types are defined with the following form: TYPE [[, attr-list] :: ] name [(name-list)] [def-stmts] [PRIVATE statement or SEQUENCE statement]. . . ...
In order to obtain class-like behavior, type and related procedures (subroutine and functions) shall be placed in a module: Example: module MShape implicit none private type, public :: Shape private integer :: radius contains procedure :: set => sh...
An extensible derived type may be abstract type, abstract :: base_type end type Such a derived type may never be instantiated, such as by type(base_type) t1 allocate(type(base_type) :: t2) but a polymorphic object may have this as its declared type class(base_type), allocatable :: t1 o...
A derived type is extensible if it has neither the bind attribute nor the sequence attribute. Such a type may be extended by another type. module mod type base_type integer i end type base_type type, extends(base_type) :: higher_type integer j end type higher_type end ...
Custom constructors can be made for derived types by using an interface to overload the type name. This way, keyword arguments that don't correspond to components can be used when constructing an object of that type. module ball_mod implicit none ! only export the derived type, and not any ...

Page 1 of 1