Fortran 77 Version 5.0

Download Fortran 77 Version 5.0

Post on 03-Apr-2018

218 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • 7/28/2019 Fortran 77 Version 5.0

    1/372

    FORTRAN 77 Language Reference

    FORTRAN 77 Version 5.0

    901 San Antonio RoadPalo Alto, , CA 94303-4900

    USA 650 960-1300 fax 650 969-9131

    Part No: 805-4939Revision A, February 1999

  • 7/28/2019 Fortran 77 Version 5.0

    2/372

    Copyright Copyright 1999 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California 94303-4900 U.S.A. All rights reserved.

    All rights reserved. This product or document is protected by copyright and distributed under licenses restricting its use, copying,distribution, and decompilation. No part of this product or document may be reproduced in any form by any means without prior writtenauthorization of Sun and its licensors, if any.

    Portions of this product may be derived from the UNIX system, licensed from Novell, Inc., and from the Berkeley 4.3 BSD system,licensed from the University of California. UNIX is a registered trademark in the United States and in other countries and is exclusivelylicensed by X/Open Company Ltd. Third-party software, including font technology in this product, is protected by copyright and licensedfrom Suns suppliers. RESTRICTED RIGHTS: Use, duplication, or disclosure by the U.S. Government is subject to restrictions of FAR52.227-14(g)(2)(6/87) and FAR 52.227-19(6/87), or DFAR 252.227-7015(b)(6/95) and DFAR 227.7202-3(a).

    Sun, Sun Microsystems, the Sun logo, SunDocs, SunExpress, Solaris, Sun Performance Library, Sun Performance WorkShop, Sun VisualWorkShop, Sun WorkShop, and Sun WorkShop Professional are trademarks or registered trademarks of Sun Microsystems, Inc. in theUnited States and in other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARCInternational, Inc. in the United States and in other countries. Products bearing SPARC trademarks are based upon an architecturedeveloped by Sun Microsystems, Inc.

    The OPEN LOOK and SunTM

    Graphical User Interfaces were developed by Sun Microsystems, Inc. for its users and licensees. Sunacknowledges the pioneering efforts of Xerox Corporation in researching and developing the concept of visual or graphical user interfacesfor the computer industry. Sun holds a nonexclusive license from Xerox to the Xerox Graphical User Interface, which license also coversSuns licensees who implement OPEN LOOK GUIs and otherwise comply with Suns written license agreements.

    THIS PUBLICATION IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, ORNON-INFRINGEMENT.

    Copyright 1999 Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, Californie 94303-4900 U.S.A. Tous droits rservs.

    Ce produit ou document est protg par un copyright et distribu avec des licences qui en restreignent lutilisation, la copie et ladcompilation. Aucune partie de ce produit ou de sa documentation associe ne peut tre reproduite sous aucune forme, par quelquemoyen que ce soit, sans lautorisation pralable et crite de Sun et de ses bailleurs de licence, sil y en a.

    Des parties de ce produit pourront tre derives du systme UNIX licenci par Novell, Inc. et du systme Berkeley 4.3 BSD licenci parlUniversit de Californie. UNIX est une marque enregistre aux Etats-Unis et dans dautres pays, et licencie exclusivement par X/OpenCompany Ltd. Le logiciel dtenu par des tiers, et qui comprend la technologie relative aux polices de caractres, est protg par uncopyright et licenci par des fournisseurs de Sun.

    Sun, Sun Microsystems, le logo Sun, SunDocs, SunExpress, Solaris, Sun Performance Library, Sun Performance WorkShop, Sun VisualWorkShop, Sun WorkShop, et Sun WorkShop Professional sont des marques dposes ou enregistres de Sun Microsystems, Inc. auxEtats-Unis et dans dautres pays. Toutes les marques SPARC, utilises sous licence, sont des marques dposes ou enregistres de SPARCInternational, Inc. aux Etats-Unis et dans dautres pays. Les produits portant les marques SPARC sont bass sur une architecturedveloppe par Sun Microsystems, Inc.

    Les utilisateurs dinterfaces graphiques OPEN LOOK et SunTM

    ont t dvelopps de Sun Microsystems, Inc. pour ses utilisateurs etlicencis. Sun reconnat les efforts de pionniers de Xerox Corporation pour la recherche et le dveloppement du concept des interfacesdutilisation visuelle ou graphique pour lindustrie de linformatique. Sun dtient une licence non exclusive de Xerox sur linterfacedutilisation graphique, cette licence couvrant aussi les licencis de Sun qui mettent en place les utilisateurs dinterfaces graphiques OPENLOOK et qui en outre se conforment aux licences crites de Sun.

    CETTE PUBLICATION EST FOURNIE "EN LETAT" SANS GARANTIE DAUCUNE SORTE, NI EXPRESSE NI IMPLICITE, Y COMPRIS,ET SANS QUE CETTE LISTE NE SOIT LIMITATIVE, DES GARANTIES CONCERNANT LA VALEUR MARCHANDE, LAPTITUDE DESPRODUITS A REPONDRE A UNE UTILISATION PARTICULIERE OU LE FAIT QUILS NE SOIENT PAS CONTREFAISANTS DEPRODUITS DE TIERS.

    PleaseRecycle

  • 7/28/2019 Fortran 77 Version 5.0

    3/372

    Contents

    Preface xix

    1. Elements of FORTRAN 1

    Standards Conformance 1

    Extensions 2

    Basic Terms 2

    Character Set 2

    Symbolic Names 4

    Program Units 6

    Statements 7

    Executable and Nonexecutable Statements 7

    FORTRAN Statements 7

    Source Line Formats 8

    Standard Fixed Format 9

    Tab-Format 9

    Mixing Formats 9

    Continuation Lines 9

    Extended Lines 10

    Padding 10

    Comments and Blank Lines 10

    Contents iii

  • 7/28/2019 Fortran 77 Version 5.0

    4/372

    Directives 11

    2. Data Types and Data Items 13

    Types 13

    Rules for Data Typing 13

    Array Elements 14

    Functions 14Properties of Data Types 15

    Size and Alignment of Data Types 20

    Constants 24

    Character Constants 24

    Complex Constants 27

    COMPLEX*16 Constants 27

    COMPLEX*32 (Quad Complex) Constants 27

    Integer Constants 28

    Logical Constants 29

    Real Constants 29

    REAL*8 (Double-Precision Real) Constants 31

    REAL*16 (Quad Real) Constants 32

    Typeless Constants (Binary, Octal, Hexadecimal) 32

    Fortran 90-Style Constants @ 36

    Variables 36

    Arrays 37

    Array Declarators 37

    Array Names with No Subscripts 40

    Array Subscripts 40

    Array Ordering 42

    Substrings 43

    Structures 45

    iv FORTRAN 77 Language Reference Revision A, February 1999

  • 7/28/2019 Fortran 77 Version 5.0

    5/372

    Syntax 45

    Field Declaration 45

    Rules and Restrictions for Structures 46

    Rules and Restrictions for Fields 46

    Record Declaration 47

    Record and Field Reference 48Substructure Declaration 49

    Unions and Maps 50

    Pointers 52

    Syntax Rules 52

    Usage of Pointers 53

    Address and Memory 53

    Optimization and Pointers 55

    3. Expressions 59

    Expressions, Operators, and Operands 59

    Arithmetic Expressions 60

    Basic Arithmetic Expressions 61

    Mixed Mode 62

    Arithmetic Assignment 65

    Character Expressions 66

    Character String Assignment 67

    Rules of Assignment 69

    Logical Expressions 69

    Relational Operator 72

    Constant Expressions 73

    Record Assignment 74

    Evaluation of Expressions 75

    4. Statements 77

    Contents v

  • 7/28/2019 Fortran 77 Version 5.0

    6/372

    ACCEPT 77

    Description 78

    ASSIGN 78

    Description 78

    Restrictions 78

    Examples 79Assignment 79

    Description 80

    Examples 82

    AUTOMATIC 84

    Description 84

    Restrictions 84

    Examples 85

    Restrictions 85

    BACKSPACE 85

    Description 86

    Examples 86

    BLOCK DATA 87

    Description 87

    Restrictions 88

    Example 88

    BYTE 88

    Description 89

    Example 89

    CALL 89

    Description 89

    Examples 91

    CHARACTER 92

    vi FORTRAN 77 Language Reference Revision A, February 1999

  • 7/28/2019 Fortran 77 Version 5.0

    7/372

    Description 93

    Examples 93

    CLOSE 95

    Description 95

    Comments 96

    Examples 96COMMON 97

    Description 97

    Restrictions 97

    Examples 98

    COMPLEX 98

    Description 99

    Comments 100

    Examples 100

    CONTINUE 101

    Description 101

    Example 101

    DATA 102

    Description 102

    Examples 104

    DECODE/ENCODE 105

    Description 105

    Example 106

    DIMENSION 107

    Description 107

    Examples 108

    DO 109

    Description 110

    Contents vii

  • 7/28/2019 Fortran 77 Version 5.0

    8/372

    Restrictions 112

    Comments 112

    Examples 112

    DO WHILE 113

    Description 114

    Restrictions 115Comments 115

    Examples 116

    DOUBLE COMPLEX 116

    Description 116

    Comments 117

    DOUBLE PRECISION 117

    Description 118

    Example 118

    ELSE 118

    Description 119

    Restrictions 119

    Examples 119

    ELSE IF 120

    Description 120

    Restrictions 121

    Example 121

    ENCODE/DECODE 121

    Description 122

    Example 122

    END 122

    Description 122

    Example 123

    viii FORTRAN 77 Language Reference Revision A, February 1999

  • 7/28/2019 Fortran 77 Version 5.0

    9/372

    END DO 123

    Description 123

    Examples 123

    END FILE 124

    Description 124

    Restrictions 125Examples 125

    END IF 125

    Description 126

    Examples 126

    END MAP 126

    Description 126

    Restrictions 126

    Example 127

    END STRUCTURE 127

    Description 127

    Example 127

    END UNION 127

    Description 128

    Example 128

    ENTRY 128

    Description 128

    Restrictions 129

    Examples 129

    EQUIVALENCE 130

    Description 131

    Restrictions 131

    Example 132

    Contents ix

  • 7/28/2019 Fortran 77 Version 5.0

    10/372

    EXTERNAL 132

    Description 133

    Restrictions 133

    Examples 133

    FORMAT 134

    Description 136Restrictions 137

    Warnings 137

    Examples 137

    FUNCTION (External) 138

    Description 140

    Restrictions 141

    Examples 141

    GO TO (Assigned) 142

    Description 142

    Restrictions 143

    Example 143

    GO TO (Computed) 143

    Description 144

    Restrictions 144

    Example 144

    GO TO (Unconditional) 145

    Description 145

    Restrictions 145

    Example 145

    IF (Arithmetic) 145

    Description 146

    Example 146

    x FORTRAN 77 Language Reference Revision A, February 1999

  • 7/28/2019 Fortran 77 Version 5.0

    11/372

    IF (Block) 146

    Description 147

    Restrictions 148

    Examples 148

    IF (Logical) 149

    Description 149Example 150

    IMPLICIT 150

    Description 152

    Restrictions 152

    Examples 153

    INCLUDE 154

    Description 154

    Examples 155

    INQUIRE 156

    Description 157

    Examples 162

    INTEGER 163

    Description 163

    Restrictions 164

    Examples 164

    INTRINSIC 164

    Description 165

    Restrictions 165

    LOGICAL 166

    Description 167

    Examples 168

    MAP 168

    Contents xi

  • 7/28/2019 Fortran 77 Version 5.0

    12/372

    Description 168

    Example 169

    NAMELIST 169

    Description 169

    Restrictions 170

    Example 170OPEN 171

    Description 171

    Examples 176

    OPTIONS 178

    Description 178

    Restrictions 179

    Example 179

    PARAMETER 179

    Description 180

    Restrictions 180

    Examples 181

    PAUSE 182

    Description 182

    POINTER 183

    Description 183

    Examples 184

    PRINT 186

    Description 187

    Restrictions 188

    Examples 188

    PROGRAM 189

    Description 189

    xii FORTRAN 77 Language Reference Revision A, February 1999

  • 7/28/2019 Fortran 77 Version 5.0

    13/372

    Restrictions 190

    Example 190

    READ 190

    Description 191

    Examples 194

    REAL 196Description 196

    Examples 197

    RECORD 198

    Description 198

    Restrictions 198

    Example 199

    RETURN 200

    Description 200

    Examples 200

    REWIND 201

    Description 202

    Examples 202

    SAVE 202

    Description 203

    Restrictions 203

    Example 203

    Statement Function 204

    Description 204

    Restrictions 205

    Examples 205

    STATIC 206

    Description 206

    Contents xiii

  • 7/28/2019 Fortran 77 Version 5.0

    14/372

    Example 207

    STOP 207

    Description 207

    Examples 208

    STRUCTURE 208

    Description 209Restrictions 209

    Restrictions for Fields 209

    Examples 210

    SUBROUTINE 211

    Description 211

    Examples 212

    TYPE 213

    Description 213

    Example 213

    The Type Statement 214

    Description 216

    Restrictions 217

    Example 217

    UNION and MAP 217

    Description 218

    Example 218

    VIRTUAL 219

    Description 219

    Example 219

    VOLATILE 220

    Description 220

    Example 220

    xiv FORTRAN 77 Language Reference Revision A, February 1999

  • 7/28/2019 Fortran 77 Version 5.0

    15/372

    WRITE 220

    Description 221

    Restrictions 224

    Comments 224

    Examples 225

    5. Input and Output 227Essential FORTRAN I/O Concepts 227

    Logical Units 227

    I/O Errors 228

    General Restriction 228

    Kinds of I/O 229

    Combinations of I/O 229

    Printing Files 230

    Special Uses of OPEN 231

    Scratch Files 232

    Changing I/O Initialization with IOINIT 232

    Direct Access 234

    Unformatted I/O 234

    Formatted I/O 235

    Internal Files 235

    Sequential Formatted I/O 235

    Direct Access I/O 235

    Formatted I/O 236

    Input Actions 236

    Output Actions 237

    Format Specifiers 237

    Runtime Formats 267

    Variable Format Expressions () 268

    Contents xv

  • 7/28/2019 Fortran 77 Version 5.0

    16/372

    Unformatted I/O 269

    Sequential Access I/O 269

    Direct Access I/O 270

    List-Directed I/O 271

    Output Format 272

    Unquoted Strings 274Internal I/O 275

    NAMELIST I/O 275

    Syntax Rules 275

    Restrictions 276

    Output Actions 277

    Input Actions 278

    Data Syntax 278

    Name Requests 282

    6. Intrinsic Functions 283

    Arithmetic and Mathematical Functions 284

    Arithmetic 284

    Type Conversion 286

    Trigonometric Functions 288

    Other Mathematical Functions 291

    Character Functions 292

    Miscellaneous Functions 294

    Bit Manipulation @ 294

    Environmental Inquiry Functions @ 295

    Memory @ 296

    Remarks 296

    Notes on Functions 298

    VMS Intrinsic Functions 302

    xvi FORTRAN 77 Language Reference Revision A, February 1999

  • 7/28/2019 Fortran 77 Version 5.0

    17/372

    VMS Double-Precision Complex 302

    VMS Degree-Based Trigonometric 302

    VMS Bit-Manipulation 303

    VMS Multiple Integer Types 305

    Functions Coerced to a Particular Type 306

    Functions Translated to a Generic Name 307Zero Extend 307

    A. ASCII Character Set 309

    B. Sample Statements 313

    C. Data Representations 329

    Real, Double, and Quadruple Precision 329

    Extreme Exponents 330

    Zero (signed) 330

    Subnormal Number 330

    Signed Infinity 330

    Not a Number (NaN) 330

    IEEE Representation of Selected Numbers 331

    Arithmetic Operations on Extreme Values 331

    Bits and Bytes by Architecture 334

    D. VMS Language Extensions 337

    Background 337

    VMS Language Features in Sun Fortran 337

    VMS Features Requiring -xl or -vax=spec 341

    Summary of Features That Require -xl[d] 341

    Details of Features That Require -xl[d] 341

    Unsupported VMS FORTRAN 344

    Index 347

    Contents xvii

  • 7/28/2019 Fortran 77 Version 5.0

    18/372

    xviii FORTRAN 77 Language Reference Revision A, February 1999

  • 7/28/2019 Fortran 77 Version 5.0

    19/372

    Preface

    This manual provides a reference to the Fortran 77 language accepted by the SunTM

    FORTRAN 5.0 compiler f77.

    Who Should Use This BookThis is a reference manual intended for programmers with a working knowledge ofthe Fortran language and some understanding of the Solaris

    TM

    operating environmentand UNIX commands.

    How This Book Is OrganizedThis book is organized into the following chapters and appendixes:

    Chapter 1, "Elements of FORTRAN" introduces the basic parts of Sun FORTRAN 77,standards conformance, and elements of the language.

    Chapter 2, "Data Types and Data Items" describes the data types and data structuresin the language, including arrays, substrings, structures, and pointers.

    Chapter 3, "Expressions" discusses FORTRAN expressions and how they areevaluated.

    Chapter 4, "Statements" details the statements in the FORTRAN 77 language and theextensions recognized by the Sun compiler.

    Preface xix

  • 7/28/2019 Fortran 77 Version 5.0

    20/372

    Chapter 5, "Input and Output" describes the general concepts of FORTRAN input/output and provides details on the different I/O operations.

    Chapter 6, "Intrinsic Functions" tabulates and explains the intrinsic functions that arepart of Sun FORTRAN 77, including VAX VMS extensions.

    Appendix A, "ASCII Character Set" lists the standard ASCII character set.

    Appendix B, "Sample Statements" shows samples of selected FORTRAN 77statements...

Recommended

View more >