The book was conceived as a result of my experience writing and maintaining large Fortran programs in both the defense and geophysical fields and as a follow-up to my FORTRAN 77 book published by HarperCollins. During my time in industry, it became obvious that the strategies and techniques required to write large, maintainable Fortran programs were quite different from those that new engineers were learning in their Fortran programming classes at school. The incredible cost of maintaining and modifying large programs once they are placed into service absolutely demands that they be written to be easily understood and modified by people other than their original programmers. My goal for this book is to teach simultaneously both the fundamentals of the Fortran language and a programming style that results in good, maintainable programs. In addition, it is intended to serve as a reference for graduates working in industry.

    It is quite difficult to teach undergraduates the importance of taking extra effort during the early stages of the program design process in order to make their programs more maintainable. Class programming assignments must by their very nature be simple enough for one person to complete in a short period of time, and the programs do not have to be maintained for years. Because the projects are simple, a student can often "wing it" and still produce working code. A student can take a course, perform all of the programming assignments, pass all of the tests, and still not learn the habits that are really needed when working on large projects in industry.

    From the very beginning this book teaches Fortran in a style suitable for use on large projects. It emphasizes the importance of going through a detailed design process before any code is written, using a top-down design technique to break the program into logical portions that can be implemented separately. It stresses the use of procedures to implement those individual portions and the importance of unit testing before combining the procedures into a finished product. Finally, it emphasizes the importance of exhaustively testing the finished program with many different input data sets before releasing it for use.

    In addition, this book teaches Fortran as it is actually encountered by engineers and scientists working in industry and in laboratories. Two facts of life are common in all programming environments: large amounts of old legacy code that have to be maintained and the existence of subroutine libraries to make some programming tasks easier. The legacy code at a particular site may have been originally written in FORTRAN IV (or an even earlier version!), and it may use programming constructs that are no longer common today. For example, such code may use arithmetic IF statements, or computed or assigned GO TO statements. Chapter 14 is devoted to the older features of the language that are no longer in common use, but are encountered in legacy code. The chapter emphasizes that these features should never be used in a new program but also prepares the student to handle them when he or she encounters them.

    Similarly, Chapter 13 prepares the student to use Fortran libraries. It teaches the student about the types of libraries available and about how to select and interface with a particular procedure from a library. It introduces commonly used mathematical libraries such as the NAG Library, the IMSL Library, and the LAPACK Library. Both a small subset of the LAPACK Library and a small library called BOOKLIB are supplied for use with this book. These libraries are used in Chapter 13 to teach the student to use library indexes, to read manual pages, and to interface with library procedures.

Features of this Book

    Many features of this book are designed to emphasize the proper way to write reliable Fortran programs. These features should serve a student well as he or she is first learning Fortran and should also be useful to the practitioner on the job.

1. Emphasis on Modern Fortran 90/95

The book consistently teaches the best current practice in all of its examples. Many Fortran 90/95 features duplicate and supersede older features of the Fortran language. In those cases the proper usage of the modern language is presented. Examples of older usage are largely relegated to Chapter 14 where their old/undesirable nature is emphasized. Examples of Fortran 90/95 features that supersede older features are the use of modules to share data instead of COMMON blocks, the use of DO ... END DO loops instead of DO ... CONTINUE loops, the use of internal procedures instead of statement functions, and the use of CASE constructs instead of computed GO TOs.

2. Emphasis on Strong Typing

    The IMPLICIT NONE statement is used consistently throughout the book to force the explicit typing of every variable used in every program and to catch common typographical errors at compilation time. In conjunction with the explicit declaration of every variable in a program, the book emphasizes the importance of creating a data dictionary that describes the purpose of each variable in a program unit.

3. Emphasis on Top-Down Design Methodology

    The book introduces a top-down design methodology in Chapter 3 and then uses it consistently throughout the rest of the book. This methodology encourages a student to think about the proper design of a program before beginning to code. It emphasizes the importance of clearly defining the problem to be solved and the required inputs and outputs before beginning any other work. Once the problem is properly defined, the book teaches the student to employ stepwise refinement to break the task down into successively smaller subtasks and to implement the subtasks as separate subroutines or functions. Finally, it teaches the importance of testing at all stages of the process, both unit testing of the component routines and exhaustive testing of the final product. Several examples are given of programs that work properly for some data sets and then fail for others.

    The formal design process taught by the book may be summarized as follows:

  1. Clearly state the problem that you are trying to solve.

  2. Define the inputs required by the program and the outputs to be produced by the program.

  3. Describe the algorithm that you intend to implement in the program. This step involves top-down design and stepwise decomposition, using pseudocode or flow charts.

  4. Turn the algorithm into Fortran statements.

  5. Test the Fortran program. This step includes unit testing of specific subprograms and also exhaustive testing of the final program with many different data sets.

4. Emphasis on Procedures

    The book emphasizes the use of subroutines and functions to logically decompose tasks into smaller subtasks. It teaches the advantages of procedures for data hiding. It also emphasizes the importance of unit testing procedures before they are combined into the final program. In addition, the book explains how to avoid the common mistakes made with procedures (argument type mismatches, array length mismatches, etc.). It emphasizes the advantages associated with explicit interfaces to procedures, which allow the Fortran compiler to catch most common programming errors at compilation time.

5. Libraries

    The book introduces the concept of Fortran libraries to the student. It teaches the student about the types of libraries available and about how to select and interface with a particular procedure from a library. It introduces commonly used mathematical libraries such as the NAG Library, the IMSL Library, and the LAPACK Library. Both a small subset of the LAPACK Library and a small library called BOOKLIB are included with the instructor's manual that accompanies this book and are available for downloading at the book's World Wide Web site. Documentation for the libraries is available from the same sources. These sample libraries are used in Chapter 13 to teach the student how to use library indexes, to read manual pages, and to interface with library procedures.

6. Emphasis on Portability and Standard Fortran 90/95

    The book stresses the importance of writing portable Fortran code so that a program can easily be moved from one type of computer to another one. It teaches students to use only standard Fortran 90/95 statements in their programs so that they will be as portable as possible. In addition, it teaches the use of features such as the SELECTED_REAL_KIND function to avoid precision and kind differences when moving from computer to computer and the ACHAR and IACHAR functions to avoid problems when moving from ASCII to EBCDIC computers.

    The book also teaches students to isolate machine-dependent code (such as code that calls machine-dependent system libraries) into a few specific procedures so that only those procedures will have to be rewritten when a program is ported between computers.

7. Good Programming Practice Boxes

    These boxes highlight good programming practices when they are introduced. In addition, the good programming practices introduced in a chapter are summarized at the end of the chapter.

8. Programming Pitfalls Boxes

    These boxes highlight common errors so that they can be avoided. A sample Programming Pitfalls box is shown below.

9. Fortran 95-only Features

    Fortran 95-only features are distinguished by a special background. An example of a
Fortran 95-only feature is shown below.

    Fortran 95 provides an intrinsic function NULL() that can be used to nullify
a pointer at the time it is declared (or at any time during the execution of a program).
In Fortran 95, pointers can be declared and nullified as follows:

REAL, POINTER :: p1 = NULL(), p2 = NULL()
INTEGER, POINTER :: i1 = NULL()
...

(additional specification statements)

The details of the NULL() function are described in Appendix B.

10. Emphasis on the Limits of Computer Mathematics

    Chapters 8 and 12 introduce problems associated with the limited precision of computer mathematics and discuss ways to avoid them. In the discussion of double-precision real data in Chapter 8, the book introduces ill-conditioned systems of equations and shows how the limited precision of computer mathematics can lead to incorrect answers even though the algorithm being used is correct. It then provides guidelines for using the double-precision real data type to avoid these problems.

    Chapter 12 is an introduction to numerical methods. It expands on the material in Chapter 8 to discuss truncation and rounding errors, errors caused by the subtraction of nearly equal numbers, cascading errors, and errors associated with incorrect models. The examples in the chapter include higher-order least-squares fits, numerical integration, and finding the roots of equations. Examples of numerical methods from other chapters include random number generators, statistical subroutines, sorting, solving simultaneous equations, and taking derivatives.

11. Emphasis on Pointers and Dynamic Data Structures

    Chapter 11 contains a detailed discussion of Fortran pointers, including possible problems resulting from the incorrect use of pointers, such as memory leaks and pointers to deallocated memory. Examples of dynamic data structures in the chapter include linked lists and binary trees.

12. Sidebars

    Sidebars scattered throughout the book provide additional information of potential interest to the student. Some sidebars are historical in nature. For example, one sidebar in Chapter 1 describes the IBM Model 704, the first computer to ever run Fortran. Other sidebars reinforce lessons from the main text. For example, Chapter 6 contains a sidebar reviewing and summarizing the many different types of arrays found in Fortran 90/95.

13. Completeness

    Finally, the book endeavors to be a complete reference to the Fortran 90/95 language so that a practitioner can locate any required information quickly. Special attention has been paid to the index to make features easy to find. A special effort has also been made to cover such obscure and little-understood features as passing subprogram names by reference and defaulting values in list-directed input statements.

Pedagogical Features

    The book includes several features designed to aid student comprehension. A total of 20 quizzes are scattered throughout the chapters; answers to all questions appear in Appendix E. These quizzes can serve as useful self-tests of comprehension. In addition, there are approximately 310 end-of-chapter exercises. Answers to selected exercises are available at the book's Web site, and of course, answers to all exercises are included in the instructor's manual. Good programming practices are highlighted in all chapters with special Good Programming Practice boxes, and common errors are highlighted in Programming Pitfalls boxes. End-of-chapter materials include summaries of the Good Programming Practice boxes and summaries of Fortran statements and structures. Finally, a detailed description of every Fortran 90/95 intrinsic procedure is included in Appendix B, and an extensive glossary appears as Appendix D.

    A very important pedagogical feature of the book is the LAPACK subset library and the BOOKLIB library, which are supplied on a diskette that accompanies the instructor's manual and are available for download at the book's Web site http://auth.mhhe.com/engineering/chapman. The instructor can compile and install these libraries on whatever computer is being used to teach Fortran, and the students can use them to learn how to choose and link to library subroutines.

    The book is accompanied by an instructor's manual, containing the solutions to all end-of-chapter exercises and the descriptions of the LAPACK subset and BOOKLIB libraries. The instructor's manual comes with a floppy disk containing the source code for all examples in the book, all end-of-chapter exercises, the LAPACK subset library and BOOKLIB library, and a few useful utilities such as one to convert a fixed-source form program to free form.

A Brief Note About Fortran Compilers

    Three Fortran 90 compilers were used during the preparation of this book: the Lahey Fortran 90 compiler, the Microsoft Fortran Powerstation version 4.0, and NAGWare Fortran 90 compiler. After this book was in production, Microsoft dropped all of its Fortran products, and all future development of the product was taken over by Digital Equipment Corporation (DEC). Therefore, any reference to Microsoft Fortran in this book may be considered a reference to DEC Fortran.

References to all three compiler vendors may be found at this book's World Wide Web site.

A Final Note to the User

    No matter how hard I try to proofread a document like this book, it is inevitable that some typographical errors will slip through and appear in print. If you should spot any such errors, please drop me a note via the publisher, and I will do my best to get them eliminated from subsequent printings and editions. Thank you very much for your help in this matter.

    I will maintain a complete list of errata and corrections at the book's World Wide Web site, which is http://auth.mhhe.com/engineering/chapman. Please check that site for any updates and/or corrections.

Acknowledgments

    I would like to thank Mr. Bob Runyan of Lahey Computer Systems, Inc., for providing me with copies of Lahey's Fortran 90 compiler to use while developing this book. Lahey was also kind enough to allow the readers of this book to purchase its ELF90 compiler at a discount. I would like to thank Mr. Sunil Alagade of Microsoft Corporation for providing me with a copy of Microsoft Fortran Powerstation 4.0 Professional, and Ms. Margaret Day of NAG, Ltd., for providing me with a copy of the NAGWare Fortran 90 compiler. I have been able to ensure that every example is compatible with all three compilers.

    I would especially like to thank Eric Munson and the staff at McGraw-Hill for publishing this book after the project was dropped when my previous publisher was purchased by Addison-Wesley.

    Finally, I would like to thank my wife Rosa and our children Avi, David, Rachel, Aaron, Sarah, Naomi, and Shira for putting up with me during the two years it took me to finish this book. Sometimes it seemed that it would never end. Maybe we'll see more of each other now!

Stephen J. Chapman
Adelaide, South Australia
September 24, 1996

Return to Fortran 90/95 Home | MHHE Home

feedback form | permissions | international | locate your campus rep | request a review copy

digital solutions | publish with us | customer service | mhhe home


Copyright ©2001 The McGraw-Hill Companies.
Any use is subject to the Terms of Use and Privacy Policy.
McGraw-Hill Higher Education is one of the many fine businesses of the The McGraw-Hill Companies.