Tutorial by Examples

The following are data types intrinsic to Fortran: integer real character complex logical integer, real and complex are numeric types. character is a type used to store character strings. logical is used to store binary values .true. or .false.. All numeric and logical intrinsic types are...
Define a new type, mytype: type :: mytype integer :: int real :: float end type mytype Declare a variable of type mytype: type(mytype) :: foo The components of a derived type can be accessed with the % operator1: foo%int = 4 foo%float = 3.142 A Fortran 2003 feature (not yet ...
Floating point numbers of type real cannot have any real value. They can represent real numbers up to certain amount of decimal digits. FORTRAN 77 guaranteed two floating point types and more recent standards guarantee at least two real types. Real variables may be declared as real x double prec...
Variables of character type or of a derived type with length parameter may have the length parameter either assumed or deferred. The character variable name character(len=len) name is of length len throughout execution. Conversely the length specifier may be either character(len=*) ... ! Ass...
Program units often make use of literal constants. These cover the obvious cases like print *, "Hello", 1, 1.0 Except in one case, each literal constant is a scalar which has type, type parameters and value given by the syntax. Integer literal constants are of the form 1 -1 -1_1 ...
For the character entity character(len=5), parameter :: greeting = "Hello" a substring may be referenced with the syntax greeting(2:4) ! "ell" To access a single letter it isn't sufficient to write greeting(1) ! This isn't the letter "H" but greeting(1:...
The complex entity complex, parameter :: x = (1., 4.) has real part 1. and complex part 4.. We can access these individual components as real(x) ! The real component aimag(x) ! The complex component x%re ! The real component y%im ! The complex component The x%.. form is new to F...
Throughout the topics and examples here we'll see many declarations of variables, functions and so on. As well as their name, data objects may have attributes. Covered in this topic are declaration statements like integer, parameter :: single_kind = kind(1.) which gives the object single_kind...

Page 1 of 1