Fortran 90 Handbook Complete ANSI / ISO Reference
Total Page:16
File Type:pdf, Size:1020Kb
Fortran 90 Handbook Complete ANSI / ISO Reference Jeanne C. Adams Walter S. Brainerd Jeanne T. Martin Brian T. Smith Jerrold L. Wagener Intertext Publications McGraw-Hill Book Company Library of Congress Catalog Card Number 91-77211 Copyright © 1992 by Jeanne C. Adams, Walter S. Brainerd, Jeanne T. Martin, Brian T. Smith, and Jerrold L. Wagener. All rights reserved. Printed in the United States of America. Except as permitted under the United States Copyright Act of 1976, no part of this book may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system without the prior written permission of the authors and the publisher. 10 9 8 7 6 5 4 3 2 1 ISBN 0-07-000406-4 Intertext Publications/Multiscience Press, Inc. One Lincoln Plaza New York, NY 10023 McGraw-Hill Book Company 1221 Avenue of the Americas New York, NY 10020 Composition by UNICOMP Preface The Fortran 90 Handbook is a definitive and comprehensive guide to Fortran 90 and its use. Fortran 90, the latest standard version of Fortran, has many excellent new features that will assist the programmer in writing efficient, portable, and maintainable programs. The Fortran 90 Handbook is an informal description of Fortran 90, developed to provide not only a readable explanation of features, but also some rationale for the inclusion of features and their use. In addition, “models” give the reader better insight as to why things are done as they are in the language. This handbook is intended for anyone who wants a comprehensive survey of Fortran 90, including those familiar with programming language concepts but unfamiliar with Fortran. Experienced Fortran 77 programmers will be able to use this volume to assimilate quickly those features in Fortran 90 that are not in Fortran 77 (Fortran 90 is a superset of Fortran 77). Chapter 0 provides a brief overview of several of the most important features that are new in Fortran 90. Chapters 1–14 correspond to Sections 1–14 in the standard. (The standard is the complete official description of the language, but it is written in a legally airtight, formal style without tutorial material and can be difficult to understand in places.) The handbook and the standard can be examined in parallel for insights into the Fortran language. This makes it feasible to use this handbook to “decipher” the standard, and this is an ideal use of this book. Although the handbook is written for use in conjunction with the standard, it is also designed as a practical stand-alone description of Fortran 90. In the interest of readability, a few of the more obscure aspects of the standard may iii not be treated rigorously; any such cases should not impact the usefulness of this handbook in describing Fortran 90. On the other hand, in places where the standard is not completely clear, a reasonable interpretation is often given, together with ways to implement and program that will avoid potential problems due to misinterpretation of the standard. Of course, if information is being sought to understand a fine point of compiler implementation, settle a bet, resolve a court case, or determine the answer to a Fortran trivia question, the standard itself should be considered the final authority. The syntactic features of the language are described completely in the appendices, and these can serve as continual concise references for Fortran 90. Other Sources of Information Other parts of the book can be used to help find information. • Each of the intrinsic functions is described in detail in Appendix A, although a general discussion of the intrinsic functions is included in Chapter 13. • The complete syntax of Fortran 90 may be found in Appendix B. The syntax rules are numbered exactly as they are in the Fortran standard. There is a cross reference that lists, for each nonterminal syntactic term, the number of the rule in which it is defined, and all rules in which it is referenced. • Appendix C contains a listing of the obsolescent features. • The index is unusually comprehensive. • There is an index of examples, giving the location of program examples that illustrate the use of many Fortran 90 features. For an informal and tutorial approach to learning Fortran 90, the book, Programmers Guide to Fortran 90, Second Edition, by Brainerd, Goldberg, and Adams (Unicomp, Albuquerque, NM, 1993) is more appropriate. Style of the Programming Examples In order to illustrate many features of the language and as many uses of these features as possible, no single particular style has been used when writing the examples. In many cases, the style illustrated is not necessarily one that the authors recommend. iv FORTRAN User’s Guide Acknowledgments Material in the appendices of this book was developed by the ANSI committee X3J3 and the ISO committee SC22/WG5 for inclusion in the Fortran 90 standard ISO/IEC 1539 : 1991. This material is reprinted with the permission of the International Standards Organization. Comments provided by Charles Goldberg have increased the accuracy and readability of this book enormously. Copyright Fortran 90 Handbook is reproduced herein with the permission of McGraw- Hill, Inc., Copyright 1992, by Walter S. Brainerd, Jeanne C. Adams, Jeanne T. Martin, Brian T. Smith, and Jerrold L. Wagener. All rights reserved. Printed Copies Printed copies of this book may be obtained by ordering from Unicomp, Inc. 1874 San Bernardino Ave NE Albuquerque, NM 87122 USA +1-505-275-0800 +1-505-856-1501 (fax) Visit the Fortran market: http://www.fortran.com/fortran The home page includes how to order this book in hard copy. Jeanne C. Adams Walter S. Brainerd, [email protected] Jeanne. T. Martin Brian T. Smith Jerrold L. Wagener January 1992 v vi FORTRAN User’s Guide Table of Contents Preface. iii Sneak Preview . 1 1. Introduction . 13 1.1 History . 13 1.2 Why a New Standard? . 15 1.3 Why Not Use Another Language? . 17 1.4 Development of Fortran 90 . 18 1.5 Fortran 77 Compatibility . 19 1.6 Extensibility. 20 1.7 Intrinsic and Standard Modules . 20 1.8 The Fortran 90 Language Standard . 21 1.9 References . 24 2. Fortran Concepts and Terms . 27 2.1 Scope and Association . 27 2.2 Program Organization . 35 2.3 Data Environment . 39 2.4 Program Execution . 43 2.5 Terms . 46 2.6 Summary of Forms. 52 2.7 Ordering Requirements . 57 vii Copyright © 1992 J. Adams, W. Brainerd, J. Martin, B. Smith, and J. Wagener 2.8 Example Fortran 90 Program . 59 2.9 Summary . 59 3. Language Elements and Source Form . 65 3.1 The Processor Character Set . 66 3.2 Lexical Tokens. 69 3.3 Source Form . 73 3.4 Rules for Fixed/Free Source Form . 82 3.5 The INCLUDE Line . 83 3.6 Low-Level Syntax. 84 3.7 Summary . 84 4. Data Types . 89 4.1 Building the Data Environment for a Problem Solution . 91 4.2 What Is Meant by “Type” in Fortran? . 96 4.3 Intrinsic Data Types . 99 4.4 Derived Types . 110 4.5 Structure Constructors. 121 4.6 Array Constructors. 124 4.7 Summary . 127 5. Declarations . 131 5.1 Type Declaration Statements. 134 5.2 Implicit Typing . 142 5.3 Array Properties . 144 5.4 Pointer Properties. 152 5.5 Value Attributes . 155 5.6 Object Accessibility and Use . 161 5.7 Procedure Properties . 171 5.8 Automatic Data Objects. 174 5.9 NAMELIST Statement . 175 5.10 Storage Association . 176 5.11 Summary . 186 viii Fortran 90 Handbook Copyright © 1992 J. Adams, W. Brainerd, J. Martin, B. Smith, and J. Wagener 6. Using Data . 197 6.1 Constants and Variables . 199 6.2 Substrings . 201 6.3 Structure Components . 203 6.4 Arrays . 205 6.5 Pointers and Allocatable Arrays. 215 6.6 Summary . 222 7. Expressions and Assignment . 227 7.1 Introduction to Fortran 90 Expressions . 228 7.2 Formation of Expressions . 234 7.3 Interpretation of Expressions . 276 7.4 Evaluation of Expressions . 284 7.5 Assignment . 290 7.6 Summary . 303 8. Controlling Execution . 309 8.1 The Execution Sequence . 310 8.2 Blocks and Executable Constructs . 310 8.3 IF Construct and IF Statement . 312 8.4 The CASE Construct. 316 8.5 The DO Construct. 321 8.6 Branching. 333 8.7 Obsolescent Control Statements . 337 8.8 Summary . 341 9. Input and Output Processing . ..