« Back

Modern Fortran: Style and Usage

Fortranning It with Style

by Jacob Moldenhauer

The book is a powerful tool for any programmer who uses Fortran. More specifically, it's a great quick reference. Whether you're writing Fortran code from scratch; updating code for readability, efficiency, and performance improvements; or learning what the newest version of Fortran has to offer, this book will have something for you.

It's written for Fortran programmers of all levels, but shouldn't be used as a textbook and shouldn't be read straight through. The authors sought to make each chapter and section independent of the others to support quick referencing for a topic. I read the book jumping around from chapter to chapter when preparing for this review, and I found it to work quite well.

The book is organized as a collection of strategies that the authors refer to as rules for creating powerful, well-organized Fortran programs, using the modern structure and performance capabilities of the current Fortran standard. Many of these rules describe general coding techniques and styles not specific to Fortran. Other rules apply specifically to new features in the latest versions of Fortran. In this book, as in life, there are some rules that must be followed and some that are mere suggestions. Overall, though, following the rules in this book will alleviate many headaches that you would otherwise encounter when designing programs.

The chapters were all well laid out and consistently organized to introduce the topic, present a rule and the reasons to follow it, present sample code, and show the output for either correct adherence or dismissing the rule (if applicable or available). This organization made it easy to navigate from chapter to chapter, finding different topics of interest. Also, each rule was presented clearly and concisely with consistent reasoning. If the rule involved a change from how an earlier version of Fortran did something, then this is explained, as well as the improvement by the updated feature. If it's a new feature, then the authors explain the needed improvement it provides.

For organization, completeness, and appeal to programmers new to Fortran, the earlier chapters contain rules for more general programming, but are given with specific reference to the Fortran standard and its new features when available. Chapter 1 contains the font key and source code description. The rules begin in Chapter 2, outlining the reasons for some basic commonsense rules: making code easy to read, compile, efficient, transferrable to other problems, documented, reusable, and accessible to others.

Chapters 3–9 describe rules that will accomplish these things by adhering to certain formatting (Chapter 3), naming (Chapter 4), documentation (Chapter 5), programming (Chapter 7), and packaging (Chapter 9) conventions. Chapter 10 handles generic programming so that identical or slightly modified code can be used for different applications. There's also a small section about using preprocessors within Fortran.

The remaining chapters detail advancements in Fortran. For this review, I actually started with Chapter 12 on parallel processing, which had the most relevance for me at the time. It explains the differences between the two supported methods of parallel computing in Fortran: Open Multiprocessing (OpenMP) and message passing interface (MPI). It covers the basics, from "Hello World" in parallel for the programmer unfamiliar with newer parallel features. I found the section on new Fortran 2008 features — such as incorporating coarrays into parallel programming and supplied source program with output — quite useful. I then proceeded to jump around a bit, sticking to most of the advanced chapters in the book (Chapters 11–15).

Chapter 11 introduces object-oriented programming (OOP) as a new feature to Fortran 2003. The authors give a great introduction to OOP for those who haven't encountered it before, as well as those who might need a refresher. The final section discusses polymorphism, with sample source code and output, specifically warning against confusing the polymorphic keyword class in Fortran and the derived data-type keyword type in Fortran. I found the clarifications given in this chapter to be highly beneficial.

Chapter 13 deals with advancements in how Fortran handles numerical precision, explaining "kinds" of floating-point operations, exceptions, and bit manipulation. Chapter 14 is useful for programmers who need a program written in Fortran to interact with a C program or vice versa. Finally, Chapter 15 explains step by step how to update existing codes that contain obsolete or unsupported features for some compilers to the Fortran standard.

The book provides a number of full-sample source codes and demos for use by the reader as examples. There's also a list of all the source code for the book at the front, as well as two full source code demos in the appendix. Some of the source codes were incomplete by design, and I would have enjoyed a file version of all the sample source code to avoid typing them in, to save time and errors. A second appendix contains a comprehensive list of all the rules given in the book.

Reading this opened my eyes to the many inconsistencies in programming style today. There are some great rules to add to how I program, to improve my code for clarity and performance. I have begun using underscore names, self-documentation for different versions of code, and plurals for arrays. This has also provided me with a great guide for learning how to incorporate the new features of 2003 and 2008 into my work. After reading it, I wish more people coded like this.

Jacob Moldenhauer is an assistant professor in the Department of Physics and Astronomy at Francis Marion University. Contact him at jmoldenhauer@fmarion.edu.

This review is an abbreviation of the original, which appeared in the September/October 2012 issue of Computing in Science and Engineering, pp. 5–6.

 

More Reviews