You are previewing Modern Fortran in Practice.
O'Reilly logo
Modern Fortran in Practice

Book Description

From its earliest days, the Fortran programming language has been designed with computing efficiency in mind. The latest standard, Fortran 2008, incorporates a host of modern features, including object-orientation, array operations, user-defined types, and provisions for parallel computing. This tutorial guide shows Fortran programmers how to apply these features in twenty-first-century style: modular, concise, object-oriented, and resource-efficient, using multiple processors. It offers practical real-world examples of interfacing to C, memory management, graphics and GUIs, and parallel computing using MPI, OpenMP, and coarrays. The author also analyzes several numerical algorithms and their implementations and illustrates the use of several open source libraries. Full source code for the examples is available on the book's Web site.

Table of Contents

  1. Title Page
  2. Copyright Page
  3. Contents
  4. Foreword
  5. Preface
  6. 1. Introduction to Modern Fortran
    1. 1.1 The Flavor of Modern Fortran
    2. 1.2 Fortran 90
    3. 1.3 Fortran 95
    4. 1.4 Fortran 2003
    5. 1.5 Fortran 2008
    6. 1.6 What Has Not Changed?
  7. 2. Array-Valued Functions
    1. 2.1 Passing Arrays
    2. 2.2 Elemental Functions and Automatic Reallocation
    3. 2.3 Two More Advanced Examples
    4. 2.4 Concise Style
  8. 3. Mathematical Abstractions
    1. 3.1 Automatic Differentiation
    2. 3.2 Integer Programming
    3. 3.3 Enumerating Solutions of Diophantine Equations
    4. 3.4 Delayed Evaluation
  9. 4. Memory Management
    1. 4.1 Flexible Arrays
    2. 4.2 Memory Leaks with Pointers
    3. 4.3 Extending an Array
    4. 4.4 Character Strings with Adjustable Length
    5. 4.5 Combining Automatic and Allocatable Arrays
    6. 4.6 Performance of Various Types of Arrays
    7. 4.7 Parametrized Derived Types
    8. 4.8 Avoiding Memory Leaks with Derived Types
    9. 4.9 Performance and Memory Access
  10. 5. An Interface Problem
    1. 5.1 Filling in the Parameters
    2. 5.2 Using a Pool of Data
    3. 5.3 Passing Extra Arguments
    4. 5.4 Control Structures
    5. 5.5 Dealing with Different Precisions
    6. 5.6 Overview
  11. 6. Interfacing to C: SQLite As an Example
    1. 6.1 Matching Data Types
    2. 6.2 Passing Arguments Between C and Fortran Routines
    3. 6.3 Naming and Calling Conventions
    4. 6.4 Dealing with Derived Types
    5. 6.5 Interfacing to SQLite
  12. 7. Graphics, GUIs, and the Internet
    1. 7.1 Plotting the Results
    2. 7.2 Graphical User-Interfaces
    3. 7.3 The Internet
    4. 7.4 Dealing with XML Files
  13. 8. Unit Testing
    1. 8.1 Testing Frameworks
    2. 8.2 Tridiagonal Matrices As an Example
    3. 8.3 Design and Implementation
    4. 8.4 Concluding Remarks
  14. 9. Code Reviews
    1. 9.1 Be Explicit
    2. 9.2 Don't Stray
    3. 9.3 Avoid Traps
    4. 9.4 Clean Code
  15. 10. Robust Implementation of Several Simple Algorithms
    1. 10.1 Related Approaches
    2. 10.2 Linear Interpolation
    3. 10.3 Basic Statistics
    4. 10.4 Finding the Roots of an Equation
  16. 11. Object-Oriented Programming
    1. 11.1 Extending Types and Type-Bound Procedures
    2. 11.2 Interfaces As Contracts
    3. 11.3 Using a Prototype Approach
    4. 11.4 Abstract Data Types and Generic Programming
    5. 11.5 Changing the Behavior of a Type
    6. 11.6 Design Patterns
  17. 12. Parallel Programming
    1. 12.1 Prime Numbers
    2. 12.2 Domain Decomposition
    3. 12.3 Alternatives
    4. 12.4 Overview
  18. A. Tools for Development and Maintenance
    1. A.1 The Compiler
    2. A.2 Build Tools
    3. A.3 Integrated Development Environments
    4. A.4 Run-Time Checking
    5. A.5 Version Control Systems
    6. A.6 Documenting the Source Code
    7. A.7 Code Coverage and Static Analysis
  19. B. Caveats
    1. B.1 Details of the Standard
    2. B.2 Arrays
    3. B.3 Dynamic Libraries
  20. C. Trademarks
  21. Bibliography
  22. Index