938
IBM XL Fortran for AIX, V14.1 Language Reference Version 14.1 SC14-7337-00

XL Fortran: Language Reference - Colorado School of Minesgeco.mines.edu/files/manuals/xlf/langref.pdf · 2014-09-01 · IBM XL Fortran for AIX, V14.1 Language Reference Version 141

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

  • IBM XL Fortran for AIX, V14.1

    Language ReferenceVersion 14.1

    SC14-7337-00

    ���

  • IBM XL Fortran for AIX, V14.1

    Language ReferenceVersion 14.1

    SC14-7337-00

    ���

  • NoteBefore using this information and the product it supports, read the information in “Notices” on page 881.

    First edition

    This edition applies to IBM XL Fortran for AIX, V14.1 (Program 5765-J04; 5725-C74) and to all subsequent releasesand modifications until otherwise indicated in new editions. Make sure you are using the correct edition for thelevel of the product.

    © Copyright IBM Corporation 1996, 2012.US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contractwith IBM Corp.

  • Contents

    About this document . . . . . . . . xiiiWho should read this document . . . . . . . xiiiHow to use this document . . . . . . . . . xiiiHow this document is organized . . . . . . . xiiiConventions . . . . . . . . . . . . . . xivRelated information . . . . . . . . . . . xviii

    IBM XL Fortran information . . . . . . . xviiiStandards and specifications . . . . . . . xixOther IBM information . . . . . . . . . xx

    Technical support . . . . . . . . . . . . xxHow to send your comments . . . . . . . . xx

    Chapter 1. XL Fortran for AIX . . . . . 1Fortran language standards . . . . . . . . . 1

    Fortran 2008 . . . . . . . . . . . . . 1Fortran 2003 . . . . . . . . . . . . . 2Fortran 95 . . . . . . . . . . . . . . 2Fortran 90 . . . . . . . . . . . . . . 2FORTRAN 77 . . . . . . . . . . . . . 2IBM extensions . . . . . . . . . . . . 3

    OpenMP API Version 3.1 . . . . . . . . . . 3Standards documents . . . . . . . . . . . 3

    Chapter 2. XL Fortran languagefundamentals . . . . . . . . . . . . 5Characters . . . . . . . . . . . . . . . 5Names . . . . . . . . . . . . . . . . 6Designators . . . . . . . . . . . . . . . 6Operators . . . . . . . . . . . . . . . 7Statements . . . . . . . . . . . . . . . 7

    Statement keywords . . . . . . . . . . . 7Statement labels . . . . . . . . . . . . 7

    Delimiters . . . . . . . . . . . . . . . 7Lines and source formats . . . . . . . . . . 8

    Fixed source form . . . . . . . . . . . 9Free source form. . . . . . . . . . . . 11IBM free source form (IBM extension) . . . . 12Conditional compilation (IBM extension) . . . 13

    Order of statements and execution sequence . . . 14Data types. . . . . . . . . . . . . . . 15

    Type declaration: type parameters and specifiers 15Determining Type . . . . . . . . . . . 17

    Data objects . . . . . . . . . . . . . . 17Constants . . . . . . . . . . . . . . 17Automatic objects . . . . . . . . . . . 18Polymorphic entities (Fortran 2003) . . . . . 18Definition status of variables . . . . . . . 19Allocation status. . . . . . . . . . . . 25Storage classes for variables (IBM extension) . . 26

    Typeless literal constants . . . . . . . . . . 28Hexadecimal constants . . . . . . . . . 28Octal constants . . . . . . . . . . . . 29Binary constants . . . . . . . . . . . . 29Hollerith constants . . . . . . . . . . . 30Using typeless constants . . . . . . . . . 30

    Chapter 3. Intrinsic data types . . . . 35Integer . . . . . . . . . . . . . . . . 35Real . . . . . . . . . . . . . . . . . 36Complex . . . . . . . . . . . . . . . 39Logical . . . . . . . . . . . . . . . . 41Character . . . . . . . . . . . . . . . 42

    Examples of character constants . . . . . . 43Character substrings . . . . . . . . . . 44

    Byte (IBM extension) . . . . . . . . . . . 45Vector (IBM extension). . . . . . . . . . . 45Pixel (IBM extension) . . . . . . . . . . . 46Unsigned (IBM extension) . . . . . . . . . 46

    Chapter 4. Derived types . . . . . . . 47Syntax of a derived type . . . . . . . . . . 47Derived type parameters (Fortran 2003) . . . . . 48Derived type components . . . . . . . . . 49

    Allocatable components . . . . . . . . . 50Pointer components . . . . . . . . . . 51Procedure pointer components . . . . . . . 52Array components . . . . . . . . . . . 53Default initialization for components . . . . . 53Component order . . . . . . . . . . . 54Referencing components . . . . . . . . . 54

    Component and procedure accessibility . . . . . 56Sequence derived types . . . . . . . . . . 57Extensible derived types (Fortran 2003) . . . . . 57Abstract types and deferred bindings (Fortran 2003) 58Derived type Values . . . . . . . . . . . 59Type-bound procedures (Fortran 2003) . . . . . 59

    Syntax of a type-bound procedure . . . . . . 59Specific binding . . . . . . . . . . . . 60Generic binding . . . . . . . . . . . . 61Final binding . . . . . . . . . . . . . 63Procedure overriding . . . . . . . . . . 65

    Finalization (Fortran 2003) . . . . . . . . . 66The finalization process . . . . . . . . . 66When finalization occurs . . . . . . . . . 67

    Determining declared type for derived types . . . 67Structure constructor . . . . . . . . . . . 69

    Chapter 5. Array concepts . . . . . . 73Array basics . . . . . . . . . . . . . . 73

    Bounds of a dimension . . . . . . . . . 73Extent of a dimension . . . . . . . . . . 74Rank, shape, and size of an array . . . . . . 74

    Array declarators . . . . . . . . . . . . 74Explicit-shape arrays . . . . . . . . . . . 75

    Automatic arrays . . . . . . . . . . . 76Adjustable arrays . . . . . . . . . . . 77Pointee arrays (IBM extension) . . . . . . . 77

    Assumed-shape arrays. . . . . . . . . . . 77Implied-shape arrays (Fortran 2008) . . . . . . 78Deferred-shape arrays . . . . . . . . . . . 79

    Allocatable arrays . . . . . . . . . . . 80

    © Copyright IBM Corp. 1996, 2012 iii

  • Array pointers . . . . . . . . . . . . 81Assumed-size arrays . . . . . . . . . . . 82Array elements . . . . . . . . . . . . . 83Array sections . . . . . . . . . . . . . 85

    Subscript triplets . . . . . . . . . . . 86Vector subscripts . . . . . . . . . . . 88Substring ranges. . . . . . . . . . . . 88Array sections and structure components . . . 89Rank and shape of array sections . . . . . . 90

    Array constructors . . . . . . . . . . . . 91Implied-DO list for an array constructor . . . . 93

    Contiguity (Fortran 2008) . . . . . . . . . . 94Expressions involving arrays . . . . . . . . 96

    Chapter 6. Expressions andassignment . . . . . . . . . . . . . 97Introduction to expressions and assignment . . . 97

    Primary . . . . . . . . . . . . . . 97Constant expressions . . . . . . . . . . . 98Specification expressions . . . . . . . . . . 99Operators and expressions . . . . . . . . . 101

    Arithmetic . . . . . . . . . . . . . 101Character. . . . . . . . . . . . . . 104General . . . . . . . . . . . . . . 104Logical . . . . . . . . . . . . . . 105Primary . . . . . . . . . . . . . . 107Relational . . . . . . . . . . . . . 108

    Extended intrinsic and defined operations . . . . 109How expressions are evaluated . . . . . . . 110

    Precedence of operators . . . . . . . . . 110Using BYTE data objects (IBM extension) . . . 112

    Intrinsic assignment . . . . . . . . . . . 113Arithmetic conversion . . . . . . . . . 115

    WHERE construct . . . . . . . . . . . . 116Interpreting masked array assignments . . . . 118

    FORALL construct. . . . . . . . . . . . 122Interpreting the FORALL construct . . . . . 123

    Data pointer assignment. . . . . . . . . . 124Procedure pointer assignment (Fortran 2003) . . . 128Integer pointer assignment (IBM extension) . . . 129

    Chapter 7. Execution control . . . . . 131Statement blocks . . . . . . . . . . . . 131ASSOCIATE Construct (Fortran 2003) . . . . . 131BLOCK construct (Fortran 2008) . . . . . . . 133DO construct . . . . . . . . . . . . . 134

    The terminal statement . . . . . . . . . 135DO WHILE construct. . . . . . . . . . 138

    IF construct . . . . . . . . . . . . . . 139CASE construct. . . . . . . . . . . . . 140SELECT TYPE construct (Fortran 2003) . . . . . 142Associate names . . . . . . . . . . . . 144Branching . . . . . . . . . . . . . . 145CONTINUE statement . . . . . . . . . . 146STOP statement . . . . . . . . . . . . 146ERROR STOP statement (Fortran 2008) . . . . . 146

    Chapter 8. Program units andprocedures . . . . . . . . . . . . 147Scope . . . . . . . . . . . . . . . . 147

    The scope of a name . . . . . . . . . . 148Association . . . . . . . . . . . . . . 152

    Host association . . . . . . . . . . . 152Use association . . . . . . . . . . . . 153Construct Association . . . . . . . . . 154Pointer association . . . . . . . . . . 154Integer pointer association (IBM extension) . . 156

    Program units, procedures, and subprograms. . . 156Internal procedures . . . . . . . . . . 157Interface concepts . . . . . . . . . . . 158

    Interface blocks. . . . . . . . . . . . . 160Generic interface blocks . . . . . . . . . . 163

    Unambiguous generic procedure references . . 163Extending intrinsic procedures with genericinterface blocks . . . . . . . . . . . . 165Defined operators . . . . . . . . . . . 165Defined assignment . . . . . . . . . . 167User-defined derived-type Input/Outputprocedures (Fortran 2003) . . . . . . . . 168

    Abstract interface (Fortran 2003) . . . . . . . 170Main program . . . . . . . . . . . . . 172Modules . . . . . . . . . . . . . . . 173Block data program unit. . . . . . . . . . 175Function and subroutine subprograms . . . . . 177

    Declaring procedures . . . . . . . . . . 178Procedure references . . . . . . . . . . 179

    Intrinsic procedures . . . . . . . . . . . 181Conflicts between intrinsic procedure namesand other names . . . . . . . . . . . 182

    Arguments . . . . . . . . . . . . . . 182Actual argument specification . . . . . . . 182

    Argument association . . . . . . . . . . 184%VAL and %REF (IBM extension) . . . . . 186Intent of dummy arguments . . . . . . . 187Optional dummy arguments . . . . . . . 188The passed-object dummy argument . . . . 188Restrictions on optional dummy arguments notpresent . . . . . . . . . . . . . . 188Length of character arguments . . . . . . 189Variables as dummy arguments . . . . . . 190Allocatable objects as dummy arguments(Fortran 2003) . . . . . . . . . . . . 192Pointers as dummy arguments . . . . . . 193Procedures as dummy arguments . . . . . 194Asterisks as dummy arguments . . . . . . 195

    Resolution of procedure references . . . . . . 196Rules for resolving procedure references tonames . . . . . . . . . . . . . . . 196

    Recursion . . . . . . . . . . . . . . 197Pure procedures . . . . . . . . . . . . 198Elemental procedures. . . . . . . . . . . 200

    Chapter 9. XL Fortran Input/Output 203Records . . . . . . . . . . . . . . . 203

    Formatted records . . . . . . . . . . . 203Unformatted records . . . . . . . . . . 204Endfile records . . . . . . . . . . . . 204

    Files . . . . . . . . . . . . . . . . 204Definition of an external file . . . . . . . 204File access methods . . . . . . . . . . 205

    Units . . . . . . . . . . . . . . . . 206

    iv XL Fortran: Language Reference

  • Connection of a unit . . . . . . . . . . 207Data transfer statements . . . . . . . . . . 208

    Asynchronous Input/Output . . . . . . . 209Advancing and nonadvancing Input/Output 210User-defined derived-type Input/Outputprocedure interfaces (Fortran 2003) . . . . . 211User-defined derived-type Input/Output(Fortran 2003) . . . . . . . . . . . . 211File position before and after data transfer. . . 213

    Conditions and IOSTAT values . . . . . . . 215End-of-record conditions . . . . . . . . 215End-of-file conditions. . . . . . . . . . 215Error conditions . . . . . . . . . . . 216

    Chapter 10. Input/Output formatting 227Format-directed formatting . . . . . . . . . 227

    Complex editing . . . . . . . . . . . 227Data edit descriptors . . . . . . . . . . 227Control edit descriptors . . . . . . . . . 232Character string edit descriptors . . . . . . 233Effective list items (Fortran 2003) . . . . . . 234Interaction of Input/Output lists and formatspecifications . . . . . . . . . . . . 234Comma-separated Input/Output (IBMextension) . . . . . . . . . . . . . 236

    Data edit descriptors . . . . . . . . . . . 237A (Character) Editing. . . . . . . . . . 237B (Binary) Editing . . . . . . . . . . . 237E, D, and Q (Extended Precision) Editing . . . 239DT Editing (Fortran 2003) . . . . . . . . 240EN Editing . . . . . . . . . . . . . 241ES Editing . . . . . . . . . . . . . 242F (Real without Exponent) Editing . . . . . 243G (General) Editing . . . . . . . . . . 244H Editing . . . . . . . . . . . . . 246I (Integer) Editing . . . . . . . . . . . 247L (Logical) Editing. . . . . . . . . . . 248O (Octal) Editing . . . . . . . . . . . 249Q (Character Count) Editing (IBM extension) 250Z (Hexadecimal) Editing . . . . . . . . 251

    Control edit descriptors . . . . . . . . . . 253/ (Slash) Editing . . . . . . . . . . . 253: (Colon) Editing . . . . . . . . . . . 253$ (Dollar) Editing (IBM extension) . . . . . 254BN (Blank Null) and BZ (Blank Zero) Editing 254DC and DP (Decimal) Editing (Fortran 2003) 255P (Scale Factor) Editing . . . . . . . . . 255RC, RD, RN, RP, RU, and RZ (Round) Editing(Fortran 2003) . . . . . . . . . . . . 256S, SP, and SS (Sign Control) Editing . . . . . 257T, TL, TR, and X (Positional) Editing . . . . 257

    List-directed formatting . . . . . . . . . . 259Value separators . . . . . . . . . . . 259List-directed input. . . . . . . . . . . 259List-directed output . . . . . . . . . . 260

    Namelist formatting . . . . . . . . . . . 262Namelist input . . . . . . . . . . . . 263Namelist output . . . . . . . . . . . 267

    Chapter 11. Statements and attributes 271

    Attributes . . . . . . . . . . . . . . 274ABSTRACT (Fortran 2003) . . . . . . . . . 274ALLOCATABLE (Fortran 2003) . . . . . . . 275ALLOCATE . . . . . . . . . . . . . . 277ASSIGN . . . . . . . . . . . . . . . 280ASSOCIATE (Fortran 2003) . . . . . . . . . 281ASYNCHRONOUS . . . . . . . . . . . 282AUTOMATIC (IBM extension). . . . . . . . 283BACKSPACE . . . . . . . . . . . . . 285BIND (Fortran 2003) . . . . . . . . . . . 286BLOCK (Fortran 2008) . . . . . . . . . . 287BLOCK DATA . . . . . . . . . . . . . 288BYTE (IBM extension) . . . . . . . . . . 289CALL . . . . . . . . . . . . . . . . 292CASE . . . . . . . . . . . . . . . . 294CHARACTER . . . . . . . . . . . . . 296CLASS (Fortran 2003) . . . . . . . . . . 300CLOSE . . . . . . . . . . . . . . . 302COMMON . . . . . . . . . . . . . . 304

    Common association . . . . . . . . . . 306COMPLEX . . . . . . . . . . . . . . 307CONTAINS . . . . . . . . . . . . . . 311CONTIGUOUS (Fortran 2008) . . . . . . . . 312CONTINUE . . . . . . . . . . . . . . 314CYCLE . . . . . . . . . . . . . . . 315DATA . . . . . . . . . . . . . . . . 316DEALLOCATE . . . . . . . . . . . . . 319Derived Type . . . . . . . . . . . . . 321DIMENSION . . . . . . . . . . . . . 323DO . . . . . . . . . . . . . . . . . 324DO WHILE . . . . . . . . . . . . . . 325DOUBLE COMPLEX (IBM extension) . . . . . 327DOUBLE PRECISION . . . . . . . . . . 330ELSE . . . . . . . . . . . . . . . . 333ELSE IF . . . . . . . . . . . . . . . 333ELSEWHERE . . . . . . . . . . . . . 334END . . . . . . . . . . . . . . . . 335END (Construct) . . . . . . . . . . . . 337END INTERFACE . . . . . . . . . . . . 340END TYPE . . . . . . . . . . . . . . 341ENDFILE. . . . . . . . . . . . . . . 342ENTRY . . . . . . . . . . . . . . . 344ENUM/END ENUM (Fortran 2003) . . . . . . 347EQUIVALENCE . . . . . . . . . . . . 348ERROR STOP (Fortran 2008) . . . . . . . . 350EXIT . . . . . . . . . . . . . . . . 352EXTERNAL . . . . . . . . . . . . . . 354FLUSH (Fortran 2003) . . . . . . . . . . 355FORALL . . . . . . . . . . . . . . . 357

    Interpreting the FORALL statement . . . . . 359Loop parallelization . . . . . . . . . . 359

    FORALL (construct) . . . . . . . . . . . 360FORMAT . . . . . . . . . . . . . . . 362

    Character format specification . . . . . . . 363FUNCTION . . . . . . . . . . . . . . 364

    Recursion . . . . . . . . . . . . . 367Elemental procedures. . . . . . . . . . 367

    GO TO (assigned) . . . . . . . . . . . . 367GO TO (computed) . . . . . . . . . . . 368GO TO (unconditional) . . . . . . . . . . 369IF (arithmetic) . . . . . . . . . . . . . 370

    Contents v

  • IF (block) . . . . . . . . . . . . . . . 371IF (logical) . . . . . . . . . . . . . . 372IMPLICIT . . . . . . . . . . . . . . 372IMPORT (Fortran 2003) . . . . . . . . . . 375INQUIRE. . . . . . . . . . . . . . . 375INTEGER . . . . . . . . . . . . . . 383INTENT . . . . . . . . . . . . . . . 387INTERFACE. . . . . . . . . . . . . . 389INTRINSIC . . . . . . . . . . . . . . 391LOGICAL . . . . . . . . . . . . . . 393MODULE . . . . . . . . . . . . . . 396NAMELIST . . . . . . . . . . . . . . 397NULLIFY. . . . . . . . . . . . . . . 398OPEN . . . . . . . . . . . . . . . . 399OPTIONAL . . . . . . . . . . . . . . 406PARAMETER . . . . . . . . . . . . . 407PAUSE . . . . . . . . . . . . . . . 408POINTER (Fortran 90) . . . . . . . . . . 409POINTER (integer) (IBM extension) . . . . . . 411PRINT. . . . . . . . . . . . . . . . 413

    Implied-DO List . . . . . . . . . . . 414PRIVATE . . . . . . . . . . . . . . . 414PROCEDURE . . . . . . . . . . . . . 416PROCEDURE declaration (Fortran 2003) . . . . 417PROGRAM . . . . . . . . . . . . . . 420PROTECTED (Fortran 2003) . . . . . . . . 420PUBLIC . . . . . . . . . . . . . . . 422READ . . . . . . . . . . . . . . . . 423

    Implied-DO List . . . . . . . . . . . 431REAL . . . . . . . . . . . . . . . . 431RECORD (IBM extension) . . . . . . . . . 435RETURN . . . . . . . . . . . . . . . 436REWIND . . . . . . . . . . . . . . . 438SAVE . . . . . . . . . . . . . . . . 439SELECT CASE . . . . . . . . . . . . . 441SELECT TYPE (Fortran 2003) . . . . . . . . 442SEQUENCE . . . . . . . . . . . . . . 443Statement Function . . . . . . . . . . . 444STATIC (IBM extension) . . . . . . . . . . 445STOP . . . . . . . . . . . . . . . . 447SUBROUTINE . . . . . . . . . . . . . 449TARGET . . . . . . . . . . . . . . . 451TYPE . . . . . . . . . . . . . . . . 452Type Declaration . . . . . . . . . . . . 456Type Guard (Fortran 2003) . . . . . . . . . 462USE . . . . . . . . . . . . . . . . 463VALUE (Fortran 2003) . . . . . . . . . . 467VECTOR (IBM extension) . . . . . . . . . 468VIRTUAL (IBM extension) . . . . . . . . . 468VOLATILE . . . . . . . . . . . . . . 469WAIT (Fortran 2003) . . . . . . . . . . . 471WHERE . . . . . . . . . . . . . . . 473WRITE . . . . . . . . . . . . . . . 475

    Implied-DO List . . . . . . . . . . . 481

    Chapter 12. Directives (IBM extension) 483Comment and noncomment form directives . . . 483

    Comment form directives . . . . . . . . 483Noncomment form directives . . . . . . . 485

    Directives and optimization . . . . . . . . 486Assertive directives . . . . . . . . . . 486

    Directives for Loop Optimization . . . . . . 486Detailed directive descriptions. . . . . . . . 486

    ALIGN . . . . . . . . . . . . . . 486ASSERT . . . . . . . . . . . . . . 487BLOCK_LOOP . . . . . . . . . . . . 490CNCALL . . . . . . . . . . . . . . 491COLLAPSE . . . . . . . . . . . . . 492EJECT . . . . . . . . . . . . . . . 494EXECUTION_FREQUENCY (IBM extension) 494EXPECTED_VALUE . . . . . . . . . . 495FUNCTRACE_XLF_CATCH . . . . . . . 496FUNCTRACE_XLF_ENTER . . . . . . . 497FUNCTRACE_XLF_EXIT . . . . . . . . 497IGNORE_TKR (IBM extension) . . . . . . 498INCLUDE . . . . . . . . . . . . . 499INDEPENDENT . . . . . . . . . . . 501#LINE . . . . . . . . . . . . . . . 504LOOPID . . . . . . . . . . . . . . 506MEM_DELAY . . . . . . . . . . . . 507NEW . . . . . . . . . . . . . . . 507NOFUNCTRACE . . . . . . . . . . . 508NOSIMD . . . . . . . . . . . . . . 510NOVECTOR. . . . . . . . . . . . . 510PERMUTATION . . . . . . . . . . . 511@PROCESS . . . . . . . . . . . . . 512SNAPSHOT . . . . . . . . . . . . . 513SOURCEFORM. . . . . . . . . . . . 514STREAM_UNROLL . . . . . . . . . . 515SUBSCRIPTORDER . . . . . . . . . . 517UNROLL . . . . . . . . . . . . . . 519UNROLL_AND_FUSE . . . . . . . . . 520

    Chapter 13. Hardware-specificdirectives . . . . . . . . . . . . . 523Cache control . . . . . . . . . . . . . 523

    CACHE_ZERO . . . . . . . . . . . . 523DCBF . . . . . . . . . . . . . . . 523DCBFL . . . . . . . . . . . . . . 524DCBFLP . . . . . . . . . . . . . . 524DCBST . . . . . . . . . . . . . . 524EIEIO . . . . . . . . . . . . . . . 525ISYNC. . . . . . . . . . . . . . . 525LIGHT_SYNC . . . . . . . . . . . . 525

    PREFETCH . . . . . . . . . . . . . . 526DCBTSTT . . . . . . . . . . . . . 526DCBTT . . . . . . . . . . . . . . 527PARTIAL_DCBT . . . . . . . . . . . 527PREFETCH_BY_LOAD . . . . . . . . . 528PREFETCH_BY_STREAM . . . . . . . . 528PREFETCH_FOR_LOAD . . . . . . . . 529PREFETCH_FOR_STORE . . . . . . . . 529PROTECTED_STORE_STREAM_SET . . . . 529PROTECTED_STREAM_COUNT . . . . . . 530PROTECTED_STREAM_COUNT_DEPTH . . . 531PROTECTED_STREAM_GO . . . . . . . 531PROTECTED_STREAM_SET . . . . . . . 532PROTECTED_STREAM_STRIDE . . . . . . 532PROTECTED_STREAM_STOP. . . . . . . 533PROTECTED_STREAM_STOP_ALL . . . . . 533PROTECTED_UNLIMITED_STORE_STREAM_SET . . . . . . . . . . . . . . . 534

    vi XL Fortran: Language Reference

  • PROTECTED_UNLIMITED_STREAM_SET . . 534PROTECTED_UNLIMITED_STREAM_SET_GO 535TRANSIENT_PROTECTED_STREAM_COUNT_DEPTH . . . . . . . . . . . . . . 536TRANSIENT_UNLIMITED_PROTECTED_STREAM_DEPTH . . . . . . . . . . 536UNLIMITED_PROTECTED_STREAM_DEPTH 537Examples . . . . . . . . . . . . . . 537

    Chapter 14. Intrinsic procedures . . . 539Classes of intrinsic procedures. . . . . . . . 539

    Inquiry intrinsic functions . . . . . . . . 539Elemental intrinsic procedures. . . . . . . 539System inquiry intrinsic functions (IBMextension) . . . . . . . . . . . . . 540Transformational intrinsic functions . . . . . 541Intrinsic subroutines . . . . . . . . . . 541

    Data representation models. . . . . . . . . 541Integer bit model . . . . . . . . . . . 541Integer data model . . . . . . . . . . 542Real data model . . . . . . . . . . . 543

    Detailed descriptions of intrinsic procedures . . . 544ABORT() (IBM extension) . . . . . . . . 544ABS(A) . . . . . . . . . . . . . . 545ACHAR(I, KIND) . . . . . . . . . . . 545ACOS(X) . . . . . . . . . . . . . . 546ACOSD(X) (IBM extension). . . . . . . . 547ACOSH(X) (Fortran 2008) . . . . . . . . 548ADJUSTL(STRING) . . . . . . . . . . 548ADJUSTR(STRING) . . . . . . . . . . 549AIMAG(Z), IMAG(Z). . . . . . . . . . 549AINT(A, KIND) . . . . . . . . . . . 550ALIGNX(K,M) (IBM extension) . . . . . . 551ALL(MASK, DIM) . . . . . . . . . . . 551ALLOCATED(X) . . . . . . . . . . . 552ANINT(A, KIND) . . . . . . . . . . . 553ANY(MASK, DIM) . . . . . . . . . . 554ASIN(X) . . . . . . . . . . . . . . 554ASIND(X) (IBM extension) . . . . . . . . 555ASINH(X) (Fortran 2008) . . . . . . . . 556ASSOCIATED(POINTER, TARGET) . . . . . 557ATAN(X) . . . . . . . . . . . . . . 558ATAN(Y, X) (Fortran 2008) . . . . . . . . 559ATAN2(Y, X) . . . . . . . . . . . . 559ATAN2D(Y, X) (IBM extension) . . . . . . 560ATAND(X) (IBM extension). . . . . . . . 561ATANH(X) (Fortran 2008) . . . . . . . . 562BTEST(I, POS) . . . . . . . . . . . . 562BIT_SIZE(I) . . . . . . . . . . . . . 563CEILING(A, KIND) . . . . . . . . . . 564CHAR(I, KIND) . . . . . . . . . . . 564CMPLX(X, Y, KIND) . . . . . . . . . . 565COMMAND_ARGUMENT_COUNT() (Fortran2003) . . . . . . . . . . . . . . . 566CONJG(Z) . . . . . . . . . . . . . 567COS(X) . . . . . . . . . . . . . . 567COSD(X) (IBM extension) . . . . . . . . 568COSH(X) . . . . . . . . . . . . . . 569COUNT(MASK, DIM, KIND) . . . . . . . 570CPU_TIME(TIME) (Fortran 95) . . . . . . 570CSHIFT(ARRAY, SHIFT, DIM) . . . . . . . 572

    CVMGx(TSOURCE, FSOURCE, MASK) (IBMextension) . . . . . . . . . . . . . 573DATE_AND_TIME(DATE, TIME, ZONE,VALUES) . . . . . . . . . . . . . . 574DBLE(A) . . . . . . . . . . . . . . 576DCMPLX(X, Y) (IBM extension) . . . . . . 577DIGITS(X) . . . . . . . . . . . . . 577DIM(X, Y) . . . . . . . . . . . . . 578DOT_PRODUCT(VECTOR_A, VECTOR_B) . . 579DPROD(X, Y) . . . . . . . . . . . . 580EOSHIFT(ARRAY, SHIFT, BOUNDARY, DIM) 580EPSILON(X) . . . . . . . . . . . . . 582ERF(X) (Fortran 2008) . . . . . . . . . 583ERFC(X) (Fortran 2008) . . . . . . . . . 583ERFC_SCALED(X) (Fortran 2008). . . . . . 584EXECUTE_COMMAND_LINE(COMMAND,WAIT, EXITSTAT, CMDSTAT, CMDMSG)(Fortran 2008) . . . . . . . . . . . . 585EXP(X) . . . . . . . . . . . . . . 586EXPONENT(X) . . . . . . . . . . . . 587EXTENDS_TYPE_OF(A, MOLD) (Fortran 2003) 588FLOOR(A, KIND) . . . . . . . . . . . 588FRACTION(X) . . . . . . . . . . . . 589GAMMA(X) (Fortran 2008) . . . . . . . . 590GET_COMMAND(COMMAND, LENGTH,STATUS) (Fortran 2003) . . . . . . . . . 590GET_COMMAND_ARGUMENT(NUMBER,VALUE, LENGTH, STATUS) (Fortran 2003) . . 591GET_ENVIRONMENT_VARIABLE(NAME,VALUE, LENGTH, STATUS, TRIM_NAME)(Fortran 2003) . . . . . . . . . . . . 592GETENV(NAME, VALUE) (IBM extension) . . 593HFIX(A) (IBM extension) . . . . . . . . 594HYPOT(X, Y) (Fortran 2008) . . . . . . . 595HUGE(X). . . . . . . . . . . . . . 595IACHAR(C, KIND) . . . . . . . . . . 596IAND(I, J) . . . . . . . . . . . . . 597IBCLR(I, POS) . . . . . . . . . . . . 597IBITS(I, POS, LEN) . . . . . . . . . . 598IBSET(I, POS) . . . . . . . . . . . . 599ICHAR(C, KIND) . . . . . . . . . . . 600IEOR(I, J) . . . . . . . . . . . . . . 600ILEN(I) (IBM extension) . . . . . . . . 601IMAG(Z) (IBM extension) . . . . . . . . 602INDEX(STRING, SUBSTRING, BACK, KIND) 602INT(A, KIND) . . . . . . . . . . . . 603INT2(A) (IBM extension) . . . . . . . . 604IOR(I, J) . . . . . . . . . . . . . . 605IS_CONTIGUOUS(ARRAY) (Fortran 2008). . . 605IS_IOSTAT_END(I) (Fortran 2003) . . . . . 606IS_IOSTAT_EOR(I) (Fortran 2003). . . . . . 607ISHFT(I, SHIFT) . . . . . . . . . . . 607ISHFTC(I, SHIFT, SIZE) . . . . . . . . . 608KIND(X) . . . . . . . . . . . . . . 609LBOUND(ARRAY, DIM, KIND) . . . . . . 609LEADZ(I) (Fortran 2008). . . . . . . . . 610LEN(STRING, KIND). . . . . . . . . . 611LEN_TRIM(STRING, KIND) . . . . . . . 611LGAMMA(X) (IBM extension) . . . . . . . 612LGE(STRING_A, STRING_B) . . . . . . . 613LGT(STRING_A, STRING_B) . . . . . . . 613

    Contents vii

  • LLE(STRING_A, STRING_B) . . . . . . . 614LLT(STRING_A, STRING_B) . . . . . . . 615LOC(X) (IBM extension) . . . . . . . . . 616LOG(X) . . . . . . . . . . . . . . 616LOG_GAMMA(X) (Fortran 2008) . . . . . . 617LOG10(X) . . . . . . . . . . . . . 618LOGICAL(L, KIND) . . . . . . . . . . 619LSHIFT(I, SHIFT) (IBM extension) . . . . . 619MATMUL(MATRIX_A, MATRIX_B, MINDIM) 620MAX(A1, A2, A3, ...) . . . . . . . . . . 622MAXEXPONENT(X) . . . . . . . . . . 623MAXLOC(ARRAY, DIM, MASK, KIND) orMAXLOC(ARRAY, MASK, KIND) . . . . . 624MAXVAL(ARRAY, DIM, MASK) orMAXVAL(ARRAY, MASK) . . . . . . . . 625MERGE(TSOURCE, FSOURCE, MASK). . . . 627MIN(A1, A2, A3, ...) . . . . . . . . . . 628MINEXPONENT(X) . . . . . . . . . . 628MINLOC(ARRAY, DIM, MASK, KIND) orMINLOC(ARRAY, MASK, KIND). . . . . . 629MINVAL(ARRAY, DIM, MASK) orMINVAL(ARRAY, MASK) . . . . . . . . 631MOD(A, P) . . . . . . . . . . . . . 632MODULO(A, P) . . . . . . . . . . . 633MOVE_ALLOC(FROM, TO) (Fortran 2003) . . 634MVBITS(FROM, FROMPOS, LEN, TO, TOPOS) 634NEAREST(X,S) . . . . . . . . . . . . 635NEW_LINE(A) (Fortran 2003) . . . . . . . 635NINT(A, KIND) . . . . . . . . . . . 636NOT(I) . . . . . . . . . . . . . . 637NULL(MOLD) . . . . . . . . . . . . 638NUM_PARTHDS() (IBM extension) . . . . . 639NUM_USRTHDS() (IBM extension) . . . . . 639NUMBER_OF_PROCESSORS(DIM) (IBMextension) . . . . . . . . . . . . . 640PACK(ARRAY, MASK, VECTOR) . . . . . . 640POPCNT(I) (Fortran 2008) . . . . . . . . 642POPPAR(I) (Fortran 2008) . . . . . . . . 642PRECISION(X) . . . . . . . . . . . . 643PRESENT(A) . . . . . . . . . . . . 644PROCESSORS_SHAPE() (IBM extension) . . . 645PRODUCT(ARRAY, DIM, MASK) orPRODUCT(ARRAY, MASK) . . . . . . . 645QCMPLX(X, Y) (IBM extension) . . . . . . 647QEXT(A) (IBM extension) . . . . . . . . 647RADIX(X) . . . . . . . . . . . . . 648RAND() (IBM extension) . . . . . . . . 648RANDOM_NUMBER(HARVEST) . . . . . 649RANDOM_SEED(SIZE, PUT, GET,GENERATOR) . . . . . . . . . . . . 650RANGE(X) . . . . . . . . . . . . . 651REAL(A, KIND) . . . . . . . . . . . 652REPEAT(STRING, NCOPIES) . . . . . . . 653RESHAPE(SOURCE, SHAPE, PAD, ORDER) 653RRSPACING(X) . . . . . . . . . . . 655RSHIFT(I, SHIFT) (IBM extension) . . . . . 655SAME_TYPE_AS(A,B) (Fortran 2003) . . . . 656SCALE(X,I) . . . . . . . . . . . . . 656SCAN(STRING, SET, BACK, KIND) . . . . . 657SELECTED_CHAR_KIND(NAME) (Fortran2003) . . . . . . . . . . . . . . . 658

    SELECTED_INT_KIND(R) . . . . . . . . 658SELECTED_REAL_KIND(P, R, RADIX) . . . . 659SET_EXPONENT(X,I). . . . . . . . . . 661SHAPE(SOURCE, KIND) . . . . . . . . 661SIGN(A, B) . . . . . . . . . . . . . 662SIGNAL(I, PROC) (IBM extension) . . . . . 663SIN(X). . . . . . . . . . . . . . . 664SIND(X) (IBM extension) . . . . . . . . 665SINH(X) . . . . . . . . . . . . . . 665SIZE(ARRAY, DIM, KIND) . . . . . . . . 666SIZEOF(A) (IBM extension). . . . . . . . 667SPACING(X) . . . . . . . . . . . . 668SPREAD(SOURCE, DIM, NCOPIES). . . . . 669SQRT(X) . . . . . . . . . . . . . . 670SRAND(SEED) (IBM extension) . . . . . . 671SUM(ARRAY, DIM, MASK) or SUM(ARRAY,MASK) . . . . . . . . . . . . . . 672SYSTEM(CMD, RESULT) (IBM extension) . . . 673SYSTEM_CLOCK(COUNT, COUNT_RATE,COUNT_MAX) . . . . . . . . . . . . 674TAN(X) . . . . . . . . . . . . . . 675TAND(X) (IBM extension) . . . . . . . . 676TANH(X). . . . . . . . . . . . . . 676TINY(X) . . . . . . . . . . . . . . 677TRAILZ(I) (Fortran 2008) . . . . . . . . 678TRANSFER(SOURCE, MOLD, SIZE). . . . . 678TRANSPOSE(MATRIX) . . . . . . . . . 680TRIM(STRING) . . . . . . . . . . . . 680UBOUND(ARRAY, DIM, KIND) . . . . . . 681UNPACK(VECTOR, MASK, FIELD) . . . . . 682VERIFY(STRING, SET, BACK, KIND) . . . . 683

    Chapter 15. Hardware-specificintrinsic procedures (IBM extension) . 685BPERMD(MASK, SOURCE) . . . . . . . . 685CMPB(X,Y) . . . . . . . . . . . . . . 686DIVDE(X,Y) . . . . . . . . . . . . . . 686DIVWE(X,Y). . . . . . . . . . . . . . 687FCFI(I) . . . . . . . . . . . . . . . 687FCFID(I) . . . . . . . . . . . . . . . 688FCFUD(I). . . . . . . . . . . . . . . 688FCTID(X). . . . . . . . . . . . . . . 689FCTIDZ(X) . . . . . . . . . . . . . . 690FCTIW(X) . . . . . . . . . . . . . . 690FCTIWZ(X) . . . . . . . . . . . . . . 691FCTUDZ(X) . . . . . . . . . . . . . . 691FCTUWZ(X). . . . . . . . . . . . . . 692FMADD(A, X, Y) . . . . . . . . . . . . 692FMSUB(A, X, Y) . . . . . . . . . . . . 693FNABS(X) . . . . . . . . . . . . . . 693FNMADD(A, X, Y) . . . . . . . . . . . 694FNMSUB(A, X, Y) . . . . . . . . . . . . 694FRE(X) . . . . . . . . . . . . . . . 695FRES(X) . . . . . . . . . . . . . . . 695FRIC(A) . . . . . . . . . . . . . . . 696FRIM(A) . . . . . . . . . . . . . . . 696FRIN(A) . . . . . . . . . . . . . . . 697FRIP(A) . . . . . . . . . . . . . . . 697FRIZ(A) . . . . . . . . . . . . . . . 698FRSQRTE(X). . . . . . . . . . . . . . 698FRSQRTES(X) . . . . . . . . . . . . . 699

    viii XL Fortran: Language Reference

  • FSEL(X,Y,Z) . . . . . . . . . . . . . . 699MTFSF(MASK, R) . . . . . . . . . . . . 700MTFSFI(BF, I) . . . . . . . . . . . . . 700MULHY(RA, RB) . . . . . . . . . . . . 700POPCNTB(I) . . . . . . . . . . . . . 701ROTATELI(RS, IS, SHIFT, MASK) . . . . . . 701ROTATELM(RS, SHIFT, MASK) . . . . . . . 702SETFSB0(BT) . . . . . . . . . . . . . 703SETFSB1(BT) . . . . . . . . . . . . . 703SFTI(M, Y) . . . . . . . . . . . . . . 703SWDIV(X,Y) . . . . . . . . . . . . . . 704SWDIV_NOCHK(X,Y) . . . . . . . . . . 705TRAP(A, B, TO) . . . . . . . . . . . . 706

    Chapter 16. Vector intrinsicprocedures (IBM extension) . . . . . 707VEC_ABS(ARG1) . . . . . . . . . . . . 707VEC_ABSS(ARG1). . . . . . . . . . . . 707VEC_ADD(ARG1, ARG2) . . . . . . . . . 708VEC_ADDC(ARG1, ARG2) . . . . . . . . . 708VEC_ADDS(ARG1, ARG2) . . . . . . . . . 709VEC_ALL_EQ(ARG1, ARG2) . . . . . . . . 709VEC_ALL_GE(ARG1, ARG2) . . . . . . . . 710VEC_ALL_GT(ARG1, ARG2) . . . . . . . . 710VEC_ALL_IN(ARG1, ARG2) . . . . . . . . 711VEC_ALL_LE(ARG1, ARG2) . . . . . . . . 711VEC_ALL_LT(ARG1, ARG2) . . . . . . . . 712VEC_ALL_NAN(ARG1) . . . . . . . . . . 712VEC_ALL_NE(ARG1, ARG2) . . . . . . . . 713VEC_ALL_NGE(ARG1, ARG2) . . . . . . . 713VEC_ALL_NGT(ARG1, ARG2) . . . . . . . 714VEC_ALL_NLE(ARG1, ARG2). . . . . . . . 714VEC_ALL_NLT(ARG1, ARG2). . . . . . . . 715VEC_ALL_NUMERIC(ARG1) . . . . . . . . 715VEC_AND(ARG1, ARG2) . . . . . . . . . 716VEC_ANDC(ARG1, ARG2) . . . . . . . . . 716VEC_ANY_EQ(ARG1, ARG2) . . . . . . . . 717VEC_ANY_GE(ARG1, ARG2) . . . . . . . . 717VEC_ANY_GT(ARG1, ARG2) . . . . . . . . 718VEC_ANY_LE(ARG1, ARG2) . . . . . . . . 718VEC_ANY_LT(ARG1, ARG2) . . . . . . . . 719VEC_ANY_NAN(ARG1) . . . . . . . . . 719VEC_ANY_NE(ARG1, ARG2) . . . . . . . . 719VEC_ANY_NGE(ARG1, ARG2) . . . . . . . 720VEC_ANY_NGT(ARG1, ARG2) . . . . . . . 720VEC_ANY_NLE(ARG1, ARG2) . . . . . . . 721VEC_ANY_NLT(ARG1, ARG2) . . . . . . . 721VEC_ANY_NUMERIC(ARG1) . . . . . . . . 722VEC_ANY_OUT(ARG1, ARG2) . . . . . . . 722VEC_AVG(ARG1, ARG2) . . . . . . . . . 723VEC_CEIL(ARG1) . . . . . . . . . . . . 723VEC_CMPB(ARG1, ARG2) . . . . . . . . . 724VEC_CMPEQ(ARG1, ARG2) . . . . . . . . 725VEC_CMPGE(ARG1, ARG2) . . . . . . . . 725VEC_CMPGT(ARG1, ARG2) . . . . . . . . 726VEC_CMPLE(ARG1, ARG2) . . . . . . . . 727VEC_CMPLT(ARG1, ARG2) . . . . . . . . 727VEC_CONVERT(V, MOLD). . . . . . . . . 728VEC_CPSGN(ARG1, ARG2) . . . . . . . . 729VEC_CTD(ARG1, ARG2) . . . . . . . . . 729VEC_CTF(ARG1, ARG2). . . . . . . . . . 730

    VEC_CTS(ARG1, ARG2). . . . . . . . . . 730VEC_CTSL(ARG1, ARG2) . . . . . . . . . 731VEC_CTU(ARG1, ARG2) . . . . . . . . . 731VEC_CTUL(ARG1, ARG2) . . . . . . . . . 732VEC_CVF(ARG1) . . . . . . . . . . . . 732VEC_DIV(ARG1, ARG2). . . . . . . . . . 733VEC_DSS(ARG1) . . . . . . . . . . . . 733VEC_DSSALL . . . . . . . . . . . . . 733VEC_DST(ARG1, ARG2, ARG3) . . . . . . . 734VEC_DSTST(ARG1, ARG2, ARG3) . . . . . . 734VEC_DSTSTT(ARG1, ARG2, ARG3) . . . . . . 735VEC_DSTT(ARG1, ARG2, ARG3) . . . . . . . 735VEC_EXPTE(ARG1) . . . . . . . . . . . 736VEC_EXTRACT(ARG1, ARG2) . . . . . . . 736VEC_FLOOR(ARG1) . . . . . . . . . . . 737VEC_INSERT(ARG1, ARG2, ARG3) . . . . . . 737VEC_LD(ARG1, ARG2) . . . . . . . . . . 738VEC_LDE(ARG1, ARG2) . . . . . . . . . 738VEC_LDL(ARG1, ARG2) . . . . . . . . . 739VEC_LOGE(ARG1) . . . . . . . . . . . 740VEC_LVSL(ARG1, ARG2) . . . . . . . . . 740VEC_LVSR(ARG1, ARG2) . . . . . . . . . 741VEC_MADD(ARG1, ARG2, ARG3) . . . . . . 741VEC_MADDS(ARG1, ARG2, ARG3) . . . . . . 742VEC_MAX(ARG1, ARG2) . . . . . . . . . 742VEC_MERGEH(ARG1, ARG2) . . . . . . . . 743VEC_MERGEL(ARG1, ARG2) . . . . . . . . 743VEC_MFVSCR . . . . . . . . . . . . . 744VEC_MIN(ARG1, ARG2) . . . . . . . . . 744VEC_MLADD(ARG1, ARG2, ARG3) . . . . . . 745VEC_MRADDS(ARG1, ARG2, ARG3) . . . . . 745VEC_MSUB(ARG1, ARG2, ARG3) . . . . . . 746VEC_MSUM(ARG1, ARG2, ARG3) . . . . . . 747VEC_MSUMS(ARG1, ARG2, ARG3) . . . . . . 747VEC_MTVSCR(ARG1) . . . . . . . . . . 748VEC_MUL(ARG1, ARG2) . . . . . . . . . 748VEC_MULE(ARG1, ARG2) . . . . . . . . . 749VEC_MULO(ARG1, ARG2) . . . . . . . . . 749VEC_NABS(ARG1) . . . . . . . . . . . 750VEC_NEG(ARG1) . . . . . . . . . . . . 750VEC_NMADD(ARG1, ARG2, ARG3) . . . . . 751VEC_NMSUB(ARG1, ARG2, ARG3) . . . . . . 751VEC_NOR(ARG1, ARG2) . . . . . . . . . 752VEC_OR(ARG1, ARG2) . . . . . . . . . . 752VEC_PACK(ARG1, ARG2) . . . . . . . . . 753VEC_PACKPX(ARG1, ARG2) . . . . . . . . 753VEC_PACKS(ARG1, ARG2) . . . . . . . . 754VEC_PACKSU(ARG1, ARG2) . . . . . . . . 755VEC_PERM(ARG1, ARG2, ARG3) . . . . . . 755VEC_PERMI(ARG1, ARG2, ARG3) . . . . . . 756VEC_PROMOTE(ARG1, ARG2) . . . . . . . 756VEC_RE(ARG1) . . . . . . . . . . . . 757VEC_RL(ARG1, ARG2) . . . . . . . . . . 757VEC_ROUND(ARG1) . . . . . . . . . . 758VEC_ROUNDC(ARG1) . . . . . . . . . . 758VEC_ROUNDM(ARG1) . . . . . . . . . . 759VEC_ROUNDP(ARG1) . . . . . . . . . . 759VEC_ROUNDZ(ARG1) . . . . . . . . . . 759VEC_RSQRTE(ARG1). . . . . . . . . . . 759VEC_SEL(ARG1, ARG2, ARG3) . . . . . . . 760VEC_SL(ARG1, ARG2) . . . . . . . . . . 760

    Contents ix

  • VEC_SLD(ARG1, ARG2, ARG3) . . . . . . . 761VEC_SLDW(ARG1, ARG2, ARG3) . . . . . . 761VEC_SLL(ARG1, ARG2) . . . . . . . . . . 762VEC_SLO(ARG1, ARG2) . . . . . . . . . 763VEC_SPLAT(ARG1, ARG2) . . . . . . . . . 763VEC_SPLATS(ARG1) . . . . . . . . . . . 764VEC_SPLAT_S8(ARG1) . . . . . . . . . . 764VEC_SPLAT_S16(ARG1). . . . . . . . . . 765VEC_SPLAT_S32(ARG1). . . . . . . . . . 765VEC_SPLAT_U8(ARG1) . . . . . . . . . . 765VEC_SPLAT_U16(ARG1) . . . . . . . . . 766VEC_SPLAT_U32(ARG1) . . . . . . . . . 766VEC_SQRT(ARG1) . . . . . . . . . . . 767VEC_SR(ARG1, ARG2) . . . . . . . . . . 767VEC_SRA(ARG1, ARG2) . . . . . . . . . 768VEC_SRL(ARG1, ARG2) . . . . . . . . . . 768VEC_SRO(ARG1, ARG2) . . . . . . . . . 769VEC_ST(ARG1, ARG2, ARG3) . . . . . . . . 769VEC_STE(ARG1, ARG2, ARG3) . . . . . . . 770VEC_STL(ARG1, ARG2, ARG3) . . . . . . . 771VEC_SUB(ARG1, ARG2). . . . . . . . . . 771VEC_SUBC(ARG1, ARG2) . . . . . . . . . 772VEC_SUBS(ARG1, ARG2) . . . . . . . . . 773VEC_SUM2S(ARG1, ARG2) . . . . . . . . 773VEC_SUM4S(ARG1, ARG2) . . . . . . . . 774VEC_SUMS(ARG1, ARG2) . . . . . . . . . 774VEC_TRUNC(ARG1) . . . . . . . . . . . 775VEC_UNPACKH(ARG1). . . . . . . . . . 775VEC_UNPACKL(ARG1) . . . . . . . . . . 776VEC_XLD2(ARG1, ARG2) . . . . . . . . . 776VEC_XLDS(ARG1, ARG2) . . . . . . . . . 777VEC_XLW4(ARG1, ARG2) . . . . . . . . . 778VEC_XOR(ARG1, ARG2) . . . . . . . . . 779VEC_XSTD2(ARG1, ARG2, ARG3) . . . . . . 779VEC_XSTW4(ARG1, ARG2, ARG3) . . . . . . 780

    Chapter 17. Language interoperabilityfeatures (Fortran 2003) . . . . . . . 781Interoperability of types . . . . . . . . . . 781

    Intrinsic types . . . . . . . . . . . . 781Derived types . . . . . . . . . . . . 781

    Interoperability of Variables . . . . . . . . 782Interoperability of common blocks . . . . . . 782Interoperability of procedures . . . . . . . . 782The ISO_C_BINDING module . . . . . . . . 783

    Constants for use as kind type parameters . . 783Character constants . . . . . . . . . . 785Other constants. . . . . . . . . . . . 785Types . . . . . . . . . . . . . . . 785Procedures . . . . . . . . . . . . . 785

    Binding labels . . . . . . . . . . . . . 788

    Chapter 18. The ISO_FORTRAN_ENVintrinsic module . . . . . . . . . . 789ISO_FORTRAN_ENV constants . . . . . . . 789

    CHARACTER_KINDS (Fortran 2008) . . . . 789CHARACTER_STORAGE_SIZE . . . . . . 789ERROR_UNIT . . . . . . . . . . . . 789FILE_STORAGE_SIZE . . . . . . . . . 790INT8 (Fortran 2008) . . . . . . . . . . 790

    INT16 (Fortran 2008) . . . . . . . . . . 790INT32 (Fortran 2008) . . . . . . . . . . 790INT64 (Fortran 2008) . . . . . . . . . . 791INTEGER_KINDS (Fortran 2008) . . . . . . 791INPUT_UNIT . . . . . . . . . . . . 791IOSTAT_END . . . . . . . . . . . . 791IOSTAT_EOR . . . . . . . . . . . . 792IOSTAT_INQUIRE_INTERNAL_UNIT (Fortran2008) . . . . . . . . . . . . . . . 792LOGICAL_KINDS (Fortran 2008) . . . . . . 793NUMERIC_STORAGE_SIZE . . . . . . . 793OUTPUT_UNIT . . . . . . . . . . . 793REAL32 (Fortran 2008) . . . . . . . . . 793REAL64 (Fortran 2008) . . . . . . . . . 794REAL128 (Fortran 2008) . . . . . . . . . 794REAL_KINDS (Fortran 2008) . . . . . . . 794

    ISO_FORTRAN_ENV functions . . . . . . . 794COMPILER_OPTIONS (Fortran 2008) . . . . 795COMPILER_VERSION (Fortran 2008) . . . . 795

    Chapter 19. Floating-point control andinquiry procedures . . . . . . . . . 797fpgets fpsets . . . . . . . . . . . . . . 797Efficient floating-point control and inquiryprocedures . . . . . . . . . . . . . . 798

    xlf_fp_util floating-point procedures . . . . . 800IEEE Modules and support (Fortran 2003) . . . . 804

    Compiling and exception handling . . . . . 805General rules for implementing IEEE modules 805IEEE derived data types and constants . . . . 805IEEE Operators . . . . . . . . . . . . 807IEEE procedures . . . . . . . . . . . 808Rules for floating-point status . . . . . . . 831Examples . . . . . . . . . . . . . . 832

    Chapter 20. Service and utilityprocedures (IBM extension) . . . . . 837General service and utility procedures . . . . . 837List of service and utility procedures . . . . . 838alarm_(time, func) . . . . . . . . . . . . 838bic_(X1, X2) . . . . . . . . . . . . . . 839bis_(X1, X2) . . . . . . . . . . . . . . 839bit_(X1, X2) . . . . . . . . . . . . . . 840clock_() . . . . . . . . . . . . . . . 840ctime_(STR, TIME) . . . . . . . . . . . 841date() . . . . . . . . . . . . . . . . 841dtime_(dtime_struct) . . . . . . . . . . . 841etime_(etime_struct) . . . . . . . . . . . 842exit_(exit_status) . . . . . . . . . . . . 842fdate_(str) . . . . . . . . . . . . . . 843fiosetup_(unit, command, argument) . . . . . 843flush_(lunit) . . . . . . . . . . . . . . 844ftell_(lunit) . . . . . . . . . . . . . . 844ftell64_(lunit) . . . . . . . . . . . . . 845getarg(i1,c1) . . . . . . . . . . . . . . 845getcwd_(name) . . . . . . . . . . . . . 846getfd(lunit) . . . . . . . . . . . . . . 846getgid_() . . . . . . . . . . . . . . . 847getlog_(name) . . . . . . . . . . . . . 847getpid_() . . . . . . . . . . . . . . . 847

    x XL Fortran: Language Reference

  • getuid_() . . . . . . . . . . . . . . . 848global_timef() . . . . . . . . . . . . . 848gmtime_(stime, tarray) . . . . . . . . . . 848hostnm_(name) . . . . . . . . . . . . . 849iargc() . . . . . . . . . . . . . . . . 849idate_(idate_struct) . . . . . . . . . . . 850ierrno_() . . . . . . . . . . . . . . . 850irand(). . . . . . . . . . . . . . . . 851irtc() . . . . . . . . . . . . . . . . 851itime_(itime_struct) . . . . . . . . . . . 851jdate() . . . . . . . . . . . . . . . . 852lenchr_(str) . . . . . . . . . . . . . . 852lnblnk_(str) . . . . . . . . . . . . . . 852ltime_(stime, tarray) . . . . . . . . . . . 853mclock() . . . . . . . . . . . . . . . 853qsort_(array, len, isize, compar) . . . . . . . 854qsort_down(array, len, isize) . . . . . . . . 854qsort_up(array, len, isize) . . . . . . . . . 855rtc() . . . . . . . . . . . . . . . . 856setrteopts(c1) . . . . . . . . . . . . . 856sleep_(sec) . . . . . . . . . . . . . . 856time_() . . . . . . . . . . . . . . . 857timef() . . . . . . . . . . . . . . . . 857timef_delta(t) . . . . . . . . . . . . . 857umask_(cmask) . . . . . . . . . . . . . 858

    usleep_(msec) . . . . . . . . . . . . . 858xl__trbk() . . . . . . . . . . . . . . . 859

    Chapter 21. Extensions for sourcecompatibility (IBM extension) . . . . 861Record structures . . . . . . . . . . . . 861

    Declaring record structures . . . . . . . . 862Storage mapping . . . . . . . . . . . 864

    Union and map (IBM extension) . . . . . . . 865

    Appendix. . . . . . . . . . . . . 869Compatibility across standards . . . . . . . 869

    Fortran 90 compatibility . . . . . . . . . 870Obsolescent features . . . . . . . . . . 870Deleted features . . . . . . . . . . . 872

    ASCII and EBCDIC character sets . . . . . . 872

    Notices . . . . . . . . . . . . . . 881Trademarks and service marks . . . . . . . 883

    Glossary . . . . . . . . . . . . . 885

    Index . . . . . . . . . . . . . . . 903

    Contents xi

  • xii XL Fortran: Language Reference

  • About this document

    This document, which is part of the XL Fortran documentation suite, describes thesyntax, semantics, and IBM® implementation of the Fortran programming languageon the AIX® operating system. Although XL Fortran implementations conform topartial Fortran 2008, full Fortran 2003, and other specifications maintained by theISO standards for the Fortran programming language, they also incorporate manyextensions to the core language. These extensions have been implemented with theaims of enhancing usability in specific operating environments, assuringcompatibility with other compilers, and supporting new hardware capabilities.

    Who should read this documentThis document is a reference for users who already have experience programmingin Fortran. Users new to Fortran can still use this document to find information onthe language and features unique to XL Fortran; however, it does not aim to teachprogramming concepts nor to promote specific programming practices.

    How to use this documentWhile this document covers both standard and implementation-specific features ofXL Fortran, it does not include information on the following topics, which arecovered in other documents:v Installation, system requirements, last-minute updates: see the XL Fortran

    Installation Guide and product README.v Overview of XL Fortran features: see the Getting Started with XL Fortran.v Compiler setup, compiling and running programs, compiler options, diagnostics:

    see the XL Fortran Compiler Reference.v Optimizing, porting, OpenMP and SMP programming: see the XL Fortran

    Optimization and Programming Guide.v Operating system commands related to the use of the compiler: AIX Commands

    Reference, Volumes 1 - 6 and the AIX information center.v Operating system commands related to the use of the compiler: consult your

    man page help and documentation of the specific distribution.

    How this document is organizedThe following lists group information into sections that provide details onparticular language topics and implementations:v XL Fortran language elements:

    – XL Fortran for AIX– XL Fortran language fundamentals– Intrinsic data types– Derived types– Arrays concepts– Expressions and assignment– Execution control– Program units and procedures– XL Fortran Input/Output

    © Copyright IBM Corp. 1996, 2012 xiii

  • – Input/Output formatting– Statements and attributes– Directives (IBM extension)– Intrinsic procedures– Vector intrinsic procedures (IBM extension)– Language interoperability features (Fortran 2003)– The ISO_FORTRAN_ENV intrinsic module– Extensions for source compatibility (IBM extension)

    v Procedures that provide hardware-related functionality, and additional featuresfor those already familiar with the Fortran language:– Floating-point control and inquiry procedures– Hardware–specific directives– Hardware–specific intrinsic procedures (IBM extension)– Service and utility procedures (IBM extension)

    v The appendices provide information on compatibility across standards for usersof earlier versions of Fortran, and the ASCII and EBCDIC character setsmapping table.

    ConventionsTypographical conventions

    The following table explains the typographical conventions used in the IBM XLFortran for AIX, V14.1 information.

    Table 1. Typographical conventions

    Typeface Indicates Example

    bold Lowercase commands, executablenames, compiler options, anddirectives.

    The compiler provides basicinvocation commands, xlf, along withseveral other compiler invocationcommands to support various Fortranlanguage levels and compilationenvironments.

    italics Parameters or variables whoseactual names or values are to besupplied by the user. Italics arealso used to introduce new terms.

    Make sure that you update the sizeparameter if you return more thanthe size requested.

    underlining The default setting of a parameterof a compiler option or directive.

    nomaf | maf

    monospace Programming keywords andlibrary functions, compiler builtins,examples of program code,command strings, or user-definednames.

    To compile and optimizemyprogram.f, enter: xlf myprogram.f-O3.

    UPPERCASEbold

    Fortran programming keywords,statements, directives, and intrinsicprocedures. Uppercase letters mayalso be used to indicate theminimum number of charactersrequired to invoke a compileroption/suboption.

    The ASSERT directive applies only tothe DO loop immediately followingthe directive, and not to any nestedDO loops.

    xiv XL Fortran: Language Reference

  • Qualifying elements (icons and bracket separators)

    In descriptions of language elements, this information uses icons and markedbracket separators to delineate the Fortran language standard text as follows:

    Table 2. Qualifying elements

    IconBracketseparator text Meaning

    F2008

    F2008

    N/A The text describes an IBM XL Fortran implementation ofthe Fortran 2008 standard.

    Fortran 2003begins / ends

    The text describes an IBM XL Fortran implementation ofthe Fortran 2003 standard, and it applies to all laterstandards.

    IBM extensionbegins / ends

    The text describes a feature that is an IBM XL Fortranextension to the standard language specifications.

    Note: If the information is marked with a Fortran language standard icon orbracket separators, it applies to this specific Fortran language standard and all laterones. If it is not marked, it applies to all Fortran language standards.

    Syntax diagrams

    Throughout this information, diagrams illustrate XL Fortran syntax. This sectionwill help you to interpret and use those diagrams.v Read the syntax diagrams from left to right, from top to bottom, following the

    path of the line.The ��─── symbol indicates the beginning of a command, directive, or statement.The ───� symbol indicates that the command, directive, or statement syntax iscontinued on the next line.The �─── symbol indicates that a command, directive, or statement is continuedfrom the previous line.The ───�� symbol indicates the end of a command, directive, or statement.Fragments, which are diagrams of syntactical units other than completecommands, directives, or statements, start with the │─── symbol and end withthe ───│ symbol.IBM XL Fortran extensions are marked by a number in the syntax diagram withan explanatory note immediately following the diagram.Program units, procedures, constructs, interface blocks and derived-typedefinitions consist of several individual statements. For such items, a boxencloses the syntax representation, and individual syntax diagrams show therequired order for the equivalent Fortran statements.

    v Required items are shown on the horizontal line (the main path):

    �� keyword required_argument ��

    v Optional items are shown below the main path:

    About this document xv

  • �� keywordoptional_argument

    ��

    Note: Optional items (not in syntax diagrams) are enclosed by square brackets ([and ]). For example, [UNIT=]u

    v If you can choose from two or more items, they are shown vertically, in a stack.If you must choose one of the items, one item of the stack is shown on the mainpath.

    �� keyword required_argument1required_argument2

    ��

    If choosing one of the items is optional, the entire stack is shown below themain path.

    �� keywordoptional_argument1optional_argument2

    ��

    v An arrow returning to the left above the main line (a repeat arrow) indicatesthat you can make more than one choice from the stacked items or repeat anitem. The separator character, if it is other than a blank, is also indicated:

    �� �

    ,

    keyword repeatable_argument ��

    v The item that is the default is shown above the main path.

    �� keyworddefault_argumentalternate_argument ��

    v Keywords are shown in nonitalic letters and should be entered exactly as shown.v Variables are shown in italicized lowercase letters. They represent user-supplied

    names or values. If a variable or user-specified name ends in _list, you canprovide a list of these terms separated by commas.

    v If punctuation marks, parentheses, arithmetic operators, or other such symbolsare shown, you must enter them as part of the syntax.

    Sample syntax diagram

    The following is an example of a syntax diagram with an interpretation:

    xvi XL Fortran: Language Reference

  • How to read syntax statements

    Syntax statements are read from left to right:v Individual required arguments are shown with no special notation.v When you must make a choice between a set of alternatives, they are enclosed

    by { and } symbols.v Optional arguments are enclosed by [ and ] symbols.v When you can select from a group of choices, they are separated by | characters.v Arguments that you can repeat are followed by ellipses (...).

    Example of a syntax statementEXAMPLE char_constant {a|b}[c|d]e[,e]... name_list{name_list}...

    The following list explains the syntax statement:v Enter the keyword EXAMPLE.v Enter a value for char_constant.v Enter a value for a or b, but not for both.v Optionally, enter a value for c or d.v Enter at least one value for e. If you enter more than one value, you must put a

    comma between each.v Optionally, enter the value of at least one name for name_list. If you enter more

    than one value, you must put a comma between each name.

    Note: The same example is used in both the syntax-statement and syntax-diagramrepresentations.

    ��(1)

    EXAMPLE char_constant ab c

    d

    ,

    e name_list ��

    Notes:

    1 IBM extension

    Interpret the diagram as follows:

    v Enter the keyword EXAMPLE.v EXAMPLE is an IBM extension.v Enter a value for char_constant.v Enter a value for a or b, but not for both.v Optionally, enter a value for c or d.v Enter at least one value for e. If you enter more than one value, you must put a

    comma between each.

    v Enter the value of at least one name for name_list. If you enter more than one value,you must put a comma between each. (The _list syntax is equivalent to the previoussyntax for e.)

    About this document xvii

  • Examples in this information

    The examples in this information, except where otherwise noted, are coded in asimple style that does not try to conserve storage, check for errors, achieve fastperformance, or demonstrate all possible methods to achieve a specific result.

    The examples for installation information are labelled as either Example or Basicexample. Basic examples are intended to document a procedure as it would beperformed during a basic, or default, installation; these need little or nomodification.

    Notes on the terminology used

    Some of the terminology in this information is shortened as follows:v The term free source form format often appears as free source form.v The term fixed source form format often appears as fixed source form.v The term XL Fortran often appears as XLF.

    Related information

    The following sections provide related information for XL Fortran:

    IBM XL Fortran information

    XL Fortran provides product information in the following formats:v README files

    README files contain late-breaking information, including changes andcorrections to the product information. README files are located by default inthe XL Fortran directory and in the root directory of the installation CD.

    v Installable man pagesMan pages are provided for the compiler invocations and all command-lineutilities provided with the product. Instructions for installing and accessing theman pages are provided in the IBM XL Fortran for AIX, V14.1 Installation Guide.

    v Information centerThe information center of searchable HTML files can be launched on a networkand accessed remotely or locally. Instructions for installing and accessing theonline information center are provided in the IBM XL Fortran for AIX, V14.1Installation Guide.The information center is viewable on the web at http://publib.boulder.ibm.com/infocenter/comphelp/v121v141/index.jsp.

    v PDF documentsPDF documents are located by default in the /usr/lpp/xlf/doc/LANG/pdf/directory, where LANG is one of en_US or ja_JP. The PDF files are also availableon the web at http://www.ibm.com/software/awdtools/fortran/xlfortran/aix/library/.The following files comprise the full set of XL Fortran product information:

    xviii XL Fortran: Language Reference

    http://publib.boulder.ibm.com/infocenter/comphelp/v121v141/index.jsphttp://publib.boulder.ibm.com/infocenter/comphelp/v121v141/index.jsphttp://www.ibm.com/software/awdtools/fortran/xlfortran/aix/library/http://www.ibm.com/software/awdtools/fortran/xlfortran/aix/library/

  • Table 3. XL Fortran PDF files

    Document titlePDF filename Description

    IBM XL Fortran for AIX,V14.1 Installation Guide,GC14-7335-00

    install.pdf Contains information for installing XL Fortranand configuring your environment for basiccompilation and program execution.

    Getting Started with IBMXL Fortran for AIX, V14.1,SC14-7334-00

    getstart.pdf Contains an introduction to the XL Fortranproduct, with information on setting up andconfiguring your environment, compiling andlinking programs, and troubleshootingcompilation errors.

    IBM XL Fortran for AIX,V14.1 Compiler Reference,SC14-7336-00

    compiler.pdf Contains information about the variouscompiler options and environment variables.

    IBM XL Fortran for AIX,V14.1 Language Reference,SC14-7337-00

    langref.pdf Contains information about the Fortranprogramming language as supported by IBM,including language extensions for portabilityand conformance to nonproprietary standards,compiler directives and intrinsic procedures.

    IBM XL Fortran for AIX,V14.1 Optimization andProgramming Guide,SC14-7338-00

    proguide.pdf Contains information on advancedprogramming topics, such as applicationporting, interlanguage calls, floating-pointoperations, input/output, applicationoptimization and parallelization, and the XLFortran high-performance libraries.

    To read a PDF file, use the Adobe Reader. If you do not have the Adobe Reader,you can download it (subject to license terms) from the Adobe website athttp://www.adobe.com.

    More information related to XL Fortran including IBM Redbooks® publications,white papers, tutorials, and other articles, is available on the web at:

    http://www.ibm.com/software/awdtools/fortran/xlfortran/aix/library/

    Standards and specifications

    XL Fortran is designed to support the following standards and specifications. Youcan refer to these standards for precise definitions of some of the features found inthis information.v American National Standard Programming Language FORTRAN, ANSI X3.9-1978.v American National Standard Programming Language Fortran 90, ANSI X3.198-1992.v ANSI/IEEE Standard for Binary Floating-Point Arithmetic, ANSI/IEEE Std 754-1985.v Federal (USA) Information Processing Standards Publication Fortran, FIPS PUB 69-1.v Information technology - Programming languages - Fortran, ISO/IEC 1539-1:1991 (E).

    (This information uses its informal name, Fortran 90.)v Information technology - Programming languages - Fortran - Part 1: Base language,

    ISO/IEC 1539-1:1997. (This information uses its informal name, Fortran 95.)v Information technology - Programming languages - Fortran - Part 1: Base language,

    ISO/IEC 1539-1:2004. (This information uses its informal name, Fortran 2003.)v Information technology - Programming languages - Fortran - Part 1: Base language,

    ISO/IEC 1539-1:2010. (This information uses its informal name, Fortran 2008.)

    About this document xix

    http://www.adobe.comhttp://www.ibm.com/software/awdtools/fortran/xlfortran/aix/library/

  • v Military Standard Fortran DOD Supplement to ANSI X3.9-1978, MIL-STD-1753(United States of America, Department of Defense standard). Note that XLFortran supports only those extensions documented in this standard that havealso been subsequently incorporated into the Fortran 90 standard.

    v OpenMP Application Program Interface Version 3.1, available athttp://www.openmp.org

    Other IBM informationv Parallel Environment for AIX: Operation and Usev The IBM Systems Information Center, at http://publib.boulder.ibm.com/

    infocenter/systems/index.jsp?topic=/com.ibm.aix.doc/doc/base/aixparent.htmis a resource for AIX information.You can find the following books for your specific AIX system:– AIX Commands Reference, Volumes 1 - 6– Technical Reference: Base Operating System and Extensions, Volumes 1 & 2– AIX National Language Support Guide and Reference– AIX General Programming Concepts: Writing and Debugging Programs– AIX Assembler Language Reference

    v ESSL for AIX V5.1/ESSL for Linux on POWER V5.1 Guide and Reference available atthe Engineering and Scientific Subroutine Library (ESSL) and Parallel ESSL webpage.

    Technical support

    Additional technical support is available from the XL Fortran Support page athttp://www.ibm.com/software/awdtools/fortran/xlfortran/aix/support/. Thispage provides a portal with search capabilities to a large selection of Technotes andother support information.

    If you cannot find what you need, you can send email to [email protected].

    For the latest information about XL Fortran, visit the product information site athttp://www.ibm.com/software/awdtools/fortran/xlfortran/aix/.

    How to send your comments

    Your feedback is important in helping to provide accurate and high-qualityinformation. If you have any comments about this information or any other XLFortran information, send your comments by email to [email protected].

    Be sure to include the name of the information, the part number of theinformation, the version of XL Fortran, and, if applicable, the specific location ofthe text you are commenting on (for example, a page number or table number).

    xx XL Fortran: Language Reference

    http://www.openmp.orghttp://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.doc/doc/base/aixparent.htmhttp://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.doc/doc/base/aixparent.htmhttp://publib.boulder.ibm.com/infocenter/clresctr/vxrx/topic/com.ibm.cluster.essl.doc/esslbooks.htmlhttp://www.ibm.com/software/awdtools/fortran/xlfortran/aix/support/http://www.ibm.com/software/awdtools/fortran/xlfortran/aix/

  • Chapter 1. XL Fortran for AIX

    The XL Fortran Language Reference is part of a documentation suite that offersinformation on installing and using the XL Fortran compiler on AIX. Thisdocument defines the syntax, semantics, and restrictions you must follow to writevalid XL Fortran programs.

    Fortran (FORmula TRANslation) is a high-level programming language primarilyuseful for engineering, mathematical, and scientific applications involving numericcomputations.

    XL Fortran implements partial Fortran 2008, full Fortran 2003, and other languagespecifications maintained by the ISO standards for the Fortran programminglanguage, and also incorporates many extensions to the core language. Theseextensions have been implemented with the aims of enhancing usability in specificoperating environments, assuring compatibility with other compilers, andsupporting new hardware capabilities. In theory, a program that compiles correctlyon one standard-conforming compiler will compile and execute correctly under allother conforming compilers, insofar as hardware differences permit.

    The compiler detects most non-conformities to the XL Fortran language rules, butmay not detect some syntactic and semantic combinations. The compiler cannotdetect all combinations for performance reasons, or because the nonconformance isonly detectable at run time. XL Fortran programs that contain these undiagnosedcombinations are not valid, whether or not the programs run as expected.

    Fortran language standards

    Fortran 2008Segments of this document contain information based on the Fortran 2008Standard. The standard is open to continual interpretation, modification andrevision. IBM reserves the right to modify the behavior of any features of thisproduct to conform with future interpretations of this standard.

    The Fortran standard committees respond to questions of interpretation aboutaspects of Fortran. Some questions can relate to language features alreadyimplemented in the XL Fortran compiler. Any answers given by these committeesrelating to these language features can result in changes to future releases of theXL Fortran compiler, even if these changes result in incompatibilities with previousreleases of the product.

    Some of the new features in Fortran 2008 are:v Execution control: “STOP” on page 447, “ERROR STOP (Fortran 2008)” on page

    350, and “BLOCK construct (Fortran 2008)” on page 133v Data types: “Implied-shape arrays (Fortran 2008)” on page 78 and Complex part

    designatorsv Intrinsic procedures and modules: Chapter 18, “The ISO_FORTRAN_ENV

    intrinsic module,” on page 789, “IS_CONTIGUOUS(ARRAY) (Fortran 2008)” onpage 605, “POPCNT(I) (Fortran 2008)” on page 642

    v Pointer dummy argument enhancements

    © Copyright IBM Corp. 1996, 2012 1

  • Fortran 2003Fortran 2003 offers many new features and feature enhancements to Fortran 95.Some of the major new features in Fortran 2003 are:v Derived type enhancementsv Object-oriented programming support: type extension, type-bound procedures,

    type finalization, abstract and generic interfaces, polymorphism and PASSattribute

    v Scoping and data manipulation enhancements: allocatable components,VOLATILE attribute, MAX, MIN, MAXLOC, MINLOC, MAXVAL and MINVALintrinsics for character type

    v Input/Output enhancements: User defined derived type I/O, asynchronoustransfer including the WAIT statement

    v Subroutine enhancements: VALUE attribute, Procedure pointers, deferredCHARACTER length

    v Support for IEEE Floating Point Standard (IEEE 1989) exceptionsv Interoperability with the C programming language

    Fortran 95The Fortran 95 language standard is upward-compatible with the FORTRAN 77and Fortran 90 language standards, excluding deleted features. Some of theimprovements provided by the Fortran 95 standard are:v Default initializationv ELEMENTAL proceduresv The FORALL construct statementv POINTER initializationv PURE functionsv Specification expressions

    Fortran 90Fortran 90 offers many new features and feature enhancements to FORTRAN 77.The following topics outline some of the key features that Fortran 90 brings to theFORTRAN 77 language:v Array enhancementsv Control construct enhancementsv Derived typesv Dynamic behaviorv Free source formv Modulesv Parameterized data typesv Procedure enhancementsv Pointers

    FORTRAN 77FORTRAN 77 introduced new features and enhancements to FORTRAN 66, formore information see:v The full American National Standard FORTRAN 77 language (referred to as

    FORTRAN 77), defined in the document American National StandardProgramming Language FORTRAN, ANSI X3.9-1978.

    2 XL Fortran: Language Reference

  • IBM extensionsAn IBM extension generally modifies a rule or restriction from a given standardsimplementation. In this document, IBM extensions to the Fortran 2008, Fortran2003, Fortran 95, and Fortran 90 standards are marked as indicated in theConventions section under Conventions, Standards, and Documentation.

    OpenMP API Version 3.1The OpenMP API provides additional features which you can use to supplementthe existing FORTRAN 77, Fortran 90, and Fortran 95 language standards.

    The OpenMP Architecture Review Board (ARB) responds to questions ofinterpretation about aspects of the API. Some of these questions can relate tointerface features implemented in this version of the XL Fortran compiler. Anyanswers given by this committee relating to the interface can result in changes infuture releases of the XL Fortran compiler, even if these changes result inincompatibilities with previous releases of the product.

    You can find information pertaining to the implementation of OpenMP API Version3.1 in the following sections:v OpenMP environment variables in the XL Fortran Optimization and Programming

    Guide

    v SMP Directives in the XL Fortran Optimization and Programming Guide

    Standards documentsXL Fortran is designed according to the standards listed in the Standardsdocuments section. You can refer to these standards for precise definitions of someof the features found in this document.

    Chapter 1. XL Fortran for AIX 3

  • 4 XL Fortran: Language Reference

  • Chapter 2. XL Fortran language fundamentals

    This section describes the fundamental aspects of an XL Fortran application. Referto the following headings for more information:

    CharactersThe XL Fortran character set consists of letters, digits, and special characters:

    Table 4. The XL Fortran character set

    Letters Digits Special Characters

    A N a nB O b oC P c pD Q d qE R e rF S f sG T g tH U h uI V i vJ W j wK X k xL Y l yM Z m z

    0123456789

    BlankTab

    = Equal sign+ Plus sign- Minus sign* Asterisk/ Slash( Left parenthesis) Right parenthesis[ Right square bracket] Left square bracket, Comma. Decimal point / period$ Currency symbol’ Apostrophe: Colon! Exclamation point" Double quotation mark% Percent sign& Ampersand; Semicolon? Question mark< Less than> Greater than_ Underscore

    The characters have an order known as a collating sequence, which is thearrangement of characters that determines their sequence order for such processesas sorting, merging, and comparing. XL Fortran uses American National StandardCode for Information Interchange (ASCII) to determine the ordinal sequence ofcharacters. See “ASCII and EBCDIC character sets” on page 872 for a completelisting of the ASCII character set.

    White space refers to blanks and tabs. The significance of white space depends onthe source format. See “Lines and source formats” on page 8 for details.

    A lexical token is a sequence of characters with an indivisible interpretation thatforms a building block of a program. A lexical token can be a keyword, name,literal constant (not of type complex), operator, label, delimiter, comma, equal sign,colon, semicolon, percent sign, ::, or =>.

    © Copyright IBM Corp. 1996, 2012 5

  • NamesA name is a sequence of any or all of the following elements:v Letters (A-Z, a-z)v Digits (0-9)v Underscores (_)v Dollar signs ($)

    The first character of a name must not be a digit.

    In Fortran 2003, the maximum length of a name is 63 characters. In Fortran 90 andFortran 95, the maximum length of a name is 31 characters.

    IBM extension

    In XL Fortran, the maximum length of a name is 250 characters. Although you canbegin a name with an underscore, the AIX operating system as well as the XLFortran compiler and libraries use reserved names that begin with underscores.

    The compiler translates all letters in a source program into lowercase unless theyare in a character context. Character context refers to characters within characterliteral constants, character-string edit descriptors, and Hollerith constants.

    Note: When you specify the -qmixed compiler option, the compiler does nottranslate names to lowercase. For example, XL Fortran treatsia Ia iA IA

    the same by default, but treats lower and uppercase letters as distinct if youspecify -qmixed.

    End of IBM extension

    A name can identify entities such as:v A variablev A named constantv A procedurev A derived typev A constructv A CRITICAL constructv A program unitv A common blockv A namelist group

    DesignatorsA designator is a name that identifies a data object followed by zero or moreselectors such as array element selectors, array section selectors, F2008 complexpart selectors F2008 , component selectors, and substring selectors. A subobjectdesignator identifies the following items:v An array elementv An array sectionv A character substring

    6 XL Fortran: Language Reference

  • v F2008 A complex part F2008v A structure component

    OperatorsIn Fortran an expression is comprised of operands and operators. For a detaileddescription of Fortran operators, see “Operators and expressions” on page 101

    Table 5. XL Fortran operators

    Arithmetic Logical

    Character Primary

    General Relational

    StatementsA Fortran statement is a sequence of lexical tokens. Statements are used to formprogram units.

    The maximum length of a statement in XL Fortran is 34 000 characters.

    See Statements and Attributes for more information on statements supported byXL Fortran.

    Statement keywordsA statement keyword is part of the syntax of a statement. A sequence of charactersis not reserved in all contexts. A statement keyword is interpreted as an entityname if the keyword is used in such a context.

    Statement labelsA statement label is a sequence of one to five digits, one of which must benonzero, that you can use to identify statements in a Fortran scoping unit. In fixedsource form, a statement label can appear anywhere in columns 1 through 5 of theinitial line of the statement. In free source form, such column restrictions do notapply.

    XL Fortran ignores all characters that appear in columns 1 through 5 onfixed source form continuation lines.

    Giving the same label to more than one statement in a scoping unit causesambiguity, and the compiler generates an error. White space and leading zeros arenot significant in distinguishing between statement labels. You can label anystatement, but a statement label reference can only refer to an executable statementor a FORMAT statement. The statement making the reference and the statementreferenced must be in the same scoping unit for the reference to resolve.

    DelimitersDelimiters are pairs used to enclose syntactic lists. XL Fortran supports thefollowing delimiters:v Parentheses: (...)v Slashes: /.../

    Chapter 2. XL Fortran language fundamentals 7

  • v Array constructors: (/.../)v Array constructors: [...]

    Lines and source formatsA line is a horizontal arrangement of characters. A column is a verticalarrangement of characters, where each character, or each byte of a multibytecharacter, in a given column shares the same horizontal line position.

    Because XL Fortran measures lines in bytes, these definitions apply onlyto lines containing single-byte characters. Each byte of a multibyte characteroccupies one column.

    The kinds of lines are:

    Initial line Is the first line of a statement.

    Continuationline

    Continues a statement beyond its initial line.

    Comment line Does not affect the executable program and can be used fordocumentation. The comment text continues to the end of a line.Although comment lines can follow one another, a comment line cannotbe continued. A line of all white space or a zero-length line is acomment line without any text. Comment text can contain anycharacters allowed in a character context.

    If an initial line or continuation line is not continued, or if it iscontinued but not in a character context, an inline comment can beplaced on the same line, to the right of any statement label, statementtext, and continuation character that may be present. An exclamationmark (!) begins an inline comment.

    Conditionalcompilation line

    Indicates that the line should only be compiled if recognition ofconditional compilation lines is enabled. A conditional compilationsentinel should appear on a conditional compilation line. For moreinformation, see Conditional compilation.

    Debug Line Indicates that the line is for debugging code (for fixed source formonly). In XL Fortran the letter D or X must be specified in column 1. Formore information, see Debug lines.

    Directive line Provides instructions or information to the compiler in XL Fortran. Formore information, see Comment form directives.

    IBM extension

    In XL Fortran source lines can be in fixed source form or free source form format.Use the SOURCEFORM directive to mix source formats within the same programunit. Fixed source form is the default when using the f77, fort77, xlf, xlf_r, orxlf_r7 invocation commands. Fortran 90 free source form is the default when usingthe f90, xlf90, xlf90_r, xlf90_r7, f95, xlf95, xlf95_r, xlf95_r7, f2003, xlf2003, orxlf2003_r invocation commands.

    See Compiling XL Fortran Programs in the XL Fortran Compiler Reference for detailson invocation commands.

    End of IBM extension

    8 XL Fortran: Language Reference

  • Fixed source formA fixed source form line is a sequence of 1 to 132 characters. The default

    line size is 72 characters. This is also the Fortran standard line size. You can changethe default using the -qfixed=right_margin compiler option. In XL Fortran there isno limit to the number of continuation lines for a statement, but the statementcannot be longer than 34 000 characters. Fortran 2003 limits the number ofcontinuation lines to 255, while Fortran 95 limits the number of continuation linesto 19.

    In fixed source form, columns beyond the right margin are not part of the line andyou can use these columns for identification, sequencing, or any other purpose.

    Except within a character context, white space is insignificant. You can embedwhite space between and within lexical tokens, without affecting the way thecompiler treats them.

    Tab formatting means that there is a tab character in columns 1 through 6of an initial line in XL Fortran, which directs the compiler to interpret the nextcharacter as being in column 7.

    Requirements for lines and for items on those lines are:v A comment line begins with a C, c, or an asterisk (*) in column 1, or is all white

    space. Comments can also follow an exclamation mark (!), except when theexclamation mark is in column 6 or in a character context.

    v For an initial line without tab formatting:– Columns 1 through 5 contain either blanks, a statement label, a D or

    an X in column 1 optionally followed by a statement label.– Column 6 contains a blank or zero.– Columns 7 through to the right margin contain statement text, possibly

    followed by other statements or by an inline comment.v For an initial line with tab formatting in XL Fortran:

    – Columns 1 through 6 begin with either blanks, a statement label, or a D or anX in column 1, optionally followed by a statement label. You must follow thiswith a tab character.

    – If you specify the -qxflag=oldtab compiler option, all columns from thecolumn immediately following the tab character through to the right margincontain statement text, possibly followed by other statements and by an inlinecomment.

    – If you do not specify -qxflag=oldtab compiler option, all columns fromcolumn 7, which corresponds to the character after the tab, to the rightmargin contain statement text, possibly followed by other statements and byan inline comment.

    v For a continuation line:– Column 1 must not contain C, c, or an asterisk. Columns 1 through 5 must

    not contain an exclamation mark as the leftmost nonblank character.Column 1 can contain a D or an X which signifies a debug line in XL

    Fortran. Otherwise, these columns can contain any characters allowed in acharacter context; these characters are ignored.

    – Column 6 must contain either a nonzero character or a nonwhite spacecharacter. The character in column 6 is the continuation character.Exclamation marks and semicolons are valid continuation characters.

    Chapter 2. XL Fortran language fundamentals 9

  • – Columns 7 through to the right margin contain continued statement text,possibly followed by other statements and an inline comment.

    – Neither the END statement or a statement whose initial line appears to be aprogram unit END statement can be continued.

    F2008 A semicolon separates statements on a single source line, except whenappearing in a character context, in a comment, or in columns 1 through 6.

    F2008 Two or more semicolon separators that are on the same line and arethemselves separated by only white space or other semicolons are considered to bea single separator. A separator that is the last character on a line or before an inlinecomment is ignored. Statements following a semicolon on the same line cannot belabeled. Additional statements cannot follow a program unit END statement on thesame line.

    Debug lines (IBM extension)A debug line, allowed only for fixed source form, contains source code used fordebugging and is specified in XL Fortran by the letter D, or the letter X in column1. The handling of debug lines depends on the -qdlines or the -qxlines compileroptions:v If you specify the -qdlines option, the compiler interprets the D in column 1 as a

    blank, and handles such lines as lines of source code. If you specify -qxlines ,the compiler interprets the X in column 1 as a blank and treats these lines assource code.

    v If you do not specify -qdlines or -qxlines, the compiler handles such lines ascomment lines. This is the default setting.

    If you continue a debugging statement on more than one line, every continuationline must have a continuation character as well as a D or an X in column 1. If theinitial line is not a debugging line, you can designate any continuation lines asdebug lines provided that the statement is syntactically correct, whether or not youspecify the -qdlines or -qxlines compiler option.

    Example of fixed source formC Column Numbers:C 1 2 3 4 5 6 7C23456789012345678901234567890123456789012345678901234567890123456789012

    !IBM* SOURCEFORM (FIXED)CHARACTER CHARSTR ; LOGICAL X ! 2 statements on 1 lineDO 10 I=1,10

    PRINT *,’this is the index’,I ! with an inline comment10 CONTINUEC

    CHARSTR="THIS IS A CONTINUEDX CHARACTER STRING"

    ! There will be 38 blanks in the string between "CONTINUED"! and "CHARACTER". You cannot have an inline comment on! the initial line because it would be interpreted as part! of CHARSTR (character context).

    100 PRINT *, IERROR! The following debug lines are compiled as source lines if! you use -qdlinesD IF (I.EQ.IDEBUG.AND.D + J.EQ.IDEBUG) WRITE(6,*) IERRORD IF (I.EQ.D + IDEBUG )D + WRITE(6,*) INFO

    END

    10 XL Fortran: Language Reference

  • Free source formA free source form line can specify up to 132 characters on each line. In XLFortran, there is no limit to the number of continuation lines for a statement, butthe statement cannot be longer than 34 000 characters. Fortran 2003 limits thenumber of continuation lines to 255, while Fortran 95 limits the number ofcontinuation lines to 39.

    Items can begin in any column of a line, subject to the following requirements forlines and items on those lines:v A comment line is a line of white space or begins with an exclamation mark that

    is not in a character context.v An initial line can contain any of the following items, in the following sequence:

    – A statement label.– Statement text. Note that statement text is required in an initial line.– Additional statements.– The ampersand continuation character.– An inline comment.

    v If you want to continue an initial line or continuation line in a non-charactercontext, the continuation line must start on the first noncomment line thatfollows the intial line or continuation line. To define a line as a continuation line,you must place an ampersand after the statements on the previousnon-comment line.

    v White space before and after the ampersand is optional, with the followingrestrictions:– If you also place an ampersand in the first nonblank character position of the

    continuation line, the statement continues at the next character positionfollowing the ampersand.

    – If a lexical token is continued, the ampersand must immediately follow theinitial part of the token, and the remainder of the token must immediatelystart after the ampersand on the continuation line.

    v A character context can be continued if the following conditions are true:– The last character of the continued line is an ampersand and is not followed

    by an inline comment. If the rightmost character of the statement text to becontinued is an ampersand, you must enter a second ampersand as acontinuation character.

    – The first nonblank character of the next noncomment line is an ampersand.

    F2008 A semicolon separates statements on a single source line, except when thesemicolon appears in a character context or in a comment. F2008 Two or moreseparators that are on the same line and are themselves separated by only whitespace or other semicolons are considered to be a single separator. A separator thatis the last character on a line or before an inline comment is ignored. Additionalstatements cannot follow a program unit END statement on the same line.

    White spaceWhite space must not appear within lexical tokens, except in a character context orin a format specification. You can freely insert white space between tokens toimprove readability, and white space must separate names, constants, and labelsfrom adjacent keywords, names, constants, and labels.

    Certain adjacent keywords can require white space. The following table listskeywords where white space is optional.

    Chapter 2. XL Fortran language fundamentals 11

  • Table 6. Keywords where white space is optional

    BLOCK DATA END FILE END SUBROUTINE

    DOUBLE COMPLEX �1� END FORALL END TYPE

    DOUBLE PRECISION END FUNCTION END UNION

    ELSE IF END IF END WHERE

    ELSE WHERE END INTERFACE GO TO

    END ASSOCIATE END MAP �1� IN OUT

    END BLOCK �2� END MODULE SELECT CASE

    END BLOCK DATA END PROGRAM SELECT TYPE �3�

    END DO END SELECT

    END ENUM �3� END STRUCTURE

    Note:

    �1� IBM extension

    �2� Fortran 2008

    �3� Fortran 2003

    Example of free source form!IBM* SOURCEFORM (FREE(F90))!! Column Numbers:! 1 2 3 4 5 6 7!23456789012345678901234567890123456789012345678901234567890123456789012DO I=1,20

    PRINT *,’this statement&& is continued’ ; IF (I.LT.5) PRINT *, I

    ENDDOEN&

    &D ! A lexical token can be continued

    IBM free source form (IBM extension)An IBM free source form line or statement is a sequence of up to 34000 characters.Items can begin in any column of a line, subject to the following requirements:v A comment line begins with a double quotation mark in column 1, is a line of

    all white space, or is a zero-length line. A comment line must not follow acontinued line. Comments can follow an exclamation mark except in a charactercontext.

    v An initial line can contain any of the following items, in the following sequence:– A statement label– Statement text– The minus sign continuation character– An inline comment

    v A continuation line immediately follows a continued line and can contain any ofthe following items, in the following sequence:– Statement text– A continuation character– An inline comment

    12 XL Fortran: Language Reference

  • If statement text on an initial line or continuation line is to continue, a minus signindicates continuation of the statement text on the next line. In a character context,if the rightmost character of the statement text to continue is a minus sign, asecond minus sign must be entered as a continuation character.

    Except within a character context, white space is insignificant. You can embedwhite space between and within lexical tokens, without affecting how the compilertreats those tokens.

    Example of IBM free source form!IBM* SOURCEFORM (FREE(IBM))"" Column Numbers:" 1 2 3 4 5 6 7"23456789012345678901234567890123456789012345678901234567890123456789012DO I=1,10PRINT *,’this is -

    the index’,I ! There will be 14 blanks in the string! between "is" and "the"

    END DOEND

    Conditional compilation (IBM extension)You can use sentinels to mark specific lines of an XL Fortran program forconditional compilation. This allows you to port code that contains statements thatare only valid or applicable in an SMP environment to a non-SMP environment.

    Conditional compilation is not supported with IBM free source form.

    Syntax for conditional compilation

    cond_comp_sentinelis a conditional compilation sentinel defined by the current source formand is either:v !$, C$, c$, or *$, for fixed source form, orv !$, for free source form

    fortran_source_lineis an XL Fortran source line

    Conditional compilation rules

    General rules:

    A valid XL Fortran source line must follow the conditional compilation sentinel.

    A conditional compilation line can contain the EJECT, INCLUDE or noncommentdirectives.

    A conditional compilation sentinel must not contain embedded white space.

    A conditional compilation sentinel must not follow a source statement or directiveon the same line.

    �� cond_comp_sentinel fortran_source_line ��

    Chapter 2. XL Fortran language fundamentals 13

  • If you are continuing a conditional compilation line, the conditional compilationsentinel must appear on at least one of the continuation lines or on the initial line.

    You must specify the -qcclines compiler option for conditional compilation lines tobe recognized. To disable recognition of conditional compilation lines, specify the-qnocclines compiler option.

    Trigger directives take precedence over co