Exploring Modern Fortran Basics
With chapters selected by Milan Curcic
  • May 2020
  • ISBN 9781617298103
  • 92 pages
Fortran has come a long way since IBM first developed it in 1956. Flexible, powerful, and high performing, this general purpose programming language remains the dominant one in the field of scientific and engineering applications. Continuously improving, the latest version of Fortran includes new parallel features and improved interoperability with C. As more and more data is generated every day, parallel programming has become vital to modern computing, making modern Fortran more relevant than ever!

About the book

Exploring Modern Fortran Basics presents three chapters from Modern Fortran: Building Efficient Parallel Applications by meteorologist, oceanographer, and Fortran programmer, Milan Curcic. Inside, you’ll learn the core features of modern Fortran as you build a simple tsunami simulator. First you’ll master the basics, including variables, data types, control flow, and arithmetic operations and assignments. Then you’ll add complexity to your program with Fortran’s functions and subroutines, the building blocks that enable us to define self-contained and reusable nuggets of code. In the last chapter, you’ll advance to using Fortran modules for organizing your code in a meaningful way as well as making them accessible for use in programs, procedures, or other modules. At the end of this practical guide, you’ll have a working Fortran program and valuable basic Fortran skills!
Table of Contents detailed table of contents

Introduction

Part 1: 2 Getting started: Minimal working app

Getting started: Minimal working app

2.1 Compiling and running your first program

2.2 Simulating the motion of an object

2.2.1 What should our app do?

2.2.2 What is advection?

2.3 Implementing the minimal working app

2.3.1 Implementation strategy

2.3.1 Implementation strategy

2.3.2 Defining the main program

2.3.3 Declaring and initializing variables

2.3.4 Numeric data types

2.3.5 Declaring variables

2.3.6 Declaring constants

2.3.7 Declaring arrays

2.3.8 Branching with an if-block

2.3.9 Using a do-loop to iterate

2.3.10 Setting the initial water height values

2.3.11 Predicting the movement of the object

2.3.12 Printing results to the screen

2.3.13 Putting it all together

2.4 Going forward with the tsunami simulator

2.5 Answer Key

2.5.1 Exercise: Cold front propagation

2.6 New Fortran elements, at a glance

2.7 Further reading

2.8 Summary

Part 2: Exploring data

Writing reusable code with functions and subroutine

3.1 Toward higher app complexity

3.1.1 Refactoring the tsunami simulator

3.1.2 Revisiting the cold front problem

3.1.3 An overview of Fortran program units

3.2 Don’t repeat yourself, use procedures

3.2.1 Your first function

3.2.2 Expressing finite difference as a function in the tsunami simulator

3.3 Modifying program state with subroutines

3.3.1 Defining and calling a subroutine

3.3.2 When to use a subroutine over a function?

3.3.3 Initializing water height in the tsunami simulator

3.4 Writing pure procedures to avoid side effects

3.4.1 What is a pure procedure?

3.4.2 Some restrictions on pure procedures

3.4.3 Why are pure functions important?

3.5 Writing procedures that operate on both scalars and arrays

3.6 Procedures with optional arguments

3.7 Tsunami simulator: Putting it all together

3.8 Answer key

3.8.1 Exercise 1: Modifying state with a subroutine

3.8.2 Exercise 2: Writing an elemental function that operates on both scalars and arrays

3.9 New Fortran elements, at a glance

3.10 Further reading

Part 3: Organizing your Fortran code using modules

Organizing your Fortran code using modules

4.1 Accessing a module

4.1.1 Getting compiler version and options

4.1.2 Using portable data types

4.2 Creating your first module

4.2.1 A structure of a custom module

4.2.2 Defining a module

4.2.3 Compiling Fortran modules

4.2.4 Controlling the visibility and access to variables and procedures

4.2.5 Putting it all together in the tsunami simulator

4.3 Toward realistic wave simulations

4.3.1 A brief look at the physics

4.3.2 Update to the finite difference calculation

4.3.3 Renaming imported entities to avoid name conflict

4.3.4 The complete code

4.4 Answer key

4.4.1 Exercise 1: Using portable type kinds in the tsunami simulator

4.4.2 Exercise 2: Define the set_gaussian subroutine in a module

4.5 New Fortran elements, at a glance

4.6 Further reading

4.7 Summary

What's inside

From Modern Fortran: Building Efficient Parallel Applications by Milan Curcic:
  • Chapter 2 - “Getting started: Minimal working app”
  • Chapter 3 - “Writing reusable code with functions and subroutines”
  • Chapter 4 - “Organizing your Fortran code using modules”

About the author

Milan Curcic is a meteorologist and oceanographer. A Fortran programmer since 2006, he has worked with teams in the United States Navy and NASA on developing and improving Earth system prediction models. Milan has authored two general-purpose Fortran libraries and is currently working on a startup porting Fortran to the cloud for weather and ocean prediction.

placing your order...

Don't refresh or navigate away from the page.
eBook $0.00 PDF only + liveBook
Check your email for instructions on downloading Exploring Modern Fortran Basics (eBook) or read it now
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.
customers also reading

This book 1-hop 2-hops 3-hops

FREE domestic shipping on three or more pBooks