Skip to main content
Top

2015 | Book

Introduction to Programming with Fortran

With Coverage of Fortran 90, 95, 2003, 2008 and 77

insite
SEARCH

About this book

In response to feedback from course delegates this third edition has been revised throughout. It expands on the second edition with new and updated examples in the chapters on arithmetic, i/o, character data, modules, data structuring and generic programming with minor updates to the rest of the chapters.

Key Features

· lots of clear, simple examples highlighting the core language features of modern Fortran including data typing, array processing, control structures, functions, subroutines, modules, user defined types, pointers, operator overloading, generic programming, object oriented programming and parallel programming

· pinpoints common problems that occur when programming

· illustrates the use of several compilers

· with better standards conformance in compilers there are new examples illustrating the following major features:

- C Interop

- IEEE arithmetic

- parameterised derived types

Introduction to Programming with Fortran will appeal to the complete beginner, existing

Fortran programmers wishing to update their code and those with programming experience in other languages.

Ian Chivers and Jane Sleightholme are the joint owners of comp-fortran-90 which is a lively forum for the exchange of technical details of the Fortran language. Ian is the editor of the ACM Fortran Forum, and Jane and Ian have both been involved in the Fortran standardisation process. The authors have been teaching and supporting Fortran and related areas for over 40 years and their latest book reflects the lessons that have been learnt from this.

Table of Contents

Frontmatter
Chapter 1. Overview

The aims of the chapter are to provide a background to the organisation of the book.

Ian Chivers, Jane Sleightholme
Chapter 2. Introduction to Problem Solving

The aims of this chapter are:

To examine some of the ideas and concepts involved in problem solving.

Problem solving

To introduce the concept of an algorithm.

Algorithm

Problem solving

algorithm

To introduce two ways of approaching algorithmic problem solving.

Problem solving

algorithmic problem solving

To introduce the ideas involved with systems

analysis

Systems analysis

and

design

Systems analysis and design

, i.e., to show the need for pencil and paper study before using a computer system.

Problem solving

systems analysis and design

To introduce the Unified Modeling Language—UML, a general purpose modeling language used in the field of software engineering.

Problem solving

UML

Problem solving

software engineering

Ian Chivers, Jane Sleightholme
Chapter 3. Introduction to Programming Languages

The primary aim of this chapter is to provide a short history of program language development and give some idea as to the concepts that have had an impact on Fortran. It concentrates on some but not all of the major milestones of the last 40 years, in roughly chronological order. The secondary aim is to show the breadth of languages available. The chapter concludes with coverage of a small number of more specialised languages.

Ian Chivers, Jane Sleightholme
Chapter 4. Introduction to Programming

The aims of the chapter are:

To introduce the idea that there is a wide class of problems that can be solved with a computer and, further, that there is a relationship between the kind of problem to be solved and the choice of programming language that is used.

To give some of the reasons for the choice of Fortran.

To introduce the fundamental components or kinds of statements to be found in a general purpose programming language.

To introduce the three concepts of name, type and value.

To illustrate the above with sample programs based on three of the five intrinsic data

type

Intrinsic data type

s:

character, integer and real

To introduce some of the formal syntactical rules of Fortran.

Ian Chivers, Jane Sleightholme
Chapter 5. Arithmetic

The aims of this chapter are to introduce:

The Fortran rules for the evaluation of arithmetic

expressions

Arithmetic expressions

to ensure that they are evaluated as you intend;

The idea of truncation and rounding;

The use of the parameter

attribute

Parameter attribute

to define or set up constants;

The use of Fortran’s kind

types

Kind types

to determine and control the precision by which arithmetic in Fortran is carried out;

The concept of numeric

models

Numeric models

and positional number

systems

Positional number systems

for integer and real arithmetic and their implementation on binary devices;

Testing the numerical representation of different integer kind

types

Integer kind type

on a system—8, 16, 32 and 64 bit integers;

Testing the numerical representation of different real kind

types

Real kind type

Kind types

on

a system—32, 64, 80 and 128 bit reals;

round off;

relative error;

absolute error.

Ian Chivers, Jane Sleightholme
Chapter 6. Arrays 1: Some Fundamentals

The aims of the chapter are to introduce the fundamental

concepts

Do statement

of

arrays

Arrays

and do

loop

Do loop

s, in particular:

To introduce the idea of tables of data and some of the formal terms used to describe them:

Array.

Vector.

List and linear list.

To discuss the array as a random access structure where any element can be accessed as readily as any other and to note that the data in an array are all of the same type.

To introduce the twin concepts of data structure and corresponding control

structure

Control structure

.

To introduce the statements necessary in Fortran to support and manipulate these data

structures

Data structures

.

Ian Chivers, Jane Sleightholme
Chapter 7. Arrays 2: Further Examples

The aims of the chapter are to extend the concepts introduced in the previous chapter and in particular:

To set an array

size

Array size

at run time—allocatable

arrays

Allocatable arrays

.

To introduce the idea of an array with more than one dimension and the corresponding control

structure

Control structure

to permit easy manipulation of higher-dimensioned arrays.

To introduce an extended form of the dimension

attribute

Dimension attribute

declaration, and the corresponding alternative form to the do

statement

Do statement

, to manipulate the array in this new form.

To introduce the do

loop

Do loop

as a mechanism for the control of repetition in general, not just for manipulating arrays.

To formally

define

Array

allocatable

Array

varying the size at run time

the

block do syntax.

Ian Chivers, Jane Sleightholme
Chapter 8. Whole Array and Additional Array Features

The aims of the chapter are:

To look more formally at the terminology required to precisely describe arrays.

To introduce ways in which we can manipulate whole

arrays

Whole array

and parts of arrays (sections).

To introduce the concept of array

element

Array element

ordering

Array element order

and physical and virtual memory.

To introduce ways in which we can initialise arrays using array

constructors

Array constructor

.

To introduce the

where

statement and array masking.

To introduce the

forall

statement and construct.

Physical and virtual memory

Type declaration statement summary

Ian Chivers, Jane Sleightholme
Chapter 9. Output of Results

The aims here are to introduce some of the facilities for producing neat output using edit

descriptor

Edit descriptor

s. There is also coverage of how to write the results to a file, rather than to the screen. There are examples which will illustrate the use of

The

i

edit

descriptor

i edit descriptor

for integer data

The

f

edit

descriptor

f edit descriptor

for real data

The

e

edit

descriptor

e edit descriptor

for real data

The

g

edit

descriptor

g edit descriptor

for real data

The

x

edit

descriptor

x edit descriptor

for spaces

The

a

edit

descriptor

a edit descriptor

for character data

Repetition of edit

descriptor

Edit descriptor

s

New lines

Output using array

section

Array section

s

Output using whole

array

Whole array

s

The

open

,

write

, and

close

statements.

We will also provide a brief summary of the rest of the control and data edit

descriptor

Edit descriptor

s, as people may see them in existing code.

Ian Chivers, Jane Sleightholme
Chapter 10. Reading in Data

The aims of this chapter are to introduce some of the ideas involved in reading data into a program. In particular, using the following:

Reading from files

Reading integer data

Reading real data

Skipping columns of data in a file

Skipping lines in a file

Reading from several files consecutively

Reading using internal files

Timing of formatted and unformatted reads.

Ian Chivers, Jane Sleightholme
Chapter 11. Summary of I/O Concepts

This chapter covers more formally some of the concepts introduced in Chaps.

9

and

10

. There is a coverage of

I/O concepts and I/O statements

Files, records and streams

Sequential, direct and stream access

Options or specifiers on the

open

statement

Options or specifiers on the

close

statement

Options or specifiers on the

write

statement

Options or specifiers on the

read

statement

Ian Chivers, Jane Sleightholme
Chapter 12. Functions

The role of functions in a programming language and in the problem-solving process is considerable and includes.

Ian Chivers, Jane Sleightholme
Chapter 13. Control Structures

The aims of this chapter are to introduce:

Selection among various courses of action as part of the algorithm.

The concepts and statements in Fortran needed to support the above:

Logical expressions

Logical expression

and logical

operators

Logical operators

.

One or more blocks of statements.

The

if then endif

construct

If then endif construct

.

The

if then else if endif

construct

If then else if endif construct

.

To introduce the

case

statement

Case statement

with examples.

To introduce the

do loop

Do loop

, in three forms with examples, in particular:

The iterative

do loop

Iterative do loop

.

The

do while

form.

The

do

...

if then exit end do

or repeat until form.

The

cycle

statement

Cycle statement

.

The

exit

statement

Exit statement

.

Ian Chivers, Jane Sleightholme
Chapter 14. Characters

The aims of this chapter are:

To extend the ideas about characters introduced in earlier chapters.

To demonstrate that this enables us to solve a whole new range of problems in a satisfactory way.

Ian Chivers, Jane Sleightholme
Chapter 15. Complex

The aims of this chapter are:

To introduce the last predefined numeric data type in Fortran.

To illustrate with examples how to use this type.

Ian Chivers, Jane Sleightholme
Chapter 16. Logical

The aims of this chapter are:

To examine the last predefined type available in Fortran: logical.

To introduce the concepts necessary to use logical

expression

Logical expression

s effectively:

Logical variables.

Logical operators.

The hierarchy of operations.

Truth tables.

Ian Chivers, Jane Sleightholme
Chapter 17. Introduction to Derived Types

The aim of this chapter is to introduce the concepts and ideas involved in using the facilities offered in modern Fortran for

the

Derived types

User defined types

construction

and use of derived or user defined types;

defining our own types.

declaring variables to be of a user defined type.

manipulating variables of our own types.

nesting types within types.

Ian Chivers, Jane Sleightholme
Chapter 18. An Introduction to Pointers

The primary aim of the chapter is to introduce some of the key concepts of pointers in Fortran.

Ian Chivers, Jane Sleightholme
Chapter 19. Introduction to Subroutines

The aims of this chapter are:

To consider some of the reasons for the inclusion of subroutines in a programming language.

To introduce with a concrete example some of the concepts and ideas involved with the definition and use of subroutines.

Arguments or parameters.

The

intent

attribute

Intent attribute

for parameters.

The

call

statement

Call statement

.

Scope of variables.

Local variables and the

save

attribute

Save attribute

.

The use of parameters to report on the status of the action carried out in the subroutine.

Module procedures to provide interfaces.

Ian Chivers, Jane Sleightholme
Chapter 20. Subroutines: 2

The aims of this chapter are to extend the ideas in the earlier chapter on subroutines and look in more depth at parameter

passing

Parameter passing

, in particular using a variety of ways of passing arrays.

Ian Chivers, Jane Sleightholme
Chapter 21. Modules

The aims of this chapter are to look at the facilities found in Fortran provided by modules, in particular:

The use of a module to aid in the consistent definition of precision throughout a program and subprograms.

The use of modules for global

data

Modules for global data

.

The use of modules for derived data types.

Modules for derived data types

Derived data types

Modules containing procedures

A module for timing programs

Public, private and protected

attributes

Protected attribute

The use statement and its extensions

Ian Chivers, Jane Sleightholme
Chapter 22. Data Structuring in Fortran

The aims of this chapter are to look at several complete examples illustrating data structuring in Fortran using the following

Singly linked

list

Linked list

Ragged arrays

A perfectly balanced tree

A date data type

Ian Chivers, Jane Sleightholme
Chapter 23. An Introduction to Algorithms and the Big O Notation

The aims of this chapter are to provide an introduction to algorithms and their behaviour. In Computer Science this is normally done using the so called big O notation.

Ian Chivers, Jane Sleightholme
Chapter 24. Operator Overloading

The aims of this chapter are to look at operator overloading in Fortran.

Ian Chivers, Jane Sleightholme
Chapter 25. Generic Programming

This chapter looks at some examples that implement generic programming in Fortran.

Ian Chivers, Jane Sleightholme
Chapter 26. Mathematical Examples

The aims of this chapter are to look at several mathematical examples in Fortran.

Using linked

list

Linked list

s for sparse matrix

problems

Sparse matrix problems

.

The solution of a set of ordinary differential

equations

Ordinary differential equations

using the Runge–Kutta–Merson method, with the use of a procedure as a parameter, and the use of work arrays.

Diagonal extraction of a matrix.

The solution of a system of linear simultaneous equations using Gaussian Elimination

An elemental e**x function

Ian Chivers, Jane Sleightholme
Chapter 27. Parameterised Derived Types (PDTs) in Fortran

The aims of this chapter are to look at some additional data structuring examples in Fortran that use parameterised derived types - PDTs.

Ian Chivers, Jane Sleightholme
Chapter 28. Object Oriented Programming

The aims of this chapter are to look at object oriented

programming

Object oriented programming

in Fortran.

Ian Chivers, Jane Sleightholme
Chapter 29. Introduction to Parallel Programming

The

aims

Parallel programming

of this chapter is to provide a short introduction to parallel programming.

Ian Chivers, Jane Sleightholme
Chapter 30. MPI—Message Passing Interface

The aims of this chapter is to provide a short introduction to MPI programming in Fortran.

Ian Chivers, Jane Sleightholme
Chapter 31. OpenMP

The aims of this chapter is to provide a short introduction to OpenMP programming in Fortran.

Ian Chivers, Jane Sleightholme
Chapter 32. Coarray Fortran

The aims of this chapter is to provide a short introduction to coarray programming in Fortran.

Ian Chivers, Jane Sleightholme
Chapter 33. C Interop

This chapter looks briefly at C interoperability.

Ian Chivers, Jane Sleightholme
Chapter 34. IEEE Arithmetic

The aims of this chapter are to look in more depth at arithmetic and in particular at the support that Fortran provides for the IEEE 754 and later standards.

Ian Chivers, Jane Sleightholme
Chapter 35. Miscellaneous Examples

We look at a number of additional examples including

the earlier date derived type extended with US and ISO date

formats

E formats

a binary search example

three sorting examples, including a recursive algorithm, a non recursive algorithm and a parallelised subroutine from the Nag library

timing details for our generic serial Quicksort algorithm for five of the numeric kind

types

Kind types

Serial recursive Quicksort

timing details of the Netlib serial non recursive Quicksort for 32 bit

integers

Bit integers

, 32 bit

reals

Bit reals

and

64 bit

reals

Serial non recursive Quicksort

a comparison of the timing of the above two sorting algorithms

the Nag SMP sorting routine m01caf for 64 bit

reals

Bit reals

timing details of the parallel Nag sorting subroutine

graphics libraries

the dislin graphics

library

Dislin graphics library

examples calling the dislin library.

Ian Chivers, Jane Sleightholme
Chapter 36. Converting from Fortran 77

This chapter looks at some of the options available when working with older Fortran code.

Ian Chivers, Jane Sleightholme
Backmatter
Metadata
Title
Introduction to Programming with Fortran
Authors
Ian Chivers
Jane Sleightholme
Copyright Year
2015
Electronic ISBN
978-3-319-17701-4
Print ISBN
978-3-319-17700-7
DOI
https://doi.org/10.1007/978-3-319-17701-4

Premium Partner