Fortran 90 Handbook - 90 Fortran 90 Handbook is a definitive and comprehensive guide to Fortran 90 ... Fortran 90, including those familiar with programming language concepts but

Download Fortran 90 Handbook -   90   Fortran 90 Handbook is a definitive and comprehensive guide to Fortran 90 ... Fortran 90, including those familiar with programming language concepts but

Post on 07-Feb-2018

219 views

Category:

Documents

5 download

Embed Size (px)

TRANSCRIPT

  • Fortran 90 HandbookComplete ANSI / ISO Reference

    Jeanne C. AdamsWalter S. Brainerd

    Jeanne T. MartinBrian T. Smith

    Jerrold L. Wagener

    Intertext PublicationsMcGraw-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 rightsreserved. Printed in the United States of America. Except as permitted under the United States Copyright Act of 1976, no part ofthis book may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system without theprior 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 10023McGraw-Hill Book Company 1221 Avenue of the Americas New York, NY 10020

    Composition by UNICOMP

  • iii

    Preface

    The Fortran 90 Handbook is a definitive and comprehensive guide to Fortran 90and its use. Fortran 90, the latest standard version of Fortran, has manyexcellent new features that will assist the programmer in writing efficient,portable, and maintainable programs. The Fortran 90 Handbook is an informaldescription of Fortran 90, developed to provide not only a readableexplanation of features, but also some rationale for the inclusion of featuresand their use. In addition, models give the reader better insight as to whythings are done as they are in the language.

    This handbook is intended for anyone who wants a comprehensive survey ofFortran 90, including those familiar with programming language concepts butunfamiliar with Fortran. Experienced Fortran 77 programmers will be able touse this volume to assimilate quickly those features in Fortran 90 that are notin Fortran 77 (Fortran 90 is a superset of Fortran 77).

    Chapter 0 provides a brief overview of several of the most important featuresthat are new in Fortran 90. Chapters 114 correspond to Sections 114 in thestandard. (The standard is the complete official description of the language,but it is written in a legally airtight, formal style without tutorial material andcan be difficult to understand in places.) The handbook and the standard canbe examined in parallel for insights into the Fortran language. This makes itfeasible to use this handbook to decipher the standard, and this is an idealuse of this book.

    Although the handbook is written for use in conjunction with the standard, itis also designed as a practical stand-alone description of Fortran 90. In theinterest of readability, a few of the more obscure aspects of the standard may

  • iv FORTRAN Users Guide

    not be treated rigorously; any such cases should not impact the usefulness ofthis handbook in describing Fortran 90. On the other hand, in places where thestandard is not completely clear, a reasonable interpretation is often given,together with ways to implement and program that will avoid potentialproblems due to misinterpretation of the standard. Of course, if information isbeing sought to understand a fine point of compiler implementation, settle abet, 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 theappendices, and these can serve as continual concise references for Fortran 90.

    Other Sources of InformationOther 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 inChapter 13.

    The complete syntax of Fortran 90 may be found in Appendix B. The syntaxrules are numbered exactly as they are in the Fortran standard. There is across reference that lists, for each nonterminal syntactic term, the number ofthe 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, andAdams (Unicomp, Albuquerque, NM, 1993) is more appropriate.

    Style of the Programming ExamplesIn order to illustrate many features of the language and as many uses of thesefeatures as possible, no single particular style has been used when writing theexamples. In many cases, the style illustrated is not necessarily one that theauthors recommend.

  • v

    AcknowledgmentsMaterial in the appendices of this book was developed by the ANSI committeeX3J3 and the ISO committee SC22/WG5 for inclusion in the Fortran 90standard ISO/IEC 1539 : 1991. This material is reprinted with the permission ofthe International Standards Organization.

    Comments provided by Charles Goldberg have increased the accuracy andreadability of this book enormously.

    CopyrightFortran 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 CopiesPrinted copies of this book may be obtained by ordering from

    Unicomp, Inc.1874 San Bernardino Ave NEAlbuquerque, 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, walt@fortran.com

    Jeanne. T. Martin

    Brian T. Smith

    Jerrold L. Wagener

    January 1992

  • vi FORTRAN Users Guide

  • vii

    Copyright 1992 J. Adams, W. Brainerd, J. Martin, B. Smith, and J. Wagener

    Table of Contents

    Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iii

    Sneak Preview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    1.1 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.2 Why a New Standard? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151.3 Why Not Use Another Language? . . . . . . . . . . . . . . . . . . . 171.4 Development of Fortran 90 . . . . . . . . . . . . . . . . . . . . . . . . . 181.5 Fortran 77 Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . 191.6 Extensibility. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201.7 Intrinsic and Standard Modules . . . . . . . . . . . . . . . . . . . . . 201.8 The Fortran 90 Language Standard . . . . . . . . . . . . . . . . . . 211.9 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

    2. Fortran Concepts and Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

    2.1 Scope and Association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272.2 Program Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352.3 Data Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392.4 Program Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432.5 Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462.6 Summary of Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522.7 Ordering Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

  • viii Fortran 90 Handbook

    Copyright 1992 J. Adams, W. Brainerd, J. Martin, B. Smith, and J. Wagener

    2.8 Example Fortran 90 Program . . . . . . . . . . . . . . . . . . . . . . . 592.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

    3. Language Elementsand Source Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

    3.1 The Processor Character Set . . . . . . . . . . . . . . . . . . . . . . . . 663.2 Lexical Tokens. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693.3 Source Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733.4 Rules for Fixed/Free Source Form . . . . . . . . . . . . . . . . . . . 823.5 The INCLUDE Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 833.6 Low-Level Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

    4. Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

    4.1 Building the Data Environment for a Problem Solution . 914.2 What Is Meant by Type in Fortran? . . . . . . . . . . . . . . . . 964.3 Intrinsic Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 994.4 Derived Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1104.5 Structure Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1214.6 Array Constructors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1244.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

    5. Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131

    5.1 Type Declaration Statements. . . . . . . . . . . . . . . . . . . . . . . . 1345.2 Implicit Typing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1425.3 Array Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1445.4 Pointer Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1525.5 Value Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1555.6 Object Accessibility and Use . . . . . . . . . . . . . . . . . . . . . . . . 1615.7 Procedure Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1715.8 Automatic Data Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1745.9 NAMELIST Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

    5.10 Storage Association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1765.11 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186

  • Table of Contents ix

    Copyright 1992 J. Adams, W. Brainerd, J. Martin, B. Smith, and J. Wagener

    6. Using Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197

    6.1 Constants and Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 1996.2 Substrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2016.3 Structure Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2036.4 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2056.5 Pointers and Allocatable Arrays. . . . . . . . . . . . . . . . . . . . . 2156.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222

    7. Expressions and Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . 227

    7.1 Introduction to Fortran 90 Expressions . . . . . . . . . . . . . . . 2287.2 Formation of Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 2347.3 Interpretation of Expressions . . . . . . . . . . . . . . . . . . . . . . . 2767.4 Evaluation of Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 2847.5 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2907.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303

    8. Controlling Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

    8.1 The Execution Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . 3108.2 Blocks and Executable Constructs . . . . . . . . . . . . . . . . . . . 3108.3 IF Construct and IF Statement . . . . . . . . . . . . . . . . . . . . . . 3128.4 The CASE Construct. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3168.5 The DO Construct. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3218.6 Branching. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3338.7 Obsolescent Control Statements . . . . . . . . . . . . . . . . . . . . . 3378.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341

    9. Input and Output Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . 345

    9.1 Records, Files, Access Methods, and Units . . . . . . . . . . . . 3469.2 Data Transfer Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . 3599.3 Execution Model for Data Transfer Statements . . . . . . . . 3899.4 Error and Other Conditions in Input/Output Statements 3929.5 The OPEN Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3959.6 The CLOSE Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4059.7 Inquiring about Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4089.8 File Positioning Statements . . . . . . . . . . . . . . . . . . . . . . . . . 417

  • x Fortran 90 Handbook

    Copyright 1992 J. Adams, W. Brainerd, J. Martin, B. Smith, and J. Wagener

    9.9 Restrictions: I/O Specifiers, List Items, and Statements . 4229.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423

    10. Input and Output Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427

    10.1 Explicit Formatting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42910.2 Format Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43210.3 Character String Edit Descriptor Form . . . . . . . . . . . . . . . 43510.4 Formatted Data Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . 43610.5 File Positioning by Format Control . . . . . . . . . . . . . . . . . . 44110.6 Numeric Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44210.7 Logical Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45510.8 Character Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45610.9 Control Edit Descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . 457

    10.10 List-Directed Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . 46510.11 Namelist Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47110.12 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480

    11. Program Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483

    11.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48311.2 Main Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48511.3 Internal Procedures . . . . . . . . . . . . . . . . . . . . . ....

Recommended

View more >