Home | History | Annotate | Line # | Download | only in fortran
      1      1.1  mrg \input texinfo  @c -*-texinfo-*-
      2      1.1  mrg @c %**start of header
      3      1.1  mrg @setfilename gfortran.info
      4  1.1.1.3  mrg @set copyrights-gfortran 1999-2022
      5      1.1  mrg 
      6      1.1  mrg @include gcc-common.texi
      7      1.1  mrg 
      8      1.1  mrg @settitle The GNU Fortran Compiler
      9      1.1  mrg 
     10      1.1  mrg @c Create a separate index for command line options
     11      1.1  mrg @defcodeindex op
     12      1.1  mrg @c Merge the standard indexes into a single one.
     13      1.1  mrg @syncodeindex fn cp
     14      1.1  mrg @syncodeindex vr cp
     15      1.1  mrg @syncodeindex ky cp
     16      1.1  mrg @syncodeindex pg cp
     17      1.1  mrg @syncodeindex tp cp
     18      1.1  mrg 
     19      1.1  mrg @c TODO: The following "Part" definitions are included here temporarily
     20      1.1  mrg @c until they are incorporated into the official Texinfo distribution.
     21      1.1  mrg @c They borrow heavily from Texinfo's \unnchapentry definitions.
     22      1.1  mrg 
     23      1.1  mrg @tex
     24      1.1  mrg \gdef\part#1#2{%
     25      1.1  mrg   \pchapsepmacro
     26      1.1  mrg   \gdef\thischapter{}
     27      1.1  mrg   \begingroup
     28      1.1  mrg     \vglue\titlepagetopglue
     29      1.1  mrg     \titlefonts \rm
     30      1.1  mrg     \leftline{Part #1:@* #2}
     31      1.1  mrg     \vskip4pt \hrule height 4pt width \hsize \vskip4pt
     32      1.1  mrg   \endgroup
     33      1.1  mrg   \writetocentry{part}{#2}{#1}
     34      1.1  mrg }
     35      1.1  mrg \gdef\blankpart{%
     36      1.1  mrg   \writetocentry{blankpart}{}{}
     37      1.1  mrg }
     38      1.1  mrg % Part TOC-entry definition for summary contents.
     39      1.1  mrg \gdef\dosmallpartentry#1#2#3#4{%
     40      1.1  mrg   \vskip .5\baselineskip plus.2\baselineskip
     41      1.1  mrg   \begingroup
     42      1.1  mrg     \let\rm=\bf \rm
     43      1.1  mrg     \tocentry{Part #2: #1}{\doshortpageno\bgroup#4\egroup}
     44      1.1  mrg   \endgroup
     45      1.1  mrg }
     46      1.1  mrg \gdef\dosmallblankpartentry#1#2#3#4{%
     47      1.1  mrg   \vskip .5\baselineskip plus.2\baselineskip
     48      1.1  mrg }
     49      1.1  mrg % Part TOC-entry definition for regular contents.  This has to be
     50      1.1  mrg % equated to an existing entry to not cause problems when the PDF
     51      1.1  mrg % outline is created.
     52      1.1  mrg \gdef\dopartentry#1#2#3#4{%
     53      1.1  mrg   \unnchapentry{Part #2: #1}{}{#3}{#4}
     54      1.1  mrg }
     55      1.1  mrg \gdef\doblankpartentry#1#2#3#4{}
     56      1.1  mrg @end tex
     57      1.1  mrg 
     58      1.1  mrg @c %**end of header
     59      1.1  mrg 
     60      1.1  mrg @c Use with @@smallbook.
     61      1.1  mrg 
     62      1.1  mrg @c %** start of document
     63      1.1  mrg 
     64      1.1  mrg @c Cause even numbered pages to be printed on the left hand side of
     65      1.1  mrg @c the page and odd numbered pages to be printed on the right hand
     66      1.1  mrg @c side of the page.  Using this, you can print on both sides of a
     67      1.1  mrg @c sheet of paper and have the text on the same part of the sheet.
     68      1.1  mrg 
     69      1.1  mrg @c The text on right hand pages is pushed towards the right hand
     70      1.1  mrg @c margin and the text on left hand pages is pushed toward the left
     71      1.1  mrg @c hand margin.
     72      1.1  mrg @c (To provide the reverse effect, set bindingoffset to -0.75in.)
     73      1.1  mrg 
     74      1.1  mrg @c @tex
     75      1.1  mrg @c \global\bindingoffset=0.75in
     76      1.1  mrg @c \global\normaloffset =0.75in
     77      1.1  mrg @c @end tex
     78      1.1  mrg 
     79      1.1  mrg @copying
     80      1.1  mrg Copyright @copyright{} @value{copyrights-gfortran} Free Software Foundation, Inc.
     81      1.1  mrg 
     82      1.1  mrg Permission is granted to copy, distribute and/or modify this document
     83      1.1  mrg under the terms of the GNU Free Documentation License, Version 1.3 or
     84      1.1  mrg any later version published by the Free Software Foundation; with the
     85      1.1  mrg Invariant Sections being ``Funding Free Software'', the Front-Cover
     86      1.1  mrg Texts being (a) (see below), and with the Back-Cover Texts being (b)
     87      1.1  mrg (see below).  A copy of the license is included in the section entitled
     88      1.1  mrg ``GNU Free Documentation License''.
     89      1.1  mrg 
     90      1.1  mrg (a) The FSF's Front-Cover Text is:
     91      1.1  mrg 
     92      1.1  mrg      A GNU Manual
     93      1.1  mrg 
     94      1.1  mrg (b) The FSF's Back-Cover Text is:
     95      1.1  mrg 
     96      1.1  mrg      You have freedom to copy and modify this GNU Manual, like GNU
     97      1.1  mrg      software.  Copies published by the Free Software Foundation raise
     98      1.1  mrg      funds for GNU development.
     99      1.1  mrg @end copying
    100      1.1  mrg 
    101      1.1  mrg @ifinfo
    102      1.1  mrg @dircategory Software development
    103      1.1  mrg @direntry
    104      1.1  mrg * gfortran: (gfortran).                  The GNU Fortran Compiler.
    105      1.1  mrg @end direntry
    106      1.1  mrg This file documents the use and the internals of
    107      1.1  mrg the GNU Fortran compiler, (@command{gfortran}).
    108      1.1  mrg 
    109      1.1  mrg Published by the Free Software Foundation
    110      1.1  mrg 51 Franklin Street, Fifth Floor
    111      1.1  mrg Boston, MA 02110-1301 USA
    112      1.1  mrg 
    113      1.1  mrg @insertcopying
    114      1.1  mrg @end ifinfo
    115      1.1  mrg 
    116      1.1  mrg 
    117      1.1  mrg @setchapternewpage odd
    118      1.1  mrg @titlepage
    119      1.1  mrg @title Using GNU Fortran
    120      1.1  mrg @versionsubtitle
    121      1.1  mrg @author The @t{gfortran} team
    122      1.1  mrg @page
    123      1.1  mrg @vskip 0pt plus 1filll
    124      1.1  mrg Published by the Free Software Foundation@*
    125      1.1  mrg 51 Franklin Street, Fifth Floor@*
    126      1.1  mrg Boston, MA 02110-1301, USA@*
    127      1.1  mrg @c Last printed ??ber, 19??.@*
    128      1.1  mrg @c Printed copies are available for $? each.@*
    129      1.1  mrg @c ISBN ???
    130      1.1  mrg @sp 1
    131      1.1  mrg @insertcopying
    132      1.1  mrg @end titlepage
    133      1.1  mrg 
    134      1.1  mrg @c TODO: The following "Part" definitions are included here temporarily
    135      1.1  mrg @c until they are incorporated into the official Texinfo distribution.
    136      1.1  mrg 
    137      1.1  mrg @tex
    138      1.1  mrg \global\let\partentry=\dosmallpartentry
    139      1.1  mrg \global\let\blankpartentry=\dosmallblankpartentry
    140      1.1  mrg @end tex
    141      1.1  mrg @summarycontents
    142      1.1  mrg 
    143      1.1  mrg @tex
    144      1.1  mrg \global\let\partentry=\dopartentry
    145      1.1  mrg \global\let\blankpartentry=\doblankpartentry
    146      1.1  mrg @end tex
    147      1.1  mrg @contents
    148      1.1  mrg 
    149      1.1  mrg @page
    150      1.1  mrg 
    151      1.1  mrg @c ---------------------------------------------------------------------
    152      1.1  mrg @c TexInfo table of contents.
    153      1.1  mrg @c ---------------------------------------------------------------------
    154      1.1  mrg 
    155      1.1  mrg @ifnottex
    156      1.1  mrg @node Top
    157      1.1  mrg @top Introduction
    158      1.1  mrg @cindex Introduction
    159      1.1  mrg 
    160      1.1  mrg This manual documents the use of @command{gfortran},
    161      1.1  mrg the GNU Fortran compiler.  You can find in this manual how to invoke
    162      1.1  mrg @command{gfortran}, as well as its features and incompatibilities.
    163      1.1  mrg 
    164      1.1  mrg @ifset DEVELOPMENT
    165      1.1  mrg @emph{Warning:} This document, and the compiler it describes, are still
    166      1.1  mrg under development.  While efforts are made to keep it up-to-date, it might
    167      1.1  mrg not accurately reflect the status of the most recent GNU Fortran compiler.
    168      1.1  mrg @end ifset
    169      1.1  mrg 
    170      1.1  mrg @comment
    171      1.1  mrg @comment  When you add a new menu item, please keep the right hand
    172      1.1  mrg @comment  aligned to the same column.  Do not use tabs.  This provides
    173      1.1  mrg @comment  better formatting.
    174      1.1  mrg @comment
    175      1.1  mrg @menu
    176      1.1  mrg * Introduction::
    177      1.1  mrg 
    178      1.1  mrg Part I: Invoking GNU Fortran
    179      1.1  mrg * Invoking GNU Fortran:: Command options supported by @command{gfortran}.
    180      1.1  mrg * Runtime::              Influencing runtime behavior with environment variables.
    181      1.1  mrg 
    182      1.1  mrg Part II: Language Reference
    183      1.1  mrg * Compiler Characteristics::      User-visible implementation details.
    184      1.1  mrg * Extensions::                    Language extensions implemented by GNU Fortran.
    185      1.1  mrg * Mixed-Language Programming::    Interoperability with C
    186      1.1  mrg * Coarray Programming::
    187      1.1  mrg * Intrinsic Procedures:: Intrinsic procedures supported by GNU Fortran.
    188      1.1  mrg * Intrinsic Modules::    Intrinsic modules supported by GNU Fortran.
    189      1.1  mrg 
    190      1.1  mrg * Contributing::         How you can help.
    191      1.1  mrg * Copying::              GNU General Public License says
    192      1.1  mrg                          how you can copy and share GNU Fortran.
    193      1.1  mrg * GNU Free Documentation License::
    194      1.1  mrg                          How you can copy and share this manual.
    195      1.1  mrg * Funding::              How to help assure continued work for free software.
    196      1.1  mrg * Option Index::         Index of command line options
    197      1.1  mrg * Keyword Index::        Index of concepts
    198      1.1  mrg @end menu
    199      1.1  mrg @end ifnottex
    200      1.1  mrg 
    201      1.1  mrg @c ---------------------------------------------------------------------
    202      1.1  mrg @c Introduction
    203      1.1  mrg @c ---------------------------------------------------------------------
    204      1.1  mrg 
    205      1.1  mrg @node Introduction
    206      1.1  mrg @chapter Introduction
    207      1.1  mrg 
    208      1.1  mrg @c The following duplicates the text on the TexInfo table of contents.
    209      1.1  mrg @iftex
    210      1.1  mrg This manual documents the use of @command{gfortran}, the GNU Fortran
    211      1.1  mrg compiler.  You can find in this manual how to invoke @command{gfortran},
    212      1.1  mrg as well as its features and incompatibilities.
    213      1.1  mrg 
    214      1.1  mrg @ifset DEVELOPMENT
    215      1.1  mrg @emph{Warning:} This document, and the compiler it describes, are still
    216      1.1  mrg under development.  While efforts are made to keep it up-to-date, it
    217      1.1  mrg might not accurately reflect the status of the most recent GNU Fortran
    218      1.1  mrg compiler.
    219      1.1  mrg @end ifset
    220      1.1  mrg @end iftex
    221      1.1  mrg 
    222      1.1  mrg @menu
    223      1.1  mrg * About GNU Fortran::    What you should know about the GNU Fortran compiler.
    224      1.1  mrg * GNU Fortran and GCC::  You can compile Fortran, C, or other programs.
    225      1.1  mrg * Standards::            Standards supported by GNU Fortran.
    226      1.1  mrg @end menu
    227      1.1  mrg 
    228      1.1  mrg 
    229      1.1  mrg @c ---------------------------------------------------------------------
    230      1.1  mrg @c About GNU Fortran
    231      1.1  mrg @c ---------------------------------------------------------------------
    232      1.1  mrg 
    233      1.1  mrg @node About GNU Fortran
    234      1.1  mrg @section About GNU Fortran
    235      1.1  mrg 
    236  1.1.1.3  mrg The GNU Fortran compiler is the successor to @command{g77}, the
    237  1.1.1.3  mrg Fortran 77 front end included in GCC prior to version 4 (released in
    238  1.1.1.3  mrg 2005).  While it is backward-compatible with most @command{g77}
    239  1.1.1.3  mrg extensions and command-line options, @command{gfortran} is a completely new
    240  1.1.1.3  mrg implemention designed to support more modern dialects of Fortran.
    241  1.1.1.3  mrg GNU Fortran implements the Fortran 77, 90 and 95 standards
    242  1.1.1.3  mrg completely, most of the Fortran 2003 and 2008 standards, and some
    243  1.1.1.3  mrg features from the 2018 standard.  It also implements several extensions
    244  1.1.1.3  mrg including OpenMP and OpenACC support for parallel programming.
    245  1.1.1.3  mrg 
    246  1.1.1.3  mrg The GNU Fortran compiler passes the
    247  1.1.1.3  mrg @uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html,
    248  1.1.1.3  mrg NIST Fortran 77 Test Suite}, and produces acceptable results on the
    249  1.1.1.3  mrg @uref{https://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.
    250  1.1.1.3  mrg It also provides respectable performance on
    251  1.1.1.3  mrg the @uref{https://polyhedron.com/?page_id=175,
    252  1.1.1.3  mrg Polyhedron Fortran compiler benchmarks} and the
    253  1.1.1.3  mrg @uref{https://www.netlib.org/benchmark/livermore,
    254  1.1.1.3  mrg Livermore Fortran Kernels test}.  It has been used to compile a number of
    255  1.1.1.3  mrg large real-world programs, including
    256  1.1.1.3  mrg @uref{http://hirlam.org/, the HARMONIE and HIRLAM weather forecasting code} and
    257  1.1.1.3  mrg @uref{https://github.com/dylan-jayatilaka/tonto,
    258  1.1.1.3  mrg the Tonto quantum chemistry package}; see
    259  1.1.1.3  mrg @url{https://gcc.gnu.org/@/wiki/@/GfortranApps} for an extended list.
    260  1.1.1.3  mrg 
    261  1.1.1.3  mrg GNU Fortran provides the following functionality:
    262      1.1  mrg 
    263      1.1  mrg @itemize @bullet
    264      1.1  mrg @item
    265  1.1.1.3  mrg Read a program, stored in a file and containing @dfn{source code}
    266  1.1.1.3  mrg instructions written in Fortran 77.
    267      1.1  mrg 
    268      1.1  mrg @item
    269  1.1.1.3  mrg Translate the program into instructions a computer
    270      1.1  mrg can carry out more quickly than it takes to translate the
    271  1.1.1.3  mrg original Fortran instructions.
    272  1.1.1.3  mrg The result after compilation of a program is
    273      1.1  mrg @dfn{machine code},
    274  1.1.1.3  mrg which is efficiently translated and processed
    275      1.1  mrg by a machine such as your computer.
    276      1.1  mrg Humans usually are not as good writing machine code
    277      1.1  mrg as they are at writing Fortran (or C++, Ada, or Java),
    278      1.1  mrg because it is easy to make tiny mistakes writing machine code.
    279      1.1  mrg 
    280      1.1  mrg @item
    281  1.1.1.3  mrg Provide information about the reasons why
    282  1.1.1.3  mrg the compiler may be unable to create a binary from the source code,
    283  1.1.1.3  mrg for example if the source code is flawed.
    284  1.1.1.3  mrg The Fortran language standards require that the compiler can point out
    285  1.1.1.3  mrg mistakes in your code.
    286      1.1  mrg An incorrect usage of the language causes an @dfn{error message}.
    287      1.1  mrg 
    288  1.1.1.3  mrg The compiler also attempts to diagnose cases where your
    289  1.1.1.3  mrg program contains a correct usage of the language,
    290      1.1  mrg but instructs the computer to do something questionable.
    291  1.1.1.3  mrg This kind of diagnostic message is called a @dfn{warning message}.
    292      1.1  mrg 
    293      1.1  mrg @item
    294      1.1  mrg Provide optional information about the translation passes
    295      1.1  mrg from the source code to machine code.
    296  1.1.1.3  mrg This can help you to find the cause of
    297      1.1  mrg certain bugs which may not be obvious in the source code,
    298      1.1  mrg but may be more easily found at a lower level compiler output.
    299      1.1  mrg It also helps developers to find bugs in the compiler itself.
    300      1.1  mrg 
    301      1.1  mrg @item
    302      1.1  mrg Provide information in the generated machine code that can
    303      1.1  mrg make it easier to find bugs in the program (using a debugging tool,
    304      1.1  mrg called a @dfn{debugger}, such as the GNU Debugger @command{gdb}).
    305      1.1  mrg 
    306      1.1  mrg @item
    307      1.1  mrg Locate and gather machine code already generated to
    308  1.1.1.3  mrg perform actions requested by statements in the program.
    309      1.1  mrg This machine code is organized into @dfn{modules} and is located
    310      1.1  mrg and @dfn{linked} to the user program.
    311      1.1  mrg @end itemize
    312      1.1  mrg 
    313      1.1  mrg The GNU Fortran compiler consists of several components:
    314      1.1  mrg 
    315      1.1  mrg @itemize @bullet
    316      1.1  mrg @item
    317      1.1  mrg A version of the @command{gcc} command
    318      1.1  mrg (which also might be installed as the system's @command{cc} command)
    319      1.1  mrg that also understands and accepts Fortran source code.
    320      1.1  mrg The @command{gcc} command is the @dfn{driver} program for
    321      1.1  mrg all the languages in the GNU Compiler Collection (GCC);
    322      1.1  mrg With @command{gcc},
    323      1.1  mrg you can compile the source code of any language for
    324      1.1  mrg which a front end is available in GCC.
    325      1.1  mrg 
    326      1.1  mrg @item
    327      1.1  mrg The @command{gfortran} command itself,
    328      1.1  mrg which also might be installed as the
    329      1.1  mrg system's @command{f95} command.
    330      1.1  mrg @command{gfortran} is just another driver program,
    331      1.1  mrg but specifically for the Fortran compiler only.
    332  1.1.1.3  mrg The primary difference between the @command{gcc} and @command{gfortran}
    333  1.1.1.3  mrg commands is that the latter automatically links the correct libraries
    334  1.1.1.3  mrg to your program.
    335      1.1  mrg 
    336      1.1  mrg @item
    337      1.1  mrg A collection of run-time libraries.
    338      1.1  mrg These libraries contain the machine code needed to support
    339      1.1  mrg capabilities of the Fortran language that are not directly
    340      1.1  mrg provided by the machine code generated by the
    341      1.1  mrg @command{gfortran} compilation phase,
    342      1.1  mrg such as intrinsic functions and subroutines,
    343      1.1  mrg and routines for interaction with files and the operating system.
    344      1.1  mrg @c and mechanisms to spawn,
    345      1.1  mrg @c unleash and pause threads in parallelized code.
    346      1.1  mrg 
    347      1.1  mrg @item
    348      1.1  mrg The Fortran compiler itself, (@command{f951}).
    349      1.1  mrg This is the GNU Fortran parser and code generator,
    350      1.1  mrg linked to and interfaced with the GCC backend library.
    351      1.1  mrg @command{f951} ``translates'' the source code to
    352      1.1  mrg assembler code.  You would typically not use this
    353      1.1  mrg program directly;
    354      1.1  mrg instead, the @command{gcc} or @command{gfortran} driver
    355  1.1.1.3  mrg programs call it for you.
    356      1.1  mrg @end itemize
    357      1.1  mrg 
    358      1.1  mrg 
    359      1.1  mrg @c ---------------------------------------------------------------------
    360      1.1  mrg @c GNU Fortran and GCC
    361      1.1  mrg @c ---------------------------------------------------------------------
    362      1.1  mrg 
    363      1.1  mrg @node GNU Fortran and GCC
    364      1.1  mrg @section GNU Fortran and GCC
    365      1.1  mrg @cindex GNU Compiler Collection
    366      1.1  mrg @cindex GCC
    367      1.1  mrg 
    368      1.1  mrg GNU Fortran is a part of GCC, the @dfn{GNU Compiler Collection}.  GCC
    369      1.1  mrg consists of a collection of front ends for various languages, which
    370      1.1  mrg translate the source code into a language-independent form called
    371      1.1  mrg @dfn{GENERIC}.  This is then processed by a common middle end which
    372      1.1  mrg provides optimization, and then passed to one of a collection of back
    373      1.1  mrg ends which generate code for different computer architectures and
    374      1.1  mrg operating systems.
    375      1.1  mrg 
    376      1.1  mrg Functionally, this is implemented with a driver program (@command{gcc})
    377      1.1  mrg which provides the command-line interface for the compiler.  It calls
    378      1.1  mrg the relevant compiler front-end program (e.g., @command{f951} for
    379      1.1  mrg Fortran) for each file in the source code, and then calls the assembler
    380      1.1  mrg and linker as appropriate to produce the compiled output.  In a copy of
    381  1.1.1.3  mrg GCC that has been compiled with Fortran language support enabled,
    382  1.1.1.3  mrg @command{gcc} recognizes files with @file{.f}, @file{.for}, @file{.ftn},
    383      1.1  mrg @file{.f90}, @file{.f95}, @file{.f03} and @file{.f08} extensions as
    384  1.1.1.3  mrg Fortran source code, and compiles it accordingly.  A @command{gfortran}
    385      1.1  mrg driver program is also provided, which is identical to @command{gcc}
    386      1.1  mrg except that it automatically links the Fortran runtime libraries into the
    387      1.1  mrg compiled program.
    388      1.1  mrg 
    389      1.1  mrg Source files with @file{.f}, @file{.for}, @file{.fpp}, @file{.ftn}, @file{.F},
    390      1.1  mrg @file{.FOR}, @file{.FPP}, and @file{.FTN} extensions are treated as fixed form.
    391      1.1  mrg Source files with @file{.f90}, @file{.f95}, @file{.f03}, @file{.f08},
    392      1.1  mrg @file{.F90}, @file{.F95}, @file{.F03} and @file{.F08} extensions are
    393      1.1  mrg treated as free form.  The capitalized versions of either form are run
    394      1.1  mrg through preprocessing.  Source files with the lower case @file{.fpp}
    395      1.1  mrg extension are also run through preprocessing.
    396      1.1  mrg 
    397      1.1  mrg This manual specifically documents the Fortran front end, which handles
    398      1.1  mrg the programming language's syntax and semantics.  The aspects of GCC
    399  1.1.1.3  mrg that relate to the optimization passes and the back-end code generation
    400      1.1  mrg are documented in the GCC manual; see
    401      1.1  mrg @ref{Top,,Introduction,gcc,Using the GNU Compiler Collection (GCC)}.
    402      1.1  mrg The two manuals together provide a complete reference for the GNU
    403      1.1  mrg Fortran compiler.
    404      1.1  mrg 
    405      1.1  mrg @c ---------------------------------------------------------------------
    406      1.1  mrg @c Standards
    407      1.1  mrg @c ---------------------------------------------------------------------
    408      1.1  mrg 
    409      1.1  mrg @node Standards
    410      1.1  mrg @section Standards
    411      1.1  mrg @cindex Standards
    412      1.1  mrg 
    413      1.1  mrg @menu
    414  1.1.1.3  mrg * Fortran 95 status::
    415  1.1.1.3  mrg * Fortran 2003 status::
    416  1.1.1.3  mrg * Fortran 2008 status::
    417  1.1.1.3  mrg * Fortran 2018 status::
    418      1.1  mrg @end menu
    419      1.1  mrg 
    420  1.1.1.3  mrg Fortran is developed by the Working Group 5 of Sub-Committee 22 of the
    421  1.1.1.3  mrg Joint Technical Committee 1 of the International Organization for
    422  1.1.1.3  mrg Standardization and the International Electrotechnical Commission (IEC).
    423  1.1.1.3  mrg This group is known as @uref{http://www.nag.co.uk/sc22wg5/, WG5}.
    424  1.1.1.3  mrg Official Fortran standard documents are available for purchase
    425  1.1.1.3  mrg from ISO; a collection of free documents (typically final drafts) are
    426  1.1.1.3  mrg also available on the @uref{https://gcc.gnu.org/wiki/GFortranStandards, wiki}.
    427  1.1.1.3  mrg 
    428  1.1.1.3  mrg The GNU Fortran compiler implements ISO/IEC 1539:1997 (Fortran 95).
    429  1.1.1.3  mrg As such, it can also compile essentially all standard-compliant
    430  1.1.1.3  mrg Fortran 90 and Fortran 77 programs.  It also supports the ISO/IEC
    431  1.1.1.3  mrg TR-15581 enhancements to allocatable arrays.
    432  1.1.1.3  mrg 
    433  1.1.1.3  mrg GNU Fortran also supports almost all of ISO/IEC 1539-1:2004
    434  1.1.1.3  mrg (Fortran 2003) and ISO/IEC 1539-1:2010 (Fortran 2008).
    435  1.1.1.3  mrg It has partial support for features introduced in ISO/IEC
    436  1.1.1.3  mrg 1539:2018 (Fortran 2018), the most recent version of the Fortran
    437  1.1.1.3  mrg language standard, including full support for the Technical Specification
    438  1.1.1.3  mrg @code{Further Interoperability of Fortran with C} (ISO/IEC TS 29113:2012).
    439  1.1.1.3  mrg More details on support for these standards can be
    440  1.1.1.3  mrg found in the following sections of the documentation.
    441      1.1  mrg 
    442      1.1  mrg Additionally, the GNU Fortran compilers supports the OpenMP specification
    443  1.1.1.3  mrg (version 4.5 and partial support of the features of the 5.0 version,
    444  1.1.1.3  mrg @url{https://openmp.org/@/openmp-specifications/}).
    445  1.1.1.2  mrg There also is support for the OpenACC specification (targeting
    446  1.1.1.3  mrg version 2.6, @uref{https://www.openacc.org/}).  See
    447      1.1  mrg @uref{https://gcc.gnu.org/wiki/OpenACC} for more information.
    448      1.1  mrg 
    449  1.1.1.3  mrg @node Fortran 95 status
    450  1.1.1.3  mrg @subsection Fortran 95 status
    451      1.1  mrg @cindex Varying length strings
    452      1.1  mrg @cindex strings, varying length
    453  1.1.1.3  mrg @cindex conditional compilation
    454      1.1  mrg 
    455      1.1  mrg The Fortran 95 standard specifies in Part 2 (ISO/IEC 1539-2:2000)
    456      1.1  mrg varying length character strings.  While GNU Fortran currently does not
    457      1.1  mrg support such strings directly, there exist two Fortran implementations
    458      1.1  mrg for them, which work with GNU Fortran.  They can be found at
    459  1.1.1.3  mrg @uref{https://www.fortran.com/@/iso_varying_string.f95} and at
    460      1.1  mrg @uref{ftp://ftp.nag.co.uk/@/sc22wg5/@/ISO_VARYING_STRING/}.
    461      1.1  mrg 
    462      1.1  mrg Deferred-length character strings of Fortran 2003 supports part of
    463      1.1  mrg the features of @code{ISO_VARYING_STRING} and should be considered as
    464      1.1  mrg replacement. (Namely, allocatable or pointers of the type
    465      1.1  mrg @code{character(len=:)}.)
    466      1.1  mrg 
    467  1.1.1.3  mrg Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
    468  1.1.1.3  mrg Conditional Compilation, which is not widely used and not directly
    469  1.1.1.3  mrg supported by the GNU Fortran compiler.  You can use the program coco
    470  1.1.1.3  mrg to preprocess such files (@uref{http://www.daniellnagle.com/coco.html}).
    471  1.1.1.3  mrg 
    472  1.1.1.3  mrg @node Fortran 2003 status
    473  1.1.1.3  mrg @subsection Fortran 2003 status
    474  1.1.1.3  mrg 
    475  1.1.1.3  mrg GNU Fortran implements the Fortran 2003 (ISO/IEC 1539-1:2004) standard
    476  1.1.1.3  mrg except for finalization support, which is incomplete.
    477  1.1.1.3  mrg See the
    478  1.1.1.3  mrg @uref{https://gcc.gnu.org/wiki/Fortran2003, wiki page} for a full list
    479  1.1.1.3  mrg of new features introduced by Fortran 2003 and their implementation status.
    480  1.1.1.3  mrg 
    481  1.1.1.3  mrg @node Fortran 2008 status
    482  1.1.1.3  mrg @subsection Fortran 2008 status
    483  1.1.1.3  mrg 
    484  1.1.1.3  mrg The GNU Fortran compiler supports almost all features of Fortran 2008;
    485  1.1.1.3  mrg the @uref{https://gcc.gnu.org/wiki/Fortran2008Status, wiki}
    486  1.1.1.3  mrg has some information about the current implementation status.
    487  1.1.1.3  mrg In particular, the following are not yet supported:
    488  1.1.1.3  mrg 
    489  1.1.1.3  mrg @itemize @bullet
    490  1.1.1.3  mrg @item
    491  1.1.1.3  mrg @code{DO CONCURRENT} and @code{FORALL} do not recognize a
    492  1.1.1.3  mrg type-spec in the loop header.
    493  1.1.1.3  mrg 
    494  1.1.1.3  mrg @item
    495  1.1.1.3  mrg The change to permit any constant expression in subscripts and
    496  1.1.1.3  mrg nested implied-do limits in a @code{DATA} statement has not been implemented.
    497  1.1.1.3  mrg @end itemize
    498  1.1.1.3  mrg 
    499  1.1.1.3  mrg 
    500  1.1.1.3  mrg @node Fortran 2018 status
    501  1.1.1.3  mrg @subsection Fortran 2018 status
    502  1.1.1.3  mrg 
    503  1.1.1.3  mrg Fortran 2018 (ISO/IEC 1539:2018) is the most recent version
    504  1.1.1.3  mrg of the Fortran language standard.  GNU Fortran implements some of the
    505  1.1.1.3  mrg new features of this standard:
    506  1.1.1.3  mrg 
    507  1.1.1.3  mrg @itemize @bullet
    508  1.1.1.3  mrg @item
    509  1.1.1.3  mrg All Fortran 2018 features derived from ISO/IEC TS 29113:2012,
    510  1.1.1.3  mrg ``Further Interoperability of Fortran with C'', are supported by GNU Fortran.
    511  1.1.1.3  mrg This includes assumed-type and assumed-rank objects and
    512  1.1.1.3  mrg the @code{SELECT RANK} construct as well as the parts relating to
    513  1.1.1.3  mrg @code{BIND(C)} functions.
    514  1.1.1.3  mrg See also @ref{Further Interoperability of Fortran with C}.
    515  1.1.1.3  mrg 
    516  1.1.1.3  mrg @item
    517  1.1.1.3  mrg GNU Fortran supports a subset of features derived from ISO/IEC TS 18508:2015,
    518  1.1.1.3  mrg ``Additional Parallel Features in Fortran'':
    519  1.1.1.3  mrg 
    520  1.1.1.3  mrg @itemize @bullet
    521  1.1.1.3  mrg @item
    522  1.1.1.3  mrg The new atomic ADD, CAS, FETCH and ADD/OR/XOR, OR and XOR intrinsics.
    523  1.1.1.3  mrg 
    524  1.1.1.3  mrg @item
    525  1.1.1.3  mrg The @code{CO_MIN} and @code{CO_MAX} and @code{SUM} reduction intrinsics,
    526  1.1.1.3  mrg and the @code{CO_BROADCAST} and @code{CO_REDUCE} intrinsic, except that those
    527  1.1.1.3  mrg do not support polymorphic types or types with allocatable, pointer or
    528  1.1.1.3  mrg polymorphic components.
    529  1.1.1.3  mrg 
    530  1.1.1.3  mrg @item
    531  1.1.1.3  mrg Events (@code{EVENT POST}, @code{EVENT WAIT}, @code{EVENT_QUERY}).
    532  1.1.1.3  mrg 
    533  1.1.1.3  mrg @item
    534  1.1.1.3  mrg Failed images (@code{FAIL IMAGE}, @code{IMAGE_STATUS},
    535  1.1.1.3  mrg @code{FAILED_IMAGES}, @code{STOPPED_IMAGES}).
    536  1.1.1.3  mrg 
    537  1.1.1.3  mrg @end itemize
    538  1.1.1.3  mrg 
    539  1.1.1.3  mrg @item
    540  1.1.1.3  mrg An @code{ERROR STOP} statement is permitted in a @code{PURE}
    541  1.1.1.3  mrg procedure.
    542  1.1.1.3  mrg 
    543  1.1.1.3  mrg @item
    544  1.1.1.3  mrg GNU Fortran supports the @code{IMPLICIT NONE} statement with an
    545  1.1.1.3  mrg @code{implicit-none-spec-list}.
    546  1.1.1.3  mrg 
    547  1.1.1.3  mrg @item
    548  1.1.1.3  mrg The behavior of the @code{INQUIRE} statement with the @code{RECL=}
    549  1.1.1.3  mrg specifier now conforms to Fortran 2018.
    550  1.1.1.3  mrg 
    551  1.1.1.3  mrg @end itemize
    552  1.1.1.3  mrg 
    553      1.1  mrg 
    554      1.1  mrg @c =====================================================================
    555      1.1  mrg @c PART I: INVOCATION REFERENCE
    556      1.1  mrg @c =====================================================================
    557      1.1  mrg 
    558      1.1  mrg @tex
    559      1.1  mrg \part{I}{Invoking GNU Fortran}
    560      1.1  mrg @end tex
    561      1.1  mrg 
    562      1.1  mrg @c ---------------------------------------------------------------------
    563      1.1  mrg @c Compiler Options
    564      1.1  mrg @c ---------------------------------------------------------------------
    565      1.1  mrg 
    566      1.1  mrg @include invoke.texi
    567      1.1  mrg 
    568      1.1  mrg 
    569      1.1  mrg @c ---------------------------------------------------------------------
    570      1.1  mrg @c Runtime
    571      1.1  mrg @c ---------------------------------------------------------------------
    572      1.1  mrg 
    573      1.1  mrg @node Runtime
    574      1.1  mrg @chapter Runtime:  Influencing runtime behavior with environment variables
    575      1.1  mrg @cindex environment variable
    576      1.1  mrg 
    577      1.1  mrg The behavior of the @command{gfortran} can be influenced by
    578      1.1  mrg environment variables.
    579      1.1  mrg 
    580      1.1  mrg Malformed environment variables are silently ignored.
    581      1.1  mrg 
    582      1.1  mrg @menu
    583      1.1  mrg * TMPDIR:: Directory for scratch files
    584      1.1  mrg * GFORTRAN_STDIN_UNIT:: Unit number for standard input
    585      1.1  mrg * GFORTRAN_STDOUT_UNIT:: Unit number for standard output
    586      1.1  mrg * GFORTRAN_STDERR_UNIT:: Unit number for standard error
    587  1.1.1.2  mrg * GFORTRAN_UNBUFFERED_ALL:: Do not buffer I/O for all units
    588      1.1  mrg * GFORTRAN_UNBUFFERED_PRECONNECTED:: Do not buffer I/O for preconnected units.
    589      1.1  mrg * GFORTRAN_SHOW_LOCUS::  Show location for runtime errors
    590      1.1  mrg * GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted
    591      1.1  mrg * GFORTRAN_LIST_SEPARATOR::  Separator for list output
    592  1.1.1.3  mrg * GFORTRAN_CONVERT_UNIT::  Set conversion for unformatted I/O
    593      1.1  mrg * GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
    594  1.1.1.2  mrg * GFORTRAN_FORMATTED_BUFFER_SIZE:: Buffer size for formatted files
    595  1.1.1.2  mrg * GFORTRAN_UNFORMATTED_BUFFER_SIZE:: Buffer size for unformatted files
    596      1.1  mrg @end menu
    597      1.1  mrg 
    598      1.1  mrg @node TMPDIR
    599      1.1  mrg @section @env{TMPDIR}---Directory for scratch files
    600      1.1  mrg 
    601      1.1  mrg When opening a file with @code{STATUS='SCRATCH'}, GNU Fortran tries to
    602      1.1  mrg create the file in one of the potential directories by testing each
    603      1.1  mrg directory in the order below.
    604      1.1  mrg 
    605      1.1  mrg @enumerate
    606      1.1  mrg @item
    607      1.1  mrg The environment variable @env{TMPDIR}, if it exists.
    608      1.1  mrg 
    609      1.1  mrg @item
    610      1.1  mrg On the MinGW target, the directory returned by the @code{GetTempPath}
    611      1.1  mrg function. Alternatively, on the Cygwin target, the @env{TMP} and
    612      1.1  mrg @env{TEMP} environment variables, if they exist, in that order.
    613      1.1  mrg 
    614      1.1  mrg @item
    615      1.1  mrg The @code{P_tmpdir} macro if it is defined, otherwise the directory
    616      1.1  mrg @file{/tmp}.
    617      1.1  mrg @end enumerate
    618      1.1  mrg 
    619      1.1  mrg @node GFORTRAN_STDIN_UNIT
    620      1.1  mrg @section @env{GFORTRAN_STDIN_UNIT}---Unit number for standard input
    621      1.1  mrg 
    622      1.1  mrg This environment variable can be used to select the unit number
    623      1.1  mrg preconnected to standard input.  This must be a positive integer.
    624      1.1  mrg The default value is 5.
    625      1.1  mrg 
    626      1.1  mrg @node GFORTRAN_STDOUT_UNIT
    627      1.1  mrg @section @env{GFORTRAN_STDOUT_UNIT}---Unit number for standard output
    628      1.1  mrg 
    629      1.1  mrg This environment variable can be used to select the unit number
    630      1.1  mrg preconnected to standard output.  This must be a positive integer.
    631      1.1  mrg The default value is 6.
    632      1.1  mrg 
    633      1.1  mrg @node GFORTRAN_STDERR_UNIT
    634      1.1  mrg @section @env{GFORTRAN_STDERR_UNIT}---Unit number for standard error
    635      1.1  mrg 
    636      1.1  mrg This environment variable can be used to select the unit number
    637      1.1  mrg preconnected to standard error.  This must be a positive integer.
    638      1.1  mrg The default value is 0.
    639      1.1  mrg 
    640      1.1  mrg @node GFORTRAN_UNBUFFERED_ALL
    641      1.1  mrg @section @env{GFORTRAN_UNBUFFERED_ALL}---Do not buffer I/O on all units
    642      1.1  mrg 
    643      1.1  mrg This environment variable controls whether all I/O is unbuffered.  If
    644      1.1  mrg the first letter is @samp{y}, @samp{Y} or @samp{1}, all I/O is
    645      1.1  mrg unbuffered.  This will slow down small sequential reads and writes.  If
    646      1.1  mrg the first letter is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.
    647      1.1  mrg This is the default.
    648      1.1  mrg 
    649      1.1  mrg @node GFORTRAN_UNBUFFERED_PRECONNECTED
    650      1.1  mrg @section @env{GFORTRAN_UNBUFFERED_PRECONNECTED}---Do not buffer I/O on preconnected units
    651      1.1  mrg 
    652      1.1  mrg The environment variable named @env{GFORTRAN_UNBUFFERED_PRECONNECTED} controls
    653      1.1  mrg whether I/O on a preconnected unit (i.e.@: STDOUT or STDERR) is unbuffered.  If
    654      1.1  mrg the first letter is @samp{y}, @samp{Y} or @samp{1}, I/O is unbuffered.  This
    655      1.1  mrg will slow down small sequential reads and writes.  If the first letter
    656      1.1  mrg is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.  This is the default.
    657      1.1  mrg 
    658      1.1  mrg @node GFORTRAN_SHOW_LOCUS
    659      1.1  mrg @section @env{GFORTRAN_SHOW_LOCUS}---Show location for runtime errors
    660      1.1  mrg 
    661      1.1  mrg If the first letter is @samp{y}, @samp{Y} or @samp{1}, filename and
    662      1.1  mrg line numbers for runtime errors are printed.  If the first letter is
    663      1.1  mrg @samp{n}, @samp{N} or @samp{0}, do not print filename and line numbers
    664      1.1  mrg for runtime errors.  The default is to print the location.
    665      1.1  mrg 
    666      1.1  mrg @node GFORTRAN_OPTIONAL_PLUS
    667      1.1  mrg @section @env{GFORTRAN_OPTIONAL_PLUS}---Print leading + where permitted
    668      1.1  mrg 
    669      1.1  mrg If the first letter is @samp{y}, @samp{Y} or @samp{1},
    670      1.1  mrg a plus sign is printed
    671      1.1  mrg where permitted by the Fortran standard.  If the first letter
    672      1.1  mrg is @samp{n}, @samp{N} or @samp{0}, a plus sign is not printed
    673      1.1  mrg in most cases.  Default is not to print plus signs.
    674      1.1  mrg 
    675      1.1  mrg @node GFORTRAN_LIST_SEPARATOR
    676      1.1  mrg @section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list output
    677      1.1  mrg 
    678      1.1  mrg This environment variable specifies the separator when writing
    679      1.1  mrg list-directed output.  It may contain any number of spaces and
    680      1.1  mrg at most one comma.  If you specify this on the command line,
    681      1.1  mrg be sure to quote spaces, as in
    682      1.1  mrg @smallexample
    683      1.1  mrg $ GFORTRAN_LIST_SEPARATOR='  ,  ' ./a.out
    684      1.1  mrg @end smallexample
    685      1.1  mrg when @command{a.out} is the compiled Fortran program that you want to run.
    686      1.1  mrg Default is a single space.
    687      1.1  mrg 
    688      1.1  mrg @node GFORTRAN_CONVERT_UNIT
    689  1.1.1.3  mrg @section @env{GFORTRAN_CONVERT_UNIT}---Set conversion for unformatted I/O
    690      1.1  mrg 
    691      1.1  mrg By setting the @env{GFORTRAN_CONVERT_UNIT} variable, it is possible
    692      1.1  mrg to change the representation of data for unformatted files.
    693  1.1.1.3  mrg The syntax for the @env{GFORTRAN_CONVERT_UNIT} variable for
    694  1.1.1.3  mrg most systems is:
    695      1.1  mrg @smallexample
    696      1.1  mrg GFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;
    697      1.1  mrg mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;
    698      1.1  mrg exception: mode ':' unit_list | unit_list ;
    699      1.1  mrg unit_list: unit_spec | unit_list unit_spec ;
    700      1.1  mrg unit_spec: INTEGER | INTEGER '-' INTEGER ;
    701      1.1  mrg @end smallexample
    702      1.1  mrg The variable consists of an optional default mode, followed by
    703      1.1  mrg a list of optional exceptions, which are separated by semicolons
    704      1.1  mrg from the preceding default and each other.  Each exception consists
    705      1.1  mrg of a format and a comma-separated list of units.  Valid values for
    706      1.1  mrg the modes are the same as for the @code{CONVERT} specifier:
    707      1.1  mrg 
    708      1.1  mrg @itemize @w{}
    709      1.1  mrg @item @code{NATIVE} Use the native format.  This is the default.
    710      1.1  mrg @item @code{SWAP} Swap between little- and big-endian.
    711      1.1  mrg @item @code{LITTLE_ENDIAN} Use the little-endian format
    712      1.1  mrg for unformatted files.
    713      1.1  mrg @item @code{BIG_ENDIAN} Use the big-endian format for unformatted files.
    714      1.1  mrg @end itemize
    715  1.1.1.3  mrg For POWER systems which support @option{-mabi=ieeelongdouble},
    716  1.1.1.3  mrg there are additional options, which can be combined with the
    717  1.1.1.3  mrg others with commas. Those are
    718  1.1.1.3  mrg @itemize @w{}
    719  1.1.1.3  mrg @item @code{R16_IEEE} Use IEEE 128-bit format for @code{REAL(KIND=16)}.
    720  1.1.1.3  mrg @item @code{R16_IBM} Use IBM @code{long double} format for
    721  1.1.1.3  mrg @code{REAL(KIND=16)}.
    722  1.1.1.3  mrg @end itemize
    723      1.1  mrg A missing mode for an exception is taken to mean @code{BIG_ENDIAN}.
    724      1.1  mrg Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:
    725      1.1  mrg @itemize @w{}
    726      1.1  mrg @item @code{'big_endian'}  Do all unformatted I/O in big_endian mode.
    727      1.1  mrg @item @code{'little_endian;native:10-20,25'}  Do all unformatted I/O
    728      1.1  mrg in little_endian mode, except for units 10 to 20 and 25, which are in
    729      1.1  mrg native format.
    730      1.1  mrg @item @code{'10-20'}  Units 10 to 20 are big-endian, the rest is native.
    731  1.1.1.3  mrg @item @code{'big_endian,r16_ibm'} Do all unformatted I/O in big-endian
    732  1.1.1.3  mrg mode and use IBM long double for output of @code{REAL(KIND=16)} values.
    733      1.1  mrg @end itemize
    734      1.1  mrg 
    735      1.1  mrg Setting the environment variables should be done on the command
    736      1.1  mrg line or via the @command{export}
    737      1.1  mrg command for @command{sh}-compatible shells and via @command{setenv}
    738      1.1  mrg for @command{csh}-compatible shells.
    739      1.1  mrg 
    740      1.1  mrg Example for @command{sh}:
    741      1.1  mrg @smallexample
    742      1.1  mrg $ gfortran foo.f90
    743      1.1  mrg $ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out
    744      1.1  mrg @end smallexample
    745      1.1  mrg 
    746      1.1  mrg Example code for @command{csh}:
    747      1.1  mrg @smallexample
    748      1.1  mrg % gfortran foo.f90
    749      1.1  mrg % setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'
    750      1.1  mrg % ./a.out
    751      1.1  mrg @end smallexample
    752      1.1  mrg 
    753      1.1  mrg Using anything but the native representation for unformatted data
    754      1.1  mrg carries a significant speed overhead.  If speed in this area matters
    755      1.1  mrg to you, it is best if you use this only for data that needs to be
    756      1.1  mrg portable.
    757      1.1  mrg 
    758      1.1  mrg @xref{CONVERT specifier}, for an alternative way to specify the
    759      1.1  mrg data representation for unformatted files.  @xref{Runtime Options}, for
    760      1.1  mrg setting a default data representation for the whole program.  The
    761      1.1  mrg @code{CONVERT} specifier overrides the @option{-fconvert} compile options.
    762      1.1  mrg 
    763      1.1  mrg @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
    764      1.1  mrg environment variable will override the CONVERT specifier in the
    765      1.1  mrg open statement}.  This is to give control over data formats to
    766      1.1  mrg users who do not have the source code of their program available.
    767      1.1  mrg 
    768      1.1  mrg @node GFORTRAN_ERROR_BACKTRACE
    769      1.1  mrg @section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors
    770      1.1  mrg 
    771      1.1  mrg If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to @samp{y},
    772      1.1  mrg @samp{Y} or @samp{1} (only the first letter is relevant) then a
    773      1.1  mrg backtrace is printed when a serious run-time error occurs.  To disable
    774      1.1  mrg the backtracing, set the variable to @samp{n}, @samp{N}, @samp{0}.
    775      1.1  mrg Default is to print a backtrace unless the @option{-fno-backtrace}
    776      1.1  mrg compile option was used.
    777      1.1  mrg 
    778      1.1  mrg @node GFORTRAN_FORMATTED_BUFFER_SIZE
    779      1.1  mrg @section @env{GFORTRAN_FORMATTED_BUFFER_SIZE}---Set buffer size for formatted I/O
    780      1.1  mrg 
    781      1.1  mrg The @env{GFORTRAN_FORMATTED_BUFFER_SIZE} environment variable
    782      1.1  mrg specifies buffer size in bytes to be used for formatted output.
    783      1.1  mrg The default value is 8192.
    784      1.1  mrg 
    785      1.1  mrg @node GFORTRAN_UNFORMATTED_BUFFER_SIZE
    786      1.1  mrg @section @env{GFORTRAN_UNFORMATTED_BUFFER_SIZE}---Set buffer size for unformatted I/O
    787      1.1  mrg 
    788      1.1  mrg The @env{GFORTRAN_UNFORMATTED_BUFFER_SIZE} environment variable
    789      1.1  mrg specifies buffer size in bytes to be used for unformatted output.
    790      1.1  mrg The default value is 131072.
    791      1.1  mrg 
    792      1.1  mrg @c =====================================================================
    793      1.1  mrg @c PART II: LANGUAGE REFERENCE
    794      1.1  mrg @c =====================================================================
    795      1.1  mrg 
    796      1.1  mrg @tex
    797      1.1  mrg \part{II}{Language Reference}
    798      1.1  mrg @end tex
    799      1.1  mrg 
    800      1.1  mrg 
    801      1.1  mrg 
    802      1.1  mrg @c ---------------------------------------------------------------------
    803      1.1  mrg @c Compiler Characteristics
    804      1.1  mrg @c ---------------------------------------------------------------------
    805      1.1  mrg 
    806      1.1  mrg @node Compiler Characteristics
    807      1.1  mrg @chapter Compiler Characteristics
    808      1.1  mrg 
    809      1.1  mrg This chapter describes certain characteristics of the GNU Fortran
    810      1.1  mrg compiler, that are not specified by the Fortran standard, but which
    811      1.1  mrg might in some way or another become visible to the programmer.
    812      1.1  mrg 
    813      1.1  mrg @menu
    814      1.1  mrg * KIND Type Parameters::
    815      1.1  mrg * Internal representation of LOGICAL variables::
    816      1.1  mrg * Evaluation of logical expressions::
    817      1.1  mrg * MAX and MIN intrinsics with REAL NaN arguments::
    818      1.1  mrg * Thread-safety of the runtime library::
    819      1.1  mrg * Data consistency and durability::
    820      1.1  mrg * Files opened without an explicit ACTION= specifier::
    821      1.1  mrg * File operations on symbolic links::
    822      1.1  mrg * File format of unformatted sequential files::
    823      1.1  mrg * Asynchronous I/O::
    824      1.1  mrg @end menu
    825      1.1  mrg 
    826      1.1  mrg 
    827      1.1  mrg @node KIND Type Parameters
    828      1.1  mrg @section KIND Type Parameters
    829      1.1  mrg @cindex kind
    830      1.1  mrg 
    831      1.1  mrg The @code{KIND} type parameters supported by GNU Fortran for the primitive
    832      1.1  mrg data types are:
    833      1.1  mrg 
    834      1.1  mrg @table @code
    835      1.1  mrg 
    836      1.1  mrg @item INTEGER
    837      1.1  mrg 1, 2, 4, 8*, 16*, default: 4**
    838      1.1  mrg 
    839      1.1  mrg @item LOGICAL
    840      1.1  mrg 1, 2, 4, 8*, 16*, default: 4**
    841      1.1  mrg 
    842      1.1  mrg @item REAL
    843      1.1  mrg 4, 8, 10*, 16*, default: 4***
    844      1.1  mrg 
    845      1.1  mrg @item COMPLEX
    846      1.1  mrg 4, 8, 10*, 16*, default: 4***
    847      1.1  mrg 
    848      1.1  mrg @item DOUBLE PRECISION
    849      1.1  mrg 4, 8, 10*, 16*, default: 8***
    850      1.1  mrg 
    851      1.1  mrg @item CHARACTER
    852      1.1  mrg 1, 4, default: 1
    853      1.1  mrg 
    854      1.1  mrg @end table
    855      1.1  mrg 
    856      1.1  mrg @noindent
    857      1.1  mrg * not available on all systems @*
    858      1.1  mrg ** unless @option{-fdefault-integer-8} is used @*
    859      1.1  mrg *** unless @option{-fdefault-real-8} is used (see @ref{Fortran Dialect Options})
    860      1.1  mrg 
    861      1.1  mrg @noindent
    862      1.1  mrg The @code{KIND} value matches the storage size in bytes, except for
    863      1.1  mrg @code{COMPLEX} where the storage size is twice as much (or both real and
    864      1.1  mrg imaginary part are a real value of the given size).  It is recommended to use
    865      1.1  mrg the @ref{SELECTED_CHAR_KIND}, @ref{SELECTED_INT_KIND} and
    866      1.1  mrg @ref{SELECTED_REAL_KIND} intrinsics or the @code{INT8}, @code{INT16},
    867      1.1  mrg @code{INT32}, @code{INT64}, @code{REAL32}, @code{REAL64}, and @code{REAL128}
    868      1.1  mrg parameters of the @code{ISO_FORTRAN_ENV} module instead of the concrete values.
    869      1.1  mrg The available kind parameters can be found in the constant arrays
    870      1.1  mrg @code{CHARACTER_KINDS}, @code{INTEGER_KINDS}, @code{LOGICAL_KINDS} and
    871      1.1  mrg @code{REAL_KINDS} in the @ref{ISO_FORTRAN_ENV} module.  For C interoperability,
    872      1.1  mrg the kind parameters of the @ref{ISO_C_BINDING} module should be used.
    873      1.1  mrg 
    874      1.1  mrg 
    875      1.1  mrg @node Internal representation of LOGICAL variables
    876      1.1  mrg @section Internal representation of LOGICAL variables
    877      1.1  mrg @cindex logical, variable representation
    878      1.1  mrg 
    879      1.1  mrg The Fortran standard does not specify how variables of @code{LOGICAL}
    880      1.1  mrg type are represented, beyond requiring that @code{LOGICAL} variables
    881      1.1  mrg of default kind have the same storage size as default @code{INTEGER}
    882      1.1  mrg and @code{REAL} variables.  The GNU Fortran internal representation is
    883      1.1  mrg as follows.
    884      1.1  mrg 
    885      1.1  mrg A @code{LOGICAL(KIND=N)} variable is represented as an
    886      1.1  mrg @code{INTEGER(KIND=N)} variable, however, with only two permissible
    887      1.1  mrg values: @code{1} for @code{.TRUE.} and @code{0} for
    888      1.1  mrg @code{.FALSE.}.  Any other integer value results in undefined behavior.
    889      1.1  mrg 
    890      1.1  mrg See also @ref{Argument passing conventions} and @ref{Interoperability with C}.
    891      1.1  mrg 
    892      1.1  mrg 
    893      1.1  mrg @node Evaluation of logical expressions
    894      1.1  mrg @section Evaluation of logical expressions
    895      1.1  mrg 
    896      1.1  mrg The Fortran standard does not require the compiler to evaluate all parts of an
    897      1.1  mrg expression, if they do not contribute to the final result.  For logical
    898      1.1  mrg expressions with @code{.AND.} or @code{.OR.} operators, in particular, GNU
    899      1.1  mrg Fortran will optimize out function calls (even to impure functions) if the
    900      1.1  mrg result of the expression can be established without them.  However, since not
    901      1.1  mrg all compilers do that, and such an optimization can potentially modify the
    902      1.1  mrg program flow and subsequent results, GNU Fortran throws warnings for such
    903      1.1  mrg situations with the @option{-Wfunction-elimination} flag.
    904      1.1  mrg 
    905      1.1  mrg 
    906      1.1  mrg @node MAX and MIN intrinsics with REAL NaN arguments
    907      1.1  mrg @section MAX and MIN intrinsics with REAL NaN arguments
    908      1.1  mrg @cindex MAX, MIN, NaN
    909      1.1  mrg 
    910      1.1  mrg The Fortran standard does not specify what the result of the
    911      1.1  mrg @code{MAX} and @code{MIN} intrinsics are if one of the arguments is a
    912      1.1  mrg @code{NaN}.  Accordingly, the GNU Fortran compiler does not specify
    913      1.1  mrg that either, as this allows for faster and more compact code to be
    914      1.1  mrg generated.  If the programmer wishes to take some specific action in
    915      1.1  mrg case one of the arguments is a @code{NaN}, it is necessary to
    916      1.1  mrg explicitly test the arguments before calling @code{MAX} or @code{MIN},
    917      1.1  mrg e.g. with the @code{IEEE_IS_NAN} function from the intrinsic module
    918      1.1  mrg @code{IEEE_ARITHMETIC}.
    919      1.1  mrg 
    920      1.1  mrg 
    921      1.1  mrg @node Thread-safety of the runtime library
    922      1.1  mrg @section Thread-safety of the runtime library
    923      1.1  mrg @cindex thread-safety, threads
    924      1.1  mrg 
    925      1.1  mrg GNU Fortran can be used in programs with multiple threads, e.g.@: by
    926      1.1  mrg using OpenMP, by calling OS thread handling functions via the
    927      1.1  mrg @code{ISO_C_BINDING} facility, or by GNU Fortran compiled library code
    928      1.1  mrg being called from a multi-threaded program.
    929      1.1  mrg 
    930      1.1  mrg The GNU Fortran runtime library, (@code{libgfortran}), supports being
    931      1.1  mrg called concurrently from multiple threads with the following
    932      1.1  mrg exceptions.
    933      1.1  mrg 
    934      1.1  mrg During library initialization, the C @code{getenv} function is used,
    935      1.1  mrg which need not be thread-safe.  Similarly, the @code{getenv}
    936      1.1  mrg function is used to implement the @code{GET_ENVIRONMENT_VARIABLE} and
    937      1.1  mrg @code{GETENV} intrinsics.  It is the responsibility of the user to
    938      1.1  mrg ensure that the environment is not being updated concurrently when any
    939      1.1  mrg of these actions are taking place.
    940      1.1  mrg 
    941      1.1  mrg The @code{EXECUTE_COMMAND_LINE} and @code{SYSTEM} intrinsics are
    942      1.1  mrg implemented with the @code{system} function, which need not be
    943      1.1  mrg thread-safe.  It is the responsibility of the user to ensure that
    944      1.1  mrg @code{system} is not called concurrently.
    945      1.1  mrg 
    946      1.1  mrg For platforms not supporting thread-safe POSIX functions, further
    947      1.1  mrg functionality might not be thread-safe.  For details, please consult
    948      1.1  mrg the documentation for your operating system.
    949      1.1  mrg 
    950      1.1  mrg The GNU Fortran runtime library uses various C library functions that
    951      1.1  mrg depend on the locale, such as @code{strtod} and @code{snprintf}.  In
    952      1.1  mrg order to work correctly in locale-aware programs that set the locale
    953      1.1  mrg using @code{setlocale}, the locale is reset to the default ``C''
    954      1.1  mrg locale while executing a formatted @code{READ} or @code{WRITE}
    955      1.1  mrg statement.  On targets supporting the POSIX 2008 per-thread locale
    956      1.1  mrg functions (e.g. @code{newlocale}, @code{uselocale},
    957      1.1  mrg @code{freelocale}), these are used and thus the global locale set
    958      1.1  mrg using @code{setlocale} or the per-thread locales in other threads are
    959      1.1  mrg not affected.  However, on targets lacking this functionality, the
    960      1.1  mrg global LC_NUMERIC locale is set to ``C'' during the formatted I/O.
    961      1.1  mrg Thus, on such targets it's not safe to call @code{setlocale}
    962      1.1  mrg concurrently from another thread while a Fortran formatted I/O
    963      1.1  mrg operation is in progress.  Also, other threads doing something
    964      1.1  mrg dependent on the LC_NUMERIC locale might not work correctly if a
    965      1.1  mrg formatted I/O operation is in progress in another thread.
    966      1.1  mrg 
    967      1.1  mrg @node Data consistency and durability
    968      1.1  mrg @section Data consistency and durability
    969      1.1  mrg @cindex consistency, durability
    970      1.1  mrg 
    971      1.1  mrg This section contains a brief overview of data and metadata
    972      1.1  mrg consistency and durability issues when doing I/O.
    973      1.1  mrg 
    974      1.1  mrg With respect to durability, GNU Fortran makes no effort to ensure that
    975      1.1  mrg data is committed to stable storage. If this is required, the GNU
    976      1.1  mrg Fortran programmer can use the intrinsic @code{FNUM} to retrieve the
    977      1.1  mrg low level file descriptor corresponding to an open Fortran unit. Then,
    978      1.1  mrg using e.g. the @code{ISO_C_BINDING} feature, one can call the
    979      1.1  mrg underlying system call to flush dirty data to stable storage, such as
    980      1.1  mrg @code{fsync} on POSIX, @code{_commit} on MingW, or @code{fcntl(fd,
    981      1.1  mrg F_FULLSYNC, 0)} on Mac OS X. The following example shows how to call
    982      1.1  mrg fsync:
    983      1.1  mrg 
    984      1.1  mrg @smallexample
    985      1.1  mrg   ! Declare the interface for POSIX fsync function
    986      1.1  mrg   interface
    987      1.1  mrg     function fsync (fd) bind(c,name="fsync")
    988      1.1  mrg     use iso_c_binding, only: c_int
    989      1.1  mrg       integer(c_int), value :: fd
    990      1.1  mrg       integer(c_int) :: fsync
    991      1.1  mrg     end function fsync
    992      1.1  mrg   end interface
    993      1.1  mrg 
    994      1.1  mrg   ! Variable declaration
    995      1.1  mrg   integer :: ret
    996      1.1  mrg 
    997      1.1  mrg   ! Opening unit 10
    998      1.1  mrg   open (10,file="foo")
    999      1.1  mrg 
   1000      1.1  mrg   ! ...
   1001      1.1  mrg   ! Perform I/O on unit 10
   1002      1.1  mrg   ! ...
   1003      1.1  mrg 
   1004      1.1  mrg   ! Flush and sync
   1005      1.1  mrg   flush(10)
   1006      1.1  mrg   ret = fsync(fnum(10))
   1007      1.1  mrg 
   1008      1.1  mrg   ! Handle possible error
   1009      1.1  mrg   if (ret /= 0) stop "Error calling FSYNC"
   1010      1.1  mrg @end smallexample
   1011      1.1  mrg 
   1012      1.1  mrg With respect to consistency, for regular files GNU Fortran uses
   1013      1.1  mrg buffered I/O in order to improve performance. This buffer is flushed
   1014      1.1  mrg automatically when full and in some other situations, e.g. when
   1015      1.1  mrg closing a unit. It can also be explicitly flushed with the
   1016      1.1  mrg @code{FLUSH} statement. Also, the buffering can be turned off with the
   1017      1.1  mrg @code{GFORTRAN_UNBUFFERED_ALL} and
   1018      1.1  mrg @code{GFORTRAN_UNBUFFERED_PRECONNECTED} environment variables. Special
   1019      1.1  mrg files, such as terminals and pipes, are always unbuffered. Sometimes,
   1020      1.1  mrg however, further things may need to be done in order to allow other
   1021      1.1  mrg processes to see data that GNU Fortran has written, as follows.
   1022      1.1  mrg 
   1023      1.1  mrg The Windows platform supports a relaxed metadata consistency model,
   1024      1.1  mrg where file metadata is written to the directory lazily. This means
   1025      1.1  mrg that, for instance, the @code{dir} command can show a stale size for a
   1026      1.1  mrg file. One can force a directory metadata update by closing the unit,
   1027      1.1  mrg or by calling @code{_commit} on the file descriptor. Note, though,
   1028      1.1  mrg that @code{_commit} will force all dirty data to stable storage, which
   1029      1.1  mrg is often a very slow operation.
   1030      1.1  mrg 
   1031      1.1  mrg The Network File System (NFS) implements a relaxed consistency model
   1032      1.1  mrg called open-to-close consistency. Closing a file forces dirty data and
   1033      1.1  mrg metadata to be flushed to the server, and opening a file forces the
   1034      1.1  mrg client to contact the server in order to revalidate cached
   1035      1.1  mrg data. @code{fsync} will also force a flush of dirty data and metadata
   1036      1.1  mrg to the server. Similar to @code{open} and @code{close}, acquiring and
   1037      1.1  mrg releasing @code{fcntl} file locks, if the server supports them, will
   1038      1.1  mrg also force cache validation and flushing dirty data and metadata.
   1039      1.1  mrg 
   1040      1.1  mrg 
   1041      1.1  mrg @node Files opened without an explicit ACTION= specifier
   1042      1.1  mrg @section Files opened without an explicit ACTION= specifier
   1043      1.1  mrg @cindex open, action
   1044      1.1  mrg 
   1045      1.1  mrg The Fortran standard says that if an @code{OPEN} statement is executed
   1046      1.1  mrg without an explicit @code{ACTION=} specifier, the default value is
   1047      1.1  mrg processor dependent.  GNU Fortran behaves as follows:
   1048      1.1  mrg 
   1049      1.1  mrg @enumerate
   1050      1.1  mrg @item Attempt to open the file with @code{ACTION='READWRITE'}
   1051      1.1  mrg @item If that fails, try to open with @code{ACTION='READ'}
   1052      1.1  mrg @item If that fails, try to open with @code{ACTION='WRITE'}
   1053      1.1  mrg @item If that fails, generate an error
   1054      1.1  mrg @end enumerate
   1055      1.1  mrg 
   1056      1.1  mrg 
   1057      1.1  mrg @node File operations on symbolic links
   1058      1.1  mrg @section File operations on symbolic links
   1059      1.1  mrg @cindex file, symbolic link
   1060      1.1  mrg 
   1061      1.1  mrg This section documents the behavior of GNU Fortran for file operations on
   1062      1.1  mrg symbolic links, on systems that support them.
   1063      1.1  mrg 
   1064      1.1  mrg @itemize
   1065      1.1  mrg 
   1066      1.1  mrg @item Results of INQUIRE statements of the ``inquire by file'' form will
   1067      1.1  mrg relate to the target of the symbolic link. For example,
   1068      1.1  mrg @code{INQUIRE(FILE="foo",EXIST=ex)} will set @var{ex} to @var{.true.} if
   1069      1.1  mrg @var{foo} is a symbolic link pointing to an existing file, and @var{.false.}
   1070      1.1  mrg if @var{foo} points to an non-existing file (``dangling'' symbolic link).
   1071      1.1  mrg 
   1072      1.1  mrg @item Using the @code{OPEN} statement with a @code{STATUS="NEW"} specifier
   1073      1.1  mrg on a symbolic link will result in an error condition, whether the symbolic
   1074      1.1  mrg link points to an existing target or is dangling.
   1075      1.1  mrg 
   1076      1.1  mrg @item If a symbolic link was connected, using the @code{CLOSE} statement
   1077      1.1  mrg with a @code{STATUS="DELETE"} specifier will cause the symbolic link itself
   1078      1.1  mrg to be deleted, not its target.
   1079      1.1  mrg 
   1080      1.1  mrg @end itemize
   1081      1.1  mrg 
   1082      1.1  mrg @node File format of unformatted sequential files
   1083      1.1  mrg @section File format of unformatted sequential files
   1084      1.1  mrg @cindex file, unformatted sequential
   1085      1.1  mrg @cindex unformatted sequential
   1086      1.1  mrg @cindex sequential, unformatted
   1087      1.1  mrg @cindex record marker
   1088      1.1  mrg @cindex subrecord
   1089      1.1  mrg 
   1090      1.1  mrg Unformatted sequential files are stored as logical records using
   1091      1.1  mrg record markers.  Each logical record consists of one of more
   1092      1.1  mrg subrecords.
   1093      1.1  mrg 
   1094      1.1  mrg Each subrecord consists of a leading record marker, the data written
   1095      1.1  mrg by the user program, and a trailing record marker.  The record markers
   1096      1.1  mrg are four-byte integers by default, and eight-byte integers if the
   1097      1.1  mrg @option{-fmax-subrecord-length=8} option (which exists for backwards
   1098      1.1  mrg compability only) is in effect.
   1099      1.1  mrg 
   1100      1.1  mrg The representation of the record markers is that of unformatted files
   1101      1.1  mrg given with the @option{-fconvert} option, the @ref{CONVERT specifier}
   1102      1.1  mrg in an open statement or the @ref{GFORTRAN_CONVERT_UNIT} environment
   1103      1.1  mrg variable.
   1104      1.1  mrg 
   1105      1.1  mrg The maximum number of bytes of user data in a subrecord is 2147483639
   1106      1.1  mrg (2 GiB - 9) for a four-byte record marker.  This limit can be lowered
   1107  1.1.1.3  mrg with the @option{-fmax-subrecord-length} option, although this is
   1108      1.1  mrg rarely useful. If the length of a logical record exceeds this limit,
   1109      1.1  mrg the data is distributed among several subrecords.
   1110      1.1  mrg 
   1111      1.1  mrg The absolute of the number stored in the record markers is the number
   1112      1.1  mrg of bytes of user data in the corresponding subrecord.  If the leading
   1113      1.1  mrg record marker of a subrecord contains a negative number, another
   1114      1.1  mrg subrecord follows the current one.  If the trailing record marker
   1115      1.1  mrg contains a negative number, then there is a preceding subrecord.
   1116      1.1  mrg 
   1117      1.1  mrg In the most simple case, with only one subrecord per logical record,
   1118      1.1  mrg both record markers contain the number of bytes of user data in the
   1119      1.1  mrg record.
   1120      1.1  mrg 
   1121      1.1  mrg The format for unformatted sequential data can be duplicated using
   1122      1.1  mrg unformatted stream, as shown in the example program for an unformatted
   1123      1.1  mrg record containing a single subrecord:
   1124      1.1  mrg 
   1125      1.1  mrg @smallexample
   1126      1.1  mrg program main
   1127      1.1  mrg   use iso_fortran_env, only: int32
   1128      1.1  mrg   implicit none
   1129      1.1  mrg   integer(int32) :: i
   1130      1.1  mrg   real, dimension(10) :: a, b
   1131      1.1  mrg   call random_number(a)
   1132      1.1  mrg   open (10,file='test.dat',form='unformatted',access='stream')
   1133      1.1  mrg   inquire (iolength=i) a
   1134      1.1  mrg   write (10) i, a, i
   1135      1.1  mrg   close (10)
   1136      1.1  mrg   open (10,file='test.dat',form='unformatted')
   1137      1.1  mrg   read (10) b
   1138      1.1  mrg   if (all (a == b)) print *,'success!'
   1139      1.1  mrg end program main
   1140      1.1  mrg @end smallexample
   1141      1.1  mrg 
   1142      1.1  mrg @node Asynchronous I/O
   1143      1.1  mrg @section Asynchronous I/O
   1144      1.1  mrg @cindex input/output, asynchronous
   1145      1.1  mrg @cindex asynchronous I/O
   1146      1.1  mrg 
   1147      1.1  mrg Asynchronous I/O is supported if the program is linked against the
   1148      1.1  mrg POSIX thread library. If that is not the case, all I/O is performed
   1149      1.1  mrg as synchronous. On systems which do not support pthread condition
   1150      1.1  mrg variables, such as AIX, I/O is also performed as synchronous.
   1151      1.1  mrg 
   1152      1.1  mrg On some systems, such as Darwin or Solaris, the POSIX thread library
   1153      1.1  mrg is always linked in, so asynchronous I/O is always performed. On other
   1154      1.1  mrg sytems, such as Linux, it is necessary to specify @option{-pthread},
   1155      1.1  mrg @option{-lpthread} or @option{-fopenmp} during the linking step.
   1156      1.1  mrg 
   1157      1.1  mrg @c ---------------------------------------------------------------------
   1158      1.1  mrg @c Extensions
   1159      1.1  mrg @c ---------------------------------------------------------------------
   1160      1.1  mrg 
   1161      1.1  mrg @c Maybe this chapter should be merged with the 'Standards' section,
   1162      1.1  mrg @c whenever that is written :-)
   1163      1.1  mrg 
   1164      1.1  mrg @node Extensions
   1165      1.1  mrg @chapter Extensions
   1166      1.1  mrg @cindex extensions
   1167      1.1  mrg 
   1168      1.1  mrg The two sections below detail the extensions to standard Fortran that are
   1169      1.1  mrg implemented in GNU Fortran, as well as some of the popular or
   1170      1.1  mrg historically important extensions that are not (or not yet) implemented.
   1171      1.1  mrg For the latter case, we explain the alternatives available to GNU Fortran
   1172      1.1  mrg users, including replacement by standard-conforming code or GNU
   1173      1.1  mrg extensions.
   1174      1.1  mrg 
   1175      1.1  mrg @menu
   1176      1.1  mrg * Extensions implemented in GNU Fortran::
   1177      1.1  mrg * Extensions not implemented in GNU Fortran::
   1178      1.1  mrg @end menu
   1179      1.1  mrg 
   1180      1.1  mrg 
   1181      1.1  mrg @node Extensions implemented in GNU Fortran
   1182      1.1  mrg @section Extensions implemented in GNU Fortran
   1183      1.1  mrg @cindex extensions, implemented
   1184      1.1  mrg 
   1185      1.1  mrg GNU Fortran implements a number of extensions over standard Fortran.
   1186      1.1  mrg This chapter contains information on their syntax and meaning.  There
   1187      1.1  mrg are currently two categories of GNU Fortran extensions, those that
   1188      1.1  mrg provide functionality beyond that provided by any standard, and those
   1189      1.1  mrg that are supported by GNU Fortran purely for backward compatibility
   1190      1.1  mrg with legacy compilers.  By default, @option{-std=gnu} allows the
   1191      1.1  mrg compiler to accept both types of extensions, but to warn about the use
   1192      1.1  mrg of the latter.  Specifying either @option{-std=f95},
   1193      1.1  mrg @option{-std=f2003}, @option{-std=f2008}, or @option{-std=f2018}
   1194      1.1  mrg disables both types of extensions, and @option{-std=legacy} allows
   1195      1.1  mrg both without warning.  The special compile flag @option{-fdec} enables
   1196      1.1  mrg additional compatibility extensions along with those enabled by
   1197      1.1  mrg @option{-std=legacy}.
   1198      1.1  mrg 
   1199      1.1  mrg @menu
   1200      1.1  mrg * Old-style kind specifications::
   1201      1.1  mrg * Old-style variable initialization::
   1202      1.1  mrg * Extensions to namelist::
   1203      1.1  mrg * X format descriptor without count field::
   1204      1.1  mrg * Commas in FORMAT specifications::
   1205      1.1  mrg * Missing period in FORMAT specifications::
   1206  1.1.1.2  mrg * Default widths for F@comma{} G and I format descriptors::
   1207      1.1  mrg * I/O item lists::
   1208      1.1  mrg * @code{Q} exponent-letter::
   1209      1.1  mrg * BOZ literal constants::
   1210      1.1  mrg * Real array indices::
   1211      1.1  mrg * Unary operators::
   1212      1.1  mrg * Implicitly convert LOGICAL and INTEGER values::
   1213      1.1  mrg * Hollerith constants support::
   1214  1.1.1.2  mrg * Character conversion::
   1215      1.1  mrg * Cray pointers::
   1216      1.1  mrg * CONVERT specifier::
   1217      1.1  mrg * OpenMP::
   1218      1.1  mrg * OpenACC::
   1219      1.1  mrg * Argument list functions::
   1220      1.1  mrg * Read/Write after EOF marker::
   1221      1.1  mrg * STRUCTURE and RECORD::
   1222      1.1  mrg * UNION and MAP::
   1223      1.1  mrg * Type variants for integer intrinsics::
   1224      1.1  mrg * AUTOMATIC and STATIC attributes::
   1225      1.1  mrg * Extended math intrinsics::
   1226      1.1  mrg * Form feed as whitespace::
   1227      1.1  mrg * TYPE as an alias for PRINT::
   1228      1.1  mrg * %LOC as an rvalue::
   1229      1.1  mrg * .XOR. operator::
   1230      1.1  mrg * Bitwise logical operators::
   1231      1.1  mrg * Extended I/O specifiers::
   1232      1.1  mrg * Legacy PARAMETER statements::
   1233      1.1  mrg * Default exponents::
   1234      1.1  mrg @end menu
   1235      1.1  mrg 
   1236      1.1  mrg @node Old-style kind specifications
   1237      1.1  mrg @subsection Old-style kind specifications
   1238      1.1  mrg @cindex kind, old-style
   1239      1.1  mrg 
   1240      1.1  mrg GNU Fortran allows old-style kind specifications in declarations.  These
   1241      1.1  mrg look like:
   1242      1.1  mrg @smallexample
   1243      1.1  mrg       TYPESPEC*size x,y,z
   1244      1.1  mrg @end smallexample
   1245      1.1  mrg @noindent
   1246      1.1  mrg where @code{TYPESPEC} is a basic type (@code{INTEGER}, @code{REAL},
   1247      1.1  mrg etc.), and where @code{size} is a byte count corresponding to the
   1248      1.1  mrg storage size of a valid kind for that type.  (For @code{COMPLEX}
   1249      1.1  mrg variables, @code{size} is the total size of the real and imaginary
   1250      1.1  mrg parts.)  The statement then declares @code{x}, @code{y} and @code{z} to
   1251      1.1  mrg be of type @code{TYPESPEC} with the appropriate kind.  This is
   1252      1.1  mrg equivalent to the standard-conforming declaration
   1253      1.1  mrg @smallexample
   1254      1.1  mrg       TYPESPEC(k) x,y,z
   1255      1.1  mrg @end smallexample
   1256      1.1  mrg @noindent
   1257      1.1  mrg where @code{k} is the kind parameter suitable for the intended precision.  As
   1258      1.1  mrg kind parameters are implementation-dependent, use the @code{KIND},
   1259      1.1  mrg @code{SELECTED_INT_KIND} and @code{SELECTED_REAL_KIND} intrinsics to retrieve
   1260      1.1  mrg the correct value, for instance @code{REAL*8 x} can be replaced by:
   1261      1.1  mrg @smallexample
   1262      1.1  mrg INTEGER, PARAMETER :: dbl = KIND(1.0d0)
   1263      1.1  mrg REAL(KIND=dbl) :: x
   1264      1.1  mrg @end smallexample
   1265      1.1  mrg 
   1266      1.1  mrg @node Old-style variable initialization
   1267      1.1  mrg @subsection Old-style variable initialization
   1268      1.1  mrg 
   1269      1.1  mrg GNU Fortran allows old-style initialization of variables of the
   1270      1.1  mrg form:
   1271      1.1  mrg @smallexample
   1272      1.1  mrg       INTEGER i/1/,j/2/
   1273      1.1  mrg       REAL x(2,2) /3*0.,1./
   1274      1.1  mrg @end smallexample
   1275      1.1  mrg The syntax for the initializers is as for the @code{DATA} statement, but
   1276      1.1  mrg unlike in a @code{DATA} statement, an initializer only applies to the
   1277      1.1  mrg variable immediately preceding the initialization.  In other words,
   1278      1.1  mrg something like @code{INTEGER I,J/2,3/} is not valid.  This style of
   1279      1.1  mrg initialization is only allowed in declarations without double colons
   1280      1.1  mrg (@code{::}); the double colons were introduced in Fortran 90, which also
   1281      1.1  mrg introduced a standard syntax for initializing variables in type
   1282      1.1  mrg declarations.
   1283      1.1  mrg 
   1284      1.1  mrg Examples of standard-conforming code equivalent to the above example
   1285      1.1  mrg are:
   1286      1.1  mrg @smallexample
   1287      1.1  mrg ! Fortran 90
   1288      1.1  mrg       INTEGER :: i = 1, j = 2
   1289      1.1  mrg       REAL :: x(2,2) = RESHAPE((/0.,0.,0.,1./),SHAPE(x))
   1290      1.1  mrg ! Fortran 77
   1291      1.1  mrg       INTEGER i, j
   1292      1.1  mrg       REAL x(2,2)
   1293      1.1  mrg       DATA i/1/, j/2/, x/3*0.,1./
   1294      1.1  mrg @end smallexample
   1295      1.1  mrg 
   1296      1.1  mrg Note that variables which are explicitly initialized in declarations
   1297      1.1  mrg or in @code{DATA} statements automatically acquire the @code{SAVE}
   1298      1.1  mrg attribute.
   1299      1.1  mrg 
   1300      1.1  mrg @node Extensions to namelist
   1301      1.1  mrg @subsection Extensions to namelist
   1302      1.1  mrg @cindex Namelist
   1303      1.1  mrg 
   1304      1.1  mrg GNU Fortran fully supports the Fortran 95 standard for namelist I/O
   1305      1.1  mrg including array qualifiers, substrings and fully qualified derived types.
   1306      1.1  mrg The output from a namelist write is compatible with namelist read.  The
   1307      1.1  mrg output has all names in upper case and indentation to column 1 after the
   1308      1.1  mrg namelist name.  Two extensions are permitted:
   1309      1.1  mrg 
   1310      1.1  mrg Old-style use of @samp{$} instead of @samp{&}
   1311      1.1  mrg @smallexample
   1312      1.1  mrg $MYNML
   1313      1.1  mrg  X(:)%Y(2) = 1.0 2.0 3.0
   1314      1.1  mrg  CH(1:4) = "abcd"
   1315      1.1  mrg $END
   1316      1.1  mrg @end smallexample
   1317      1.1  mrg 
   1318      1.1  mrg It should be noted that the default terminator is @samp{/} rather than
   1319      1.1  mrg @samp{&END}.
   1320      1.1  mrg 
   1321      1.1  mrg Querying of the namelist when inputting from stdin.  After at least
   1322      1.1  mrg one space, entering @samp{?} sends to stdout the namelist name and the names of
   1323      1.1  mrg the variables in the namelist:
   1324      1.1  mrg @smallexample
   1325      1.1  mrg  ?
   1326      1.1  mrg 
   1327      1.1  mrg &mynml
   1328      1.1  mrg  x
   1329      1.1  mrg  x%y
   1330      1.1  mrg  ch
   1331      1.1  mrg &end
   1332      1.1  mrg @end smallexample
   1333      1.1  mrg 
   1334      1.1  mrg Entering @samp{=?} outputs the namelist to stdout, as if
   1335      1.1  mrg @code{WRITE(*,NML = mynml)} had been called:
   1336      1.1  mrg @smallexample
   1337      1.1  mrg =?
   1338      1.1  mrg 
   1339      1.1  mrg &MYNML
   1340      1.1  mrg  X(1)%Y=  0.000000    ,  1.000000    ,  0.000000    ,
   1341      1.1  mrg  X(2)%Y=  0.000000    ,  2.000000    ,  0.000000    ,
   1342      1.1  mrg  X(3)%Y=  0.000000    ,  3.000000    ,  0.000000    ,
   1343      1.1  mrg  CH=abcd,  /
   1344      1.1  mrg @end smallexample
   1345      1.1  mrg 
   1346      1.1  mrg To aid this dialog, when input is from stdin, errors send their
   1347      1.1  mrg messages to stderr and execution continues, even if @code{IOSTAT} is set.
   1348      1.1  mrg 
   1349      1.1  mrg @code{PRINT} namelist is permitted.  This causes an error if
   1350      1.1  mrg @option{-std=f95} is used.
   1351      1.1  mrg @smallexample
   1352      1.1  mrg PROGRAM test_print
   1353      1.1  mrg   REAL, dimension (4)  ::  x = (/1.0, 2.0, 3.0, 4.0/)
   1354      1.1  mrg   NAMELIST /mynml/ x
   1355      1.1  mrg   PRINT mynml
   1356      1.1  mrg END PROGRAM test_print
   1357      1.1  mrg @end smallexample
   1358      1.1  mrg 
   1359      1.1  mrg Expanded namelist reads are permitted.  This causes an error if
   1360      1.1  mrg @option{-std=f95} is used.  In the following example, the first element
   1361      1.1  mrg of the array will be given the value 0.00 and the two succeeding
   1362      1.1  mrg elements will be given the values 1.00 and 2.00.
   1363      1.1  mrg @smallexample
   1364      1.1  mrg &MYNML
   1365      1.1  mrg   X(1,1) = 0.00 , 1.00 , 2.00
   1366      1.1  mrg /
   1367      1.1  mrg @end smallexample
   1368      1.1  mrg 
   1369      1.1  mrg When writing a namelist, if no @code{DELIM=} is specified, by default a
   1370      1.1  mrg double quote is used to delimit character strings. If -std=F95, F2003,
   1371      1.1  mrg or F2008, etc, the delim status is set to 'none'.  Defaulting to
   1372      1.1  mrg quotes ensures that namelists with character strings can be subsequently
   1373      1.1  mrg read back in accurately.
   1374      1.1  mrg 
   1375      1.1  mrg @node X format descriptor without count field
   1376      1.1  mrg @subsection @code{X} format descriptor without count field
   1377      1.1  mrg 
   1378      1.1  mrg To support legacy codes, GNU Fortran permits the count field of the
   1379      1.1  mrg @code{X} edit descriptor in @code{FORMAT} statements to be omitted.
   1380      1.1  mrg When omitted, the count is implicitly assumed to be one.
   1381      1.1  mrg 
   1382      1.1  mrg @smallexample
   1383      1.1  mrg        PRINT 10, 2, 3
   1384      1.1  mrg 10     FORMAT (I1, X, I1)
   1385      1.1  mrg @end smallexample
   1386      1.1  mrg 
   1387      1.1  mrg @node Commas in FORMAT specifications
   1388      1.1  mrg @subsection Commas in @code{FORMAT} specifications
   1389      1.1  mrg 
   1390      1.1  mrg To support legacy codes, GNU Fortran allows the comma separator
   1391      1.1  mrg to be omitted immediately before and after character string edit
   1392  1.1.1.2  mrg descriptors in @code{FORMAT} statements.  A comma with no following format
   1393  1.1.1.2  mrg decriptor is permited if the @option{-fdec-blank-format-item} is given on
   1394  1.1.1.2  mrg the command line. This is considered non-conforming code and is
   1395  1.1.1.2  mrg discouraged.
   1396      1.1  mrg 
   1397      1.1  mrg @smallexample
   1398      1.1  mrg        PRINT 10, 2, 3
   1399      1.1  mrg 10     FORMAT ('FOO='I1' BAR='I2)
   1400  1.1.1.2  mrg        print 20, 5, 6
   1401  1.1.1.2  mrg 20     FORMAT (I3, I3,)
   1402      1.1  mrg @end smallexample
   1403      1.1  mrg 
   1404      1.1  mrg 
   1405      1.1  mrg @node Missing period in FORMAT specifications
   1406      1.1  mrg @subsection Missing period in @code{FORMAT} specifications
   1407      1.1  mrg 
   1408      1.1  mrg To support legacy codes, GNU Fortran allows missing periods in format
   1409      1.1  mrg specifications if and only if @option{-std=legacy} is given on the
   1410      1.1  mrg command line.  This is considered non-conforming code and is
   1411      1.1  mrg discouraged.
   1412      1.1  mrg 
   1413      1.1  mrg @smallexample
   1414      1.1  mrg        REAL :: value
   1415      1.1  mrg        READ(*,10) value
   1416      1.1  mrg 10     FORMAT ('F4')
   1417      1.1  mrg @end smallexample
   1418      1.1  mrg 
   1419  1.1.1.2  mrg @node Default widths for F@comma{} G and I format descriptors
   1420  1.1.1.2  mrg @subsection Default widths for @code{F}, @code{G} and @code{I} format descriptors
   1421  1.1.1.2  mrg 
   1422  1.1.1.2  mrg To support legacy codes, GNU Fortran allows width to be omitted from format
   1423  1.1.1.2  mrg specifications if and only if @option{-fdec-format-defaults} is given on the
   1424  1.1.1.2  mrg command line.  Default widths will be used. This is considered non-conforming
   1425  1.1.1.2  mrg code and is discouraged.
   1426  1.1.1.2  mrg 
   1427  1.1.1.2  mrg @smallexample
   1428  1.1.1.2  mrg        REAL :: value1
   1429  1.1.1.2  mrg        INTEGER :: value2
   1430  1.1.1.2  mrg        WRITE(*,10) value1, value1, value2
   1431  1.1.1.2  mrg 10     FORMAT ('F, G, I')
   1432  1.1.1.2  mrg @end smallexample
   1433  1.1.1.2  mrg 
   1434  1.1.1.2  mrg 
   1435      1.1  mrg @node I/O item lists
   1436      1.1  mrg @subsection I/O item lists
   1437      1.1  mrg @cindex I/O item lists
   1438      1.1  mrg 
   1439      1.1  mrg To support legacy codes, GNU Fortran allows the input item list
   1440      1.1  mrg of the @code{READ} statement, and the output item lists of the
   1441      1.1  mrg @code{WRITE} and @code{PRINT} statements, to start with a comma.
   1442      1.1  mrg 
   1443      1.1  mrg @node @code{Q} exponent-letter
   1444      1.1  mrg @subsection @code{Q} exponent-letter
   1445      1.1  mrg @cindex @code{Q} exponent-letter
   1446      1.1  mrg 
   1447      1.1  mrg GNU Fortran accepts real literal constants with an exponent-letter
   1448      1.1  mrg of @code{Q}, for example, @code{1.23Q45}.  The constant is interpreted
   1449      1.1  mrg as a @code{REAL(16)} entity on targets that support this type.  If
   1450      1.1  mrg the target does not support @code{REAL(16)} but has a @code{REAL(10)}
   1451      1.1  mrg type, then the real-literal-constant will be interpreted as a
   1452      1.1  mrg @code{REAL(10)} entity.  In the absence of @code{REAL(16)} and
   1453      1.1  mrg @code{REAL(10)}, an error will occur.
   1454      1.1  mrg 
   1455      1.1  mrg @node BOZ literal constants
   1456      1.1  mrg @subsection BOZ literal constants
   1457      1.1  mrg @cindex BOZ literal constants
   1458      1.1  mrg 
   1459      1.1  mrg Besides decimal constants, Fortran also supports binary (@code{b}),
   1460      1.1  mrg octal (@code{o}) and hexadecimal (@code{z}) integer constants.  The
   1461  1.1.1.3  mrg syntax is: @samp{prefix quote digits quote}, where the prefix is
   1462      1.1  mrg either @code{b}, @code{o} or @code{z}, quote is either @code{'} or
   1463  1.1.1.2  mrg @code{"} and the digits are @code{0} or @code{1} for binary,
   1464  1.1.1.2  mrg between @code{0} and @code{7} for octal, and between @code{0} and
   1465  1.1.1.2  mrg @code{F} for hexadecimal.  (Example: @code{b'01011101'}.)
   1466  1.1.1.2  mrg 
   1467  1.1.1.2  mrg Up to Fortran 95, BOZ literal constants were only allowed to initialize
   1468  1.1.1.2  mrg integer variables in DATA statements.  Since Fortran 2003 BOZ literal
   1469  1.1.1.2  mrg constants are also allowed as actual arguments to the @code{REAL},
   1470  1.1.1.2  mrg @code{DBLE}, @code{INT} and @code{CMPLX} intrinsic functions.
   1471  1.1.1.2  mrg The BOZ literal constant is simply a string of bits, which is padded
   1472  1.1.1.2  mrg or truncated as needed, during conversion to a numeric type.  The 
   1473  1.1.1.2  mrg Fortran standard states that the treatment of the sign bit is processor
   1474  1.1.1.2  mrg dependent.  Gfortran interprets the sign bit as a user would expect.
   1475  1.1.1.2  mrg 
   1476  1.1.1.2  mrg As a deprecated extension, GNU Fortran allows hexadecimal BOZ literal
   1477  1.1.1.2  mrg constants to be specified using the @code{X} prefix.  That the BOZ literal
   1478  1.1.1.2  mrg constant can also be specified by adding a suffix to the string, for
   1479  1.1.1.2  mrg example, @code{Z'ABC'} and @code{'ABC'X} are equivalent.  Additionally,
   1480  1.1.1.2  mrg as extension, BOZ literals are permitted in some contexts outside of
   1481  1.1.1.2  mrg @code{DATA} and the intrinsic functions listed in the Fortran standard.
   1482  1.1.1.2  mrg Use @option{-fallow-invalid-boz} to enable the extension.
   1483      1.1  mrg 
   1484      1.1  mrg @node Real array indices
   1485      1.1  mrg @subsection Real array indices
   1486      1.1  mrg @cindex array, indices of type real
   1487      1.1  mrg 
   1488      1.1  mrg As an extension, GNU Fortran allows the use of @code{REAL} expressions
   1489      1.1  mrg or variables as array indices.
   1490      1.1  mrg 
   1491      1.1  mrg @node Unary operators
   1492      1.1  mrg @subsection Unary operators
   1493      1.1  mrg @cindex operators, unary
   1494      1.1  mrg 
   1495      1.1  mrg As an extension, GNU Fortran allows unary plus and unary minus operators
   1496      1.1  mrg to appear as the second operand of binary arithmetic operators without
   1497      1.1  mrg the need for parenthesis.
   1498      1.1  mrg 
   1499      1.1  mrg @smallexample
   1500      1.1  mrg        X = Y * -Z
   1501      1.1  mrg @end smallexample
   1502      1.1  mrg 
   1503      1.1  mrg @node Implicitly convert LOGICAL and INTEGER values
   1504      1.1  mrg @subsection Implicitly convert @code{LOGICAL} and @code{INTEGER} values
   1505      1.1  mrg @cindex conversion, to integer
   1506      1.1  mrg @cindex conversion, to logical
   1507      1.1  mrg 
   1508      1.1  mrg As an extension for backwards compatibility with other compilers, GNU
   1509      1.1  mrg Fortran allows the implicit conversion of @code{LOGICAL} values to
   1510      1.1  mrg @code{INTEGER} values and vice versa.  When converting from a
   1511      1.1  mrg @code{LOGICAL} to an @code{INTEGER}, @code{.FALSE.} is interpreted as
   1512      1.1  mrg zero, and @code{.TRUE.} is interpreted as one.  When converting from
   1513      1.1  mrg @code{INTEGER} to @code{LOGICAL}, the value zero is interpreted as
   1514      1.1  mrg @code{.FALSE.} and any nonzero value is interpreted as @code{.TRUE.}.
   1515      1.1  mrg 
   1516      1.1  mrg @smallexample
   1517      1.1  mrg         LOGICAL :: l
   1518      1.1  mrg         l = 1
   1519      1.1  mrg @end smallexample
   1520      1.1  mrg @smallexample
   1521      1.1  mrg         INTEGER :: i
   1522      1.1  mrg         i = .TRUE.
   1523      1.1  mrg @end smallexample
   1524      1.1  mrg 
   1525      1.1  mrg However, there is no implicit conversion of @code{INTEGER} values in
   1526      1.1  mrg @code{if}-statements, nor of @code{LOGICAL} or @code{INTEGER} values
   1527      1.1  mrg in I/O operations.
   1528      1.1  mrg 
   1529      1.1  mrg @node Hollerith constants support
   1530      1.1  mrg @subsection Hollerith constants support
   1531      1.1  mrg @cindex Hollerith constants
   1532      1.1  mrg 
   1533  1.1.1.2  mrg GNU Fortran supports Hollerith constants in assignments, @code{DATA}
   1534  1.1.1.2  mrg statements, function and subroutine arguments. A Hollerith constant is
   1535  1.1.1.2  mrg written as a string of characters preceded by an integer constant 
   1536  1.1.1.2  mrg indicating the character count, and the letter @code{H} or
   1537      1.1  mrg @code{h}, and stored in bytewise fashion in a numeric (@code{INTEGER},
   1538  1.1.1.2  mrg @code{REAL}, or @code{COMPLEX}), @code{LOGICAL} or @code{CHARACTER} variable.
   1539  1.1.1.2  mrg The constant will be padded with spaces or truncated to fit the size of
   1540  1.1.1.2  mrg the variable in which it is stored.
   1541      1.1  mrg 
   1542      1.1  mrg Examples of valid uses of Hollerith constants:
   1543      1.1  mrg @smallexample
   1544      1.1  mrg       complex*16 x(2)
   1545      1.1  mrg       data x /16Habcdefghijklmnop, 16Hqrstuvwxyz012345/
   1546      1.1  mrg       x(1) = 16HABCDEFGHIJKLMNOP
   1547      1.1  mrg       call foo (4h abc)
   1548      1.1  mrg @end smallexample
   1549      1.1  mrg 
   1550  1.1.1.2  mrg Examples of Hollerith constants:
   1551      1.1  mrg @smallexample
   1552      1.1  mrg       integer*4 a
   1553  1.1.1.2  mrg       a = 0H         ! Invalid, at least one character is needed.
   1554  1.1.1.2  mrg       a = 4HAB12     ! Valid
   1555      1.1  mrg       a = 8H12345678 ! Valid, but the Hollerith constant will be truncated.
   1556  1.1.1.2  mrg       a = 3Hxyz      ! Valid, but the Hollerith constant will be padded.
   1557      1.1  mrg @end smallexample
   1558      1.1  mrg 
   1559      1.1  mrg In general, Hollerith constants were used to provide a rudimentary
   1560      1.1  mrg facility for handling character strings in early Fortran compilers,
   1561      1.1  mrg prior to the introduction of @code{CHARACTER} variables in Fortran 77;
   1562      1.1  mrg in those cases, the standard-compliant equivalent is to convert the
   1563      1.1  mrg program to use proper character strings.  On occasion, there may be a
   1564      1.1  mrg case where the intent is specifically to initialize a numeric variable
   1565      1.1  mrg with a given byte sequence.  In these cases, the same result can be
   1566      1.1  mrg obtained by using the @code{TRANSFER} statement, as in this example.
   1567      1.1  mrg @smallexample
   1568  1.1.1.2  mrg       integer(kind=4) :: a
   1569  1.1.1.2  mrg       a = transfer ("abcd", a)     ! equivalent to: a = 4Habcd
   1570  1.1.1.2  mrg @end smallexample
   1571  1.1.1.2  mrg 
   1572  1.1.1.2  mrg The use of the @option{-fdec} option extends support of Hollerith constants
   1573  1.1.1.2  mrg to comparisons:
   1574  1.1.1.2  mrg @smallexample
   1575  1.1.1.2  mrg       integer*4 a
   1576  1.1.1.2  mrg       a = 4hABCD
   1577  1.1.1.2  mrg       if (a .ne. 4habcd) then
   1578  1.1.1.2  mrg         write(*,*) "no match"
   1579  1.1.1.2  mrg       end if
   1580  1.1.1.2  mrg @end smallexample
   1581  1.1.1.2  mrg 
   1582  1.1.1.2  mrg Supported types are numeric (@code{INTEGER}, @code{REAL}, or @code{COMPLEX}),
   1583  1.1.1.2  mrg and @code{CHARACTER}.
   1584  1.1.1.2  mrg 
   1585  1.1.1.2  mrg @node Character conversion
   1586  1.1.1.2  mrg @subsection Character conversion
   1587  1.1.1.2  mrg @cindex conversion, to character
   1588  1.1.1.2  mrg 
   1589  1.1.1.2  mrg Allowing character literals to be used in a similar way to Hollerith constants
   1590  1.1.1.2  mrg is a non-standard extension.  This feature is enabled using
   1591  1.1.1.2  mrg -fdec-char-conversions and only applies to character literals of @code{kind=1}.
   1592  1.1.1.2  mrg 
   1593  1.1.1.2  mrg Character literals can be used in @code{DATA} statements and assignments with
   1594  1.1.1.2  mrg numeric (@code{INTEGER}, @code{REAL}, or @code{COMPLEX}) or @code{LOGICAL}
   1595  1.1.1.2  mrg variables. Like Hollerith constants they are copied byte-wise fashion. The
   1596  1.1.1.2  mrg constant will be padded with spaces or truncated to fit the size of the
   1597  1.1.1.2  mrg variable in which it is stored.
   1598  1.1.1.2  mrg 
   1599  1.1.1.2  mrg Examples:
   1600  1.1.1.2  mrg @smallexample
   1601  1.1.1.2  mrg       integer*4 x
   1602  1.1.1.2  mrg       data x / 'abcd' /
   1603  1.1.1.2  mrg 
   1604  1.1.1.2  mrg       x = 'A'       ! Will be padded.
   1605  1.1.1.2  mrg       x = 'ab1234'  ! Will be truncated.
   1606      1.1  mrg @end smallexample
   1607      1.1  mrg 
   1608      1.1  mrg 
   1609      1.1  mrg @node Cray pointers
   1610      1.1  mrg @subsection Cray pointers
   1611      1.1  mrg @cindex pointer, Cray
   1612      1.1  mrg 
   1613      1.1  mrg Cray pointers are part of a non-standard extension that provides a
   1614      1.1  mrg C-like pointer in Fortran.  This is accomplished through a pair of
   1615      1.1  mrg variables: an integer "pointer" that holds a memory address, and a
   1616      1.1  mrg "pointee" that is used to dereference the pointer.
   1617      1.1  mrg 
   1618      1.1  mrg Pointer/pointee pairs are declared in statements of the form:
   1619      1.1  mrg @smallexample
   1620      1.1  mrg         pointer ( <pointer> , <pointee> )
   1621      1.1  mrg @end smallexample
   1622      1.1  mrg or,
   1623      1.1  mrg @smallexample
   1624      1.1  mrg         pointer ( <pointer1> , <pointee1> ), ( <pointer2> , <pointee2> ), ...
   1625      1.1  mrg @end smallexample
   1626      1.1  mrg The pointer is an integer that is intended to hold a memory address.
   1627      1.1  mrg The pointee may be an array or scalar.
   1628      1.1  mrg If an assumed-size array is permitted within the scoping unit, a
   1629      1.1  mrg pointee can be an assumed-size array.
   1630      1.1  mrg That is, the last dimension may be left unspecified by using a @code{*}
   1631      1.1  mrg in place of a value. A pointee cannot be an assumed shape array.
   1632      1.1  mrg No space is allocated for the pointee.
   1633      1.1  mrg 
   1634      1.1  mrg The pointee may have its type declared before or after the pointer
   1635      1.1  mrg statement, and its array specification (if any) may be declared
   1636      1.1  mrg before, during, or after the pointer statement.  The pointer may be
   1637      1.1  mrg declared as an integer prior to the pointer statement.  However, some
   1638      1.1  mrg machines have default integer sizes that are different than the size
   1639      1.1  mrg of a pointer, and so the following code is not portable:
   1640      1.1  mrg @smallexample
   1641      1.1  mrg         integer ipt
   1642      1.1  mrg         pointer (ipt, iarr)
   1643      1.1  mrg @end smallexample
   1644      1.1  mrg If a pointer is declared with a kind that is too small, the compiler
   1645      1.1  mrg will issue a warning; the resulting binary will probably not work
   1646      1.1  mrg correctly, because the memory addresses stored in the pointers may be
   1647      1.1  mrg truncated.  It is safer to omit the first line of the above example;
   1648      1.1  mrg if explicit declaration of ipt's type is omitted, then the compiler
   1649      1.1  mrg will ensure that ipt is an integer variable large enough to hold a
   1650      1.1  mrg pointer.
   1651      1.1  mrg 
   1652      1.1  mrg Pointer arithmetic is valid with Cray pointers, but it is not the same
   1653      1.1  mrg as C pointer arithmetic.  Cray pointers are just ordinary integers, so
   1654      1.1  mrg the user is responsible for determining how many bytes to add to a
   1655      1.1  mrg pointer in order to increment it.  Consider the following example:
   1656      1.1  mrg @smallexample
   1657      1.1  mrg         real target(10)
   1658      1.1  mrg         real pointee(10)
   1659      1.1  mrg         pointer (ipt, pointee)
   1660      1.1  mrg         ipt = loc (target)
   1661      1.1  mrg         ipt = ipt + 1
   1662      1.1  mrg @end smallexample
   1663      1.1  mrg The last statement does not set @code{ipt} to the address of
   1664      1.1  mrg @code{target(1)}, as it would in C pointer arithmetic.  Adding @code{1}
   1665      1.1  mrg to @code{ipt} just adds one byte to the address stored in @code{ipt}.
   1666      1.1  mrg 
   1667      1.1  mrg Any expression involving the pointee will be translated to use the
   1668      1.1  mrg value stored in the pointer as the base address.
   1669      1.1  mrg 
   1670      1.1  mrg To get the address of elements, this extension provides an intrinsic
   1671      1.1  mrg function @code{LOC()}.  The @code{LOC()} function is equivalent to the
   1672      1.1  mrg @code{&} operator in C, except the address is cast to an integer type:
   1673      1.1  mrg @smallexample
   1674      1.1  mrg         real ar(10)
   1675      1.1  mrg         pointer(ipt, arpte(10))
   1676      1.1  mrg         real arpte
   1677      1.1  mrg         ipt = loc(ar)  ! Makes arpte is an alias for ar
   1678      1.1  mrg         arpte(1) = 1.0 ! Sets ar(1) to 1.0
   1679      1.1  mrg @end smallexample
   1680      1.1  mrg The pointer can also be set by a call to the @code{MALLOC} intrinsic
   1681      1.1  mrg (see @ref{MALLOC}).
   1682      1.1  mrg 
   1683      1.1  mrg Cray pointees often are used to alias an existing variable.  For
   1684      1.1  mrg example:
   1685      1.1  mrg @smallexample
   1686      1.1  mrg         integer target(10)
   1687      1.1  mrg         integer iarr(10)
   1688      1.1  mrg         pointer (ipt, iarr)
   1689      1.1  mrg         ipt = loc(target)
   1690      1.1  mrg @end smallexample
   1691      1.1  mrg As long as @code{ipt} remains unchanged, @code{iarr} is now an alias for
   1692      1.1  mrg @code{target}.  The optimizer, however, will not detect this aliasing, so
   1693      1.1  mrg it is unsafe to use @code{iarr} and @code{target} simultaneously.  Using
   1694      1.1  mrg a pointee in any way that violates the Fortran aliasing rules or
   1695      1.1  mrg assumptions is illegal.  It is the user's responsibility to avoid doing
   1696      1.1  mrg this; the compiler works under the assumption that no such aliasing
   1697      1.1  mrg occurs.
   1698      1.1  mrg 
   1699      1.1  mrg Cray pointers will work correctly when there is no aliasing (i.e., when
   1700      1.1  mrg they are used to access a dynamically allocated block of memory), and
   1701      1.1  mrg also in any routine where a pointee is used, but any variable with which
   1702      1.1  mrg it shares storage is not used.  Code that violates these rules may not
   1703      1.1  mrg run as the user intends.  This is not a bug in the optimizer; any code
   1704      1.1  mrg that violates the aliasing rules is illegal.  (Note that this is not
   1705      1.1  mrg unique to GNU Fortran; any Fortran compiler that supports Cray pointers
   1706      1.1  mrg will ``incorrectly'' optimize code with illegal aliasing.)
   1707      1.1  mrg 
   1708      1.1  mrg There are a number of restrictions on the attributes that can be applied
   1709      1.1  mrg to Cray pointers and pointees.  Pointees may not have the
   1710      1.1  mrg @code{ALLOCATABLE}, @code{INTENT}, @code{OPTIONAL}, @code{DUMMY},
   1711      1.1  mrg @code{TARGET}, @code{INTRINSIC}, or @code{POINTER} attributes.  Pointers
   1712      1.1  mrg may not have the @code{DIMENSION}, @code{POINTER}, @code{TARGET},
   1713      1.1  mrg @code{ALLOCATABLE}, @code{EXTERNAL}, or @code{INTRINSIC} attributes, nor
   1714      1.1  mrg may they be function results.  Pointees may not occur in more than one
   1715      1.1  mrg pointer statement.  A pointee cannot be a pointer.  Pointees cannot occur
   1716      1.1  mrg in equivalence, common, or data statements.
   1717      1.1  mrg 
   1718      1.1  mrg A Cray pointer may also point to a function or a subroutine.  For
   1719      1.1  mrg example, the following excerpt is valid:
   1720      1.1  mrg @smallexample
   1721      1.1  mrg   implicit none
   1722      1.1  mrg   external sub
   1723      1.1  mrg   pointer (subptr,subpte)
   1724      1.1  mrg   external subpte
   1725      1.1  mrg   subptr = loc(sub)
   1726      1.1  mrg   call subpte()
   1727      1.1  mrg   [...]
   1728      1.1  mrg   subroutine sub
   1729      1.1  mrg   [...]
   1730      1.1  mrg   end subroutine sub
   1731      1.1  mrg @end smallexample
   1732      1.1  mrg 
   1733      1.1  mrg A pointer may be modified during the course of a program, and this
   1734      1.1  mrg will change the location to which the pointee refers.  However, when
   1735      1.1  mrg pointees are passed as arguments, they are treated as ordinary
   1736      1.1  mrg variables in the invoked function.  Subsequent changes to the pointer
   1737      1.1  mrg will not change the base address of the array that was passed.
   1738      1.1  mrg 
   1739      1.1  mrg @node CONVERT specifier
   1740      1.1  mrg @subsection @code{CONVERT} specifier
   1741      1.1  mrg @cindex @code{CONVERT} specifier
   1742      1.1  mrg 
   1743      1.1  mrg GNU Fortran allows the conversion of unformatted data between little-
   1744      1.1  mrg and big-endian representation to facilitate moving of data
   1745      1.1  mrg between different systems.  The conversion can be indicated with
   1746      1.1  mrg the @code{CONVERT} specifier on the @code{OPEN} statement.
   1747      1.1  mrg @xref{GFORTRAN_CONVERT_UNIT}, for an alternative way of specifying
   1748      1.1  mrg the data format via an environment variable.
   1749      1.1  mrg 
   1750  1.1.1.3  mrg Valid values for @code{CONVERT} on most systems are:
   1751      1.1  mrg @itemize @w{}
   1752      1.1  mrg @item @code{CONVERT='NATIVE'} Use the native format.  This is the default.
   1753      1.1  mrg @item @code{CONVERT='SWAP'} Swap between little- and big-endian.
   1754      1.1  mrg @item @code{CONVERT='LITTLE_ENDIAN'} Use the little-endian representation
   1755      1.1  mrg for unformatted files.
   1756      1.1  mrg @item @code{CONVERT='BIG_ENDIAN'} Use the big-endian representation for
   1757      1.1  mrg unformatted files.
   1758      1.1  mrg @end itemize
   1759  1.1.1.3  mrg On POWER systems which support @option{-mabi=ieeelongdouble},
   1760  1.1.1.3  mrg there are additional options, which can be combined with the others
   1761  1.1.1.3  mrg with commas. Those are
   1762  1.1.1.3  mrg @itemize @w{}
   1763  1.1.1.3  mrg @item @code{CONVERT='R16_IEEE'} Use IEEE 128-bit format for
   1764  1.1.1.3  mrg @code{REAL(KIND=16)}.
   1765  1.1.1.3  mrg @item @code{CONVERT='R16_IBM'} Use IBM @code{long double} format for
   1766  1.1.1.3  mrg real@code{REAL(KIND=16)}.
   1767  1.1.1.3  mrg @end itemize
   1768      1.1  mrg 
   1769      1.1  mrg Using the option could look like this:
   1770      1.1  mrg @smallexample
   1771      1.1  mrg   open(file='big.dat',form='unformatted',access='sequential', &
   1772      1.1  mrg        convert='big_endian')
   1773      1.1  mrg @end smallexample
   1774      1.1  mrg 
   1775      1.1  mrg The value of the conversion can be queried by using
   1776      1.1  mrg @code{INQUIRE(CONVERT=ch)}.  The values returned are
   1777      1.1  mrg @code{'BIG_ENDIAN'} and @code{'LITTLE_ENDIAN'}.
   1778      1.1  mrg 
   1779      1.1  mrg @code{CONVERT} works between big- and little-endian for
   1780      1.1  mrg @code{INTEGER} values of all supported kinds and for @code{REAL}
   1781      1.1  mrg on IEEE systems of kinds 4 and 8.  Conversion between different
   1782      1.1  mrg ``extended double'' types on different architectures such as
   1783      1.1  mrg m68k and x86_64, which GNU Fortran
   1784      1.1  mrg supports as @code{REAL(KIND=10)} and @code{REAL(KIND=16)}, will
   1785      1.1  mrg probably not work.
   1786      1.1  mrg 
   1787      1.1  mrg @emph{Note that the values specified via the GFORTRAN_CONVERT_UNIT
   1788      1.1  mrg environment variable will override the CONVERT specifier in the
   1789      1.1  mrg open statement}.  This is to give control over data formats to
   1790      1.1  mrg users who do not have the source code of their program available.
   1791      1.1  mrg 
   1792      1.1  mrg Using anything but the native representation for unformatted data
   1793      1.1  mrg carries a significant speed overhead.  If speed in this area matters
   1794      1.1  mrg to you, it is best if you use this only for data that needs to be
   1795      1.1  mrg portable.
   1796      1.1  mrg 
   1797      1.1  mrg @node OpenMP
   1798      1.1  mrg @subsection OpenMP
   1799      1.1  mrg @cindex OpenMP
   1800      1.1  mrg 
   1801      1.1  mrg OpenMP (Open Multi-Processing) is an application programming
   1802      1.1  mrg interface (API) that supports multi-platform shared memory
   1803      1.1  mrg multiprocessing programming in C/C++ and Fortran on many
   1804      1.1  mrg architectures, including Unix and Microsoft Windows platforms.
   1805      1.1  mrg It consists of a set of compiler directives, library routines,
   1806      1.1  mrg and environment variables that influence run-time behavior.
   1807      1.1  mrg 
   1808      1.1  mrg GNU Fortran strives to be compatible to the
   1809  1.1.1.3  mrg @uref{https://openmp.org/wp/openmp-specifications/,
   1810      1.1  mrg OpenMP Application Program Interface v4.5}.
   1811      1.1  mrg 
   1812      1.1  mrg To enable the processing of the OpenMP directive @code{!$omp} in
   1813      1.1  mrg free-form source code; the @code{c$omp}, @code{*$omp} and @code{!$omp}
   1814      1.1  mrg directives in fixed form; the @code{!$} conditional compilation sentinels
   1815      1.1  mrg in free form; and the @code{c$}, @code{*$} and @code{!$} sentinels
   1816      1.1  mrg in fixed form, @command{gfortran} needs to be invoked with the
   1817      1.1  mrg @option{-fopenmp}.  This also arranges for automatic linking of the
   1818      1.1  mrg GNU Offloading and Multi Processing Runtime Library
   1819      1.1  mrg @ref{Top,,libgomp,libgomp,GNU Offloading and Multi Processing Runtime
   1820      1.1  mrg Library}.
   1821      1.1  mrg 
   1822      1.1  mrg The OpenMP Fortran runtime library routines are provided both in a
   1823      1.1  mrg form of a Fortran 90 module named @code{omp_lib} and in a form of
   1824      1.1  mrg a Fortran @code{include} file named @file{omp_lib.h}.
   1825      1.1  mrg 
   1826      1.1  mrg An example of a parallelized loop taken from Appendix A.1 of
   1827      1.1  mrg the OpenMP Application Program Interface v2.5:
   1828      1.1  mrg @smallexample
   1829      1.1  mrg SUBROUTINE A1(N, A, B)
   1830      1.1  mrg   INTEGER I, N
   1831      1.1  mrg   REAL B(N), A(N)
   1832      1.1  mrg !$OMP PARALLEL DO !I is private by default
   1833      1.1  mrg   DO I=2,N
   1834      1.1  mrg     B(I) = (A(I) + A(I-1)) / 2.0
   1835      1.1  mrg   ENDDO
   1836      1.1  mrg !$OMP END PARALLEL DO
   1837      1.1  mrg END SUBROUTINE A1
   1838      1.1  mrg @end smallexample
   1839      1.1  mrg 
   1840      1.1  mrg Please note:
   1841      1.1  mrg @itemize
   1842      1.1  mrg @item
   1843      1.1  mrg @option{-fopenmp} implies @option{-frecursive}, i.e., all local arrays
   1844      1.1  mrg will be allocated on the stack.  When porting existing code to OpenMP,
   1845      1.1  mrg this may lead to surprising results, especially to segmentation faults
   1846      1.1  mrg if the stacksize is limited.
   1847      1.1  mrg 
   1848      1.1  mrg @item
   1849      1.1  mrg On glibc-based systems, OpenMP enabled applications cannot be statically
   1850      1.1  mrg linked due to limitations of the underlying pthreads-implementation.  It
   1851      1.1  mrg might be possible to get a working solution if
   1852      1.1  mrg @command{-Wl,--whole-archive -lpthread -Wl,--no-whole-archive} is added
   1853      1.1  mrg to the command line.  However, this is not supported by @command{gcc} and
   1854      1.1  mrg thus not recommended.
   1855      1.1  mrg @end itemize
   1856      1.1  mrg 
   1857      1.1  mrg @node OpenACC
   1858      1.1  mrg @subsection OpenACC
   1859      1.1  mrg @cindex OpenACC
   1860      1.1  mrg 
   1861      1.1  mrg OpenACC is an application programming interface (API) that supports
   1862      1.1  mrg offloading of code to accelerator devices.  It consists of a set of
   1863      1.1  mrg compiler directives, library routines, and environment variables that
   1864      1.1  mrg influence run-time behavior.
   1865      1.1  mrg 
   1866      1.1  mrg GNU Fortran strives to be compatible to the
   1867  1.1.1.3  mrg @uref{https://www.openacc.org/, OpenACC Application Programming
   1868  1.1.1.2  mrg Interface v2.6}.
   1869      1.1  mrg 
   1870      1.1  mrg To enable the processing of the OpenACC directive @code{!$acc} in
   1871      1.1  mrg free-form source code; the @code{c$acc}, @code{*$acc} and @code{!$acc}
   1872      1.1  mrg directives in fixed form; the @code{!$} conditional compilation
   1873      1.1  mrg sentinels in free form; and the @code{c$}, @code{*$} and @code{!$}
   1874      1.1  mrg sentinels in fixed form, @command{gfortran} needs to be invoked with
   1875      1.1  mrg the @option{-fopenacc}.  This also arranges for automatic linking of
   1876      1.1  mrg the GNU Offloading and Multi Processing Runtime Library
   1877      1.1  mrg @ref{Top,,libgomp,libgomp,GNU Offloading and Multi Processing Runtime
   1878      1.1  mrg Library}.
   1879      1.1  mrg 
   1880      1.1  mrg The OpenACC Fortran runtime library routines are provided both in a
   1881      1.1  mrg form of a Fortran 90 module named @code{openacc} and in a form of a
   1882      1.1  mrg Fortran @code{include} file named @file{openacc_lib.h}.
   1883      1.1  mrg 
   1884      1.1  mrg @node Argument list functions
   1885      1.1  mrg @subsection Argument list functions @code{%VAL}, @code{%REF} and @code{%LOC}
   1886      1.1  mrg @cindex argument list functions
   1887      1.1  mrg @cindex @code{%VAL}
   1888      1.1  mrg @cindex @code{%REF}
   1889      1.1  mrg @cindex @code{%LOC}
   1890      1.1  mrg 
   1891      1.1  mrg GNU Fortran supports argument list functions @code{%VAL}, @code{%REF}
   1892      1.1  mrg and @code{%LOC} statements, for backward compatibility with g77.
   1893      1.1  mrg It is recommended that these should be used only for code that is
   1894      1.1  mrg accessing facilities outside of GNU Fortran, such as operating system
   1895      1.1  mrg or windowing facilities.  It is best to constrain such uses to isolated
   1896      1.1  mrg portions of a program--portions that deal specifically and exclusively
   1897      1.1  mrg with low-level, system-dependent facilities.  Such portions might well
   1898      1.1  mrg provide a portable interface for use by the program as a whole, but are
   1899      1.1  mrg themselves not portable, and should be thoroughly tested each time they
   1900      1.1  mrg are rebuilt using a new compiler or version of a compiler.
   1901      1.1  mrg 
   1902      1.1  mrg @code{%VAL} passes a scalar argument by value, @code{%REF} passes it by
   1903      1.1  mrg reference and @code{%LOC} passes its memory location.  Since gfortran
   1904      1.1  mrg already passes scalar arguments by reference, @code{%REF} is in effect
   1905      1.1  mrg a do-nothing.  @code{%LOC} has the same effect as a Fortran pointer.
   1906      1.1  mrg 
   1907      1.1  mrg An example of passing an argument by value to a C subroutine foo.:
   1908      1.1  mrg @smallexample
   1909      1.1  mrg C
   1910      1.1  mrg C prototype      void foo_ (float x);
   1911      1.1  mrg C
   1912      1.1  mrg       external foo
   1913      1.1  mrg       real*4 x
   1914      1.1  mrg       x = 3.14159
   1915      1.1  mrg       call foo (%VAL (x))
   1916      1.1  mrg       end
   1917      1.1  mrg @end smallexample
   1918      1.1  mrg 
   1919      1.1  mrg For details refer to the g77 manual
   1920      1.1  mrg @uref{https://gcc.gnu.org/@/onlinedocs/@/gcc-3.4.6/@/g77/@/index.html#Top}.
   1921      1.1  mrg 
   1922      1.1  mrg Also, @code{c_by_val.f} and its partner @code{c_by_val.c} of the
   1923      1.1  mrg GNU Fortran testsuite are worth a look.
   1924      1.1  mrg 
   1925      1.1  mrg @node Read/Write after EOF marker
   1926      1.1  mrg @subsection Read/Write after EOF marker
   1927      1.1  mrg @cindex @code{EOF}
   1928      1.1  mrg @cindex @code{BACKSPACE}
   1929      1.1  mrg @cindex @code{REWIND}
   1930      1.1  mrg 
   1931      1.1  mrg Some legacy codes rely on allowing @code{READ} or @code{WRITE} after the
   1932      1.1  mrg EOF file marker in order to find the end of a file. GNU Fortran normally
   1933      1.1  mrg rejects these codes with a run-time error message and suggests the user
   1934      1.1  mrg consider @code{BACKSPACE} or @code{REWIND} to properly position
   1935      1.1  mrg the file before the EOF marker.  As an extension, the run-time error may
   1936      1.1  mrg be disabled using -std=legacy.
   1937      1.1  mrg 
   1938      1.1  mrg 
   1939      1.1  mrg @node STRUCTURE and RECORD
   1940      1.1  mrg @subsection @code{STRUCTURE} and @code{RECORD}
   1941      1.1  mrg @cindex @code{STRUCTURE}
   1942      1.1  mrg @cindex @code{RECORD}
   1943      1.1  mrg 
   1944      1.1  mrg Record structures are a pre-Fortran-90 vendor extension to create
   1945      1.1  mrg user-defined aggregate data types.  Support for record structures in GNU
   1946      1.1  mrg Fortran can be enabled with the @option{-fdec-structure} compile flag.
   1947      1.1  mrg If you have a choice, you should instead use Fortran 90's ``derived types'',
   1948      1.1  mrg which have a different syntax.
   1949      1.1  mrg 
   1950      1.1  mrg In many cases, record structures can easily be converted to derived types.
   1951      1.1  mrg To convert, replace @code{STRUCTURE /}@var{structure-name}@code{/}
   1952      1.1  mrg by @code{TYPE} @var{type-name}.  Additionally, replace
   1953      1.1  mrg @code{RECORD /}@var{structure-name}@code{/} by
   1954      1.1  mrg @code{TYPE(}@var{type-name}@code{)}. Finally, in the component access,
   1955      1.1  mrg replace the period (@code{.}) by the percent sign (@code{%}).
   1956      1.1  mrg 
   1957      1.1  mrg Here is an example of code using the non portable record structure syntax:
   1958      1.1  mrg 
   1959      1.1  mrg @example
   1960      1.1  mrg ! Declaring a structure named ``item'' and containing three fields:
   1961      1.1  mrg ! an integer ID, an description string and a floating-point price.
   1962      1.1  mrg STRUCTURE /item/
   1963      1.1  mrg   INTEGER id
   1964      1.1  mrg   CHARACTER(LEN=200) description
   1965      1.1  mrg   REAL price
   1966      1.1  mrg END STRUCTURE
   1967      1.1  mrg 
   1968      1.1  mrg ! Define two variables, an single record of type ``item''
   1969      1.1  mrg ! named ``pear'', and an array of items named ``store_catalog''
   1970      1.1  mrg RECORD /item/ pear, store_catalog(100)
   1971      1.1  mrg 
   1972      1.1  mrg ! We can directly access the fields of both variables
   1973      1.1  mrg pear.id = 92316
   1974      1.1  mrg pear.description = "juicy D'Anjou pear"
   1975      1.1  mrg pear.price = 0.15
   1976      1.1  mrg store_catalog(7).id = 7831
   1977      1.1  mrg store_catalog(7).description = "milk bottle"
   1978      1.1  mrg store_catalog(7).price = 1.2
   1979      1.1  mrg 
   1980      1.1  mrg ! We can also manipulate the whole structure
   1981      1.1  mrg store_catalog(12) = pear
   1982      1.1  mrg print *, store_catalog(12)
   1983      1.1  mrg @end example
   1984      1.1  mrg 
   1985      1.1  mrg @noindent
   1986      1.1  mrg This code can easily be rewritten in the Fortran 90 syntax as following:
   1987      1.1  mrg 
   1988      1.1  mrg @example
   1989      1.1  mrg ! ``STRUCTURE /name/ ... END STRUCTURE'' becomes
   1990      1.1  mrg ! ``TYPE name ... END TYPE''
   1991      1.1  mrg TYPE item
   1992      1.1  mrg   INTEGER id
   1993      1.1  mrg   CHARACTER(LEN=200) description
   1994      1.1  mrg   REAL price
   1995      1.1  mrg END TYPE
   1996      1.1  mrg 
   1997      1.1  mrg ! ``RECORD /name/ variable'' becomes ``TYPE(name) variable''
   1998      1.1  mrg TYPE(item) pear, store_catalog(100)
   1999      1.1  mrg 
   2000      1.1  mrg ! Instead of using a dot (.) to access fields of a record, the
   2001      1.1  mrg ! standard syntax uses a percent sign (%)
   2002      1.1  mrg pear%id = 92316
   2003      1.1  mrg pear%description = "juicy D'Anjou pear"
   2004      1.1  mrg pear%price = 0.15
   2005      1.1  mrg store_catalog(7)%id = 7831
   2006      1.1  mrg store_catalog(7)%description = "milk bottle"
   2007      1.1  mrg store_catalog(7)%price = 1.2
   2008      1.1  mrg 
   2009      1.1  mrg ! Assignments of a whole variable do not change
   2010      1.1  mrg store_catalog(12) = pear
   2011      1.1  mrg print *, store_catalog(12)
   2012      1.1  mrg @end example
   2013      1.1  mrg 
   2014      1.1  mrg @noindent
   2015      1.1  mrg GNU Fortran implements STRUCTURES like derived types with the following
   2016      1.1  mrg rules and exceptions:
   2017      1.1  mrg 
   2018      1.1  mrg @itemize @bullet
   2019      1.1  mrg @item Structures act like derived types with the @code{SEQUENCE} attribute.
   2020      1.1  mrg Otherwise they may contain no specifiers.
   2021      1.1  mrg 
   2022      1.1  mrg @item Structures may contain a special field with the name @code{%FILL}.
   2023      1.1  mrg This will create an anonymous component which cannot be accessed but occupies
   2024      1.1  mrg space just as if a component of the same type was declared in its place, useful
   2025      1.1  mrg for alignment purposes.  As an example, the following structure will consist
   2026      1.1  mrg of at least sixteen bytes:
   2027      1.1  mrg 
   2028      1.1  mrg @smallexample
   2029      1.1  mrg structure /padded/
   2030      1.1  mrg   character(4) start
   2031      1.1  mrg   character(8) %FILL
   2032      1.1  mrg   character(4) end
   2033      1.1  mrg end structure
   2034      1.1  mrg @end smallexample
   2035      1.1  mrg 
   2036      1.1  mrg @item Structures may share names with other symbols. For example, the following
   2037      1.1  mrg is invalid for derived types, but valid for structures:
   2038      1.1  mrg 
   2039      1.1  mrg @smallexample
   2040      1.1  mrg structure /header/
   2041      1.1  mrg   ! ...
   2042      1.1  mrg end structure
   2043      1.1  mrg record /header/ header
   2044      1.1  mrg @end smallexample
   2045      1.1  mrg 
   2046      1.1  mrg @item Structure types may be declared nested within another parent structure.
   2047      1.1  mrg The syntax is:
   2048      1.1  mrg @smallexample
   2049      1.1  mrg structure /type-name/
   2050      1.1  mrg     ...
   2051      1.1  mrg     structure [/<type-name>/] <field-list>
   2052      1.1  mrg ...
   2053      1.1  mrg @end smallexample
   2054      1.1  mrg 
   2055      1.1  mrg The type name may be ommitted, in which case the structure type itself is
   2056      1.1  mrg anonymous, and other structures of the same type cannot be instantiated. The
   2057      1.1  mrg following shows some examples:
   2058      1.1  mrg 
   2059      1.1  mrg @example
   2060      1.1  mrg structure /appointment/
   2061      1.1  mrg   ! nested structure definition: app_time is an array of two 'time'
   2062      1.1  mrg   structure /time/ app_time (2)
   2063      1.1  mrg     integer(1) hour, minute
   2064      1.1  mrg   end structure
   2065      1.1  mrg   character(10) memo
   2066      1.1  mrg end structure
   2067      1.1  mrg 
   2068      1.1  mrg ! The 'time' structure is still usable
   2069      1.1  mrg record /time/ now
   2070      1.1  mrg now = time(5, 30)
   2071      1.1  mrg 
   2072      1.1  mrg ...
   2073      1.1  mrg 
   2074      1.1  mrg structure /appointment/
   2075      1.1  mrg   ! anonymous nested structure definition
   2076      1.1  mrg   structure start, end
   2077      1.1  mrg     integer(1) hour, minute
   2078      1.1  mrg   end structure
   2079      1.1  mrg   character(10) memo
   2080      1.1  mrg end structure
   2081      1.1  mrg @end example
   2082      1.1  mrg 
   2083      1.1  mrg @item Structures may contain @code{UNION} blocks. For more detail see the
   2084      1.1  mrg section on @ref{UNION and MAP}.
   2085      1.1  mrg 
   2086      1.1  mrg @item Structures support old-style initialization of components, like
   2087      1.1  mrg those described in @ref{Old-style variable initialization}. For array
   2088      1.1  mrg initializers, an initializer may contain a repeat specification of the form
   2089      1.1  mrg @code{<literal-integer> * <constant-initializer>}. The value of the integer
   2090      1.1  mrg indicates the number of times to repeat the constant initializer when expanding
   2091      1.1  mrg the initializer list.
   2092      1.1  mrg @end itemize
   2093      1.1  mrg 
   2094      1.1  mrg @node UNION and MAP
   2095      1.1  mrg @subsection @code{UNION} and @code{MAP}
   2096      1.1  mrg @cindex @code{UNION}
   2097      1.1  mrg @cindex @code{MAP}
   2098      1.1  mrg 
   2099      1.1  mrg Unions are an old vendor extension which were commonly used with the
   2100      1.1  mrg non-standard @ref{STRUCTURE and RECORD} extensions. Use of @code{UNION} and
   2101      1.1  mrg @code{MAP} is automatically enabled with @option{-fdec-structure}.
   2102      1.1  mrg 
   2103      1.1  mrg A @code{UNION} declaration occurs within a structure; within the definition of
   2104      1.1  mrg each union is a number of @code{MAP} blocks. Each @code{MAP} shares storage
   2105      1.1  mrg with its sibling maps (in the same union), and the size of the union is the
   2106      1.1  mrg size of the largest map within it, just as with unions in C. The major
   2107      1.1  mrg difference is that component references do not indicate which union or map the
   2108      1.1  mrg component is in (the compiler gets to figure that out).
   2109      1.1  mrg 
   2110      1.1  mrg Here is a small example:
   2111      1.1  mrg @smallexample
   2112      1.1  mrg structure /myunion/
   2113      1.1  mrg union
   2114      1.1  mrg   map
   2115      1.1  mrg     character(2) w0, w1, w2
   2116      1.1  mrg   end map
   2117      1.1  mrg   map
   2118      1.1  mrg     character(6) long
   2119      1.1  mrg   end map
   2120      1.1  mrg end union
   2121      1.1  mrg end structure
   2122      1.1  mrg 
   2123      1.1  mrg record /myunion/ rec
   2124      1.1  mrg ! After this assignment...
   2125      1.1  mrg rec.long = 'hello!'
   2126      1.1  mrg 
   2127      1.1  mrg ! The following is true:
   2128      1.1  mrg ! rec.w0 === 'he'
   2129      1.1  mrg ! rec.w1 === 'll'
   2130      1.1  mrg ! rec.w2 === 'o!'
   2131      1.1  mrg @end smallexample
   2132      1.1  mrg 
   2133      1.1  mrg The two maps share memory, and the size of the union is ultimately six bytes:
   2134      1.1  mrg 
   2135      1.1  mrg @example
   2136      1.1  mrg 0    1    2    3    4   5   6     Byte offset
   2137      1.1  mrg -------------------------------
   2138      1.1  mrg |    |    |    |    |    |    |
   2139      1.1  mrg -------------------------------
   2140      1.1  mrg 
   2141      1.1  mrg ^    W0   ^    W1   ^    W2   ^
   2142      1.1  mrg  \-------/ \-------/ \-------/
   2143      1.1  mrg 
   2144      1.1  mrg ^             LONG            ^
   2145      1.1  mrg  \---------------------------/
   2146      1.1  mrg @end example
   2147      1.1  mrg 
   2148      1.1  mrg Following is an example mirroring the layout of an Intel x86_64 register:
   2149      1.1  mrg 
   2150      1.1  mrg @example
   2151      1.1  mrg structure /reg/
   2152      1.1  mrg   union ! U0                ! rax
   2153      1.1  mrg     map
   2154      1.1  mrg       character(16) rx
   2155      1.1  mrg     end map
   2156      1.1  mrg     map
   2157      1.1  mrg       character(8) rh         ! rah
   2158      1.1  mrg       union ! U1
   2159      1.1  mrg         map
   2160      1.1  mrg           character(8) rl     ! ral
   2161      1.1  mrg         end map
   2162      1.1  mrg         map
   2163      1.1  mrg           character(8) ex     ! eax
   2164      1.1  mrg         end map
   2165      1.1  mrg         map
   2166      1.1  mrg           character(4) eh     ! eah
   2167      1.1  mrg           union ! U2
   2168      1.1  mrg             map
   2169      1.1  mrg               character(4) el ! eal
   2170      1.1  mrg             end map
   2171      1.1  mrg             map
   2172      1.1  mrg               character(4) x  ! ax
   2173      1.1  mrg             end map
   2174      1.1  mrg             map
   2175      1.1  mrg               character(2) h  ! ah
   2176      1.1  mrg               character(2) l  ! al
   2177      1.1  mrg             end map
   2178      1.1  mrg           end union
   2179      1.1  mrg         end map
   2180      1.1  mrg       end union
   2181      1.1  mrg     end map
   2182      1.1  mrg   end union
   2183      1.1  mrg end structure
   2184      1.1  mrg record /reg/ a
   2185      1.1  mrg 
   2186      1.1  mrg ! After this assignment...
   2187      1.1  mrg a.rx     =     'AAAAAAAA.BBB.C.D'
   2188      1.1  mrg 
   2189      1.1  mrg ! The following is true:
   2190      1.1  mrg a.rx === 'AAAAAAAA.BBB.C.D'
   2191      1.1  mrg a.rh === 'AAAAAAAA'
   2192      1.1  mrg a.rl ===         '.BBB.C.D'
   2193      1.1  mrg a.ex ===         '.BBB.C.D'
   2194      1.1  mrg a.eh ===         '.BBB'
   2195      1.1  mrg a.el ===             '.C.D'
   2196      1.1  mrg a.x  ===             '.C.D'
   2197      1.1  mrg a.h  ===             '.C'
   2198      1.1  mrg a.l  ===               '.D'
   2199      1.1  mrg @end example
   2200      1.1  mrg 
   2201      1.1  mrg @node Type variants for integer intrinsics
   2202      1.1  mrg @subsection Type variants for integer intrinsics
   2203      1.1  mrg @cindex intrinsics, integer
   2204      1.1  mrg 
   2205      1.1  mrg Similar to the D/C prefixes to real functions to specify the input/output
   2206      1.1  mrg types, GNU Fortran offers B/I/J/K prefixes to integer functions for
   2207      1.1  mrg compatibility with DEC programs. The types implied by each are:
   2208      1.1  mrg 
   2209      1.1  mrg @example
   2210      1.1  mrg @code{B} - @code{INTEGER(kind=1)}
   2211      1.1  mrg @code{I} - @code{INTEGER(kind=2)}
   2212      1.1  mrg @code{J} - @code{INTEGER(kind=4)}
   2213      1.1  mrg @code{K} - @code{INTEGER(kind=8)}
   2214      1.1  mrg @end example
   2215      1.1  mrg 
   2216      1.1  mrg GNU Fortran supports these with the flag @option{-fdec-intrinsic-ints}.
   2217      1.1  mrg Intrinsics for which prefixed versions are available and in what form are noted
   2218      1.1  mrg in @ref{Intrinsic Procedures}. The complete list of supported intrinsics is
   2219      1.1  mrg here:
   2220      1.1  mrg 
   2221      1.1  mrg @multitable @columnfractions .2 .2 .2 .2 .2
   2222      1.1  mrg 
   2223      1.1  mrg @headitem Intrinsic @tab B @tab I @tab J @tab K
   2224      1.1  mrg 
   2225      1.1  mrg @item @code{@ref{ABS}}
   2226      1.1  mrg   @tab @code{BABS} @tab @code{IIABS} @tab @code{JIABS} @tab @code{KIABS}
   2227      1.1  mrg @item @code{@ref{BTEST}}
   2228      1.1  mrg   @tab @code{BBTEST} @tab @code{BITEST} @tab @code{BJTEST} @tab @code{BKTEST}
   2229      1.1  mrg @item @code{@ref{IAND}}
   2230      1.1  mrg   @tab @code{BIAND} @tab @code{IIAND} @tab @code{JIAND} @tab @code{KIAND}
   2231      1.1  mrg @item @code{@ref{IBCLR}}
   2232      1.1  mrg   @tab @code{BBCLR} @tab @code{IIBCLR} @tab @code{JIBCLR} @tab @code{KIBCLR}
   2233      1.1  mrg @item @code{@ref{IBITS}}
   2234      1.1  mrg   @tab @code{BBITS} @tab @code{IIBITS} @tab @code{JIBITS} @tab @code{KIBITS}
   2235      1.1  mrg @item @code{@ref{IBSET}}
   2236      1.1  mrg   @tab @code{BBSET} @tab @code{IIBSET} @tab @code{JIBSET} @tab @code{KIBSET}
   2237      1.1  mrg @item @code{@ref{IEOR}}
   2238      1.1  mrg   @tab @code{BIEOR} @tab @code{IIEOR} @tab @code{JIEOR} @tab @code{KIEOR}
   2239      1.1  mrg @item @code{@ref{IOR}}
   2240      1.1  mrg   @tab @code{BIOR} @tab @code{IIOR} @tab @code{JIOR} @tab @code{KIOR}
   2241      1.1  mrg @item @code{@ref{ISHFT}}
   2242      1.1  mrg   @tab @code{BSHFT} @tab @code{IISHFT} @tab @code{JISHFT} @tab @code{KISHFT}
   2243      1.1  mrg @item @code{@ref{ISHFTC}}
   2244      1.1  mrg   @tab @code{BSHFTC} @tab @code{IISHFTC} @tab @code{JISHFTC} @tab @code{KISHFTC}
   2245      1.1  mrg @item @code{@ref{MOD}}
   2246      1.1  mrg   @tab @code{BMOD} @tab @code{IMOD} @tab @code{JMOD} @tab @code{KMOD}
   2247      1.1  mrg @item @code{@ref{NOT}}
   2248      1.1  mrg   @tab @code{BNOT} @tab @code{INOT} @tab @code{JNOT} @tab @code{KNOT}
   2249      1.1  mrg @item @code{@ref{REAL}}
   2250      1.1  mrg   @tab @code{--} @tab @code{FLOATI} @tab @code{FLOATJ} @tab @code{FLOATK}
   2251      1.1  mrg @end multitable
   2252      1.1  mrg 
   2253      1.1  mrg @node AUTOMATIC and STATIC attributes
   2254      1.1  mrg @subsection @code{AUTOMATIC} and @code{STATIC} attributes
   2255      1.1  mrg @cindex variable attributes
   2256      1.1  mrg @cindex @code{AUTOMATIC}
   2257      1.1  mrg @cindex @code{STATIC}
   2258      1.1  mrg 
   2259      1.1  mrg With @option{-fdec-static} GNU Fortran supports the DEC extended attributes
   2260      1.1  mrg @code{STATIC} and @code{AUTOMATIC} to provide explicit specification of entity
   2261      1.1  mrg storage.  These follow the syntax of the Fortran standard @code{SAVE} attribute.
   2262      1.1  mrg 
   2263      1.1  mrg @code{STATIC} is exactly equivalent to @code{SAVE}, and specifies that
   2264      1.1  mrg an entity should be allocated in static memory.  As an example, @code{STATIC}
   2265      1.1  mrg local variables will retain their values across multiple calls to a function.
   2266      1.1  mrg 
   2267      1.1  mrg Entities marked @code{AUTOMATIC} will be stack automatic whenever possible.
   2268      1.1  mrg @code{AUTOMATIC} is the default for local variables smaller than
   2269      1.1  mrg @option{-fmax-stack-var-size}, unless @option{-fno-automatic} is given.  This
   2270      1.1  mrg attribute overrides @option{-fno-automatic}, @option{-fmax-stack-var-size}, and
   2271      1.1  mrg blanket @code{SAVE} statements.
   2272      1.1  mrg 
   2273      1.1  mrg 
   2274      1.1  mrg Examples:
   2275      1.1  mrg 
   2276      1.1  mrg @example
   2277      1.1  mrg subroutine f
   2278      1.1  mrg   integer, automatic :: i  ! automatic variable
   2279      1.1  mrg   integer x, y             ! static variables
   2280      1.1  mrg   save
   2281      1.1  mrg   ...
   2282      1.1  mrg endsubroutine
   2283      1.1  mrg @end example
   2284      1.1  mrg @example
   2285      1.1  mrg subroutine f
   2286      1.1  mrg   integer a, b, c, x, y, z
   2287      1.1  mrg   static :: x
   2288      1.1  mrg   save y
   2289      1.1  mrg   automatic z, c
   2290      1.1  mrg   ! a, b, c, and z are automatic
   2291      1.1  mrg   ! x and y are static
   2292      1.1  mrg endsubroutine
   2293      1.1  mrg @end example
   2294      1.1  mrg @example
   2295      1.1  mrg ! Compiled with -fno-automatic
   2296      1.1  mrg subroutine f
   2297      1.1  mrg   integer a, b, c, d
   2298      1.1  mrg   automatic :: a
   2299      1.1  mrg   ! a is automatic; b, c, and d are static
   2300      1.1  mrg endsubroutine
   2301      1.1  mrg @end example
   2302      1.1  mrg 
   2303      1.1  mrg @node Extended math intrinsics
   2304      1.1  mrg @subsection Extended math intrinsics
   2305      1.1  mrg @cindex intrinsics, math
   2306      1.1  mrg @cindex intrinsics, trigonometric functions
   2307      1.1  mrg 
   2308      1.1  mrg GNU Fortran supports an extended list of mathematical intrinsics with the
   2309      1.1  mrg compile flag @option{-fdec-math} for compatability with legacy code.
   2310      1.1  mrg These intrinsics are described fully in @ref{Intrinsic Procedures} where it is
   2311      1.1  mrg noted that they are extensions and should be avoided whenever possible.
   2312      1.1  mrg 
   2313      1.1  mrg Specifically, @option{-fdec-math} enables the @ref{COTAN} intrinsic, and
   2314      1.1  mrg trigonometric intrinsics which accept or produce values in degrees instead of
   2315      1.1  mrg radians.  Here is a summary of the new intrinsics:
   2316      1.1  mrg 
   2317      1.1  mrg @multitable @columnfractions .5 .5
   2318      1.1  mrg @headitem Radians @tab Degrees
   2319      1.1  mrg @item @code{@ref{ACOS}}   @tab @code{@ref{ACOSD}}*
   2320      1.1  mrg @item @code{@ref{ASIN}}   @tab @code{@ref{ASIND}}*
   2321      1.1  mrg @item @code{@ref{ATAN}}   @tab @code{@ref{ATAND}}*
   2322      1.1  mrg @item @code{@ref{ATAN2}}  @tab @code{@ref{ATAN2D}}*
   2323      1.1  mrg @item @code{@ref{COS}}    @tab @code{@ref{COSD}}*
   2324      1.1  mrg @item @code{@ref{COTAN}}* @tab @code{@ref{COTAND}}*
   2325      1.1  mrg @item @code{@ref{SIN}}    @tab @code{@ref{SIND}}*
   2326      1.1  mrg @item @code{@ref{TAN}}    @tab @code{@ref{TAND}}*
   2327      1.1  mrg @end multitable
   2328      1.1  mrg 
   2329      1.1  mrg * Enabled with @option{-fdec-math}.
   2330      1.1  mrg 
   2331      1.1  mrg For advanced users, it may be important to know the implementation of these
   2332      1.1  mrg functions. They are simply wrappers around the standard radian functions, which
   2333      1.1  mrg have more accurate builtin versions. These functions convert their arguments
   2334      1.1  mrg (or results) to degrees (or radians) by taking the value modulus 360 (or 2*pi)
   2335      1.1  mrg and then multiplying it by a constant radian-to-degree (or degree-to-radian)
   2336      1.1  mrg factor, as appropriate. The factor is computed at compile-time as 180/pi (or
   2337      1.1  mrg pi/180).
   2338      1.1  mrg 
   2339      1.1  mrg @node Form feed as whitespace
   2340      1.1  mrg @subsection Form feed as whitespace
   2341      1.1  mrg @cindex form feed whitespace
   2342      1.1  mrg 
   2343      1.1  mrg Historically, legacy compilers allowed insertion of form feed characters ('\f',
   2344      1.1  mrg ASCII 0xC) at the beginning of lines for formatted output to line printers,
   2345      1.1  mrg though the Fortran standard does not mention this. GNU Fortran supports the
   2346      1.1  mrg interpretation of form feed characters in source as whitespace for
   2347      1.1  mrg compatibility.
   2348      1.1  mrg 
   2349      1.1  mrg @node TYPE as an alias for PRINT
   2350      1.1  mrg @subsection TYPE as an alias for PRINT
   2351      1.1  mrg @cindex type alias print
   2352      1.1  mrg For compatibility, GNU Fortran will interpret @code{TYPE} statements as
   2353      1.1  mrg @code{PRINT} statements with the flag @option{-fdec}.  With this flag asserted,
   2354      1.1  mrg the following two examples are equivalent:
   2355      1.1  mrg 
   2356      1.1  mrg @smallexample
   2357      1.1  mrg TYPE *, 'hello world'
   2358      1.1  mrg @end smallexample
   2359      1.1  mrg 
   2360      1.1  mrg @smallexample
   2361      1.1  mrg PRINT *, 'hello world'
   2362      1.1  mrg @end smallexample
   2363      1.1  mrg 
   2364      1.1  mrg @node %LOC as an rvalue
   2365      1.1  mrg @subsection %LOC as an rvalue
   2366      1.1  mrg @cindex LOC
   2367      1.1  mrg Normally @code{%LOC} is allowed only in parameter lists.  However the intrinsic
   2368      1.1  mrg function @code{LOC} does the same thing, and is usable as the right-hand-side of
   2369      1.1  mrg assignments. For compatibility, GNU Fortran supports the use of @code{%LOC} as
   2370      1.1  mrg an alias for the builtin @code{LOC} with @option{-std=legacy}.  With this
   2371      1.1  mrg feature enabled the following two examples are equivalent:
   2372      1.1  mrg 
   2373      1.1  mrg @smallexample
   2374      1.1  mrg integer :: i, l
   2375      1.1  mrg l = %loc(i)
   2376      1.1  mrg call sub(l)
   2377      1.1  mrg @end smallexample
   2378      1.1  mrg 
   2379      1.1  mrg @smallexample
   2380      1.1  mrg integer :: i
   2381      1.1  mrg call sub(%loc(i))
   2382      1.1  mrg @end smallexample
   2383      1.1  mrg 
   2384      1.1  mrg @node .XOR. operator
   2385      1.1  mrg @subsection .XOR. operator
   2386      1.1  mrg @cindex operators, xor
   2387      1.1  mrg 
   2388      1.1  mrg GNU Fortran supports @code{.XOR.} as a logical operator with @code{-std=legacy}
   2389      1.1  mrg for compatibility with legacy code. @code{.XOR.} is equivalent to
   2390      1.1  mrg @code{.NEQV.}. That is, the output is true if and only if the inputs differ.
   2391      1.1  mrg 
   2392      1.1  mrg @node Bitwise logical operators
   2393      1.1  mrg @subsection Bitwise logical operators
   2394      1.1  mrg @cindex logical, bitwise
   2395      1.1  mrg 
   2396      1.1  mrg With @option{-fdec}, GNU Fortran relaxes the type constraints on
   2397      1.1  mrg logical operators to allow integer operands, and performs the corresponding
   2398      1.1  mrg bitwise operation instead.  This flag is for compatibility only, and should be
   2399      1.1  mrg avoided in new code.  Consider:
   2400      1.1  mrg 
   2401      1.1  mrg @smallexample
   2402      1.1  mrg   INTEGER :: i, j
   2403      1.1  mrg   i = z'33'
   2404      1.1  mrg   j = z'cc'
   2405      1.1  mrg   print *, i .AND. j
   2406      1.1  mrg @end smallexample
   2407      1.1  mrg 
   2408      1.1  mrg In this example, compiled with @option{-fdec}, GNU Fortran will
   2409      1.1  mrg replace the @code{.AND.} operation with a call to the intrinsic
   2410      1.1  mrg @code{@ref{IAND}} function, yielding the bitwise-and of @code{i} and @code{j}.
   2411      1.1  mrg 
   2412      1.1  mrg Note that this conversion will occur if at least one operand is of integral
   2413      1.1  mrg type.  As a result, a logical operand will be converted to an integer when the
   2414      1.1  mrg other operand is an integer in a logical operation.  In this case,
   2415      1.1  mrg @code{.TRUE.} is converted to @code{1} and @code{.FALSE.} to @code{0}.
   2416      1.1  mrg 
   2417      1.1  mrg Here is the mapping of logical operator to bitwise intrinsic used with
   2418      1.1  mrg @option{-fdec}:
   2419      1.1  mrg 
   2420      1.1  mrg @multitable @columnfractions .25 .25 .5
   2421      1.1  mrg @headitem Operator @tab Intrinsic @tab Bitwise operation
   2422      1.1  mrg @item @code{.NOT.} @tab @code{@ref{NOT}} @tab complement
   2423      1.1  mrg @item @code{.AND.} @tab @code{@ref{IAND}} @tab intersection
   2424      1.1  mrg @item @code{.OR.} @tab @code{@ref{IOR}} @tab union
   2425      1.1  mrg @item @code{.NEQV.} @tab @code{@ref{IEOR}} @tab exclusive or
   2426      1.1  mrg @item @code{.EQV.} @tab @code{@ref{NOT}(@ref{IEOR})} @tab complement of exclusive or
   2427      1.1  mrg @end multitable
   2428      1.1  mrg 
   2429      1.1  mrg @node Extended I/O specifiers
   2430      1.1  mrg @subsection Extended I/O specifiers
   2431      1.1  mrg @cindex @code{CARRIAGECONTROL}
   2432      1.1  mrg @cindex @code{READONLY}
   2433      1.1  mrg @cindex @code{SHARE}
   2434      1.1  mrg @cindex @code{SHARED}
   2435      1.1  mrg @cindex @code{NOSHARED}
   2436      1.1  mrg @cindex I/O specifiers
   2437      1.1  mrg 
   2438      1.1  mrg GNU Fortran supports the additional legacy I/O specifiers
   2439      1.1  mrg @code{CARRIAGECONTROL}, @code{READONLY}, and @code{SHARE} with the
   2440      1.1  mrg compile flag @option{-fdec}, for compatibility.
   2441      1.1  mrg 
   2442      1.1  mrg @table @code
   2443      1.1  mrg @item CARRIAGECONTROL
   2444      1.1  mrg The @code{CARRIAGECONTROL} specifier allows a user to control line
   2445      1.1  mrg termination settings between output records for an I/O unit. The specifier has
   2446      1.1  mrg no meaning for readonly files. When @code{CARRAIGECONTROL} is specified upon
   2447      1.1  mrg opening a unit for formatted writing, the exact @code{CARRIAGECONTROL} setting
   2448      1.1  mrg determines what characters to write between output records. The syntax is:
   2449      1.1  mrg 
   2450      1.1  mrg @smallexample
   2451      1.1  mrg OPEN(..., CARRIAGECONTROL=cc)
   2452      1.1  mrg @end smallexample
   2453      1.1  mrg 
   2454      1.1  mrg Where @emph{cc} is a character expression that evaluates to one of the
   2455      1.1  mrg following values:
   2456      1.1  mrg 
   2457      1.1  mrg @multitable @columnfractions .2 .8
   2458      1.1  mrg @item @code{'LIST'} @tab One line feed between records (default)
   2459      1.1  mrg @item @code{'FORTRAN'} @tab Legacy interpretation of the first character (see below)
   2460      1.1  mrg @item @code{'NONE'} @tab No separator between records
   2461      1.1  mrg @end multitable
   2462      1.1  mrg 
   2463      1.1  mrg With @code{CARRIAGECONTROL='FORTRAN'}, when a record is written, the first
   2464      1.1  mrg character of the input record is not written, and instead determines the output
   2465      1.1  mrg record separator as follows:
   2466      1.1  mrg 
   2467      1.1  mrg @multitable @columnfractions .3 .3 .4
   2468      1.1  mrg @headitem Leading character @tab Meaning @tab Output separating character(s)
   2469      1.1  mrg @item @code{'+'} @tab Overprinting @tab Carriage return only
   2470      1.1  mrg @item @code{'-'} @tab New line @tab Line feed and carriage return
   2471      1.1  mrg @item @code{'0'} @tab Skip line @tab Two line feeds and carriage return
   2472      1.1  mrg @item @code{'1'} @tab New page @tab Form feed and carriage return
   2473      1.1  mrg @item @code{'$'} @tab Prompting @tab Line feed (no carriage return)
   2474      1.1  mrg @item @code{CHAR(0)} @tab Overprinting (no advance) @tab None
   2475      1.1  mrg @end multitable
   2476      1.1  mrg 
   2477      1.1  mrg @item READONLY
   2478      1.1  mrg The @code{READONLY} specifier may be given upon opening a unit, and is
   2479      1.1  mrg equivalent to specifying @code{ACTION='READ'}, except that the file may not be
   2480      1.1  mrg deleted on close (i.e. @code{CLOSE} with @code{STATUS="DELETE"}). The syntax
   2481      1.1  mrg is:
   2482      1.1  mrg 
   2483      1.1  mrg @smallexample
   2484      1.1  mrg @code{OPEN(..., READONLY)}
   2485      1.1  mrg @end smallexample
   2486      1.1  mrg 
   2487      1.1  mrg @item SHARE
   2488      1.1  mrg The @code{SHARE} specifier allows system-level locking on a unit upon opening
   2489      1.1  mrg it for controlled access from multiple processes/threads. The @code{SHARE}
   2490      1.1  mrg specifier has several forms:
   2491      1.1  mrg 
   2492      1.1  mrg @smallexample
   2493      1.1  mrg OPEN(..., SHARE=sh)
   2494      1.1  mrg OPEN(..., SHARED)
   2495      1.1  mrg OPEN(..., NOSHARED)
   2496      1.1  mrg @end smallexample
   2497      1.1  mrg 
   2498      1.1  mrg Where @emph{sh} in the first form is a character expression that evaluates to
   2499      1.1  mrg a value as seen in the table below. The latter two forms are aliases
   2500      1.1  mrg for particular values of @emph{sh}:
   2501      1.1  mrg 
   2502      1.1  mrg @multitable @columnfractions .3 .3 .4
   2503      1.1  mrg @headitem Explicit form @tab Short form @tab Meaning
   2504      1.1  mrg @item @code{SHARE='DENYRW'} @tab @code{NOSHARED} @tab Exclusive (write) lock
   2505      1.1  mrg @item @code{SHARE='DENYNONE'} @tab @code{SHARED} @tab Shared (read) lock
   2506      1.1  mrg @end multitable
   2507      1.1  mrg 
   2508      1.1  mrg In general only one process may hold an exclusive (write) lock for a given file
   2509      1.1  mrg at a time, whereas many processes may hold shared (read) locks for the same
   2510      1.1  mrg file.
   2511      1.1  mrg 
   2512      1.1  mrg The behavior of locking may vary with your operating system. On POSIX systems,
   2513      1.1  mrg locking is implemented with @code{fcntl}. Consult your corresponding operating
   2514      1.1  mrg system's manual pages for further details. Locking via @code{SHARE=} is not
   2515      1.1  mrg supported on other systems.
   2516      1.1  mrg 
   2517      1.1  mrg @end table
   2518      1.1  mrg 
   2519      1.1  mrg @node Legacy PARAMETER statements
   2520      1.1  mrg @subsection Legacy PARAMETER statements
   2521      1.1  mrg @cindex PARAMETER
   2522      1.1  mrg 
   2523      1.1  mrg For compatibility, GNU Fortran supports legacy PARAMETER statements without
   2524      1.1  mrg parentheses with @option{-std=legacy}.  A warning is emitted if used with
   2525      1.1  mrg @option{-std=gnu}, and an error is acknowledged with a real Fortran standard
   2526      1.1  mrg flag (@option{-std=f95}, etc...).  These statements take the following form:
   2527      1.1  mrg 
   2528      1.1  mrg @smallexample
   2529      1.1  mrg implicit real (E)
   2530      1.1  mrg parameter e = 2.718282
   2531      1.1  mrg real c
   2532      1.1  mrg parameter c = 3.0e8
   2533      1.1  mrg @end smallexample
   2534      1.1  mrg 
   2535      1.1  mrg @node Default exponents
   2536      1.1  mrg @subsection Default exponents
   2537      1.1  mrg @cindex exponent
   2538      1.1  mrg 
   2539      1.1  mrg For compatibility, GNU Fortran supports a default exponent of zero in real
   2540      1.1  mrg constants with @option{-fdec}.  For example, @code{9e} would be
   2541      1.1  mrg interpreted as @code{9e0}, rather than an error.
   2542      1.1  mrg 
   2543      1.1  mrg 
   2544      1.1  mrg @node Extensions not implemented in GNU Fortran
   2545      1.1  mrg @section Extensions not implemented in GNU Fortran
   2546      1.1  mrg @cindex extensions, not implemented
   2547      1.1  mrg 
   2548      1.1  mrg The long history of the Fortran language, its wide use and broad
   2549      1.1  mrg userbase, the large number of different compiler vendors and the lack of
   2550      1.1  mrg some features crucial to users in the first standards have lead to the
   2551      1.1  mrg existence of a number of important extensions to the language.  While
   2552      1.1  mrg some of the most useful or popular extensions are supported by the GNU
   2553      1.1  mrg Fortran compiler, not all existing extensions are supported.  This section
   2554      1.1  mrg aims at listing these extensions and offering advice on how best make
   2555      1.1  mrg code that uses them running with the GNU Fortran compiler.
   2556      1.1  mrg 
   2557      1.1  mrg @c More can be found here:
   2558      1.1  mrg @c   -- https://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Missing-Features.html
   2559      1.1  mrg @c   -- the list of Fortran and libgfortran bugs closed as WONTFIX:
   2560      1.1  mrg @c      http://tinyurl.com/2u4h5y
   2561      1.1  mrg 
   2562      1.1  mrg @menu
   2563      1.1  mrg * ENCODE and DECODE statements::
   2564      1.1  mrg * Variable FORMAT expressions::
   2565      1.1  mrg @c * TYPE and ACCEPT I/O Statements::
   2566      1.1  mrg @c * DEFAULTFILE, DISPOSE and RECORDTYPE I/O specifiers::
   2567      1.1  mrg @c * Omitted arguments in procedure call::
   2568      1.1  mrg * Alternate complex function syntax::
   2569      1.1  mrg * Volatile COMMON blocks::
   2570      1.1  mrg * OPEN( ... NAME=)::
   2571      1.1  mrg * Q edit descriptor::
   2572      1.1  mrg @end menu
   2573      1.1  mrg 
   2574      1.1  mrg @node ENCODE and DECODE statements
   2575      1.1  mrg @subsection @code{ENCODE} and @code{DECODE} statements
   2576      1.1  mrg @cindex @code{ENCODE}
   2577      1.1  mrg @cindex @code{DECODE}
   2578      1.1  mrg 
   2579      1.1  mrg GNU Fortran does not support the @code{ENCODE} and @code{DECODE}
   2580      1.1  mrg statements.  These statements are best replaced by @code{READ} and
   2581      1.1  mrg @code{WRITE} statements involving internal files (@code{CHARACTER}
   2582      1.1  mrg variables and arrays), which have been part of the Fortran standard since
   2583      1.1  mrg Fortran 77.  For example, replace a code fragment like
   2584      1.1  mrg 
   2585      1.1  mrg @smallexample
   2586      1.1  mrg       INTEGER*1 LINE(80)
   2587      1.1  mrg       REAL A, B, C
   2588      1.1  mrg c     ... Code that sets LINE
   2589      1.1  mrg       DECODE (80, 9000, LINE) A, B, C
   2590      1.1  mrg  9000 FORMAT (1X, 3(F10.5))
   2591      1.1  mrg @end smallexample
   2592      1.1  mrg 
   2593      1.1  mrg @noindent
   2594      1.1  mrg with the following:
   2595      1.1  mrg 
   2596      1.1  mrg @smallexample
   2597      1.1  mrg       CHARACTER(LEN=80) LINE
   2598      1.1  mrg       REAL A, B, C
   2599      1.1  mrg c     ... Code that sets LINE
   2600      1.1  mrg       READ (UNIT=LINE, FMT=9000) A, B, C
   2601      1.1  mrg  9000 FORMAT (1X, 3(F10.5))
   2602      1.1  mrg @end smallexample
   2603      1.1  mrg 
   2604      1.1  mrg Similarly, replace a code fragment like
   2605      1.1  mrg 
   2606      1.1  mrg @smallexample
   2607      1.1  mrg       INTEGER*1 LINE(80)
   2608      1.1  mrg       REAL A, B, C
   2609      1.1  mrg c     ... Code that sets A, B and C
   2610      1.1  mrg       ENCODE (80, 9000, LINE) A, B, C
   2611      1.1  mrg  9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
   2612      1.1  mrg @end smallexample
   2613      1.1  mrg 
   2614      1.1  mrg @noindent
   2615      1.1  mrg with the following:
   2616      1.1  mrg 
   2617      1.1  mrg @smallexample
   2618      1.1  mrg       CHARACTER(LEN=80) LINE
   2619      1.1  mrg       REAL A, B, C
   2620      1.1  mrg c     ... Code that sets A, B and C
   2621      1.1  mrg       WRITE (UNIT=LINE, FMT=9000) A, B, C
   2622      1.1  mrg  9000 FORMAT (1X, 'OUTPUT IS ', 3(F10.5))
   2623      1.1  mrg @end smallexample
   2624      1.1  mrg 
   2625      1.1  mrg 
   2626      1.1  mrg @node Variable FORMAT expressions
   2627      1.1  mrg @subsection Variable @code{FORMAT} expressions
   2628      1.1  mrg @cindex @code{FORMAT}
   2629      1.1  mrg 
   2630      1.1  mrg A variable @code{FORMAT} expression is format statement which includes
   2631      1.1  mrg angle brackets enclosing a Fortran expression: @code{FORMAT(I<N>)}.  GNU
   2632      1.1  mrg Fortran does not support this legacy extension.  The effect of variable
   2633      1.1  mrg format expressions can be reproduced by using the more powerful (and
   2634      1.1  mrg standard) combination of internal output and string formats.  For example,
   2635      1.1  mrg replace a code fragment like this:
   2636      1.1  mrg 
   2637      1.1  mrg @smallexample
   2638      1.1  mrg       WRITE(6,20) INT1
   2639      1.1  mrg  20   FORMAT(I<N+1>)
   2640      1.1  mrg @end smallexample
   2641      1.1  mrg 
   2642      1.1  mrg @noindent
   2643      1.1  mrg with the following:
   2644      1.1  mrg 
   2645      1.1  mrg @smallexample
   2646      1.1  mrg c     Variable declaration
   2647      1.1  mrg       CHARACTER(LEN=20) FMT
   2648      1.1  mrg c
   2649      1.1  mrg c     Other code here...
   2650      1.1  mrg c
   2651      1.1  mrg       WRITE(FMT,'("(I", I0, ")")') N+1
   2652      1.1  mrg       WRITE(6,FMT) INT1
   2653      1.1  mrg @end smallexample
   2654      1.1  mrg 
   2655      1.1  mrg @noindent
   2656      1.1  mrg or with:
   2657      1.1  mrg 
   2658      1.1  mrg @smallexample
   2659      1.1  mrg c     Variable declaration
   2660      1.1  mrg       CHARACTER(LEN=20) FMT
   2661      1.1  mrg c
   2662      1.1  mrg c     Other code here...
   2663      1.1  mrg c
   2664      1.1  mrg       WRITE(FMT,*) N+1
   2665      1.1  mrg       WRITE(6,"(I" // ADJUSTL(FMT) // ")") INT1
   2666      1.1  mrg @end smallexample
   2667      1.1  mrg 
   2668      1.1  mrg 
   2669      1.1  mrg @node Alternate complex function syntax
   2670      1.1  mrg @subsection Alternate complex function syntax
   2671      1.1  mrg @cindex Complex function
   2672      1.1  mrg 
   2673      1.1  mrg Some Fortran compilers, including @command{g77}, let the user declare
   2674      1.1  mrg complex functions with the syntax @code{COMPLEX FUNCTION name*16()}, as
   2675      1.1  mrg well as @code{COMPLEX*16 FUNCTION name()}.  Both are non-standard, legacy
   2676      1.1  mrg extensions.  @command{gfortran} accepts the latter form, which is more
   2677      1.1  mrg common, but not the former.
   2678      1.1  mrg 
   2679      1.1  mrg 
   2680      1.1  mrg @node Volatile COMMON blocks
   2681      1.1  mrg @subsection Volatile @code{COMMON} blocks
   2682      1.1  mrg @cindex @code{VOLATILE}
   2683      1.1  mrg @cindex @code{COMMON}
   2684      1.1  mrg 
   2685      1.1  mrg Some Fortran compilers, including @command{g77}, let the user declare
   2686      1.1  mrg @code{COMMON} with the @code{VOLATILE} attribute. This is
   2687      1.1  mrg invalid standard Fortran syntax and is not supported by
   2688      1.1  mrg @command{gfortran}.  Note that @command{gfortran} accepts
   2689      1.1  mrg @code{VOLATILE} variables in @code{COMMON} blocks since revision 4.3.
   2690      1.1  mrg 
   2691      1.1  mrg 
   2692      1.1  mrg @node OPEN( ... NAME=)
   2693      1.1  mrg @subsection @code{OPEN( ... NAME=)}
   2694      1.1  mrg @cindex @code{NAME}
   2695      1.1  mrg 
   2696      1.1  mrg Some Fortran compilers, including @command{g77}, let the user declare
   2697      1.1  mrg @code{OPEN( ... NAME=)}. This is
   2698      1.1  mrg invalid standard Fortran syntax and is not supported by
   2699      1.1  mrg @command{gfortran}.  @code{OPEN( ... NAME=)} should be replaced
   2700      1.1  mrg with @code{OPEN( ... FILE=)}.
   2701      1.1  mrg 
   2702      1.1  mrg @node Q edit descriptor
   2703      1.1  mrg @subsection @code{Q} edit descriptor
   2704      1.1  mrg @cindex @code{Q} edit descriptor
   2705      1.1  mrg 
   2706      1.1  mrg Some Fortran compilers provide the @code{Q} edit descriptor, which
   2707      1.1  mrg transfers the number of characters left within an input record into an
   2708      1.1  mrg integer variable.
   2709      1.1  mrg 
   2710      1.1  mrg A direct replacement of the @code{Q} edit descriptor is not available
   2711      1.1  mrg in @command{gfortran}.  How to replicate its functionality using
   2712      1.1  mrg standard-conforming code depends on what the intent of the original
   2713      1.1  mrg code is.
   2714      1.1  mrg 
   2715      1.1  mrg Options to replace @code{Q} may be to read the whole line into a
   2716      1.1  mrg character variable and then counting the number of non-blank
   2717      1.1  mrg characters left using @code{LEN_TRIM}.  Another method may be to use
   2718      1.1  mrg formatted stream, read the data up to the position where the @code{Q}
   2719      1.1  mrg descriptor occurred, use @code{INQUIRE} to get the file position,
   2720      1.1  mrg count the characters up to the next @code{NEW_LINE} and then start
   2721      1.1  mrg reading from the position marked previously.
   2722      1.1  mrg 
   2723      1.1  mrg 
   2724      1.1  mrg @c ---------------------------------------------------------------------
   2725      1.1  mrg @c ---------------------------------------------------------------------
   2726      1.1  mrg @c Mixed-Language Programming
   2727      1.1  mrg @c ---------------------------------------------------------------------
   2728      1.1  mrg 
   2729      1.1  mrg @node Mixed-Language Programming
   2730      1.1  mrg @chapter Mixed-Language Programming
   2731      1.1  mrg @cindex Interoperability
   2732      1.1  mrg @cindex Mixed-language programming
   2733      1.1  mrg 
   2734      1.1  mrg @menu
   2735      1.1  mrg * Interoperability with C::
   2736      1.1  mrg * GNU Fortran Compiler Directives::
   2737      1.1  mrg * Non-Fortran Main Program::
   2738      1.1  mrg * Naming and argument-passing conventions::
   2739      1.1  mrg @end menu
   2740      1.1  mrg 
   2741  1.1.1.3  mrg This chapter is about mixed-language interoperability, but also
   2742  1.1.1.3  mrg applies if you link Fortran code compiled by different compilers.  In
   2743  1.1.1.3  mrg most cases, use of the C Binding features of the Fortran 2003 and
   2744  1.1.1.3  mrg later standards is sufficient.
   2745  1.1.1.3  mrg 
   2746  1.1.1.3  mrg For example, it is possible to mix Fortran code with C++ code as well
   2747  1.1.1.3  mrg as C, if you declare the interface functions as @code{extern "C"} on
   2748  1.1.1.3  mrg the C++ side and @code{BIND(C)} on the Fortran side, and follow the
   2749  1.1.1.3  mrg rules for interoperability with C.  Note that you cannot manipulate
   2750  1.1.1.3  mrg C++ class objects in Fortran or vice versa except as opaque pointers.
   2751  1.1.1.3  mrg 
   2752  1.1.1.3  mrg You can use the @command{gfortran} command to link both Fortran and
   2753  1.1.1.3  mrg non-Fortran code into the same program, or you can use @command{gcc}
   2754  1.1.1.3  mrg or @command{g++} if you also add an explicit @option{-lgfortran} option
   2755  1.1.1.3  mrg to link with the Fortran library.  If your main program is written in
   2756  1.1.1.3  mrg C or some other language instead of Fortran, see
   2757  1.1.1.3  mrg @ref{Non-Fortran Main Program}, below.
   2758      1.1  mrg 
   2759      1.1  mrg @node Interoperability with C
   2760      1.1  mrg @section Interoperability with C
   2761  1.1.1.3  mrg @cindex interoperability with C
   2762  1.1.1.3  mrg @cindex C interoperability
   2763      1.1  mrg 
   2764      1.1  mrg @menu
   2765      1.1  mrg * Intrinsic Types::
   2766      1.1  mrg * Derived Types and struct::
   2767      1.1  mrg * Interoperable Global Variables::
   2768      1.1  mrg * Interoperable Subroutines and Functions::
   2769  1.1.1.3  mrg * Working with C Pointers::
   2770      1.1  mrg * Further Interoperability of Fortran with C::
   2771      1.1  mrg @end menu
   2772      1.1  mrg 
   2773      1.1  mrg Since Fortran 2003 (ISO/IEC 1539-1:2004(E)) there is a
   2774      1.1  mrg standardized way to generate procedure and derived-type
   2775  1.1.1.3  mrg declarations and global variables that are interoperable with C
   2776  1.1.1.3  mrg (ISO/IEC 9899:1999).  The @code{BIND(C)} attribute has been added
   2777      1.1  mrg to inform the compiler that a symbol shall be interoperable with C;
   2778      1.1  mrg also, some constraints are added.  Note, however, that not
   2779      1.1  mrg all C features have a Fortran equivalent or vice versa.  For instance,
   2780      1.1  mrg neither C's unsigned integers nor C's functions with variable number
   2781      1.1  mrg of arguments have an equivalent in Fortran.
   2782      1.1  mrg 
   2783      1.1  mrg Note that array dimensions are reversely ordered in C and that arrays in
   2784      1.1  mrg C always start with index 0 while in Fortran they start by default with
   2785      1.1  mrg 1.  Thus, an array declaration @code{A(n,m)} in Fortran matches
   2786      1.1  mrg @code{A[m][n]} in C and accessing the element @code{A(i,j)} matches
   2787      1.1  mrg @code{A[j-1][i-1]}.  The element following @code{A(i,j)} (C: @code{A[j-1][i-1]};
   2788      1.1  mrg assuming @math{i < n}) in memory is @code{A(i+1,j)} (C: @code{A[j-1][i]}).
   2789      1.1  mrg 
   2790      1.1  mrg @node Intrinsic Types
   2791      1.1  mrg @subsection Intrinsic Types
   2792  1.1.1.3  mrg @cindex C intrinsic type interoperability
   2793  1.1.1.3  mrg @cindex intrinsic type interoperability with C
   2794  1.1.1.3  mrg @cindex interoperability, intrinsic type
   2795      1.1  mrg 
   2796      1.1  mrg In order to ensure that exactly the same variable type and kind is used
   2797  1.1.1.3  mrg in C and Fortran, you should use the named constants for kind parameters
   2798  1.1.1.3  mrg that are defined in the @code{ISO_C_BINDING} intrinsic module.
   2799  1.1.1.3  mrg That module contains named constants of character type representing
   2800  1.1.1.3  mrg the escaped special characters in C, such as newline.
   2801  1.1.1.3  mrg For a list of the constants, see @ref{ISO_C_BINDING}.
   2802      1.1  mrg 
   2803      1.1  mrg For logical types, please note that the Fortran standard only guarantees
   2804      1.1  mrg interoperability between C99's @code{_Bool} and Fortran's @code{C_Bool}-kind
   2805      1.1  mrg logicals and C99 defines that @code{true} has the value 1 and @code{false}
   2806      1.1  mrg the value 0.  Using any other integer value with GNU Fortran's @code{LOGICAL}
   2807      1.1  mrg (with any kind parameter) gives an undefined result.  (Passing other integer
   2808      1.1  mrg values than 0 and 1 to GCC's @code{_Bool} is also undefined, unless the
   2809      1.1  mrg integer is explicitly or implicitly casted to @code{_Bool}.)
   2810      1.1  mrg 
   2811      1.1  mrg @node Derived Types and struct
   2812      1.1  mrg @subsection Derived Types and struct
   2813  1.1.1.3  mrg @cindex C derived type and struct interoperability
   2814  1.1.1.3  mrg @cindex derived type interoperability with C
   2815  1.1.1.3  mrg @cindex interoperability, derived type and struct
   2816      1.1  mrg 
   2817  1.1.1.3  mrg For compatibility of derived types with @code{struct}, use
   2818      1.1  mrg the @code{BIND(C)} attribute in the type declaration.  For instance, the
   2819      1.1  mrg following type declaration
   2820      1.1  mrg 
   2821      1.1  mrg @smallexample
   2822      1.1  mrg  USE ISO_C_BINDING
   2823      1.1  mrg  TYPE, BIND(C) :: myType
   2824      1.1  mrg    INTEGER(C_INT) :: i1, i2
   2825      1.1  mrg    INTEGER(C_SIGNED_CHAR) :: i3
   2826      1.1  mrg    REAL(C_DOUBLE) :: d1
   2827      1.1  mrg    COMPLEX(C_FLOAT_COMPLEX) :: c1
   2828      1.1  mrg    CHARACTER(KIND=C_CHAR) :: str(5)
   2829      1.1  mrg  END TYPE
   2830      1.1  mrg @end smallexample
   2831      1.1  mrg 
   2832  1.1.1.3  mrg @noindent
   2833      1.1  mrg matches the following @code{struct} declaration in C
   2834      1.1  mrg 
   2835      1.1  mrg @smallexample
   2836      1.1  mrg  struct @{
   2837      1.1  mrg    int i1, i2;
   2838      1.1  mrg    /* Note: "char" might be signed or unsigned.  */
   2839      1.1  mrg    signed char i3;
   2840      1.1  mrg    double d1;
   2841      1.1  mrg    float _Complex c1;
   2842      1.1  mrg    char str[5];
   2843      1.1  mrg  @} myType;
   2844      1.1  mrg @end smallexample
   2845      1.1  mrg 
   2846      1.1  mrg Derived types with the C binding attribute shall not have the @code{sequence}
   2847      1.1  mrg attribute, type parameters, the @code{extends} attribute, nor type-bound
   2848      1.1  mrg procedures.  Every component must be of interoperable type and kind and may not
   2849      1.1  mrg have the @code{pointer} or @code{allocatable} attribute.  The names of the
   2850      1.1  mrg components are irrelevant for interoperability.
   2851      1.1  mrg 
   2852      1.1  mrg As there exist no direct Fortran equivalents, neither unions nor structs
   2853      1.1  mrg with bit field or variable-length array members are interoperable.
   2854      1.1  mrg 
   2855      1.1  mrg @node Interoperable Global Variables
   2856      1.1  mrg @subsection Interoperable Global Variables
   2857  1.1.1.3  mrg @cindex C variable interoperability
   2858  1.1.1.3  mrg @cindex variable interoperability with C
   2859  1.1.1.3  mrg @cindex interoperability, variable
   2860      1.1  mrg 
   2861      1.1  mrg Variables can be made accessible from C using the C binding attribute,
   2862      1.1  mrg optionally together with specifying a binding name.  Those variables
   2863      1.1  mrg have to be declared in the declaration part of a @code{MODULE},
   2864      1.1  mrg be of interoperable type, and have neither the @code{pointer} nor
   2865      1.1  mrg the @code{allocatable} attribute.
   2866      1.1  mrg 
   2867      1.1  mrg @smallexample
   2868      1.1  mrg   MODULE m
   2869      1.1  mrg     USE myType_module
   2870      1.1  mrg     USE ISO_C_BINDING
   2871      1.1  mrg     integer(C_INT), bind(C, name="_MyProject_flags") :: global_flag
   2872      1.1  mrg     type(myType), bind(C) :: tp
   2873      1.1  mrg   END MODULE
   2874      1.1  mrg @end smallexample
   2875      1.1  mrg 
   2876      1.1  mrg Here, @code{_MyProject_flags} is the case-sensitive name of the variable
   2877      1.1  mrg as seen from C programs while @code{global_flag} is the case-insensitive
   2878      1.1  mrg name as seen from Fortran.  If no binding name is specified, as for
   2879      1.1  mrg @var{tp}, the C binding name is the (lowercase) Fortran binding name.
   2880      1.1  mrg If a binding name is specified, only a single variable may be after the
   2881      1.1  mrg double colon.  Note of warning: You cannot use a global variable to
   2882      1.1  mrg access @var{errno} of the C library as the C standard allows it to be
   2883      1.1  mrg a macro.  Use the @code{IERRNO} intrinsic (GNU extension) instead.
   2884      1.1  mrg 
   2885      1.1  mrg @node Interoperable Subroutines and Functions
   2886      1.1  mrg @subsection Interoperable Subroutines and Functions
   2887  1.1.1.3  mrg @cindex C procedure interoperability
   2888  1.1.1.3  mrg @cindex procedure interoperability with C
   2889  1.1.1.3  mrg @cindex function interoperability with C
   2890  1.1.1.3  mrg @cindex subroutine interoperability with C
   2891  1.1.1.3  mrg @cindex interoperability, subroutine and function
   2892      1.1  mrg 
   2893      1.1  mrg Subroutines and functions have to have the @code{BIND(C)} attribute to
   2894      1.1  mrg be compatible with C.  The dummy argument declaration is relatively
   2895      1.1  mrg straightforward.  However, one needs to be careful because C uses
   2896      1.1  mrg call-by-value by default while Fortran behaves usually similar to
   2897      1.1  mrg call-by-reference.  Furthermore, strings and pointers are handled
   2898  1.1.1.3  mrg differently.
   2899      1.1  mrg 
   2900      1.1  mrg To pass a variable by value, use the @code{VALUE} attribute.
   2901      1.1  mrg Thus, the following C prototype
   2902      1.1  mrg 
   2903      1.1  mrg @smallexample
   2904      1.1  mrg @code{int func(int i, int *j)}
   2905      1.1  mrg @end smallexample
   2906      1.1  mrg 
   2907  1.1.1.3  mrg @noindent
   2908      1.1  mrg matches the Fortran declaration
   2909      1.1  mrg 
   2910      1.1  mrg @smallexample
   2911      1.1  mrg   integer(c_int) function func(i,j)
   2912      1.1  mrg     use iso_c_binding, only: c_int
   2913      1.1  mrg     integer(c_int), VALUE :: i
   2914      1.1  mrg     integer(c_int) :: j
   2915      1.1  mrg @end smallexample
   2916      1.1  mrg 
   2917      1.1  mrg Note that pointer arguments also frequently need the @code{VALUE} attribute,
   2918  1.1.1.3  mrg see @ref{Working with C Pointers}.
   2919      1.1  mrg 
   2920      1.1  mrg Strings are handled quite differently in C and Fortran.  In C a string
   2921      1.1  mrg is a @code{NUL}-terminated array of characters while in Fortran each string
   2922      1.1  mrg has a length associated with it and is thus not terminated (by e.g.
   2923  1.1.1.3  mrg @code{NUL}).  For example, if you want to use the following C function,
   2924      1.1  mrg 
   2925      1.1  mrg @smallexample
   2926      1.1  mrg   #include <stdio.h>
   2927      1.1  mrg   void print_C(char *string) /* equivalent: char string[]  */
   2928      1.1  mrg   @{
   2929      1.1  mrg      printf("%s\n", string);
   2930      1.1  mrg   @}
   2931      1.1  mrg @end smallexample
   2932      1.1  mrg 
   2933  1.1.1.3  mrg @noindent
   2934  1.1.1.3  mrg to print ``Hello World'' from Fortran, you can call it using
   2935      1.1  mrg 
   2936      1.1  mrg @smallexample
   2937      1.1  mrg   use iso_c_binding, only: C_CHAR, C_NULL_CHAR
   2938      1.1  mrg   interface
   2939      1.1  mrg     subroutine print_c(string) bind(C, name="print_C")
   2940      1.1  mrg       use iso_c_binding, only: c_char
   2941      1.1  mrg       character(kind=c_char) :: string(*)
   2942      1.1  mrg     end subroutine print_c
   2943      1.1  mrg   end interface
   2944      1.1  mrg   call print_c(C_CHAR_"Hello World"//C_NULL_CHAR)
   2945      1.1  mrg @end smallexample
   2946      1.1  mrg 
   2947  1.1.1.3  mrg As the example shows, you need to ensure that the
   2948      1.1  mrg string is @code{NUL} terminated.  Additionally, the dummy argument
   2949      1.1  mrg @var{string} of @code{print_C} is a length-one assumed-size
   2950      1.1  mrg array; using @code{character(len=*)} is not allowed.  The example
   2951      1.1  mrg above uses @code{c_char_"Hello World"} to ensure the string
   2952      1.1  mrg literal has the right type; typically the default character
   2953      1.1  mrg kind and @code{c_char} are the same and thus @code{"Hello World"}
   2954      1.1  mrg is equivalent.  However, the standard does not guarantee this.
   2955      1.1  mrg 
   2956      1.1  mrg The use of strings is now further illustrated using the C library
   2957      1.1  mrg function @code{strncpy}, whose prototype is
   2958      1.1  mrg 
   2959      1.1  mrg @smallexample
   2960      1.1  mrg   char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
   2961      1.1  mrg @end smallexample
   2962      1.1  mrg 
   2963  1.1.1.3  mrg @noindent
   2964      1.1  mrg The function @code{strncpy} copies at most @var{n} characters from
   2965      1.1  mrg string @var{s2} to @var{s1} and returns @var{s1}.  In the following
   2966      1.1  mrg example, we ignore the return value:
   2967      1.1  mrg 
   2968      1.1  mrg @smallexample
   2969      1.1  mrg   use iso_c_binding
   2970      1.1  mrg   implicit none
   2971      1.1  mrg   character(len=30) :: str,str2
   2972      1.1  mrg   interface
   2973      1.1  mrg     ! Ignore the return value of strncpy -> subroutine
   2974      1.1  mrg     ! "restrict" is always assumed if we do not pass a pointer
   2975      1.1  mrg     subroutine strncpy(dest, src, n) bind(C)
   2976      1.1  mrg       import
   2977      1.1  mrg       character(kind=c_char),  intent(out) :: dest(*)
   2978      1.1  mrg       character(kind=c_char),  intent(in)  :: src(*)
   2979      1.1  mrg       integer(c_size_t), value, intent(in) :: n
   2980      1.1  mrg     end subroutine strncpy
   2981      1.1  mrg   end interface
   2982      1.1  mrg   str = repeat('X',30) ! Initialize whole string with 'X'
   2983      1.1  mrg   call strncpy(str, c_char_"Hello World"//C_NULL_CHAR, &
   2984      1.1  mrg                len(c_char_"Hello World",kind=c_size_t))
   2985      1.1  mrg   print '(a)', str ! prints: "Hello WorldXXXXXXXXXXXXXXXXXXX"
   2986      1.1  mrg   end
   2987      1.1  mrg @end smallexample
   2988      1.1  mrg 
   2989      1.1  mrg The intrinsic procedures are described in @ref{Intrinsic Procedures}.
   2990      1.1  mrg 
   2991  1.1.1.3  mrg @node Working with C Pointers
   2992  1.1.1.3  mrg @subsection Working with C Pointers
   2993  1.1.1.3  mrg @cindex C pointers
   2994  1.1.1.3  mrg @cindex pointers, C
   2995  1.1.1.3  mrg 
   2996  1.1.1.3  mrg C pointers are represented in Fortran via the special opaque derived
   2997  1.1.1.3  mrg type @code{type(c_ptr)} (with private components).  C pointers are distinct
   2998  1.1.1.3  mrg from Fortran objects with the @code{POINTER} attribute.  Thus one needs to
   2999      1.1  mrg use intrinsic conversion procedures to convert from or to C pointers.
   3000  1.1.1.3  mrg For some applications, using an assumed type (@code{TYPE(*)}) can be
   3001  1.1.1.3  mrg an alternative to a C pointer, and you can also use library routines
   3002  1.1.1.3  mrg to access Fortran pointers from C.  See @ref{Further Interoperability
   3003  1.1.1.3  mrg of Fortran with C}.
   3004      1.1  mrg 
   3005  1.1.1.3  mrg Here is an example of using C pointers in Fortran:
   3006      1.1  mrg 
   3007      1.1  mrg @smallexample
   3008      1.1  mrg   use iso_c_binding
   3009      1.1  mrg   type(c_ptr) :: cptr1, cptr2
   3010      1.1  mrg   integer, target :: array(7), scalar
   3011      1.1  mrg   integer, pointer :: pa(:), ps
   3012      1.1  mrg   cptr1 = c_loc(array(1)) ! The programmer needs to ensure that the
   3013      1.1  mrg                           ! array is contiguous if required by the C
   3014      1.1  mrg                           ! procedure
   3015      1.1  mrg   cptr2 = c_loc(scalar)
   3016      1.1  mrg   call c_f_pointer(cptr2, ps)
   3017      1.1  mrg   call c_f_pointer(cptr2, pa, shape=[7])
   3018      1.1  mrg @end smallexample
   3019      1.1  mrg 
   3020      1.1  mrg When converting C to Fortran arrays, the one-dimensional @code{SHAPE} argument
   3021      1.1  mrg has to be passed.
   3022      1.1  mrg 
   3023  1.1.1.3  mrg If a pointer is a dummy argument of an interoperable procedure, it usually
   3024      1.1  mrg has to be declared using the @code{VALUE} attribute.  @code{void*}
   3025      1.1  mrg matches @code{TYPE(C_PTR), VALUE}, while @code{TYPE(C_PTR)} alone
   3026      1.1  mrg matches @code{void**}.
   3027      1.1  mrg 
   3028      1.1  mrg Procedure pointers are handled analogously to pointers; the C type is
   3029      1.1  mrg @code{TYPE(C_FUNPTR)} and the intrinsic conversion procedures are
   3030      1.1  mrg @code{C_F_PROCPOINTER} and @code{C_FUNLOC}.
   3031      1.1  mrg 
   3032      1.1  mrg Let us consider two examples of actually passing a procedure pointer from
   3033      1.1  mrg C to Fortran and vice versa.  Note that these examples are also very
   3034      1.1  mrg similar to passing ordinary pointers between both languages. First,
   3035      1.1  mrg consider this code in C:
   3036      1.1  mrg 
   3037      1.1  mrg @smallexample
   3038      1.1  mrg /* Procedure implemented in Fortran.  */
   3039      1.1  mrg void get_values (void (*)(double));
   3040      1.1  mrg 
   3041      1.1  mrg /* Call-back routine we want called from Fortran.  */
   3042      1.1  mrg void
   3043      1.1  mrg print_it (double x)
   3044      1.1  mrg @{
   3045      1.1  mrg   printf ("Number is %f.\n", x);
   3046      1.1  mrg @}
   3047      1.1  mrg 
   3048      1.1  mrg /* Call Fortran routine and pass call-back to it.  */
   3049      1.1  mrg void
   3050      1.1  mrg foobar ()
   3051      1.1  mrg @{
   3052      1.1  mrg   get_values (&print_it);
   3053      1.1  mrg @}
   3054      1.1  mrg @end smallexample
   3055      1.1  mrg 
   3056      1.1  mrg A matching implementation for @code{get_values} in Fortran, that correctly
   3057      1.1  mrg receives the procedure pointer from C and is able to call it, is given
   3058      1.1  mrg in the following @code{MODULE}:
   3059      1.1  mrg 
   3060      1.1  mrg @smallexample
   3061      1.1  mrg MODULE m
   3062      1.1  mrg   IMPLICIT NONE
   3063      1.1  mrg 
   3064      1.1  mrg   ! Define interface of call-back routine.
   3065      1.1  mrg   ABSTRACT INTERFACE
   3066      1.1  mrg     SUBROUTINE callback (x)
   3067      1.1  mrg       USE, INTRINSIC :: ISO_C_BINDING
   3068      1.1  mrg       REAL(KIND=C_DOUBLE), INTENT(IN), VALUE :: x
   3069      1.1  mrg     END SUBROUTINE callback
   3070      1.1  mrg   END INTERFACE
   3071      1.1  mrg 
   3072      1.1  mrg CONTAINS
   3073      1.1  mrg 
   3074      1.1  mrg   ! Define C-bound procedure.
   3075      1.1  mrg   SUBROUTINE get_values (cproc) BIND(C)
   3076      1.1  mrg     USE, INTRINSIC :: ISO_C_BINDING
   3077      1.1  mrg     TYPE(C_FUNPTR), INTENT(IN), VALUE :: cproc
   3078      1.1  mrg 
   3079      1.1  mrg     PROCEDURE(callback), POINTER :: proc
   3080      1.1  mrg 
   3081      1.1  mrg     ! Convert C to Fortran procedure pointer.
   3082      1.1  mrg     CALL C_F_PROCPOINTER (cproc, proc)
   3083      1.1  mrg 
   3084      1.1  mrg     ! Call it.
   3085      1.1  mrg     CALL proc (1.0_C_DOUBLE)
   3086      1.1  mrg     CALL proc (-42.0_C_DOUBLE)
   3087      1.1  mrg     CALL proc (18.12_C_DOUBLE)
   3088      1.1  mrg   END SUBROUTINE get_values
   3089      1.1  mrg 
   3090      1.1  mrg END MODULE m
   3091      1.1  mrg @end smallexample
   3092      1.1  mrg 
   3093      1.1  mrg Next, we want to call a C routine that expects a procedure pointer argument
   3094      1.1  mrg and pass it a Fortran procedure (which clearly must be interoperable!).
   3095      1.1  mrg Again, the C function may be:
   3096      1.1  mrg 
   3097      1.1  mrg @smallexample
   3098      1.1  mrg int
   3099      1.1  mrg call_it (int (*func)(int), int arg)
   3100      1.1  mrg @{
   3101      1.1  mrg   return func (arg);
   3102      1.1  mrg @}
   3103      1.1  mrg @end smallexample
   3104      1.1  mrg 
   3105      1.1  mrg It can be used as in the following Fortran code:
   3106      1.1  mrg 
   3107      1.1  mrg @smallexample
   3108      1.1  mrg MODULE m
   3109      1.1  mrg   USE, INTRINSIC :: ISO_C_BINDING
   3110      1.1  mrg   IMPLICIT NONE
   3111      1.1  mrg 
   3112      1.1  mrg   ! Define interface of C function.
   3113      1.1  mrg   INTERFACE
   3114      1.1  mrg     INTEGER(KIND=C_INT) FUNCTION call_it (func, arg) BIND(C)
   3115      1.1  mrg       USE, INTRINSIC :: ISO_C_BINDING
   3116      1.1  mrg       TYPE(C_FUNPTR), INTENT(IN), VALUE :: func
   3117      1.1  mrg       INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
   3118      1.1  mrg     END FUNCTION call_it
   3119      1.1  mrg   END INTERFACE
   3120      1.1  mrg 
   3121      1.1  mrg CONTAINS
   3122      1.1  mrg 
   3123      1.1  mrg   ! Define procedure passed to C function.
   3124      1.1  mrg   ! It must be interoperable!
   3125      1.1  mrg   INTEGER(KIND=C_INT) FUNCTION double_it (arg) BIND(C)
   3126      1.1  mrg     INTEGER(KIND=C_INT), INTENT(IN), VALUE :: arg
   3127      1.1  mrg     double_it = arg + arg
   3128      1.1  mrg   END FUNCTION double_it
   3129      1.1  mrg 
   3130      1.1  mrg   ! Call C function.
   3131      1.1  mrg   SUBROUTINE foobar ()
   3132      1.1  mrg     TYPE(C_FUNPTR) :: cproc
   3133      1.1  mrg     INTEGER(KIND=C_INT) :: i
   3134      1.1  mrg 
   3135      1.1  mrg     ! Get C procedure pointer.
   3136      1.1  mrg     cproc = C_FUNLOC (double_it)
   3137      1.1  mrg 
   3138      1.1  mrg     ! Use it.
   3139      1.1  mrg     DO i = 1_C_INT, 10_C_INT
   3140      1.1  mrg       PRINT *, call_it (cproc, i)
   3141      1.1  mrg     END DO
   3142      1.1  mrg   END SUBROUTINE foobar
   3143      1.1  mrg 
   3144      1.1  mrg END MODULE m
   3145      1.1  mrg @end smallexample
   3146      1.1  mrg 
   3147      1.1  mrg @node Further Interoperability of Fortran with C
   3148      1.1  mrg @subsection Further Interoperability of Fortran with C
   3149  1.1.1.3  mrg @cindex Further Interoperability of Fortran with C
   3150  1.1.1.3  mrg @cindex TS 29113
   3151  1.1.1.3  mrg @cindex array descriptor
   3152  1.1.1.3  mrg @cindex dope vector
   3153  1.1.1.3  mrg @cindex assumed-type
   3154  1.1.1.3  mrg @cindex assumed-rank
   3155  1.1.1.3  mrg 
   3156  1.1.1.3  mrg GNU Fortran implements the Technical Specification ISO/IEC TS
   3157  1.1.1.3  mrg 29113:2012, which extends the interoperability support of Fortran 2003
   3158  1.1.1.3  mrg and Fortran 2008 and is now part of the 2018 Fortran standard.
   3159  1.1.1.3  mrg Besides removing some restrictions and constraints, the Technical
   3160  1.1.1.3  mrg Specification adds assumed-type (@code{TYPE(*)}) and assumed-rank
   3161  1.1.1.3  mrg (@code{DIMENSION(..)}) variables and allows for interoperability of
   3162  1.1.1.3  mrg assumed-shape, assumed-rank, and deferred-shape arrays, as well as
   3163  1.1.1.3  mrg allocatables and pointers.  Objects of these types are passed to
   3164  1.1.1.3  mrg @code{BIND(C)} functions as descriptors with a standard interface,
   3165  1.1.1.3  mrg declared in the header file @code{<ISO_Fortran_binding.h>}.
   3166      1.1  mrg 
   3167      1.1  mrg Note: Currently, GNU Fortran does not use internally the array descriptor
   3168      1.1  mrg (dope vector) as specified in the Technical Specification, but uses
   3169  1.1.1.3  mrg an array descriptor with different fields in functions without the
   3170  1.1.1.3  mrg @code{BIND(C)} attribute.  Arguments to functions marked @code{BIND(C)}
   3171  1.1.1.3  mrg are converted to the specified form.  If you need to access GNU Fortran's
   3172  1.1.1.3  mrg internal array descriptor, you can use the Chasm Language Interoperability
   3173  1.1.1.3  mrg Tools, @url{http://chasm-interop.sourceforge.net/}.
   3174      1.1  mrg 
   3175      1.1  mrg @node GNU Fortran Compiler Directives
   3176      1.1  mrg @section GNU Fortran Compiler Directives
   3177      1.1  mrg 
   3178      1.1  mrg @menu
   3179      1.1  mrg * ATTRIBUTES directive::
   3180      1.1  mrg * UNROLL directive::
   3181      1.1  mrg * BUILTIN directive::
   3182      1.1  mrg * IVDEP directive::
   3183      1.1  mrg * VECTOR directive::
   3184      1.1  mrg * NOVECTOR directive::
   3185      1.1  mrg @end menu
   3186      1.1  mrg 
   3187      1.1  mrg @node ATTRIBUTES directive
   3188      1.1  mrg @subsection ATTRIBUTES directive
   3189      1.1  mrg 
   3190      1.1  mrg The Fortran standard describes how a conforming program shall
   3191      1.1  mrg behave; however, the exact implementation is not standardized.  In order
   3192      1.1  mrg to allow the user to choose specific implementation details, compiler
   3193      1.1  mrg directives can be used to set attributes of variables and procedures
   3194      1.1  mrg which are not part of the standard.  Whether a given attribute is
   3195      1.1  mrg supported and its exact effects depend on both the operating system and
   3196      1.1  mrg on the processor; see
   3197      1.1  mrg @ref{Top,,C Extensions,gcc,Using the GNU Compiler Collection (GCC)}
   3198      1.1  mrg for details.
   3199      1.1  mrg 
   3200      1.1  mrg For procedures and procedure pointers, the following attributes can
   3201      1.1  mrg be used to change the calling convention:
   3202      1.1  mrg 
   3203      1.1  mrg @itemize
   3204      1.1  mrg @item @code{CDECL} -- standard C calling convention
   3205      1.1  mrg @item @code{STDCALL} -- convention where the called procedure pops the stack
   3206      1.1  mrg @item @code{FASTCALL} -- part of the arguments are passed via registers
   3207      1.1  mrg instead using the stack
   3208      1.1  mrg @end itemize
   3209      1.1  mrg 
   3210      1.1  mrg Besides changing the calling convention, the attributes also influence
   3211      1.1  mrg the decoration of the symbol name, e.g., by a leading underscore or by
   3212      1.1  mrg a trailing at-sign followed by the number of bytes on the stack.  When
   3213      1.1  mrg assigning a procedure to a procedure pointer, both should use the same
   3214      1.1  mrg calling convention.
   3215      1.1  mrg 
   3216      1.1  mrg On some systems, procedures and global variables (module variables and
   3217      1.1  mrg @code{COMMON} blocks) need special handling to be accessible when they
   3218      1.1  mrg are in a shared library.  The following attributes are available:
   3219      1.1  mrg 
   3220      1.1  mrg @itemize
   3221      1.1  mrg @item @code{DLLEXPORT} -- provide a global pointer to a pointer in the DLL
   3222      1.1  mrg @item @code{DLLIMPORT} -- reference the function or variable using a
   3223      1.1  mrg global pointer
   3224      1.1  mrg @end itemize
   3225      1.1  mrg 
   3226      1.1  mrg For dummy arguments, the @code{NO_ARG_CHECK} attribute can be used; in
   3227      1.1  mrg other compilers, it is also known as @code{IGNORE_TKR}.  For dummy arguments
   3228      1.1  mrg with this attribute actual arguments of any type and kind (similar to
   3229      1.1  mrg @code{TYPE(*)}), scalars and arrays of any rank (no equivalent
   3230      1.1  mrg in Fortran standard) are accepted.  As with @code{TYPE(*)}, the argument
   3231      1.1  mrg is unlimited polymorphic and no type information is available.
   3232      1.1  mrg Additionally, the argument may only be passed to dummy arguments
   3233      1.1  mrg with the @code{NO_ARG_CHECK} attribute and as argument to the
   3234      1.1  mrg @code{PRESENT} intrinsic function and to @code{C_LOC} of the
   3235      1.1  mrg @code{ISO_C_BINDING} module.
   3236      1.1  mrg 
   3237      1.1  mrg Variables with @code{NO_ARG_CHECK} attribute shall be of assumed-type
   3238      1.1  mrg (@code{TYPE(*)}; recommended) or of type @code{INTEGER}, @code{LOGICAL},
   3239      1.1  mrg @code{REAL} or @code{COMPLEX}. They shall not have the @code{ALLOCATE},
   3240      1.1  mrg @code{CODIMENSION}, @code{INTENT(OUT)}, @code{POINTER} or @code{VALUE}
   3241      1.1  mrg attribute; furthermore, they shall be either scalar or of assumed-size
   3242      1.1  mrg (@code{dimension(*)}). As @code{TYPE(*)}, the @code{NO_ARG_CHECK} attribute
   3243      1.1  mrg requires an explicit interface.
   3244      1.1  mrg 
   3245      1.1  mrg @itemize
   3246      1.1  mrg @item @code{NO_ARG_CHECK} -- disable the type, kind and rank checking
   3247  1.1.1.3  mrg @item @code{DEPRECATED} -- print a warning when using a such-tagged
   3248  1.1.1.3  mrg deprecated procedure, variable or parameter; the warning can be suppressed
   3249  1.1.1.3  mrg with @option{-Wno-deprecated-declarations}.
   3250      1.1  mrg @end itemize
   3251      1.1  mrg 
   3252      1.1  mrg 
   3253      1.1  mrg The attributes are specified using the syntax
   3254      1.1  mrg 
   3255      1.1  mrg @code{!GCC$ ATTRIBUTES} @var{attribute-list} @code{::} @var{variable-list}
   3256      1.1  mrg 
   3257      1.1  mrg where in free-form source code only whitespace is allowed before @code{!GCC$}
   3258      1.1  mrg and in fixed-form source code @code{!GCC$}, @code{cGCC$} or @code{*GCC$} shall
   3259      1.1  mrg start in the first column.
   3260      1.1  mrg 
   3261      1.1  mrg For procedures, the compiler directives shall be placed into the body
   3262      1.1  mrg of the procedure; for variables and procedure pointers, they shall be in
   3263      1.1  mrg the same declaration part as the variable or procedure pointer.
   3264      1.1  mrg 
   3265      1.1  mrg 
   3266      1.1  mrg @node UNROLL directive
   3267      1.1  mrg @subsection UNROLL directive
   3268      1.1  mrg 
   3269      1.1  mrg The syntax of the directive is
   3270      1.1  mrg 
   3271      1.1  mrg @code{!GCC$ unroll N}
   3272      1.1  mrg 
   3273      1.1  mrg You can use this directive to control how many times a loop should be unrolled.
   3274      1.1  mrg It must be placed immediately before a @code{DO} loop and applies only to the
   3275      1.1  mrg loop that follows.  N is an integer constant specifying the unrolling factor.
   3276      1.1  mrg The values of 0 and 1 block any unrolling of the loop.
   3277      1.1  mrg 
   3278      1.1  mrg 
   3279      1.1  mrg @node BUILTIN directive
   3280      1.1  mrg @subsection BUILTIN directive
   3281      1.1  mrg 
   3282      1.1  mrg The syntax of the directive is
   3283      1.1  mrg 
   3284      1.1  mrg @code{!GCC$ BUILTIN (B) attributes simd FLAGS IF('target')}
   3285      1.1  mrg 
   3286      1.1  mrg You can use this directive to define which middle-end built-ins provide vector
   3287      1.1  mrg implementations.  @code{B} is name of the middle-end built-in.  @code{FLAGS}
   3288      1.1  mrg are optional and must be either "(inbranch)" or "(notinbranch)".
   3289      1.1  mrg @code{IF} statement is optional and is used to filter multilib ABIs
   3290      1.1  mrg for the built-in that should be vectorized.  Example usage:
   3291      1.1  mrg 
   3292      1.1  mrg @smallexample
   3293      1.1  mrg !GCC$ builtin (sinf) attributes simd (notinbranch) if('x86_64')
   3294      1.1  mrg @end smallexample
   3295      1.1  mrg 
   3296      1.1  mrg The purpose of the directive is to provide an API among the GCC compiler and
   3297      1.1  mrg the GNU C Library which would define vector implementations of math routines.
   3298      1.1  mrg 
   3299      1.1  mrg 
   3300      1.1  mrg @node IVDEP directive
   3301      1.1  mrg @subsection IVDEP directive
   3302      1.1  mrg 
   3303      1.1  mrg The syntax of the directive is
   3304      1.1  mrg 
   3305      1.1  mrg @code{!GCC$ ivdep}
   3306      1.1  mrg 
   3307      1.1  mrg This directive tells the compiler to ignore vector dependencies in the
   3308      1.1  mrg following loop.  It must be placed immediately before a @code{DO} loop
   3309      1.1  mrg and applies only to the loop that follows.
   3310      1.1  mrg 
   3311      1.1  mrg Sometimes the compiler may not have sufficient information to decide
   3312      1.1  mrg whether a particular loop is vectorizable due to potential
   3313      1.1  mrg dependencies between iterations.  The purpose of the directive is to
   3314      1.1  mrg tell the compiler that vectorization is safe.
   3315      1.1  mrg 
   3316      1.1  mrg This directive is intended for annotation of existing code.  For new
   3317      1.1  mrg code it is recommended to consider OpenMP SIMD directives as potential
   3318      1.1  mrg alternative.
   3319      1.1  mrg 
   3320      1.1  mrg 
   3321      1.1  mrg @node VECTOR directive
   3322      1.1  mrg @subsection VECTOR directive
   3323      1.1  mrg 
   3324      1.1  mrg The syntax of the directive is
   3325      1.1  mrg 
   3326      1.1  mrg @code{!GCC$ vector}
   3327      1.1  mrg 
   3328      1.1  mrg This directive tells the compiler to vectorize the following loop.  It
   3329      1.1  mrg must be placed immediately before a @code{DO} loop and applies only to
   3330      1.1  mrg the loop that follows.
   3331      1.1  mrg 
   3332      1.1  mrg 
   3333      1.1  mrg @node NOVECTOR directive
   3334      1.1  mrg @subsection NOVECTOR directive
   3335      1.1  mrg 
   3336      1.1  mrg The syntax of the directive is
   3337      1.1  mrg 
   3338      1.1  mrg @code{!GCC$ novector}
   3339      1.1  mrg 
   3340      1.1  mrg This directive tells the compiler to not vectorize the following loop.
   3341      1.1  mrg It must be placed immediately before a @code{DO} loop and applies only
   3342      1.1  mrg to the loop that follows.
   3343      1.1  mrg 
   3344      1.1  mrg 
   3345      1.1  mrg @node Non-Fortran Main Program
   3346      1.1  mrg @section Non-Fortran Main Program
   3347      1.1  mrg 
   3348      1.1  mrg @menu
   3349      1.1  mrg * _gfortran_set_args:: Save command-line arguments
   3350      1.1  mrg * _gfortran_set_options:: Set library option flags
   3351      1.1  mrg * _gfortran_set_convert:: Set endian conversion
   3352      1.1  mrg * _gfortran_set_record_marker:: Set length of record markers
   3353      1.1  mrg * _gfortran_set_fpe:: Set when a Floating Point Exception should be raised
   3354      1.1  mrg * _gfortran_set_max_subrecord_length:: Set subrecord length
   3355      1.1  mrg @end menu
   3356      1.1  mrg 
   3357      1.1  mrg Even if you are doing mixed-language programming, it is very
   3358      1.1  mrg likely that you do not need to know or use the information in this
   3359      1.1  mrg section.  Since it is about the internal structure of GNU Fortran,
   3360      1.1  mrg it may also change in GCC minor releases.
   3361      1.1  mrg 
   3362      1.1  mrg When you compile a @code{PROGRAM} with GNU Fortran, a function
   3363      1.1  mrg with the name @code{main} (in the symbol table of the object file)
   3364      1.1  mrg is generated, which initializes the libgfortran library and then
   3365      1.1  mrg calls the actual program which uses the name @code{MAIN__}, for
   3366      1.1  mrg historic reasons.  If you link GNU Fortran compiled procedures
   3367      1.1  mrg to, e.g., a C or C++ program or to a Fortran program compiled by
   3368      1.1  mrg a different compiler, the libgfortran library is not initialized
   3369      1.1  mrg and thus a few intrinsic procedures do not work properly, e.g.
   3370      1.1  mrg those for obtaining the command-line arguments.
   3371      1.1  mrg 
   3372      1.1  mrg Therefore, if your @code{PROGRAM} is not compiled with
   3373      1.1  mrg GNU Fortran and the GNU Fortran compiled procedures require
   3374      1.1  mrg intrinsics relying on the library initialization, you need to
   3375      1.1  mrg initialize the library yourself.  Using the default options,
   3376      1.1  mrg gfortran calls @code{_gfortran_set_args} and
   3377      1.1  mrg @code{_gfortran_set_options}.  The initialization of the former
   3378      1.1  mrg is needed if the called procedures access the command line
   3379      1.1  mrg (and for backtracing); the latter sets some flags based on the
   3380      1.1  mrg standard chosen or to enable backtracing.  In typical programs,
   3381      1.1  mrg it is not necessary to call any initialization function.
   3382      1.1  mrg 
   3383      1.1  mrg If your @code{PROGRAM} is compiled with GNU Fortran, you shall
   3384      1.1  mrg not call any of the following functions.  The libgfortran
   3385      1.1  mrg initialization functions are shown in C syntax but using C
   3386      1.1  mrg bindings they are also accessible from Fortran.
   3387      1.1  mrg 
   3388      1.1  mrg 
   3389      1.1  mrg @node _gfortran_set_args
   3390      1.1  mrg @subsection @code{_gfortran_set_args} --- Save command-line arguments
   3391      1.1  mrg @fnindex _gfortran_set_args
   3392      1.1  mrg @cindex libgfortran initialization, set_args
   3393      1.1  mrg 
   3394      1.1  mrg @table @asis
   3395      1.1  mrg @item @emph{Description}:
   3396      1.1  mrg @code{_gfortran_set_args} saves the command-line arguments; this
   3397      1.1  mrg initialization is required if any of the command-line intrinsics
   3398      1.1  mrg is called.  Additionally, it shall be called if backtracing is
   3399      1.1  mrg enabled (see @code{_gfortran_set_options}).
   3400      1.1  mrg 
   3401      1.1  mrg @item @emph{Syntax}:
   3402      1.1  mrg @code{void _gfortran_set_args (int argc, char *argv[])}
   3403      1.1  mrg 
   3404      1.1  mrg @item @emph{Arguments}:
   3405      1.1  mrg @multitable @columnfractions .15 .70
   3406      1.1  mrg @item @var{argc} @tab number of command line argument strings
   3407      1.1  mrg @item @var{argv} @tab the command-line argument strings; argv[0]
   3408      1.1  mrg is the pathname of the executable itself.
   3409      1.1  mrg @end multitable
   3410      1.1  mrg 
   3411      1.1  mrg @item @emph{Example}:
   3412      1.1  mrg @smallexample
   3413      1.1  mrg int main (int argc, char *argv[])
   3414      1.1  mrg @{
   3415      1.1  mrg   /* Initialize libgfortran.  */
   3416      1.1  mrg   _gfortran_set_args (argc, argv);
   3417      1.1  mrg   return 0;
   3418      1.1  mrg @}
   3419      1.1  mrg @end smallexample
   3420      1.1  mrg @end table
   3421      1.1  mrg 
   3422      1.1  mrg 
   3423      1.1  mrg @node _gfortran_set_options
   3424      1.1  mrg @subsection @code{_gfortran_set_options} --- Set library option flags
   3425      1.1  mrg @fnindex _gfortran_set_options
   3426      1.1  mrg @cindex libgfortran initialization, set_options
   3427      1.1  mrg 
   3428      1.1  mrg @table @asis
   3429      1.1  mrg @item @emph{Description}:
   3430      1.1  mrg @code{_gfortran_set_options} sets several flags related to the Fortran
   3431      1.1  mrg standard to be used, whether backtracing should be enabled
   3432      1.1  mrg and whether range checks should be performed.  The syntax allows for
   3433      1.1  mrg upward compatibility since the number of passed flags is specified; for
   3434      1.1  mrg non-passed flags, the default value is used.  See also
   3435      1.1  mrg @pxref{Code Gen Options}.  Please note that not all flags are actually
   3436      1.1  mrg used.
   3437      1.1  mrg 
   3438      1.1  mrg @item @emph{Syntax}:
   3439      1.1  mrg @code{void _gfortran_set_options (int num, int options[])}
   3440      1.1  mrg 
   3441      1.1  mrg @item @emph{Arguments}:
   3442      1.1  mrg @multitable @columnfractions .15 .70
   3443      1.1  mrg @item @var{num} @tab number of options passed
   3444      1.1  mrg @item @var{argv} @tab The list of flag values
   3445      1.1  mrg @end multitable
   3446      1.1  mrg 
   3447      1.1  mrg @item @emph{option flag list}:
   3448      1.1  mrg @multitable @columnfractions .15 .70
   3449      1.1  mrg @item @var{option}[0] @tab Allowed standard; can give run-time errors
   3450      1.1  mrg if e.g. an input-output edit descriptor is invalid in a given
   3451      1.1  mrg standard.  Possible values are (bitwise or-ed) @code{GFC_STD_F77} (1),
   3452      1.1  mrg @code{GFC_STD_F95_OBS} (2), @code{GFC_STD_F95_DEL} (4),
   3453      1.1  mrg @code{GFC_STD_F95} (8), @code{GFC_STD_F2003} (16), @code{GFC_STD_GNU}
   3454      1.1  mrg (32), @code{GFC_STD_LEGACY} (64), @code{GFC_STD_F2008} (128),
   3455      1.1  mrg @code{GFC_STD_F2008_OBS} (256), @code{GFC_STD_F2008_TS} (512),
   3456      1.1  mrg @code{GFC_STD_F2018} (1024), @code{GFC_STD_F2018_OBS} (2048), and
   3457      1.1  mrg @code{GFC_STD=F2018_DEL} (4096). Default: @code{GFC_STD_F95_OBS |
   3458      1.1  mrg GFC_STD_F95_DEL | GFC_STD_F95 | GFC_STD_F2003 | GFC_STD_F2008 |
   3459      1.1  mrg GFC_STD_F2008_TS | GFC_STD_F2008_OBS | GFC_STD_F77 | GFC_STD_F2018 |
   3460      1.1  mrg GFC_STD_F2018_OBS | GFC_STD_F2018_DEL | GFC_STD_GNU | GFC_STD_LEGACY}.
   3461      1.1  mrg @item @var{option}[1] @tab Standard-warning flag; prints a warning to
   3462      1.1  mrg standard error.  Default: @code{GFC_STD_F95_DEL | GFC_STD_LEGACY}.
   3463      1.1  mrg @item @var{option}[2] @tab If non zero, enable pedantic checking.
   3464      1.1  mrg Default: off.
   3465      1.1  mrg @item @var{option}[3] @tab Unused.
   3466      1.1  mrg @item @var{option}[4] @tab If non zero, enable backtracing on run-time
   3467      1.1  mrg errors.  Default: off. (Default in the compiler: on.)
   3468      1.1  mrg Note: Installs a signal handler and requires command-line
   3469      1.1  mrg initialization using @code{_gfortran_set_args}.
   3470      1.1  mrg @item @var{option}[5] @tab If non zero, supports signed zeros.
   3471      1.1  mrg Default: enabled.
   3472      1.1  mrg @item @var{option}[6] @tab Enables run-time checking.  Possible values
   3473      1.1  mrg are (bitwise or-ed): GFC_RTCHECK_BOUNDS (1), GFC_RTCHECK_ARRAY_TEMPS (2),
   3474  1.1.1.3  mrg GFC_RTCHECK_RECURSION (4), GFC_RTCHECK_DO (8), GFC_RTCHECK_POINTER (16),
   3475  1.1.1.3  mrg GFC_RTCHECK_MEM (32), GFC_RTCHECK_BITS (64).
   3476      1.1  mrg Default: disabled.
   3477      1.1  mrg @item @var{option}[7] @tab Unused.
   3478      1.1  mrg @item @var{option}[8] @tab Show a warning when invoking @code{STOP} and
   3479      1.1  mrg @code{ERROR STOP} if a floating-point exception occurred. Possible values
   3480      1.1  mrg are (bitwise or-ed) @code{GFC_FPE_INVALID} (1), @code{GFC_FPE_DENORMAL} (2),
   3481      1.1  mrg @code{GFC_FPE_ZERO} (4), @code{GFC_FPE_OVERFLOW} (8),
   3482      1.1  mrg @code{GFC_FPE_UNDERFLOW} (16), @code{GFC_FPE_INEXACT} (32). Default: None (0).
   3483      1.1  mrg (Default in the compiler: @code{GFC_FPE_INVALID | GFC_FPE_DENORMAL |
   3484      1.1  mrg GFC_FPE_ZERO | GFC_FPE_OVERFLOW | GFC_FPE_UNDERFLOW}.)
   3485      1.1  mrg @end multitable
   3486      1.1  mrg 
   3487      1.1  mrg @item @emph{Example}:
   3488      1.1  mrg @smallexample
   3489      1.1  mrg   /* Use gfortran 4.9 default options.  */
   3490      1.1  mrg   static int options[] = @{68, 511, 0, 0, 1, 1, 0, 0, 31@};
   3491      1.1  mrg   _gfortran_set_options (9, &options);
   3492      1.1  mrg @end smallexample
   3493      1.1  mrg @end table
   3494      1.1  mrg 
   3495      1.1  mrg 
   3496      1.1  mrg @node _gfortran_set_convert
   3497      1.1  mrg @subsection @code{_gfortran_set_convert} --- Set endian conversion
   3498      1.1  mrg @fnindex _gfortran_set_convert
   3499      1.1  mrg @cindex libgfortran initialization, set_convert
   3500      1.1  mrg 
   3501      1.1  mrg @table @asis
   3502      1.1  mrg @item @emph{Description}:
   3503      1.1  mrg @code{_gfortran_set_convert} set the representation of data for
   3504      1.1  mrg unformatted files.
   3505      1.1  mrg 
   3506      1.1  mrg @item @emph{Syntax}:
   3507      1.1  mrg @code{void _gfortran_set_convert (int conv)}
   3508      1.1  mrg 
   3509      1.1  mrg @item @emph{Arguments}:
   3510      1.1  mrg @multitable @columnfractions .15 .70
   3511      1.1  mrg @item @var{conv} @tab Endian conversion, possible values:
   3512      1.1  mrg GFC_CONVERT_NATIVE (0, default), GFC_CONVERT_SWAP (1),
   3513      1.1  mrg GFC_CONVERT_BIG (2), GFC_CONVERT_LITTLE (3).
   3514      1.1  mrg @end multitable
   3515      1.1  mrg 
   3516      1.1  mrg @item @emph{Example}:
   3517      1.1  mrg @smallexample
   3518      1.1  mrg int main (int argc, char *argv[])
   3519      1.1  mrg @{
   3520      1.1  mrg   /* Initialize libgfortran.  */
   3521      1.1  mrg   _gfortran_set_args (argc, argv);
   3522      1.1  mrg   _gfortran_set_convert (1);
   3523      1.1  mrg   return 0;
   3524      1.1  mrg @}
   3525      1.1  mrg @end smallexample
   3526      1.1  mrg @end table
   3527      1.1  mrg 
   3528      1.1  mrg 
   3529      1.1  mrg @node _gfortran_set_record_marker
   3530      1.1  mrg @subsection @code{_gfortran_set_record_marker} --- Set length of record markers
   3531      1.1  mrg @fnindex _gfortran_set_record_marker
   3532      1.1  mrg @cindex libgfortran initialization, set_record_marker
   3533      1.1  mrg 
   3534      1.1  mrg @table @asis
   3535      1.1  mrg @item @emph{Description}:
   3536      1.1  mrg @code{_gfortran_set_record_marker} sets the length of record markers
   3537      1.1  mrg for unformatted files.
   3538      1.1  mrg 
   3539      1.1  mrg @item @emph{Syntax}:
   3540      1.1  mrg @code{void _gfortran_set_record_marker (int val)}
   3541      1.1  mrg 
   3542      1.1  mrg @item @emph{Arguments}:
   3543      1.1  mrg @multitable @columnfractions .15 .70
   3544      1.1  mrg @item @var{val} @tab Length of the record marker; valid values
   3545      1.1  mrg are 4 and 8.  Default is 4.
   3546      1.1  mrg @end multitable
   3547      1.1  mrg 
   3548      1.1  mrg @item @emph{Example}:
   3549      1.1  mrg @smallexample
   3550      1.1  mrg int main (int argc, char *argv[])
   3551      1.1  mrg @{
   3552      1.1  mrg   /* Initialize libgfortran.  */
   3553      1.1  mrg   _gfortran_set_args (argc, argv);
   3554      1.1  mrg   _gfortran_set_record_marker (8);
   3555      1.1  mrg   return 0;
   3556      1.1  mrg @}
   3557      1.1  mrg @end smallexample
   3558      1.1  mrg @end table
   3559      1.1  mrg 
   3560      1.1  mrg 
   3561      1.1  mrg @node _gfortran_set_fpe
   3562      1.1  mrg @subsection @code{_gfortran_set_fpe} --- Enable floating point exception traps
   3563      1.1  mrg @fnindex _gfortran_set_fpe
   3564      1.1  mrg @cindex libgfortran initialization, set_fpe
   3565      1.1  mrg 
   3566      1.1  mrg @table @asis
   3567      1.1  mrg @item @emph{Description}:
   3568      1.1  mrg @code{_gfortran_set_fpe} enables floating point exception traps for
   3569      1.1  mrg the specified exceptions.  On most systems, this will result in a
   3570      1.1  mrg SIGFPE signal being sent and the program being aborted.
   3571      1.1  mrg 
   3572      1.1  mrg @item @emph{Syntax}:
   3573      1.1  mrg @code{void _gfortran_set_fpe (int val)}
   3574      1.1  mrg 
   3575      1.1  mrg @item @emph{Arguments}:
   3576      1.1  mrg @multitable @columnfractions .15 .70
   3577      1.1  mrg @item @var{option}[0] @tab IEEE exceptions.  Possible values are
   3578      1.1  mrg (bitwise or-ed) zero (0, default) no trapping,
   3579      1.1  mrg @code{GFC_FPE_INVALID} (1), @code{GFC_FPE_DENORMAL} (2),
   3580      1.1  mrg @code{GFC_FPE_ZERO} (4), @code{GFC_FPE_OVERFLOW} (8),
   3581      1.1  mrg @code{GFC_FPE_UNDERFLOW} (16), and @code{GFC_FPE_INEXACT} (32).
   3582      1.1  mrg @end multitable
   3583      1.1  mrg 
   3584      1.1  mrg @item @emph{Example}:
   3585      1.1  mrg @smallexample
   3586      1.1  mrg int main (int argc, char *argv[])
   3587      1.1  mrg @{
   3588      1.1  mrg   /* Initialize libgfortran.  */
   3589      1.1  mrg   _gfortran_set_args (argc, argv);
   3590      1.1  mrg   /* FPE for invalid operations such as SQRT(-1.0).  */
   3591      1.1  mrg   _gfortran_set_fpe (1);
   3592      1.1  mrg   return 0;
   3593      1.1  mrg @}
   3594      1.1  mrg @end smallexample
   3595      1.1  mrg @end table
   3596      1.1  mrg 
   3597      1.1  mrg 
   3598      1.1  mrg @node _gfortran_set_max_subrecord_length
   3599      1.1  mrg @subsection @code{_gfortran_set_max_subrecord_length} --- Set subrecord length
   3600      1.1  mrg @fnindex _gfortran_set_max_subrecord_length
   3601      1.1  mrg @cindex libgfortran initialization, set_max_subrecord_length
   3602      1.1  mrg 
   3603      1.1  mrg @table @asis
   3604      1.1  mrg @item @emph{Description}:
   3605      1.1  mrg @code{_gfortran_set_max_subrecord_length} set the maximum length
   3606      1.1  mrg for a subrecord.  This option only makes sense for testing and
   3607      1.1  mrg debugging of unformatted I/O.
   3608      1.1  mrg 
   3609      1.1  mrg @item @emph{Syntax}:
   3610      1.1  mrg @code{void _gfortran_set_max_subrecord_length (int val)}
   3611      1.1  mrg 
   3612      1.1  mrg @item @emph{Arguments}:
   3613      1.1  mrg @multitable @columnfractions .15 .70
   3614      1.1  mrg @item @var{val} @tab the maximum length for a subrecord;
   3615      1.1  mrg the maximum permitted value is 2147483639, which is also
   3616      1.1  mrg the default.
   3617      1.1  mrg @end multitable
   3618      1.1  mrg 
   3619      1.1  mrg @item @emph{Example}:
   3620      1.1  mrg @smallexample
   3621      1.1  mrg int main (int argc, char *argv[])
   3622      1.1  mrg @{
   3623      1.1  mrg   /* Initialize libgfortran.  */
   3624      1.1  mrg   _gfortran_set_args (argc, argv);
   3625      1.1  mrg   _gfortran_set_max_subrecord_length (8);
   3626      1.1  mrg   return 0;
   3627      1.1  mrg @}
   3628      1.1  mrg @end smallexample
   3629      1.1  mrg @end table
   3630      1.1  mrg 
   3631      1.1  mrg 
   3632      1.1  mrg @node Naming and argument-passing conventions
   3633      1.1  mrg @section Naming and argument-passing conventions
   3634      1.1  mrg 
   3635      1.1  mrg This section gives an overview about the naming convention of procedures
   3636      1.1  mrg and global variables and about the argument passing conventions used by
   3637      1.1  mrg GNU Fortran.  If a C binding has been specified, the naming convention
   3638      1.1  mrg and some of the argument-passing conventions change.  If possible,
   3639      1.1  mrg mixed-language and mixed-compiler projects should use the better defined
   3640      1.1  mrg C binding for interoperability.  See @pxref{Interoperability with C}.
   3641      1.1  mrg 
   3642      1.1  mrg @menu
   3643      1.1  mrg * Naming conventions::
   3644      1.1  mrg * Argument passing conventions::
   3645      1.1  mrg @end menu
   3646      1.1  mrg 
   3647      1.1  mrg 
   3648      1.1  mrg @node Naming conventions
   3649      1.1  mrg @subsection Naming conventions
   3650      1.1  mrg 
   3651      1.1  mrg According the Fortran standard, valid Fortran names consist of a letter
   3652      1.1  mrg between @code{A} to @code{Z}, @code{a} to @code{z}, digits @code{0},
   3653      1.1  mrg @code{1} to @code{9} and underscores (@code{_}) with the restriction
   3654      1.1  mrg that names may only start with a letter.  As vendor extension, the
   3655      1.1  mrg dollar sign (@code{$}) is additionally permitted with the option
   3656      1.1  mrg @option{-fdollar-ok}, but not as first character and only if the
   3657      1.1  mrg target system supports it.
   3658      1.1  mrg 
   3659      1.1  mrg By default, the procedure name is the lower-cased Fortran name with an
   3660      1.1  mrg appended underscore (@code{_}); using @option{-fno-underscoring} no
   3661      1.1  mrg underscore is appended while @code{-fsecond-underscore} appends two
   3662      1.1  mrg underscores.  Depending on the target system and the calling convention,
   3663      1.1  mrg the procedure might be additionally dressed; for instance, on 32bit
   3664      1.1  mrg Windows with @code{stdcall}, an at-sign @code{@@} followed by an integer
   3665      1.1  mrg number is appended.  For the changing the calling convention, see
   3666      1.1  mrg @pxref{GNU Fortran Compiler Directives}.
   3667      1.1  mrg 
   3668      1.1  mrg For common blocks, the same convention is used, i.e. by default an
   3669      1.1  mrg underscore is appended to the lower-cased Fortran name.  Blank commons
   3670      1.1  mrg have the name @code{__BLNK__}.
   3671      1.1  mrg 
   3672      1.1  mrg For procedures and variables declared in the specification space of a
   3673      1.1  mrg module, the name is formed by @code{__}, followed by the lower-cased
   3674      1.1  mrg module name, @code{_MOD_}, and the lower-cased Fortran name.  Note that
   3675      1.1  mrg no underscore is appended.
   3676      1.1  mrg 
   3677      1.1  mrg 
   3678      1.1  mrg @node Argument passing conventions
   3679      1.1  mrg @subsection Argument passing conventions
   3680      1.1  mrg 
   3681      1.1  mrg Subroutines do not return a value (matching C99's @code{void}) while
   3682      1.1  mrg functions either return a value as specified in the platform ABI or
   3683      1.1  mrg the result variable is passed as hidden argument to the function and
   3684      1.1  mrg no result is returned.  A hidden result variable is used when the
   3685      1.1  mrg result variable is an array or of type @code{CHARACTER}.
   3686      1.1  mrg 
   3687      1.1  mrg Arguments are passed according to the platform ABI. In particular,
   3688      1.1  mrg complex arguments might not be compatible to a struct with two real
   3689      1.1  mrg components for the real and imaginary part. The argument passing
   3690      1.1  mrg matches the one of C99's @code{_Complex}.  Functions with scalar
   3691      1.1  mrg complex result variables return their value and do not use a
   3692      1.1  mrg by-reference argument.  Note that with the @option{-ff2c} option,
   3693      1.1  mrg the argument passing is modified and no longer completely matches
   3694      1.1  mrg the platform ABI.  Some other Fortran compilers use @code{f2c}
   3695      1.1  mrg semantic by default; this might cause problems with
   3696      1.1  mrg interoperablility.
   3697      1.1  mrg 
   3698      1.1  mrg GNU Fortran passes most arguments by reference, i.e. by passing a
   3699      1.1  mrg pointer to the data.  Note that the compiler might use a temporary
   3700      1.1  mrg variable into which the actual argument has been copied, if required
   3701      1.1  mrg semantically (copy-in/copy-out).
   3702      1.1  mrg 
   3703      1.1  mrg For arguments with @code{ALLOCATABLE} and @code{POINTER}
   3704      1.1  mrg attribute (including procedure pointers), a pointer to the pointer
   3705      1.1  mrg is passed such that the pointer address can be modified in the
   3706      1.1  mrg procedure.
   3707      1.1  mrg 
   3708      1.1  mrg For dummy arguments with the @code{VALUE} attribute: Scalar arguments
   3709      1.1  mrg of the type @code{INTEGER}, @code{LOGICAL}, @code{REAL} and
   3710      1.1  mrg @code{COMPLEX} are passed by value according to the platform ABI.
   3711      1.1  mrg (As vendor extension and not recommended, using @code{%VAL()} in the
   3712      1.1  mrg call to a procedure has the same effect.) For @code{TYPE(C_PTR)} and
   3713      1.1  mrg procedure pointers, the pointer itself is passed such that it can be
   3714      1.1  mrg modified without affecting the caller.
   3715      1.1  mrg @c FIXME: Document how VALUE is handled for CHARACTER, TYPE,
   3716      1.1  mrg @c CLASS and arrays, i.e. whether the copy-in is done in the caller
   3717      1.1  mrg @c or in the callee.
   3718      1.1  mrg 
   3719      1.1  mrg For Boolean (@code{LOGICAL}) arguments, please note that GCC expects
   3720      1.1  mrg only the integer value 0 and 1.  If a GNU Fortran @code{LOGICAL}
   3721      1.1  mrg variable contains another integer value, the result is undefined.
   3722      1.1  mrg As some other Fortran compilers use @math{-1} for @code{.TRUE.},
   3723      1.1  mrg extra care has to be taken -- such as passing the value as
   3724      1.1  mrg @code{INTEGER}.  (The same value restriction also applies to other
   3725      1.1  mrg front ends of GCC, e.g. to GCC's C99 compiler for @code{_Bool}
   3726      1.1  mrg or GCC's Ada compiler for @code{Boolean}.)
   3727      1.1  mrg 
   3728      1.1  mrg For arguments of @code{CHARACTER} type, the character length is passed
   3729      1.1  mrg as a hidden argument at the end of the argument list.  For
   3730      1.1  mrg deferred-length strings, the value is passed by reference, otherwise
   3731      1.1  mrg by value.  The character length has the C type @code{size_t} (or
   3732      1.1  mrg @code{INTEGER(kind=C_SIZE_T)} in Fortran).  Note that this is
   3733      1.1  mrg different to older versions of the GNU Fortran compiler, where the
   3734      1.1  mrg type of the hidden character length argument was a C @code{int}.  In
   3735      1.1  mrg order to retain compatibility with older versions, one can e.g. for
   3736      1.1  mrg the following Fortran procedure
   3737      1.1  mrg 
   3738      1.1  mrg @smallexample
   3739      1.1  mrg subroutine fstrlen (s, a)
   3740      1.1  mrg    character(len=*) :: s
   3741      1.1  mrg    integer :: a
   3742      1.1  mrg    print*, len(s)
   3743      1.1  mrg end subroutine fstrlen
   3744      1.1  mrg @end smallexample
   3745      1.1  mrg 
   3746      1.1  mrg define the corresponding C prototype as follows:
   3747      1.1  mrg 
   3748      1.1  mrg @smallexample
   3749      1.1  mrg #if __GNUC__ > 7
   3750      1.1  mrg typedef size_t fortran_charlen_t;
   3751      1.1  mrg #else
   3752      1.1  mrg typedef int fortran_charlen_t;
   3753      1.1  mrg #endif
   3754      1.1  mrg 
   3755      1.1  mrg void fstrlen_ (char*, int*, fortran_charlen_t);
   3756      1.1  mrg @end smallexample
   3757      1.1  mrg 
   3758      1.1  mrg In order to avoid such compiler-specific details, for new code it is
   3759      1.1  mrg instead recommended to use the ISO_C_BINDING feature.
   3760      1.1  mrg 
   3761      1.1  mrg Note with C binding, @code{CHARACTER(len=1)} result variables are
   3762      1.1  mrg returned according to the platform ABI and no hidden length argument
   3763      1.1  mrg is used for dummy arguments; with @code{VALUE}, those variables are
   3764      1.1  mrg passed by value.
   3765      1.1  mrg 
   3766      1.1  mrg For @code{OPTIONAL} dummy arguments, an absent argument is denoted
   3767      1.1  mrg by a NULL pointer, except for scalar dummy arguments of type
   3768      1.1  mrg @code{INTEGER}, @code{LOGICAL}, @code{REAL} and @code{COMPLEX}
   3769      1.1  mrg which have the @code{VALUE} attribute.  For those, a hidden Boolean
   3770      1.1  mrg argument (@code{logical(kind=C_bool),value}) is used to indicate
   3771      1.1  mrg whether the argument is present.
   3772      1.1  mrg 
   3773      1.1  mrg Arguments which are assumed-shape, assumed-rank or deferred-rank
   3774      1.1  mrg arrays or, with @option{-fcoarray=lib}, allocatable scalar coarrays use
   3775      1.1  mrg an array descriptor.  All other arrays pass the address of the
   3776      1.1  mrg first element of the array.  With @option{-fcoarray=lib}, the token
   3777      1.1  mrg and the offset belonging to nonallocatable coarrays dummy arguments
   3778      1.1  mrg are passed as hidden argument along the character length hidden
   3779  1.1.1.3  mrg arguments.  The token is an opaque pointer identifying the coarray
   3780      1.1  mrg and the offset is a passed-by-value integer of kind @code{C_PTRDIFF_T},
   3781      1.1  mrg denoting the byte offset between the base address of the coarray and
   3782      1.1  mrg the passed scalar or first element of the passed array.
   3783      1.1  mrg 
   3784      1.1  mrg The arguments are passed in the following order
   3785      1.1  mrg @itemize @bullet
   3786      1.1  mrg @item Result variable, when the function result is passed by reference
   3787      1.1  mrg @item Character length of the function result, if it is a of type
   3788      1.1  mrg @code{CHARACTER} and no C binding is used
   3789      1.1  mrg @item The arguments in the order in which they appear in the Fortran
   3790      1.1  mrg declaration
   3791      1.1  mrg @item The the present status for optional arguments with value attribute,
   3792      1.1  mrg which are internally passed by value
   3793      1.1  mrg @item The character length and/or coarray token and offset for the first
   3794      1.1  mrg argument which is a @code{CHARACTER} or a nonallocatable coarray dummy
   3795      1.1  mrg argument, followed by the hidden arguments of the next dummy argument
   3796      1.1  mrg of such a type
   3797      1.1  mrg @end itemize
   3798      1.1  mrg 
   3799      1.1  mrg 
   3800      1.1  mrg @c ---------------------------------------------------------------------
   3801      1.1  mrg @c Coarray Programming
   3802      1.1  mrg @c ---------------------------------------------------------------------
   3803      1.1  mrg 
   3804      1.1  mrg @node Coarray Programming
   3805      1.1  mrg @chapter Coarray Programming
   3806      1.1  mrg @cindex Coarrays
   3807      1.1  mrg 
   3808      1.1  mrg @menu
   3809      1.1  mrg * Type and enum ABI Documentation::
   3810      1.1  mrg * Function ABI Documentation::
   3811      1.1  mrg @end menu
   3812      1.1  mrg 
   3813      1.1  mrg 
   3814      1.1  mrg @node Type and enum ABI Documentation
   3815      1.1  mrg @section Type and enum ABI Documentation
   3816      1.1  mrg 
   3817      1.1  mrg @menu
   3818      1.1  mrg * caf_token_t::
   3819      1.1  mrg * caf_register_t::
   3820      1.1  mrg * caf_deregister_t::
   3821      1.1  mrg * caf_reference_t::
   3822      1.1  mrg * caf_team_t::
   3823      1.1  mrg @end menu
   3824      1.1  mrg 
   3825      1.1  mrg @node caf_token_t
   3826      1.1  mrg @subsection @code{caf_token_t}
   3827      1.1  mrg 
   3828      1.1  mrg Typedef of type @code{void *} on the compiler side. Can be any data
   3829      1.1  mrg type on the library side.
   3830      1.1  mrg 
   3831      1.1  mrg @node caf_register_t
   3832      1.1  mrg @subsection @code{caf_register_t}
   3833      1.1  mrg 
   3834      1.1  mrg Indicates which kind of coarray variable should be registered.
   3835      1.1  mrg 
   3836      1.1  mrg @verbatim
   3837      1.1  mrg typedef enum caf_register_t {
   3838      1.1  mrg   CAF_REGTYPE_COARRAY_STATIC,
   3839      1.1  mrg   CAF_REGTYPE_COARRAY_ALLOC,
   3840      1.1  mrg   CAF_REGTYPE_LOCK_STATIC,
   3841      1.1  mrg   CAF_REGTYPE_LOCK_ALLOC,
   3842      1.1  mrg   CAF_REGTYPE_CRITICAL,
   3843      1.1  mrg   CAF_REGTYPE_EVENT_STATIC,
   3844      1.1  mrg   CAF_REGTYPE_EVENT_ALLOC,
   3845      1.1  mrg   CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY,
   3846      1.1  mrg   CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY
   3847      1.1  mrg }
   3848      1.1  mrg caf_register_t;
   3849      1.1  mrg @end verbatim
   3850      1.1  mrg 
   3851      1.1  mrg The values @code{CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY} and
   3852      1.1  mrg @code{CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY} are for allocatable components
   3853      1.1  mrg in derived type coarrays only.  The first one sets up the token without
   3854      1.1  mrg allocating memory for allocatable component.  The latter one only allocates the
   3855      1.1  mrg memory for an allocatable component in a derived type coarray.  The token
   3856      1.1  mrg needs to be setup previously by the REGISTER_ONLY.  This allows to have
   3857      1.1  mrg allocatable components un-allocated on some images.  The status whether an
   3858      1.1  mrg allocatable component is allocated on a remote image can be queried by
   3859      1.1  mrg @code{_caf_is_present} which used internally by the @code{ALLOCATED}
   3860      1.1  mrg intrinsic.
   3861      1.1  mrg 
   3862      1.1  mrg @node caf_deregister_t
   3863      1.1  mrg @subsection @code{caf_deregister_t}
   3864      1.1  mrg 
   3865      1.1  mrg @verbatim
   3866      1.1  mrg typedef enum caf_deregister_t {
   3867      1.1  mrg   CAF_DEREGTYPE_COARRAY_DEREGISTER,
   3868      1.1  mrg   CAF_DEREGTYPE_COARRAY_DEALLOCATE_ONLY
   3869      1.1  mrg }
   3870      1.1  mrg caf_deregister_t;
   3871      1.1  mrg @end verbatim
   3872      1.1  mrg 
   3873      1.1  mrg Allows to specifiy the type of deregistration of a coarray object.  The
   3874      1.1  mrg @code{CAF_DEREGTYPE_COARRAY_DEALLOCATE_ONLY} flag is only allowed for
   3875      1.1  mrg allocatable components in derived type coarrays.
   3876      1.1  mrg 
   3877      1.1  mrg @node caf_reference_t
   3878      1.1  mrg @subsection @code{caf_reference_t}
   3879      1.1  mrg 
   3880      1.1  mrg The structure used for implementing arbitrary reference chains.
   3881      1.1  mrg A @code{CAF_REFERENCE_T} allows to specify a component reference or any kind
   3882      1.1  mrg of array reference of any rank supported by gfortran.  For array references all
   3883      1.1  mrg kinds as known by the compiler/Fortran standard are supported indicated by
   3884      1.1  mrg a @code{MODE}.
   3885      1.1  mrg 
   3886      1.1  mrg @verbatim
   3887      1.1  mrg typedef enum caf_ref_type_t {
   3888      1.1  mrg   /* Reference a component of a derived type, either regular one or an
   3889      1.1  mrg      allocatable or pointer type.  For regular ones idx in caf_reference_t is
   3890      1.1  mrg      set to -1.  */
   3891      1.1  mrg   CAF_REF_COMPONENT,
   3892      1.1  mrg   /* Reference an allocatable array.  */
   3893      1.1  mrg   CAF_REF_ARRAY,
   3894      1.1  mrg   /* Reference a non-allocatable/non-pointer array.  I.e., the coarray object
   3895      1.1  mrg      has no array descriptor associated and the addressing is done
   3896      1.1  mrg      completely using the ref.  */
   3897      1.1  mrg   CAF_REF_STATIC_ARRAY
   3898      1.1  mrg } caf_ref_type_t;
   3899      1.1  mrg @end verbatim
   3900      1.1  mrg 
   3901      1.1  mrg @verbatim
   3902      1.1  mrg typedef enum caf_array_ref_t {
   3903      1.1  mrg   /* No array ref.  This terminates the array ref.  */
   3904      1.1  mrg   CAF_ARR_REF_NONE = 0,
   3905      1.1  mrg   /* Reference array elements given by a vector.  Only for this mode
   3906      1.1  mrg      caf_reference_t.u.a.dim[i].v is valid.  */
   3907      1.1  mrg   CAF_ARR_REF_VECTOR,
   3908      1.1  mrg   /* A full array ref (:).  */
   3909      1.1  mrg   CAF_ARR_REF_FULL,
   3910      1.1  mrg   /* Reference a range on elements given by start, end and stride.  */
   3911      1.1  mrg   CAF_ARR_REF_RANGE,
   3912      1.1  mrg   /* Only a single item is referenced given in the start member.  */
   3913      1.1  mrg   CAF_ARR_REF_SINGLE,
   3914      1.1  mrg   /* An array ref of the kind (i:), where i is an arbitrary valid index in the
   3915      1.1  mrg      array.  The index i is given in the start member.  */
   3916      1.1  mrg   CAF_ARR_REF_OPEN_END,
   3917      1.1  mrg   /* An array ref of the kind (:i), where the lower bound of the array ref
   3918      1.1  mrg      is given by the remote side.  The index i is given in the end member.  */
   3919      1.1  mrg   CAF_ARR_REF_OPEN_START
   3920      1.1  mrg } caf_array_ref_t;
   3921      1.1  mrg @end verbatim
   3922      1.1  mrg 
   3923      1.1  mrg @verbatim
   3924      1.1  mrg /* References to remote components of a derived type.  */
   3925      1.1  mrg typedef struct caf_reference_t {
   3926      1.1  mrg   /* A pointer to the next ref or NULL.  */
   3927      1.1  mrg   struct caf_reference_t *next;
   3928      1.1  mrg   /* The type of the reference.  */
   3929      1.1  mrg   /* caf_ref_type_t, replaced by int to allow specification in fortran FE.  */
   3930      1.1  mrg   int type;
   3931      1.1  mrg   /* The size of an item referenced in bytes.  I.e. in an array ref this is
   3932      1.1  mrg      the factor to advance the array pointer with to get to the next item.
   3933      1.1  mrg      For component refs this gives just the size of the element referenced.  */
   3934      1.1  mrg   size_t item_size;
   3935      1.1  mrg   union {
   3936      1.1  mrg     struct {
   3937      1.1  mrg       /* The offset (in bytes) of the component in the derived type.
   3938      1.1  mrg          Unused for allocatable or pointer components.  */
   3939      1.1  mrg       ptrdiff_t offset;
   3940      1.1  mrg       /* The offset (in bytes) to the caf_token associated with this
   3941      1.1  mrg          component.  NULL, when not allocatable/pointer ref.  */
   3942      1.1  mrg       ptrdiff_t caf_token_offset;
   3943      1.1  mrg     } c;
   3944      1.1  mrg     struct {
   3945      1.1  mrg       /* The mode of the array ref.  See CAF_ARR_REF_*.  */
   3946      1.1  mrg       /* caf_array_ref_t, replaced by unsigend char to allow specification in
   3947      1.1  mrg          fortran FE.  */
   3948      1.1  mrg      unsigned char mode[GFC_MAX_DIMENSIONS];
   3949      1.1  mrg       /* The type of a static array.  Unset for array's with descriptors.  */
   3950      1.1  mrg       int static_array_type;
   3951      1.1  mrg       /* Subscript refs (s) or vector refs (v).  */
   3952      1.1  mrg       union {
   3953      1.1  mrg         struct {
   3954      1.1  mrg           /* The start and end boundary of the ref and the stride.  */
   3955      1.1  mrg           index_type start, end, stride;
   3956      1.1  mrg         } s;
   3957      1.1  mrg         struct {
   3958      1.1  mrg           /* nvec entries of kind giving the elements to reference.  */
   3959      1.1  mrg           void *vector;
   3960      1.1  mrg           /* The number of entries in vector.  */
   3961      1.1  mrg           size_t nvec;
   3962      1.1  mrg           /* The integer kind used for the elements in vector.  */
   3963      1.1  mrg           int kind;
   3964      1.1  mrg         } v;
   3965      1.1  mrg       } dim[GFC_MAX_DIMENSIONS];
   3966      1.1  mrg     } a;
   3967      1.1  mrg   } u;
   3968      1.1  mrg } caf_reference_t;
   3969      1.1  mrg @end verbatim
   3970      1.1  mrg 
   3971      1.1  mrg The references make up a single linked list of reference operations.  The
   3972      1.1  mrg @code{NEXT} member links to the next reference or NULL to indicate the end of
   3973  1.1.1.3  mrg the chain.  Component and array refs can be arbitrarily mixed as long as they
   3974      1.1  mrg comply to the Fortran standard.
   3975      1.1  mrg 
   3976      1.1  mrg @emph{NOTES}
   3977      1.1  mrg The member @code{STATIC_ARRAY_TYPE} is used only when the @code{TYPE} is
   3978      1.1  mrg @code{CAF_REF_STATIC_ARRAY}.  The member gives the type of the data referenced.
   3979      1.1  mrg Because no array descriptor is available for a descriptor-less array and
   3980      1.1  mrg type conversion still needs to take place the type is transported here.
   3981      1.1  mrg 
   3982      1.1  mrg At the moment @code{CAF_ARR_REF_VECTOR} is not implemented in the front end for
   3983      1.1  mrg descriptor-less arrays.  The library caf_single has untested support for it.
   3984      1.1  mrg 
   3985      1.1  mrg @node caf_team_t
   3986      1.1  mrg @subsection @code{caf_team_t}
   3987      1.1  mrg 
   3988      1.1  mrg Opaque pointer to represent a team-handle.  This type is a stand-in for the
   3989      1.1  mrg future implementation of teams.  It is about to change without further notice.
   3990      1.1  mrg 
   3991      1.1  mrg @node Function ABI Documentation
   3992      1.1  mrg @section Function ABI Documentation
   3993      1.1  mrg 
   3994      1.1  mrg @menu
   3995      1.1  mrg * _gfortran_caf_init:: Initialiation function
   3996      1.1  mrg * _gfortran_caf_finish:: Finalization function
   3997      1.1  mrg * _gfortran_caf_this_image:: Querying the image number
   3998      1.1  mrg * _gfortran_caf_num_images:: Querying the maximal number of images
   3999      1.1  mrg * _gfortran_caf_image_status :: Query the status of an image
   4000      1.1  mrg * _gfortran_caf_failed_images :: Get an array of the indexes of the failed images
   4001      1.1  mrg * _gfortran_caf_stopped_images :: Get an array of the indexes of the stopped images
   4002      1.1  mrg * _gfortran_caf_register:: Registering coarrays
   4003      1.1  mrg * _gfortran_caf_deregister:: Deregistering coarrays
   4004      1.1  mrg * _gfortran_caf_is_present:: Query whether an allocatable or pointer component in a derived type coarray is allocated
   4005      1.1  mrg * _gfortran_caf_send:: Sending data from a local image to a remote image
   4006      1.1  mrg * _gfortran_caf_get:: Getting data from a remote image
   4007      1.1  mrg * _gfortran_caf_sendget:: Sending data between remote images
   4008      1.1  mrg * _gfortran_caf_send_by_ref:: Sending data from a local image to a remote image using enhanced references
   4009      1.1  mrg * _gfortran_caf_get_by_ref:: Getting data from a remote image using enhanced references
   4010      1.1  mrg * _gfortran_caf_sendget_by_ref:: Sending data between remote images using enhanced references
   4011      1.1  mrg * _gfortran_caf_lock:: Locking a lock variable
   4012      1.1  mrg * _gfortran_caf_unlock:: Unlocking a lock variable
   4013      1.1  mrg * _gfortran_caf_event_post:: Post an event
   4014      1.1  mrg * _gfortran_caf_event_wait:: Wait that an event occurred
   4015      1.1  mrg * _gfortran_caf_event_query:: Query event count
   4016      1.1  mrg * _gfortran_caf_sync_all:: All-image barrier
   4017      1.1  mrg * _gfortran_caf_sync_images:: Barrier for selected images
   4018      1.1  mrg * _gfortran_caf_sync_memory:: Wait for completion of segment-memory operations
   4019      1.1  mrg * _gfortran_caf_error_stop:: Error termination with exit code
   4020      1.1  mrg * _gfortran_caf_error_stop_str:: Error termination with string
   4021      1.1  mrg * _gfortran_caf_fail_image :: Mark the image failed and end its execution
   4022      1.1  mrg * _gfortran_caf_atomic_define:: Atomic variable assignment
   4023      1.1  mrg * _gfortran_caf_atomic_ref:: Atomic variable reference
   4024      1.1  mrg * _gfortran_caf_atomic_cas:: Atomic compare and swap
   4025      1.1  mrg * _gfortran_caf_atomic_op:: Atomic operation
   4026      1.1  mrg * _gfortran_caf_co_broadcast:: Sending data to all images
   4027      1.1  mrg * _gfortran_caf_co_max:: Collective maximum reduction
   4028      1.1  mrg * _gfortran_caf_co_min:: Collective minimum reduction
   4029      1.1  mrg * _gfortran_caf_co_sum:: Collective summing reduction
   4030      1.1  mrg * _gfortran_caf_co_reduce:: Generic collective reduction
   4031      1.1  mrg @end menu
   4032      1.1  mrg 
   4033      1.1  mrg 
   4034      1.1  mrg @node _gfortran_caf_init
   4035      1.1  mrg @subsection @code{_gfortran_caf_init} --- Initialiation function
   4036      1.1  mrg @cindex Coarray, _gfortran_caf_init
   4037      1.1  mrg 
   4038      1.1  mrg @table @asis
   4039      1.1  mrg @item @emph{Description}:
   4040      1.1  mrg This function is called at startup of the program before the Fortran main
   4041      1.1  mrg program, if the latter has been compiled with @option{-fcoarray=lib}.
   4042      1.1  mrg It takes as arguments the command-line arguments of the program.  It is
   4043      1.1  mrg permitted to pass two @code{NULL} pointers as argument; if non-@code{NULL},
   4044      1.1  mrg the library is permitted to modify the arguments.
   4045      1.1  mrg 
   4046      1.1  mrg @item @emph{Syntax}:
   4047      1.1  mrg @code{void _gfortran_caf_init (int *argc, char ***argv)}
   4048      1.1  mrg 
   4049      1.1  mrg @item @emph{Arguments}:
   4050      1.1  mrg @multitable @columnfractions .15 .70
   4051      1.1  mrg @item @var{argc} @tab intent(inout) An integer pointer with the number of
   4052      1.1  mrg arguments passed to the program or @code{NULL}.
   4053      1.1  mrg @item @var{argv} @tab intent(inout) A pointer to an array of strings with the
   4054      1.1  mrg command-line arguments or @code{NULL}.
   4055      1.1  mrg @end multitable
   4056      1.1  mrg 
   4057      1.1  mrg @item @emph{NOTES}
   4058      1.1  mrg The function is modelled after the initialization function of the Message
   4059      1.1  mrg Passing Interface (MPI) specification.  Due to the way coarray registration
   4060      1.1  mrg works, it might not be the first call to the library.  If the main program is
   4061      1.1  mrg not written in Fortran and only a library uses coarrays, it can happen that
   4062      1.1  mrg this function is never called.  Therefore, it is recommended that the library
   4063      1.1  mrg does not rely on the passed arguments and whether the call has been done.
   4064      1.1  mrg @end table
   4065      1.1  mrg 
   4066      1.1  mrg 
   4067      1.1  mrg @node _gfortran_caf_finish
   4068      1.1  mrg @subsection @code{_gfortran_caf_finish} --- Finalization function
   4069      1.1  mrg @cindex Coarray, _gfortran_caf_finish
   4070      1.1  mrg 
   4071      1.1  mrg @table @asis
   4072      1.1  mrg @item @emph{Description}:
   4073      1.1  mrg This function is called at the end of the Fortran main program, if it has
   4074      1.1  mrg been compiled with the @option{-fcoarray=lib} option.
   4075      1.1  mrg 
   4076      1.1  mrg @item @emph{Syntax}:
   4077      1.1  mrg @code{void _gfortran_caf_finish (void)}
   4078      1.1  mrg 
   4079      1.1  mrg @item @emph{NOTES}
   4080      1.1  mrg For non-Fortran programs, it is recommended to call the function at the end
   4081      1.1  mrg of the main program.  To ensure that the shutdown is also performed for
   4082      1.1  mrg programs where this function is not explicitly invoked, for instance
   4083      1.1  mrg non-Fortran programs or calls to the system's exit() function, the library
   4084      1.1  mrg can use a destructor function.  Note that programs can also be terminated
   4085      1.1  mrg using the STOP and ERROR STOP statements; those use different library calls.
   4086      1.1  mrg @end table
   4087      1.1  mrg 
   4088      1.1  mrg 
   4089      1.1  mrg @node _gfortran_caf_this_image
   4090      1.1  mrg @subsection @code{_gfortran_caf_this_image} --- Querying the image number
   4091      1.1  mrg @cindex Coarray, _gfortran_caf_this_image
   4092      1.1  mrg 
   4093      1.1  mrg @table @asis
   4094      1.1  mrg @item @emph{Description}:
   4095      1.1  mrg This function returns the current image number, which is a positive number.
   4096      1.1  mrg 
   4097      1.1  mrg @item @emph{Syntax}:
   4098      1.1  mrg @code{int _gfortran_caf_this_image (int distance)}
   4099      1.1  mrg 
   4100      1.1  mrg @item @emph{Arguments}:
   4101      1.1  mrg @multitable @columnfractions .15 .70
   4102      1.1  mrg @item @var{distance} @tab As specified for the @code{this_image} intrinsic
   4103      1.1  mrg in TS18508.  Shall be a non-negative number.
   4104      1.1  mrg @end multitable
   4105      1.1  mrg 
   4106      1.1  mrg @item @emph{NOTES}
   4107      1.1  mrg If the Fortran intrinsic @code{this_image} is invoked without an argument, which
   4108      1.1  mrg is the only permitted form in Fortran 2008, GCC passes @code{0} as
   4109      1.1  mrg first argument.
   4110      1.1  mrg @end table
   4111      1.1  mrg 
   4112      1.1  mrg 
   4113      1.1  mrg @node _gfortran_caf_num_images
   4114      1.1  mrg @subsection @code{_gfortran_caf_num_images} --- Querying the maximal number of images
   4115      1.1  mrg @cindex Coarray, _gfortran_caf_num_images
   4116      1.1  mrg 
   4117      1.1  mrg @table @asis
   4118      1.1  mrg @item @emph{Description}:
   4119      1.1  mrg This function returns the number of images in the current team, if
   4120      1.1  mrg @var{distance} is 0 or the number of images in the parent team at the specified
   4121      1.1  mrg distance. If failed is -1, the function returns the number of all images at
   4122      1.1  mrg the specified distance; if it is 0, the function returns the number of
   4123      1.1  mrg nonfailed images, and if it is 1, it returns the number of failed images.
   4124      1.1  mrg 
   4125      1.1  mrg @item @emph{Syntax}:
   4126      1.1  mrg @code{int _gfortran_caf_num_images(int distance, int failed)}
   4127      1.1  mrg 
   4128      1.1  mrg @item @emph{Arguments}:
   4129      1.1  mrg @multitable @columnfractions .15 .70
   4130      1.1  mrg @item @var{distance} @tab the distance from this image to the ancestor.
   4131      1.1  mrg Shall be positive.
   4132      1.1  mrg @item @var{failed} @tab shall be -1, 0, or 1
   4133      1.1  mrg @end multitable
   4134      1.1  mrg 
   4135      1.1  mrg @item @emph{NOTES}
   4136      1.1  mrg This function follows TS18508. If the num_image intrinsic has no arguments,
   4137      1.1  mrg then the compiler passes @code{distance=0} and @code{failed=-1} to the function.
   4138      1.1  mrg @end table
   4139      1.1  mrg 
   4140      1.1  mrg 
   4141      1.1  mrg @node _gfortran_caf_image_status
   4142      1.1  mrg @subsection @code{_gfortran_caf_image_status} --- Query the status of an image
   4143      1.1  mrg @cindex Coarray, _gfortran_caf_image_status
   4144      1.1  mrg 
   4145      1.1  mrg @table @asis
   4146      1.1  mrg @item @emph{Description}:
   4147      1.1  mrg Get the status of the image given by the id @var{image} of the team given by
   4148      1.1  mrg @var{team}.  Valid results are zero, for image is ok, @code{STAT_STOPPED_IMAGE}
   4149      1.1  mrg from the ISO_FORTRAN_ENV module to indicate that the image has been stopped and
   4150      1.1  mrg @code{STAT_FAILED_IMAGE} also from ISO_FORTRAN_ENV to indicate that the image
   4151      1.1  mrg has executed a @code{FAIL IMAGE} statement.
   4152      1.1  mrg 
   4153      1.1  mrg @item @emph{Syntax}:
   4154      1.1  mrg @code{int _gfortran_caf_image_status (int image, caf_team_t * team)}
   4155      1.1  mrg 
   4156      1.1  mrg @item @emph{Arguments}:
   4157      1.1  mrg @multitable @columnfractions .15 .70
   4158      1.1  mrg @item @var{image} @tab the positive scalar id of the image in the current TEAM.
   4159      1.1  mrg @item @var{team} @tab optional; team on the which the inquiry is to be
   4160      1.1  mrg performed.
   4161      1.1  mrg @end multitable
   4162      1.1  mrg 
   4163      1.1  mrg @item @emph{NOTES}
   4164      1.1  mrg This function follows TS18508.  Because team-functionality is not yet
   4165      1.1  mrg implemented a null-pointer is passed for the @var{team} argument at the moment.
   4166      1.1  mrg @end table
   4167      1.1  mrg 
   4168      1.1  mrg 
   4169      1.1  mrg @node _gfortran_caf_failed_images
   4170      1.1  mrg @subsection @code{_gfortran_caf_failed_images} --- Get an array of the indexes of the failed images
   4171      1.1  mrg @cindex Coarray, _gfortran_caf_failed_images
   4172      1.1  mrg 
   4173      1.1  mrg @table @asis
   4174      1.1  mrg @item @emph{Description}:
   4175      1.1  mrg Get an array of image indexes in the current @var{team} that have failed.  The
   4176      1.1  mrg array is sorted ascendingly.  When @var{team} is not provided the current team
   4177      1.1  mrg is to be used.  When @var{kind} is provided then the resulting array is of that
   4178      1.1  mrg integer kind else it is of default integer kind.  The returns an unallocated
   4179      1.1  mrg size zero array when no images have failed.
   4180      1.1  mrg 
   4181      1.1  mrg @item @emph{Syntax}:
   4182      1.1  mrg @code{int _gfortran_caf_failed_images (caf_team_t * team, int * kind)}
   4183      1.1  mrg 
   4184      1.1  mrg @item @emph{Arguments}:
   4185      1.1  mrg @multitable @columnfractions .15 .70
   4186      1.1  mrg @item @var{team} @tab optional; team on the which the inquiry is to be
   4187      1.1  mrg performed.
   4188      1.1  mrg @item @var{image} @tab optional; the kind of the resulting integer array.
   4189      1.1  mrg @end multitable
   4190      1.1  mrg 
   4191      1.1  mrg @item @emph{NOTES}
   4192      1.1  mrg This function follows TS18508.  Because team-functionality is not yet
   4193      1.1  mrg implemented a null-pointer is passed for the @var{team} argument at the moment.
   4194      1.1  mrg @end table
   4195      1.1  mrg 
   4196      1.1  mrg 
   4197      1.1  mrg @node _gfortran_caf_stopped_images
   4198      1.1  mrg @subsection @code{_gfortran_caf_stopped_images} --- Get an array of the indexes of the stopped images
   4199      1.1  mrg @cindex Coarray, _gfortran_caf_stopped_images
   4200      1.1  mrg 
   4201      1.1  mrg @table @asis
   4202      1.1  mrg @item @emph{Description}:
   4203      1.1  mrg Get an array of image indexes in the current @var{team} that have stopped.  The
   4204      1.1  mrg array is sorted ascendingly.  When @var{team} is not provided the current team
   4205      1.1  mrg is to be used.  When @var{kind} is provided then the resulting array is of that
   4206      1.1  mrg integer kind else it is of default integer kind.  The returns an unallocated
   4207      1.1  mrg size zero array when no images have failed.
   4208      1.1  mrg 
   4209      1.1  mrg @item @emph{Syntax}:
   4210      1.1  mrg @code{int _gfortran_caf_stopped_images (caf_team_t * team, int * kind)}
   4211      1.1  mrg 
   4212      1.1  mrg @item @emph{Arguments}:
   4213      1.1  mrg @multitable @columnfractions .15 .70
   4214      1.1  mrg @item @var{team} @tab optional; team on the which the inquiry is to be
   4215      1.1  mrg performed.
   4216      1.1  mrg @item @var{image} @tab optional; the kind of the resulting integer array.
   4217      1.1  mrg @end multitable
   4218      1.1  mrg 
   4219      1.1  mrg @item @emph{NOTES}
   4220      1.1  mrg This function follows TS18508.  Because team-functionality is not yet
   4221      1.1  mrg implemented a null-pointer is passed for the @var{team} argument at the moment.
   4222      1.1  mrg @end table
   4223      1.1  mrg 
   4224      1.1  mrg 
   4225      1.1  mrg @node _gfortran_caf_register
   4226      1.1  mrg @subsection @code{_gfortran_caf_register} --- Registering coarrays
   4227      1.1  mrg @cindex Coarray, _gfortran_caf_register
   4228      1.1  mrg 
   4229      1.1  mrg @table @asis
   4230      1.1  mrg @item @emph{Description}:
   4231      1.1  mrg Registers memory for a coarray and creates a token to identify the coarray.  The
   4232      1.1  mrg routine is called for both coarrays with @code{SAVE} attribute and using an
   4233      1.1  mrg explicit @code{ALLOCATE} statement.  If an error occurs and @var{STAT} is a
   4234      1.1  mrg @code{NULL} pointer, the function shall abort with printing an error message
   4235      1.1  mrg and starting the error termination.  If no error occurs and @var{STAT} is
   4236      1.1  mrg present, it shall be set to zero.  Otherwise, it shall be set to a positive
   4237      1.1  mrg value and, if not-@code{NULL}, @var{ERRMSG} shall be set to a string describing
   4238      1.1  mrg the failure.  The routine shall register the memory provided in the
   4239      1.1  mrg @code{DATA}-component of the array descriptor @var{DESC}, when that component
   4240      1.1  mrg is non-@code{NULL}, else it shall allocate sufficient memory and provide a
   4241      1.1  mrg pointer to it in the @code{DATA}-component of @var{DESC}.  The array descriptor
   4242      1.1  mrg has rank zero, when a scalar object is to be registered and the array
   4243      1.1  mrg descriptor may be invalid after the call to @code{_gfortran_caf_register}.
   4244      1.1  mrg When an array is to be allocated the descriptor persists.
   4245      1.1  mrg 
   4246      1.1  mrg For @code{CAF_REGTYPE_COARRAY_STATIC} and @code{CAF_REGTYPE_COARRAY_ALLOC},
   4247      1.1  mrg the passed size is the byte size requested.  For @code{CAF_REGTYPE_LOCK_STATIC},
   4248      1.1  mrg @code{CAF_REGTYPE_LOCK_ALLOC} and @code{CAF_REGTYPE_CRITICAL} it is the array
   4249      1.1  mrg size or one for a scalar.
   4250      1.1  mrg 
   4251      1.1  mrg When @code{CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY} is used, then only a token
   4252      1.1  mrg for an allocatable or pointer component is created.  The @code{SIZE} parameter
   4253      1.1  mrg is not used then.  On the contrary when
   4254      1.1  mrg @code{CAF_REGTYPE_COARRAY_ALLOC_ALLOCATE_ONLY} is specified, then the
   4255      1.1  mrg @var{token} needs to be registered by a previous call with regtype
   4256      1.1  mrg @code{CAF_REGTYPE_COARRAY_ALLOC_REGISTER_ONLY} and either the memory specified
   4257      1.1  mrg in the @var{DESC}'s data-ptr is registered or allocate when the data-ptr is
   4258      1.1  mrg @code{NULL}.
   4259      1.1  mrg 
   4260      1.1  mrg @item @emph{Syntax}:
   4261      1.1  mrg @code{void caf_register (size_t size, caf_register_t type, caf_token_t *token,
   4262      1.1  mrg gfc_descriptor_t *desc, int *stat, char *errmsg, size_t errmsg_len)}
   4263      1.1  mrg 
   4264      1.1  mrg @item @emph{Arguments}:
   4265      1.1  mrg @multitable @columnfractions .15 .70
   4266      1.1  mrg @item @var{size} @tab For normal coarrays, the byte size of the coarray to be
   4267      1.1  mrg allocated; for lock types and event types, the number of elements.
   4268      1.1  mrg @item @var{type} @tab one of the caf_register_t types.
   4269      1.1  mrg @item @var{token} @tab intent(out) An opaque pointer identifying the coarray.
   4270      1.1  mrg @item @var{desc} @tab intent(inout) The (pseudo) array descriptor.
   4271      1.1  mrg @item @var{stat} @tab intent(out) For allocatable coarrays, stores the STAT=;
   4272      1.1  mrg may be @code{NULL}
   4273      1.1  mrg @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
   4274      1.1  mrg an error message; may be @code{NULL}
   4275      1.1  mrg @item @var{errmsg_len} @tab the buffer size of errmsg.
   4276      1.1  mrg @end multitable
   4277      1.1  mrg 
   4278      1.1  mrg @item @emph{NOTES}
   4279      1.1  mrg Nonallocatable coarrays have to be registered prior use from remote images.
   4280      1.1  mrg In order to guarantee this, they have to be registered before the main
   4281      1.1  mrg program. This can be achieved by creating constructor functions. That is what
   4282      1.1  mrg GCC does such that also for nonallocatable coarrays the memory is allocated and
   4283      1.1  mrg no static memory is used.  The token permits to identify the coarray; to the
   4284      1.1  mrg processor, the token is a nonaliasing pointer. The library can, for instance,
   4285      1.1  mrg store the base address of the coarray in the token, some handle or a more
   4286      1.1  mrg complicated struct.  The library may also store the array descriptor
   4287      1.1  mrg @var{DESC} when its rank is non-zero.
   4288      1.1  mrg 
   4289      1.1  mrg For lock types, the value shall only be used for checking the allocation
   4290      1.1  mrg status. Note that for critical blocks, the locking is only required on one
   4291      1.1  mrg image; in the locking statement, the processor shall always pass an
   4292      1.1  mrg image index of one for critical-block lock variables
   4293      1.1  mrg (@code{CAF_REGTYPE_CRITICAL}). For lock types and critical-block variables,
   4294  1.1.1.3  mrg the initial value shall be unlocked (or, respectively, not in critical
   4295      1.1  mrg section) such as the value false; for event types, the initial state should
   4296      1.1  mrg be no event, e.g. zero.
   4297      1.1  mrg @end table
   4298      1.1  mrg 
   4299      1.1  mrg 
   4300      1.1  mrg @node _gfortran_caf_deregister
   4301      1.1  mrg @subsection @code{_gfortran_caf_deregister} --- Deregistering coarrays
   4302      1.1  mrg @cindex Coarray, _gfortran_caf_deregister
   4303      1.1  mrg 
   4304      1.1  mrg @table @asis
   4305      1.1  mrg @item @emph{Description}:
   4306      1.1  mrg Called to free or deregister the memory of a coarray; the processor calls this
   4307      1.1  mrg function for automatic and explicit deallocation.  In case of an error, this
   4308      1.1  mrg function shall fail with an error message, unless the @var{STAT} variable is
   4309      1.1  mrg not null.  The library is only expected to free memory it allocated itself
   4310      1.1  mrg during a call to @code{_gfortran_caf_register}.
   4311      1.1  mrg 
   4312      1.1  mrg @item @emph{Syntax}:
   4313      1.1  mrg @code{void caf_deregister (caf_token_t *token, caf_deregister_t type,
   4314      1.1  mrg int *stat, char *errmsg, size_t errmsg_len)}
   4315      1.1  mrg 
   4316      1.1  mrg @item @emph{Arguments}:
   4317      1.1  mrg @multitable @columnfractions .15 .70
   4318      1.1  mrg @item @var{token} @tab the token to free.
   4319      1.1  mrg @item @var{type} @tab the type of action to take for the coarray.  A
   4320      1.1  mrg @code{CAF_DEREGTYPE_COARRAY_DEALLOCATE_ONLY} is allowed only for allocatable or
   4321      1.1  mrg pointer components of derived type coarrays.  The action only deallocates the
   4322      1.1  mrg local memory without deleting the token.
   4323      1.1  mrg @item @var{stat} @tab intent(out) Stores the STAT=; may be NULL
   4324      1.1  mrg @item @var{errmsg} @tab intent(out) When an error occurs, this will be set
   4325      1.1  mrg to an error message; may be NULL
   4326      1.1  mrg @item @var{errmsg_len} @tab the buffer size of errmsg.
   4327      1.1  mrg @end multitable
   4328      1.1  mrg 
   4329      1.1  mrg @item @emph{NOTES}
   4330      1.1  mrg For nonalloatable coarrays this function is never called.  If a cleanup is
   4331      1.1  mrg required, it has to be handled via the finish, stop and error stop functions,
   4332      1.1  mrg and via destructors.
   4333      1.1  mrg @end table
   4334      1.1  mrg 
   4335      1.1  mrg 
   4336      1.1  mrg @node _gfortran_caf_is_present
   4337      1.1  mrg @subsection @code{_gfortran_caf_is_present} --- Query whether an allocatable or pointer component in a derived type coarray is allocated
   4338      1.1  mrg @cindex Coarray, _gfortran_caf_is_present
   4339      1.1  mrg 
   4340      1.1  mrg @table @asis
   4341      1.1  mrg @item @emph{Description}:
   4342      1.1  mrg Used to query the coarray library whether an allocatable component in a derived
   4343      1.1  mrg type coarray is allocated on a remote image.
   4344      1.1  mrg 
   4345      1.1  mrg @item @emph{Syntax}:
   4346      1.1  mrg @code{void _gfortran_caf_is_present (caf_token_t token, int image_index,
   4347      1.1  mrg gfc_reference_t *ref)}
   4348      1.1  mrg 
   4349      1.1  mrg @item @emph{Arguments}:
   4350      1.1  mrg @multitable @columnfractions .15 .70
   4351      1.1  mrg @item @var{token} @tab An opaque pointer identifying the coarray.
   4352      1.1  mrg @item @var{image_index} @tab The ID of the remote image; must be a positive
   4353      1.1  mrg number.
   4354      1.1  mrg @item @var{ref} @tab A chain of references to address the allocatable or
   4355      1.1  mrg pointer component in the derived type coarray.  The object reference needs to be
   4356      1.1  mrg a scalar or a full array reference, respectively.
   4357      1.1  mrg @end multitable
   4358      1.1  mrg 
   4359      1.1  mrg @end table
   4360      1.1  mrg 
   4361      1.1  mrg @node _gfortran_caf_send
   4362      1.1  mrg @subsection @code{_gfortran_caf_send} --- Sending data from a local image to a remote image
   4363      1.1  mrg @cindex Coarray, _gfortran_caf_send
   4364      1.1  mrg 
   4365      1.1  mrg @table @asis
   4366      1.1  mrg @item @emph{Description}:
   4367      1.1  mrg Called to send a scalar, an array section or a whole array from a local
   4368      1.1  mrg to a remote image identified by the image_index.
   4369      1.1  mrg 
   4370      1.1  mrg @item @emph{Syntax}:
   4371      1.1  mrg @code{void _gfortran_caf_send (caf_token_t token, size_t offset,
   4372      1.1  mrg int image_index, gfc_descriptor_t *dest, caf_vector_t *dst_vector,
   4373      1.1  mrg gfc_descriptor_t *src, int dst_kind, int src_kind, bool may_require_tmp,
   4374      1.1  mrg int *stat)}
   4375      1.1  mrg 
   4376      1.1  mrg @item @emph{Arguments}:
   4377      1.1  mrg @multitable @columnfractions .15 .70
   4378      1.1  mrg @item @var{token} @tab intent(in)  An opaque pointer identifying the coarray.
   4379      1.1  mrg @item @var{offset} @tab intent(in)  By which amount of bytes the actual data is
   4380      1.1  mrg shifted compared to the base address of the coarray.
   4381      1.1  mrg @item @var{image_index} @tab intent(in)  The ID of the remote image; must be a
   4382      1.1  mrg positive number.
   4383      1.1  mrg @item @var{dest} @tab intent(in)  Array descriptor for the remote image for the
   4384      1.1  mrg bounds and the size.  The @code{base_addr} shall not be accessed.
   4385      1.1  mrg @item @var{dst_vector} @tab intent(in)  If not NULL, it contains the vector
   4386      1.1  mrg subscript of the destination array; the values are relative to the dimension
   4387      1.1  mrg triplet of the dest argument.
   4388      1.1  mrg @item @var{src} @tab intent(in)  Array descriptor of the local array to be
   4389      1.1  mrg transferred to the remote image
   4390      1.1  mrg @item @var{dst_kind} @tab intent(in)  Kind of the destination argument
   4391      1.1  mrg @item @var{src_kind} @tab intent(in)  Kind of the source argument
   4392      1.1  mrg @item @var{may_require_tmp} @tab intent(in)  The variable is @code{false} when
   4393      1.1  mrg it is known at compile time that the @var{dest} and @var{src} either cannot
   4394      1.1  mrg overlap or overlap (fully or partially) such that walking @var{src} and
   4395      1.1  mrg @var{dest} in element wise element order (honoring the stride value) will not
   4396      1.1  mrg lead to wrong results.  Otherwise, the value is @code{true}.
   4397      1.1  mrg @item @var{stat} @tab intent(out) when non-NULL give the result of the
   4398      1.1  mrg operation, i.e., zero on success and non-zero on error.  When NULL and an error
   4399      1.1  mrg occurs, then an error message is printed and the program is terminated.
   4400      1.1  mrg @end multitable
   4401      1.1  mrg 
   4402      1.1  mrg @item @emph{NOTES}
   4403      1.1  mrg It is permitted to have @var{image_index} equal the current image; the memory
   4404      1.1  mrg of the send-to and the send-from might (partially) overlap in that case.  The
   4405      1.1  mrg implementation has to take care that it handles this case, e.g. using
   4406      1.1  mrg @code{memmove} which handles (partially) overlapping memory. If
   4407      1.1  mrg @var{may_require_tmp} is true, the library might additionally create a
   4408      1.1  mrg temporary variable, unless additional checks show that this is not required
   4409      1.1  mrg (e.g. because walking backward is possible or because both arrays are
   4410      1.1  mrg contiguous and @code{memmove} takes care of overlap issues).
   4411      1.1  mrg 
   4412      1.1  mrg Note that the assignment of a scalar to an array is permitted. In addition,
   4413      1.1  mrg the library has to handle numeric-type conversion and for strings, padding
   4414      1.1  mrg and different character kinds.
   4415      1.1  mrg @end table
   4416      1.1  mrg 
   4417      1.1  mrg 
   4418      1.1  mrg @node _gfortran_caf_get
   4419      1.1  mrg @subsection @code{_gfortran_caf_get} --- Getting data from a remote image
   4420      1.1  mrg @cindex Coarray, _gfortran_caf_get
   4421      1.1  mrg 
   4422      1.1  mrg @table @asis
   4423      1.1  mrg @item @emph{Description}:
   4424      1.1  mrg Called to get an array section or a whole array from a remote,
   4425      1.1  mrg image identified by the image_index.
   4426      1.1  mrg 
   4427      1.1  mrg @item @emph{Syntax}:
   4428      1.1  mrg @code{void _gfortran_caf_get (caf_token_t token, size_t offset,
   4429      1.1  mrg int image_index, gfc_descriptor_t *src, caf_vector_t *src_vector,
   4430      1.1  mrg gfc_descriptor_t *dest, int src_kind, int dst_kind, bool may_require_tmp,
   4431      1.1  mrg int *stat)}
   4432      1.1  mrg 
   4433      1.1  mrg @item @emph{Arguments}:
   4434      1.1  mrg @multitable @columnfractions .15 .70
   4435      1.1  mrg @item @var{token} @tab intent(in)  An opaque pointer identifying the coarray.
   4436      1.1  mrg @item @var{offset} @tab intent(in)  By which amount of bytes the actual data is
   4437      1.1  mrg shifted compared to the base address of the coarray.
   4438      1.1  mrg @item @var{image_index} @tab intent(in)  The ID of the remote image; must be a
   4439      1.1  mrg positive number.
   4440      1.1  mrg @item @var{dest} @tab intent(out) Array descriptor of the local array to store
   4441      1.1  mrg the data retrieved from the remote image
   4442      1.1  mrg @item @var{src} @tab intent(in) Array descriptor for the remote image for the
   4443      1.1  mrg bounds and the size.  The @code{base_addr} shall not be accessed.
   4444      1.1  mrg @item @var{src_vector} @tab intent(in)  If not NULL, it contains the vector
   4445      1.1  mrg subscript of the source array; the values are relative to the dimension
   4446      1.1  mrg triplet of the @var{src} argument.
   4447      1.1  mrg @item @var{dst_kind} @tab intent(in)  Kind of the destination argument
   4448      1.1  mrg @item @var{src_kind} @tab intent(in)  Kind of the source argument
   4449      1.1  mrg @item @var{may_require_tmp} @tab intent(in)  The variable is @code{false} when
   4450      1.1  mrg it is known at compile time that the @var{dest} and @var{src} either cannot
   4451      1.1  mrg overlap or overlap (fully or partially) such that walking @var{src} and
   4452      1.1  mrg @var{dest} in element wise element order (honoring the stride value) will not
   4453      1.1  mrg lead to wrong results.  Otherwise, the value is @code{true}.
   4454      1.1  mrg @item @var{stat} @tab intent(out) When non-NULL give the result of the
   4455      1.1  mrg operation, i.e., zero on success and non-zero on error.  When NULL and an error
   4456      1.1  mrg occurs, then an error message is printed and the program is terminated.
   4457      1.1  mrg @end multitable
   4458      1.1  mrg 
   4459      1.1  mrg @item @emph{NOTES}
   4460      1.1  mrg It is permitted to have @var{image_index} equal the current image; the memory of
   4461      1.1  mrg the send-to and the send-from might (partially) overlap in that case.  The
   4462      1.1  mrg implementation has to take care that it handles this case, e.g. using
   4463      1.1  mrg @code{memmove} which handles (partially) overlapping memory. If
   4464      1.1  mrg @var{may_require_tmp} is true, the library might additionally create a
   4465      1.1  mrg temporary variable, unless additional checks show that this is not required
   4466      1.1  mrg (e.g. because walking backward is possible or because both arrays are
   4467      1.1  mrg contiguous and @code{memmove} takes care of overlap issues).
   4468      1.1  mrg 
   4469      1.1  mrg Note that the library has to handle numeric-type conversion and for strings,
   4470      1.1  mrg padding and different character kinds.
   4471      1.1  mrg @end table
   4472      1.1  mrg 
   4473      1.1  mrg 
   4474      1.1  mrg @node _gfortran_caf_sendget
   4475      1.1  mrg @subsection @code{_gfortran_caf_sendget} --- Sending data between remote images
   4476      1.1  mrg @cindex Coarray, _gfortran_caf_sendget
   4477      1.1  mrg 
   4478      1.1  mrg @table @asis
   4479      1.1  mrg @item @emph{Description}:
   4480      1.1  mrg Called to send a scalar, an array section or a whole array from a remote image
   4481      1.1  mrg identified by the @var{src_image_index} to a remote image identified by the
   4482      1.1  mrg @var{dst_image_index}.
   4483      1.1  mrg 
   4484      1.1  mrg @item @emph{Syntax}:
   4485      1.1  mrg @code{void _gfortran_caf_sendget (caf_token_t dst_token, size_t dst_offset,
   4486      1.1  mrg int dst_image_index, gfc_descriptor_t *dest, caf_vector_t *dst_vector,
   4487      1.1  mrg caf_token_t src_token, size_t src_offset, int src_image_index,
   4488      1.1  mrg gfc_descriptor_t *src, caf_vector_t *src_vector, int dst_kind, int src_kind,
   4489      1.1  mrg bool may_require_tmp, int *stat)}
   4490      1.1  mrg 
   4491      1.1  mrg @item @emph{Arguments}:
   4492      1.1  mrg @multitable @columnfractions .15 .70
   4493      1.1  mrg @item @var{dst_token} @tab intent(in)  An opaque pointer identifying the
   4494      1.1  mrg destination coarray.
   4495      1.1  mrg @item @var{dst_offset} @tab intent(in)  By which amount of bytes the actual data
   4496      1.1  mrg is shifted compared to the base address of the destination coarray.
   4497      1.1  mrg @item @var{dst_image_index} @tab intent(in)  The ID of the destination remote
   4498      1.1  mrg image; must be a positive number.
   4499      1.1  mrg @item @var{dest} @tab intent(in) Array descriptor for the destination
   4500      1.1  mrg remote image for the bounds and the size.  The @code{base_addr} shall not be
   4501      1.1  mrg accessed.
   4502      1.1  mrg @item @var{dst_vector} @tab intent(int)  If not NULL, it contains the vector
   4503      1.1  mrg subscript of the destination array; the values are relative to the dimension
   4504      1.1  mrg triplet of the @var{dest} argument.
   4505      1.1  mrg @item @var{src_token} @tab intent(in)  An opaque pointer identifying the source
   4506      1.1  mrg coarray.
   4507      1.1  mrg @item @var{src_offset} @tab intent(in)  By which amount of bytes the actual data
   4508      1.1  mrg is shifted compared to the base address of the source coarray.
   4509      1.1  mrg @item @var{src_image_index} @tab intent(in)  The ID of the source remote image;
   4510      1.1  mrg must be a positive number.
   4511      1.1  mrg @item @var{src} @tab intent(in) Array descriptor of the local array to be
   4512      1.1  mrg transferred to the remote image.
   4513      1.1  mrg @item @var{src_vector} @tab intent(in) Array descriptor of the local array to
   4514      1.1  mrg be transferred to the remote image
   4515      1.1  mrg @item @var{dst_kind} @tab intent(in)  Kind of the destination argument
   4516      1.1  mrg @item @var{src_kind} @tab intent(in)  Kind of the source argument
   4517      1.1  mrg @item @var{may_require_tmp} @tab intent(in)  The variable is @code{false} when
   4518      1.1  mrg it is known at compile time that the @var{dest} and @var{src} either cannot
   4519      1.1  mrg overlap or overlap (fully or partially) such that walking @var{src} and
   4520      1.1  mrg @var{dest} in element wise element order (honoring the stride value) will not
   4521      1.1  mrg lead to wrong results.  Otherwise, the value is @code{true}.
   4522      1.1  mrg @item @var{stat} @tab intent(out) when non-NULL give the result of the
   4523      1.1  mrg operation, i.e., zero on success and non-zero on error.  When NULL and an error
   4524      1.1  mrg occurs, then an error message is printed and the program is terminated.
   4525      1.1  mrg @end multitable
   4526      1.1  mrg 
   4527      1.1  mrg @item @emph{NOTES}
   4528      1.1  mrg It is permitted to have the same image index for both @var{src_image_index} and
   4529      1.1  mrg @var{dst_image_index}; the memory of the send-to and the send-from might
   4530      1.1  mrg (partially) overlap in that case.  The implementation has to take care that it
   4531      1.1  mrg handles this case, e.g. using @code{memmove} which handles (partially)
   4532      1.1  mrg overlapping memory.  If @var{may_require_tmp} is true, the library
   4533      1.1  mrg might additionally create a temporary variable, unless additional checks show
   4534      1.1  mrg that this is not required (e.g. because walking backward is possible or because
   4535      1.1  mrg both arrays are contiguous and @code{memmove} takes care of overlap issues).
   4536      1.1  mrg 
   4537      1.1  mrg Note that the assignment of a scalar to an array is permitted. In addition,
   4538      1.1  mrg the library has to handle numeric-type conversion and for strings, padding and
   4539      1.1  mrg different character kinds.
   4540      1.1  mrg @end table
   4541      1.1  mrg 
   4542      1.1  mrg @node _gfortran_caf_send_by_ref
   4543      1.1  mrg @subsection @code{_gfortran_caf_send_by_ref} --- Sending data from a local image to a remote image with enhanced referencing options
   4544      1.1  mrg @cindex Coarray, _gfortran_caf_send_by_ref
   4545      1.1  mrg 
   4546      1.1  mrg @table @asis
   4547      1.1  mrg @item @emph{Description}:
   4548      1.1  mrg Called to send a scalar, an array section or a whole array from a local to a
   4549      1.1  mrg remote image identified by the @var{image_index}.
   4550      1.1  mrg 
   4551      1.1  mrg @item @emph{Syntax}:
   4552      1.1  mrg @code{void _gfortran_caf_send_by_ref (caf_token_t token, int image_index,
   4553      1.1  mrg gfc_descriptor_t *src, caf_reference_t *refs, int dst_kind, int src_kind,
   4554      1.1  mrg bool may_require_tmp, bool dst_reallocatable, int *stat, int dst_type)}
   4555      1.1  mrg 
   4556      1.1  mrg @item @emph{Arguments}:
   4557      1.1  mrg @multitable @columnfractions .15 .70
   4558      1.1  mrg @item @var{token} @tab intent(in)  An opaque pointer identifying the coarray.
   4559      1.1  mrg @item @var{image_index} @tab intent(in)  The ID of the remote image; must be a
   4560      1.1  mrg positive number.
   4561      1.1  mrg @item @var{src} @tab intent(in) Array descriptor of the local array to be
   4562      1.1  mrg transferred to the remote image
   4563      1.1  mrg @item @var{refs} @tab intent(in) The references on the remote array to store
   4564      1.1  mrg the data given by src.  Guaranteed to have at least one entry.
   4565      1.1  mrg @item @var{dst_kind} @tab intent(in)  Kind of the destination argument
   4566      1.1  mrg @item @var{src_kind} @tab intent(in)  Kind of the source argument
   4567      1.1  mrg @item @var{may_require_tmp} @tab intent(in)  The variable is @code{false} when
   4568      1.1  mrg it is known at compile time that the @var{dest} and @var{src} either cannot
   4569      1.1  mrg overlap or overlap (fully or partially) such that walking @var{src} and
   4570      1.1  mrg @var{dest} in element wise element order (honoring the stride value) will not
   4571      1.1  mrg lead to wrong results.  Otherwise, the value is @code{true}.
   4572      1.1  mrg @item @var{dst_reallocatable} @tab intent(in)  Set when the destination is of
   4573      1.1  mrg allocatable or pointer type and the refs will allow reallocation, i.e., the ref
   4574      1.1  mrg is a full array or component ref.
   4575      1.1  mrg @item @var{stat} @tab intent(out) When non-@code{NULL} give the result of the
   4576      1.1  mrg operation, i.e., zero on success and non-zero on error.  When @code{NULL} and
   4577      1.1  mrg an error occurs, then an error message is printed and the program is terminated.
   4578      1.1  mrg @item @var{dst_type} @tab intent(in)  Give the type of the destination.  When
   4579      1.1  mrg the destination is not an array, than the precise type, e.g. of a component in
   4580      1.1  mrg a derived type, is not known, but provided here.
   4581      1.1  mrg @end multitable
   4582      1.1  mrg 
   4583      1.1  mrg @item @emph{NOTES}
   4584      1.1  mrg It is permitted to have @var{image_index} equal the current image; the memory of
   4585      1.1  mrg the send-to and the send-from might (partially) overlap in that case.  The
   4586      1.1  mrg implementation has to take care that it handles this case, e.g. using
   4587      1.1  mrg @code{memmove} which handles (partially) overlapping memory.  If
   4588      1.1  mrg @var{may_require_tmp} is true, the library might additionally create a
   4589      1.1  mrg temporary variable, unless additional checks show that this is not required
   4590      1.1  mrg (e.g. because walking backward is possible or because both arrays are
   4591      1.1  mrg contiguous and @code{memmove} takes care of overlap issues).
   4592      1.1  mrg 
   4593      1.1  mrg Note that the assignment of a scalar to an array is permitted.  In addition,
   4594      1.1  mrg the library has to handle numeric-type conversion and for strings, padding
   4595      1.1  mrg and different character kinds.
   4596      1.1  mrg 
   4597      1.1  mrg Because of the more complicated references possible some operations may be
   4598      1.1  mrg unsupported by certain libraries.  The library is expected to issue a precise
   4599      1.1  mrg error message why the operation is not permitted.
   4600      1.1  mrg @end table
   4601      1.1  mrg 
   4602      1.1  mrg 
   4603      1.1  mrg @node _gfortran_caf_get_by_ref
   4604      1.1  mrg @subsection @code{_gfortran_caf_get_by_ref} --- Getting data from a remote image using enhanced references
   4605      1.1  mrg @cindex Coarray, _gfortran_caf_get_by_ref
   4606      1.1  mrg 
   4607      1.1  mrg @table @asis
   4608      1.1  mrg @item @emph{Description}:
   4609      1.1  mrg Called to get a scalar, an array section or a whole array from a remote image
   4610      1.1  mrg identified by the @var{image_index}.
   4611      1.1  mrg 
   4612      1.1  mrg @item @emph{Syntax}:
   4613      1.1  mrg @code{void _gfortran_caf_get_by_ref (caf_token_t token, int image_index,
   4614      1.1  mrg caf_reference_t *refs, gfc_descriptor_t *dst, int dst_kind, int src_kind,
   4615      1.1  mrg bool may_require_tmp, bool dst_reallocatable, int *stat, int src_type)}
   4616      1.1  mrg 
   4617      1.1  mrg @item @emph{Arguments}:
   4618      1.1  mrg @multitable @columnfractions .15 .70
   4619      1.1  mrg @item @var{token} @tab intent(in)  An opaque pointer identifying the coarray.
   4620      1.1  mrg @item @var{image_index} @tab intent(in)  The ID of the remote image; must be a
   4621      1.1  mrg positive number.
   4622      1.1  mrg @item @var{refs} @tab intent(in) The references to apply to the remote structure
   4623      1.1  mrg to get the data.
   4624      1.1  mrg @item @var{dst} @tab intent(in) Array descriptor of the local array to store
   4625      1.1  mrg the data transferred from the remote image.  May be reallocated where needed
   4626      1.1  mrg and when @var{DST_REALLOCATABLE} allows it.
   4627      1.1  mrg @item @var{dst_kind} @tab intent(in)  Kind of the destination argument
   4628      1.1  mrg @item @var{src_kind} @tab intent(in)  Kind of the source argument
   4629      1.1  mrg @item @var{may_require_tmp} @tab intent(in)  The variable is @code{false} when
   4630      1.1  mrg it is known at compile time that the @var{dest} and @var{src} either cannot
   4631      1.1  mrg overlap or overlap (fully or partially) such that walking @var{src} and
   4632      1.1  mrg @var{dest} in element wise element order (honoring the stride value) will not
   4633      1.1  mrg lead to wrong results.  Otherwise, the value is @code{true}.
   4634      1.1  mrg @item @var{dst_reallocatable} @tab intent(in)  Set when @var{DST} is of
   4635      1.1  mrg allocatable or pointer type and its refs allow reallocation, i.e., the full
   4636      1.1  mrg array or a component is referenced.
   4637      1.1  mrg @item @var{stat} @tab intent(out) When non-@code{NULL} give the result of the
   4638      1.1  mrg operation, i.e., zero on success and non-zero on error.  When @code{NULL} and an
   4639      1.1  mrg error occurs, then an error message is printed and the program is terminated.
   4640      1.1  mrg @item @var{src_type} @tab intent(in)  Give the type of the source.  When the
   4641      1.1  mrg source is not an array, than the precise type, e.g. of a component in a
   4642      1.1  mrg derived type, is not known, but provided here.
   4643      1.1  mrg @end multitable
   4644      1.1  mrg 
   4645      1.1  mrg @item @emph{NOTES}
   4646      1.1  mrg It is permitted to have @code{image_index} equal the current image; the memory
   4647      1.1  mrg of the send-to and the send-from might (partially) overlap in that case.  The
   4648      1.1  mrg implementation has to take care that it handles this case, e.g. using
   4649      1.1  mrg @code{memmove} which handles (partially) overlapping memory.  If
   4650      1.1  mrg @var{may_require_tmp} is true, the library might additionally create a
   4651      1.1  mrg temporary variable, unless additional checks show that this is not required
   4652      1.1  mrg (e.g. because walking backward is possible or because both arrays are
   4653      1.1  mrg contiguous and @code{memmove} takes care of overlap issues).
   4654      1.1  mrg 
   4655      1.1  mrg Note that the library has to handle numeric-type conversion and for strings,
   4656      1.1  mrg padding and different character kinds.
   4657      1.1  mrg 
   4658      1.1  mrg Because of the more complicated references possible some operations may be
   4659      1.1  mrg unsupported by certain libraries.  The library is expected to issue a precise
   4660      1.1  mrg error message why the operation is not permitted.
   4661      1.1  mrg @end table
   4662      1.1  mrg 
   4663      1.1  mrg 
   4664      1.1  mrg @node _gfortran_caf_sendget_by_ref
   4665      1.1  mrg @subsection @code{_gfortran_caf_sendget_by_ref} --- Sending data between remote images using enhanced references on both sides
   4666      1.1  mrg @cindex Coarray, _gfortran_caf_sendget_by_ref
   4667      1.1  mrg 
   4668      1.1  mrg @table @asis
   4669      1.1  mrg @item @emph{Description}:
   4670      1.1  mrg Called to send a scalar, an array section or a whole array from a remote image
   4671      1.1  mrg identified by the @var{src_image_index} to a remote image identified by the
   4672      1.1  mrg @var{dst_image_index}.
   4673      1.1  mrg 
   4674      1.1  mrg @item @emph{Syntax}:
   4675      1.1  mrg @code{void _gfortran_caf_sendget_by_ref (caf_token_t dst_token,
   4676      1.1  mrg int dst_image_index, caf_reference_t *dst_refs,
   4677      1.1  mrg caf_token_t src_token, int src_image_index, caf_reference_t *src_refs,
   4678      1.1  mrg int dst_kind, int src_kind, bool may_require_tmp, int *dst_stat,
   4679      1.1  mrg int *src_stat, int dst_type, int src_type)}
   4680      1.1  mrg 
   4681      1.1  mrg @item @emph{Arguments}:
   4682      1.1  mrg @multitable @columnfractions .15 .70
   4683      1.1  mrg @item @var{dst_token} @tab intent(in)  An opaque pointer identifying the
   4684      1.1  mrg destination coarray.
   4685      1.1  mrg @item @var{dst_image_index} @tab intent(in)  The ID of the destination remote
   4686      1.1  mrg image; must be a positive number.
   4687      1.1  mrg @item @var{dst_refs} @tab intent(in) The references on the remote array to store
   4688      1.1  mrg the data given by the source.  Guaranteed to have at least one entry.
   4689      1.1  mrg @item @var{src_token} @tab intent(in)  An opaque pointer identifying the source
   4690      1.1  mrg coarray.
   4691      1.1  mrg @item @var{src_image_index} @tab intent(in)  The ID of the source remote image;
   4692      1.1  mrg must be a positive number.
   4693      1.1  mrg @item @var{src_refs} @tab intent(in) The references to apply to the remote
   4694      1.1  mrg structure to get the data.
   4695      1.1  mrg @item @var{dst_kind} @tab intent(in)  Kind of the destination argument
   4696      1.1  mrg @item @var{src_kind} @tab intent(in)  Kind of the source argument
   4697      1.1  mrg @item @var{may_require_tmp} @tab intent(in)  The variable is @code{false} when
   4698      1.1  mrg it is known at compile time that the @var{dest} and @var{src} either cannot
   4699      1.1  mrg overlap or overlap (fully or partially) such that walking @var{src} and
   4700      1.1  mrg @var{dest} in element wise element order (honoring the stride value) will not
   4701      1.1  mrg lead to wrong results.  Otherwise, the value is @code{true}.
   4702      1.1  mrg @item @var{dst_stat} @tab intent(out) when non-@code{NULL} give the result of
   4703      1.1  mrg the send-operation, i.e., zero on success and non-zero on error.  When
   4704      1.1  mrg @code{NULL} and an error occurs, then an error message is printed and the
   4705      1.1  mrg program is terminated.
   4706      1.1  mrg @item @var{src_stat} @tab intent(out) When non-@code{NULL} give the result of
   4707      1.1  mrg the get-operation, i.e., zero on success and non-zero on error.  When
   4708      1.1  mrg @code{NULL} and an error occurs, then an error message is printed and the
   4709      1.1  mrg program is terminated.
   4710      1.1  mrg @item @var{dst_type} @tab intent(in)  Give the type of the destination.  When
   4711      1.1  mrg the destination is not an array, than the precise type, e.g. of a component in
   4712      1.1  mrg a derived type, is not known, but provided here.
   4713      1.1  mrg @item @var{src_type} @tab intent(in)  Give the type of the source.  When the
   4714      1.1  mrg source is not an array, than the precise type, e.g. of a component in a
   4715      1.1  mrg derived type, is not known, but provided here.
   4716      1.1  mrg @end multitable
   4717      1.1  mrg 
   4718      1.1  mrg @item @emph{NOTES}
   4719      1.1  mrg It is permitted to have the same image index for both @var{src_image_index} and
   4720      1.1  mrg @var{dst_image_index}; the memory of the send-to and the send-from might
   4721      1.1  mrg (partially) overlap in that case.  The implementation has to take care that it
   4722      1.1  mrg handles this case, e.g. using @code{memmove} which handles (partially)
   4723      1.1  mrg overlapping memory.  If @var{may_require_tmp} is true, the library
   4724      1.1  mrg might additionally create a temporary variable, unless additional checks show
   4725      1.1  mrg that this is not required (e.g. because walking backward is possible or because
   4726      1.1  mrg both arrays are contiguous and @code{memmove} takes care of overlap issues).
   4727      1.1  mrg 
   4728      1.1  mrg Note that the assignment of a scalar to an array is permitted.  In addition,
   4729      1.1  mrg the library has to handle numeric-type conversion and for strings, padding and
   4730      1.1  mrg different character kinds.
   4731      1.1  mrg 
   4732      1.1  mrg Because of the more complicated references possible some operations may be
   4733      1.1  mrg unsupported by certain libraries.  The library is expected to issue a precise
   4734      1.1  mrg error message why the operation is not permitted.
   4735      1.1  mrg @end table
   4736      1.1  mrg 
   4737      1.1  mrg 
   4738      1.1  mrg @node _gfortran_caf_lock
   4739      1.1  mrg @subsection @code{_gfortran_caf_lock} --- Locking a lock variable
   4740      1.1  mrg @cindex Coarray, _gfortran_caf_lock
   4741      1.1  mrg 
   4742      1.1  mrg @table @asis
   4743      1.1  mrg @item @emph{Description}:
   4744      1.1  mrg Acquire a lock on the given image on a scalar locking variable or for the
   4745  1.1.1.3  mrg given array element for an array-valued variable.  If the @var{acquired_lock}
   4746      1.1  mrg is @code{NULL}, the function returns after having obtained the lock.  If it is
   4747      1.1  mrg non-@code{NULL}, then @var{acquired_lock} is assigned the value true (one) when
   4748      1.1  mrg the lock could be obtained and false (zero) otherwise.  Locking a lock variable
   4749      1.1  mrg which has already been locked by the same image is an error.
   4750      1.1  mrg 
   4751      1.1  mrg @item @emph{Syntax}:
   4752      1.1  mrg @code{void _gfortran_caf_lock (caf_token_t token, size_t index, int image_index,
   4753  1.1.1.3  mrg int *acquired_lock, int *stat, char *errmsg, size_t errmsg_len)}
   4754      1.1  mrg 
   4755      1.1  mrg @item @emph{Arguments}:
   4756      1.1  mrg @multitable @columnfractions .15 .70
   4757      1.1  mrg @item @var{token} @tab intent(in)  An opaque pointer identifying the coarray.
   4758      1.1  mrg @item @var{index} @tab intent(in)  Array index; first array index is 0.  For
   4759      1.1  mrg scalars, it is always 0.
   4760      1.1  mrg @item @var{image_index} @tab intent(in)  The ID of the remote image; must be a
   4761      1.1  mrg positive number.
   4762  1.1.1.3  mrg @item @var{acquired_lock} @tab intent(out) If not NULL, it returns whether lock
   4763      1.1  mrg could be obtained.
   4764      1.1  mrg @item @var{stat} @tab intent(out) Stores the STAT=; may be NULL.
   4765      1.1  mrg @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
   4766      1.1  mrg an error message; may be NULL.
   4767      1.1  mrg @item @var{errmsg_len} @tab intent(in)  the buffer size of errmsg
   4768      1.1  mrg @end multitable
   4769      1.1  mrg 
   4770      1.1  mrg @item @emph{NOTES}
   4771      1.1  mrg This function is also called for critical blocks; for those, the array index
   4772      1.1  mrg is always zero and the image index is one.  Libraries are permitted to use other
   4773      1.1  mrg images for critical-block locking variables.
   4774      1.1  mrg @end table
   4775      1.1  mrg 
   4776      1.1  mrg @node _gfortran_caf_unlock
   4777      1.1  mrg @subsection @code{_gfortran_caf_lock} --- Unlocking a lock variable
   4778      1.1  mrg @cindex Coarray, _gfortran_caf_unlock
   4779      1.1  mrg 
   4780      1.1  mrg @table @asis
   4781      1.1  mrg @item @emph{Description}:
   4782      1.1  mrg Release a lock on the given image on a scalar locking variable or for the
   4783      1.1  mrg given array element for an array-valued variable. Unlocking a lock variable
   4784      1.1  mrg which is unlocked or has been locked by a different image is an error.
   4785      1.1  mrg 
   4786      1.1  mrg @item @emph{Syntax}:
   4787      1.1  mrg @code{void _gfortran_caf_unlock (caf_token_t token, size_t index, int image_index,
   4788      1.1  mrg int *stat, char *errmsg, size_t errmsg_len)}
   4789      1.1  mrg 
   4790      1.1  mrg @item @emph{Arguments}:
   4791      1.1  mrg @multitable @columnfractions .15 .70
   4792      1.1  mrg @item @var{token} @tab intent(in)  An opaque pointer identifying the coarray.
   4793      1.1  mrg @item @var{index} @tab intent(in)  Array index; first array index is 0.  For
   4794      1.1  mrg scalars, it is always 0.
   4795      1.1  mrg @item @var{image_index} @tab intent(in)  The ID of the remote image; must be a
   4796      1.1  mrg positive number.
   4797      1.1  mrg @item @var{stat} @tab intent(out) For allocatable coarrays, stores the STAT=;
   4798      1.1  mrg may be NULL.
   4799      1.1  mrg @item @var{errmsg} @tab intent(out) When an error occurs, this will be set to
   4800      1.1  mrg an error message; may be NULL.
   4801      1.1  mrg @item @var{errmsg_len} @tab intent(in)  the buffer size of errmsg
   4802      1.1  mrg @end multitable
   4803      1.1  mrg 
   4804      1.1  mrg @item @emph{NOTES}
   4805      1.1  mrg This function is also called for critical block; for those, the array index
   4806      1.1  mrg is always zero and the image index is one.  Libraries are permitted to use other
   4807      1.1  mrg images for critical-block locking variables.
   4808      1.1  mrg @end table
   4809      1.1  mrg 
   4810      1.1  mrg @node _gfortran_caf_event_post
   4811      1.1  mrg @subsection @code{_gfortran_caf_event_post} --- Post an event
   4812      1.1  mrg @cindex Coarray, _gfortran_caf_event_post
   4813      1.1  mrg 
   4814      1.1  mrg @table @asis
   4815      1.1  mrg @item @emph{Description}:
   4816      1.1  mrg Increment the event count of the specified event variable.
   4817      1.1  mrg 
   4818      1.1  mrg @item @emph{Syntax}:
   4819      1.1  mrg @code{void _gfortran_caf_event_post (caf_token_t token, size_t index,
   4820      1.1  mrg int image_index, int *stat, char *errmsg, size_t errmsg_len)}
   4821      1.1  mrg 
   4822      1.1  mrg @item @emph{Arguments}:
   4823      1.1  mrg @multitable @columnfractions .15 .70
   4824      1.1  mrg @item @var{token} @tab intent(in)  An opaque pointer identifying the coarray.
   4825      1.1  mrg @item @var{index} @tab intent(in)  Array index; first array index is 0.  For
   4826      1.1  mrg scalars, it is always 0.
   4827      1.1  mrg @item @var{image_index} @tab intent(in)  The ID of the remote image; must be a
   4828      1.1  mrg positive number; zero indicates the current image, when accessed noncoindexed.
   4829      1.1  mrg @item @var{stat} @tab intent(out)  Stores the STAT=; may be NULL.
   4830      1.1  mrg @item @var{errmsg} @tab intent(out)  When an error occurs, this will be set to
   4831      1.1  mrg an error message; may be NULL.
   4832      1.1  mrg @item @var{errmsg_len} @tab intent(in)  the buffer size of errmsg
   4833      1.1  mrg @end multitable
   4834      1.1  mrg 
   4835      1.1  mrg @item @emph{NOTES}
   4836      1.1  mrg This acts like an atomic add of one to the remote image's event variable.
   4837      1.1  mrg The statement is an image-control statement but does not imply sync memory.
   4838      1.1  mrg Still, all preceeding push communications of this image to the specified
   4839      1.1  mrg remote image have to be completed before @code{event_wait} on the remote
   4840      1.1  mrg image returns.
   4841      1.1  mrg @end table
   4842      1.1  mrg 
   4843      1.1  mrg 
   4844      1.1  mrg 
   4845      1.1  mrg @node _gfortran_caf_event_wait
   4846      1.1  mrg @subsection @code{_gfortran_caf_event_wait} --- Wait that an event occurred
   4847      1.1  mrg @cindex Coarray, _gfortran_caf_event_wait
   4848      1.1  mrg 
   4849      1.1  mrg @table @asis
   4850      1.1  mrg @item @emph{Description}:
   4851      1.1  mrg Wait until the event count has reached at least the specified
   4852      1.1  mrg @var{until_count}; if so, atomically decrement the event variable by this
   4853      1.1  mrg amount and return.
   4854      1.1  mrg 
   4855      1.1  mrg @item @emph{Syntax}:
   4856      1.1  mrg @code{void _gfortran_caf_event_wait (caf_token_t token, size_t index,
   4857      1.1  mrg int until_count, int *stat, char *errmsg, size_t errmsg_len)}
   4858      1.1  mrg 
   4859      1.1  mrg @item @emph{Arguments}:
   4860      1.1  mrg @multitable @columnfractions .15 .70
   4861      1.1  mrg @item @var{token} @tab intent(in)  An opaque pointer identifying the coarray.
   4862      1.1  mrg @item @var{index} @tab intent(in)  Array index; first array index is 0.  For
   4863      1.1  mrg scalars, it is always 0.
   4864      1.1  mrg @item @var{until_count} @tab intent(in)  The number of events which have to be
   4865      1.1  mrg available before the function returns.
   4866      1.1  mrg @item @var{stat} @tab intent(out)  Stores the STAT=; may be NULL.
   4867      1.1  mrg @item @var{errmsg} @tab intent(out)  When an error occurs, this will be set to
   4868      1.1  mrg an error message; may be NULL.
   4869      1.1  mrg @item @var{errmsg_len} @tab intent(in)  the buffer size of errmsg
   4870      1.1  mrg @end multitable
   4871      1.1  mrg 
   4872      1.1  mrg @item @emph{NOTES}
   4873      1.1  mrg This function only operates on a local coarray. It acts like a loop checking
   4874      1.1  mrg atomically the value of the event variable, breaking if the value is greater
   4875      1.1  mrg or equal the requested number of counts. Before the function returns, the
   4876      1.1  mrg event variable has to be decremented by the requested @var{until_count} value.
   4877      1.1  mrg A possible implementation would be a busy loop for a certain number of spins
   4878      1.1  mrg (possibly depending on the number of threads relative to the number of available
   4879      1.1  mrg cores) followed by another waiting strategy such as a sleeping wait (possibly
   4880      1.1  mrg with an increasing number of sleep time) or, if possible, a futex wait.
   4881      1.1  mrg 
   4882      1.1  mrg The statement is an image-control statement but does not imply sync memory.
   4883      1.1  mrg Still, all preceeding push communications of this image to the specified
   4884      1.1  mrg remote image have to be completed before @code{event_wait} on the remote
   4885      1.1  mrg image returns.
   4886      1.1  mrg @end table
   4887      1.1  mrg 
   4888      1.1  mrg 
   4889      1.1  mrg 
   4890      1.1  mrg @node _gfortran_caf_event_query
   4891      1.1  mrg @subsection @code{_gfortran_caf_event_query} --- Query event count
   4892      1.1  mrg @cindex Coarray, _gfortran_caf_event_query
   4893      1.1  mrg 
   4894      1.1  mrg @table @asis
   4895      1.1  mrg @item @emph{Description}:
   4896      1.1  mrg Return the event count of the specified event variable.
   4897      1.1  mrg 
   4898      1.1  mrg @item @emph{Syntax}:
   4899      1.1  mrg @code{void _gfortran_caf_event_query (caf_token_t token, size_t index,
   4900      1.1  mrg int image_index, int *count, int *stat)}
   4901      1.1  mrg 
   4902      1.1  mrg @item @emph{Arguments}:
   4903      1.1  mrg @multitable @columnfractions .15 .70
   4904      1.1  mrg @item @var{token} @tab intent(in)  An opaque pointer identifying the coarray.
   4905      1.1  mrg @item @var{index} @tab intent(in)  Array index; first array index is 0.  For
   4906      1.1  mrg scalars, it is always 0.
   4907      1.1  mrg @item @var{image_index} @tab intent(in)  The ID of the remote image; must be a
   4908      1.1  mrg positive number; zero indicates the current image when accessed noncoindexed.
   4909      1.1  mrg @item @var{count} @tab intent(out)  The number of events currently posted to
   4910      1.1  mrg the event variable.
   4911      1.1  mrg @item @var{stat} @tab intent(out)  Stores the STAT=; may be NULL.
   4912      1.1  mrg @end multitable
   4913      1.1  mrg 
   4914      1.1  mrg @item @emph{NOTES}
   4915      1.1  mrg The typical use is to check the local event variable to only call
   4916      1.1  mrg @code{event_wait} when the data is available. However, a coindexed variable
   4917      1.1  mrg is permitted; there is no ordering or synchronization implied.  It acts like
   4918      1.1  mrg an atomic fetch of the value of the event variable.
   4919      1.1  mrg @end table
   4920      1.1  mrg 
   4921      1.1  mrg 
   4922      1.1  mrg 
   4923      1.1  mrg @node _gfortran_caf_sync_all
   4924      1.1  mrg @subsection @code{_gfortran_caf_sync_all} --- All-image barrier
   4925      1.1  mrg @cindex Coarray, _gfortran_caf_sync_all
   4926      1.1  mrg 
   4927      1.1  mrg @table @asis
   4928      1.1  mrg @item @emph{Description}:
   4929      1.1  mrg Synchronization of all images in the current team; the program only continues
   4930      1.1  mrg on a given image after this function has been called on all images of the
   4931      1.1  mrg current team.  Additionally, it ensures that all pending data transfers of
   4932      1.1  mrg previous segment have completed.
   4933      1.1  mrg 
   4934      1.1  mrg @item @emph{Syntax}:
   4935      1.1  mrg @code{void _gfortran_caf_sync_all (int *stat, char *errmsg, size_t errmsg_len)}
   4936      1.1  mrg 
   4937      1.1  mrg @item @emph{Arguments}:
   4938      1.1  mrg @multitable @columnfractions .15 .70
   4939      1.1  mrg @item @var{stat} @tab intent(out)  Stores the status STAT= and may be NULL.
   4940      1.1  mrg @item @var{errmsg} @tab intent(out)  When an error occurs, this will be set to
   4941      1.1  mrg an error message; may be NULL.
   4942      1.1  mrg @item @var{errmsg_len} @tab intent(in)  the buffer size of errmsg
   4943      1.1  mrg @end multitable
   4944      1.1  mrg @end table
   4945      1.1  mrg 
   4946      1.1  mrg 
   4947      1.1  mrg 
   4948      1.1  mrg @node _gfortran_caf_sync_images
   4949      1.1  mrg @subsection @code{_gfortran_caf_sync_images} --- Barrier for selected images
   4950      1.1  mrg @cindex Coarray, _gfortran_caf_sync_images
   4951      1.1  mrg 
   4952      1.1  mrg @table @asis
   4953      1.1  mrg @item @emph{Description}:
   4954      1.1  mrg Synchronization between the specified images; the program only continues on a
   4955      1.1  mrg given image after this function has been called on all images specified for
   4956      1.1  mrg that image. Note that one image can wait for all other images in the current
   4957      1.1  mrg team (e.g. via @code{sync images(*)}) while those only wait for that specific
   4958      1.1  mrg image.  Additionally, @code{sync images} ensures that all pending data
   4959      1.1  mrg transfers of previous segments have completed.
   4960      1.1  mrg 
   4961      1.1  mrg @item @emph{Syntax}:
   4962      1.1  mrg @code{void _gfortran_caf_sync_images (int count, int images[], int *stat,
   4963      1.1  mrg char *errmsg, size_t errmsg_len)}
   4964      1.1  mrg 
   4965      1.1  mrg @item @emph{Arguments}:
   4966      1.1  mrg @multitable @columnfractions .15 .70
   4967      1.1  mrg @item @var{count} @tab intent(in)  The number of images which are provided in
   4968      1.1  mrg the next argument.  For a zero-sized array, the value is zero.  For
   4969      1.1  mrg @code{sync images (*)}, the value is @math{-1}.
   4970      1.1  mrg @item @var{images} @tab intent(in)  An array with the images provided by the
   4971      1.1  mrg user.  If @var{count} is zero, a NULL pointer is passed.
   4972      1.1  mrg @item @var{stat} @tab intent(out)  Stores the status STAT= and may be NULL.
   4973      1.1  mrg @item @var{errmsg} @tab intent(out)  When an error occurs, this will be set to
   4974      1.1  mrg an error message; may be NULL.
   4975      1.1  mrg @item @var{errmsg_len} @tab intent(in)  the buffer size of errmsg
   4976      1.1  mrg @end multitable
   4977      1.1  mrg @end table
   4978      1.1  mrg 
   4979      1.1  mrg 
   4980      1.1  mrg 
   4981      1.1  mrg @node _gfortran_caf_sync_memory
   4982      1.1  mrg @subsection @code{_gfortran_caf_sync_memory} --- Wait for completion of segment-memory operations
   4983      1.1  mrg @cindex Coarray, _gfortran_caf_sync_memory
   4984      1.1  mrg 
   4985      1.1  mrg @table @asis
   4986      1.1  mrg @item @emph{Description}:
   4987      1.1  mrg Acts as optimization barrier between different segments. It also ensures that
   4988      1.1  mrg all pending memory operations of this image have been completed.
   4989      1.1  mrg 
   4990      1.1  mrg @item @emph{Syntax}:
   4991      1.1  mrg @code{void _gfortran_caf_sync_memory (int *stat, char *errmsg, size_t errmsg_len)}
   4992      1.1  mrg 
   4993      1.1  mrg @item @emph{Arguments}:
   4994      1.1  mrg @multitable @columnfractions .15 .70
   4995      1.1  mrg @item @var{stat} @tab intent(out)  Stores the status STAT= and may be NULL.
   4996      1.1  mrg @item @var{errmsg} @tab intent(out)  When an error occurs, this will be set to
   4997      1.1  mrg an error message; may be NULL.
   4998      1.1  mrg @item @var{errmsg_len} @tab intent(in)  the buffer size of errmsg
   4999      1.1  mrg @end multitable
   5000      1.1  mrg 
   5001      1.1  mrg @item @emph{NOTE} A simple implementation could be
   5002      1.1  mrg @code{__asm__ __volatile__ ("":::"memory")} to prevent code movements.
   5003      1.1  mrg @end table
   5004      1.1  mrg 
   5005      1.1  mrg 
   5006      1.1  mrg 
   5007      1.1  mrg @node _gfortran_caf_error_stop
   5008      1.1  mrg @subsection @code{_gfortran_caf_error_stop} --- Error termination with exit code
   5009      1.1  mrg @cindex Coarray, _gfortran_caf_error_stop
   5010      1.1  mrg 
   5011      1.1  mrg @table @asis
   5012      1.1  mrg @item @emph{Description}:
   5013      1.1  mrg Invoked for an @code{ERROR STOP} statement which has an integer argument.  The
   5014      1.1  mrg function should terminate the program with the specified exit code.
   5015      1.1  mrg 
   5016      1.1  mrg 
   5017      1.1  mrg @item @emph{Syntax}:
   5018      1.1  mrg @code{void _gfortran_caf_error_stop (int error)}
   5019      1.1  mrg 
   5020      1.1  mrg @item @emph{Arguments}:
   5021      1.1  mrg @multitable @columnfractions .15 .70
   5022      1.1  mrg @item @var{error} @tab intent(in)  The exit status to be used.
   5023      1.1  mrg @end multitable
   5024      1.1  mrg @end table
   5025      1.1  mrg 
   5026      1.1  mrg 
   5027      1.1  mrg 
   5028      1.1  mrg @node _gfortran_caf_error_stop_str
   5029      1.1  mrg @subsection @code{_gfortran_caf_error_stop_str} --- Error termination with string
   5030      1.1  mrg @cindex Coarray, _gfortran_caf_error_stop_str
   5031      1.1  mrg 
   5032      1.1  mrg @table @asis
   5033      1.1  mrg @item @emph{Description}:
   5034      1.1  mrg Invoked for an @code{ERROR STOP} statement which has a string as argument.  The
   5035      1.1  mrg function should terminate the program with a nonzero-exit code.
   5036      1.1  mrg 
   5037      1.1  mrg @item @emph{Syntax}:
   5038      1.1  mrg @code{void _gfortran_caf_error_stop (const char *string, size_t len)}
   5039      1.1  mrg 
   5040      1.1  mrg @item @emph{Arguments}:
   5041      1.1  mrg @multitable @columnfractions .15 .70
   5042      1.1  mrg @item @var{string} @tab intent(in)  the error message (not zero terminated)
   5043      1.1  mrg @item @var{len} @tab intent(in)  the length of the string
   5044      1.1  mrg @end multitable
   5045      1.1  mrg @end table
   5046      1.1  mrg 
   5047      1.1  mrg 
   5048      1.1  mrg 
   5049      1.1  mrg @node _gfortran_caf_fail_image
   5050      1.1  mrg @subsection @code{_gfortran_caf_fail_image} --- Mark the image failed and end its execution
   5051      1.1  mrg @cindex Coarray, _gfortran_caf_fail_image
   5052      1.1  mrg 
   5053      1.1  mrg @table @asis
   5054      1.1  mrg @item @emph{Description}:
   5055      1.1  mrg Invoked for an @code{FAIL IMAGE} statement.  The function should terminate the
   5056      1.1  mrg current image.
   5057      1.1  mrg 
   5058      1.1  mrg @item @emph{Syntax}:
   5059      1.1  mrg @code{void _gfortran_caf_fail_image ()}
   5060      1.1  mrg 
   5061      1.1  mrg @item @emph{NOTES}
   5062      1.1  mrg This function follows TS18508.
   5063      1.1  mrg @end table
   5064      1.1  mrg 
   5065      1.1  mrg 
   5066      1.1  mrg 
   5067      1.1  mrg @node _gfortran_caf_atomic_define
   5068      1.1  mrg @subsection @code{_gfortran_caf_atomic_define} --- Atomic variable assignment
   5069      1.1  mrg @cindex Coarray, _gfortran_caf_atomic_define
   5070      1.1  mrg 
   5071      1.1  mrg @table @asis
   5072      1.1  mrg @item @emph{Description}:
   5073      1.1  mrg Assign atomically a value to an integer or logical variable.
   5074      1.1  mrg 
   5075      1.1  mrg @item @emph{Syntax}:
   5076      1.1  mrg @code{void _gfortran_caf_atomic_define (caf_token_t token, size_t offset,
   5077      1.1  mrg int image_index, void *value, int *stat, int type, int kind)}
   5078      1.1  mrg 
   5079      1.1  mrg @item @emph{Arguments}:
   5080      1.1  mrg @multitable @columnfractions .15 .70
   5081      1.1  mrg @item @var{token} @tab intent(in)  An opaque pointer identifying the coarray.
   5082      1.1  mrg @item @var{offset} @tab intent(in)  By which amount of bytes the actual data is
   5083      1.1  mrg shifted compared to the base address of the coarray.
   5084      1.1  mrg @item @var{image_index} @tab intent(in)  The ID of the remote image; must be a
   5085      1.1  mrg positive number; zero indicates the current image when used noncoindexed.
   5086      1.1  mrg @item @var{value} @tab intent(in)  the value to be assigned, passed by reference
   5087      1.1  mrg @item @var{stat} @tab intent(out)  Stores the status STAT= and may be NULL.
   5088      1.1  mrg @item @var{type} @tab intent(in)  The data type, i.e. @code{BT_INTEGER} (1) or
   5089      1.1  mrg @code{BT_LOGICAL} (2).
   5090      1.1  mrg @item @var{kind} @tab intent(in)  The kind value (only 4; always @code{int})
   5091      1.1  mrg @end multitable
   5092      1.1  mrg @end table
   5093      1.1  mrg 
   5094      1.1  mrg 
   5095      1.1  mrg 
   5096      1.1  mrg @node _gfortran_caf_atomic_ref
   5097      1.1  mrg @subsection @code{_gfortran_caf_atomic_ref} --- Atomic variable reference
   5098      1.1  mrg @cindex Coarray, _gfortran_caf_atomic_ref
   5099      1.1  mrg 
   5100      1.1  mrg @table @asis
   5101      1.1  mrg @item @emph{Description}:
   5102      1.1  mrg Reference atomically a value of a kind-4 integer or logical variable.
   5103      1.1  mrg 
   5104      1.1  mrg @item @emph{Syntax}:
   5105      1.1  mrg @code{void _gfortran_caf_atomic_ref (caf_token_t token, size_t offset,
   5106      1.1  mrg int image_index, void *value, int *stat, int type, int kind)}
   5107      1.1  mrg 
   5108      1.1  mrg @item @emph{Arguments}:
   5109      1.1  mrg @multitable @columnfractions .15 .70
   5110      1.1  mrg @item @var{token} @tab intent(in)  An opaque pointer identifying the coarray.
   5111      1.1  mrg @item @var{offset} @tab intent(in)  By which amount of bytes the actual data is
   5112      1.1  mrg shifted compared to the base address of the coarray.
   5113      1.1  mrg @item @var{image_index} @tab intent(in)  The ID of the remote image; must be a
   5114      1.1  mrg positive number; zero indicates the current image when used noncoindexed.
   5115      1.1  mrg @item @var{value} @tab intent(out)  The variable assigned the atomically
   5116      1.1  mrg referenced variable.
   5117      1.1  mrg @item @var{stat} @tab intent(out) Stores the status STAT= and may be NULL.
   5118      1.1  mrg @item @var{type} @tab the data type, i.e. @code{BT_INTEGER} (1) or
   5119      1.1  mrg @code{BT_LOGICAL} (2).
   5120      1.1  mrg @item @var{kind} @tab The kind value (only 4; always @code{int})
   5121      1.1  mrg @end multitable
   5122      1.1  mrg @end table
   5123      1.1  mrg 
   5124      1.1  mrg 
   5125      1.1  mrg 
   5126      1.1  mrg @node _gfortran_caf_atomic_cas
   5127      1.1  mrg @subsection @code{_gfortran_caf_atomic_cas} --- Atomic compare and swap
   5128      1.1  mrg @cindex Coarray, _gfortran_caf_atomic_cas
   5129      1.1  mrg 
   5130      1.1  mrg @table @asis
   5131      1.1  mrg @item @emph{Description}:
   5132      1.1  mrg Atomic compare and swap of a kind-4 integer or logical variable. Assigns
   5133      1.1  mrg atomically the specified value to the atomic variable, if the latter has
   5134      1.1  mrg the value specified by the passed condition value.
   5135      1.1  mrg 
   5136      1.1  mrg @item @emph{Syntax}:
   5137      1.1  mrg @code{void _gfortran_caf_atomic_cas (caf_token_t token, size_t offset,
   5138      1.1  mrg int image_index, void *old, void *compare, void *new_val, int *stat,
   5139      1.1  mrg int type, int kind)}
   5140      1.1  mrg 
   5141      1.1  mrg @item @emph{Arguments}:
   5142      1.1  mrg @multitable @columnfractions .15 .70
   5143      1.1  mrg @item @var{token} @tab intent(in)  An opaque pointer identifying the coarray.
   5144      1.1  mrg @item @var{offset} @tab intent(in)  By which amount of bytes the actual data is
   5145      1.1  mrg shifted compared to the base address of the coarray.
   5146      1.1  mrg @item @var{image_index} @tab intent(in)  The ID of the remote image; must be a
   5147      1.1  mrg positive number; zero indicates the current image when used noncoindexed.
   5148      1.1  mrg @item @var{old} @tab intent(out)  The value which the atomic variable had
   5149      1.1  mrg just before the cas operation.
   5150      1.1  mrg @item @var{compare} @tab intent(in)  The value used for comparision.
   5151      1.1  mrg @item @var{new_val} @tab intent(in)  The new value for the atomic variable,
   5152      1.1  mrg assigned to the atomic variable, if @code{compare} equals the value of the
   5153      1.1  mrg atomic variable.
   5154      1.1  mrg @item @var{stat} @tab intent(out)  Stores the status STAT= and may be NULL.
   5155      1.1  mrg @item @var{type} @tab intent(in)  the data type, i.e. @code{BT_INTEGER} (1) or
   5156      1.1  mrg @code{BT_LOGICAL} (2).
   5157      1.1  mrg @item @var{kind} @tab intent(in)  The kind value (only 4; always @code{int})
   5158      1.1  mrg @end multitable
   5159      1.1  mrg @end table
   5160      1.1  mrg 
   5161      1.1  mrg 
   5162      1.1  mrg 
   5163      1.1  mrg @node _gfortran_caf_atomic_op
   5164      1.1  mrg @subsection @code{_gfortran_caf_atomic_op} --- Atomic operation
   5165      1.1  mrg @cindex Coarray, _gfortran_caf_atomic_op
   5166      1.1  mrg 
   5167      1.1  mrg @table @asis
   5168      1.1  mrg @item @emph{Description}:
   5169      1.1  mrg Apply an operation atomically to an atomic integer or logical variable.
   5170      1.1  mrg After the operation, @var{old} contains the value just before the operation,
   5171      1.1  mrg which, respectively, adds (GFC_CAF_ATOMIC_ADD) atomically the @code{value} to
   5172      1.1  mrg the atomic integer variable or does a bitwise AND, OR or exclusive OR
   5173      1.1  mrg between the atomic variable and @var{value}; the result is then stored in the
   5174      1.1  mrg atomic variable.
   5175      1.1  mrg 
   5176      1.1  mrg @item @emph{Syntax}:
   5177      1.1  mrg @code{void _gfortran_caf_atomic_op (int op, caf_token_t token, size_t offset,
   5178      1.1  mrg int image_index, void *value, void *old, int *stat, int type, int kind)}
   5179      1.1  mrg 
   5180      1.1  mrg @item @emph{Arguments}:
   5181      1.1  mrg @multitable @columnfractions .15 .70
   5182      1.1  mrg @item @var{op} @tab intent(in)  the operation to be performed; possible values
   5183      1.1  mrg @code{GFC_CAF_ATOMIC_ADD} (1), @code{GFC_CAF_ATOMIC_AND} (2),
   5184      1.1  mrg @code{GFC_CAF_ATOMIC_OR} (3), @code{GFC_CAF_ATOMIC_XOR} (4).
   5185      1.1  mrg @item @var{token} @tab intent(in)  An opaque pointer identifying the coarray.
   5186      1.1  mrg @item @var{offset} @tab intent(in)  By which amount of bytes the actual data is
   5187      1.1  mrg shifted compared to the base address of the coarray.
   5188      1.1  mrg @item @var{image_index} @tab intent(in)  The ID of the remote image; must be a
   5189      1.1  mrg positive number; zero indicates the current image when used noncoindexed.
   5190      1.1  mrg @item @var{old} @tab intent(out)  The value which the atomic variable had
   5191      1.1  mrg just before the atomic operation.
   5192      1.1  mrg @item @var{val} @tab intent(in)  The new value for the atomic variable,
   5193      1.1  mrg assigned to the atomic variable, if @code{compare} equals the value of the
   5194      1.1  mrg atomic variable.
   5195      1.1  mrg @item @var{stat} @tab intent(out)  Stores the status STAT= and may be NULL.
   5196      1.1  mrg @item @var{type} @tab intent(in)  the data type, i.e. @code{BT_INTEGER} (1) or
   5197      1.1  mrg @code{BT_LOGICAL} (2)
   5198      1.1  mrg @item @var{kind} @tab intent(in)  the kind value (only 4; always @code{int})
   5199      1.1  mrg @end multitable
   5200      1.1  mrg @end table
   5201      1.1  mrg 
   5202      1.1  mrg 
   5203      1.1  mrg 
   5204      1.1  mrg 
   5205      1.1  mrg @node _gfortran_caf_co_broadcast
   5206      1.1  mrg @subsection @code{_gfortran_caf_co_broadcast} --- Sending data to all images
   5207      1.1  mrg @cindex Coarray, _gfortran_caf_co_broadcast
   5208      1.1  mrg 
   5209      1.1  mrg @table @asis
   5210      1.1  mrg @item @emph{Description}:
   5211      1.1  mrg Distribute a value from a given image to all other images in the team. Has to
   5212      1.1  mrg be called collectively.
   5213      1.1  mrg 
   5214      1.1  mrg @item @emph{Syntax}:
   5215      1.1  mrg @code{void _gfortran_caf_co_broadcast (gfc_descriptor_t *a,
   5216      1.1  mrg int source_image, int *stat, char *errmsg, size_t errmsg_len)}
   5217      1.1  mrg 
   5218      1.1  mrg @item @emph{Arguments}:
   5219      1.1  mrg @multitable @columnfractions .15 .70
   5220      1.1  mrg @item @var{a} @tab intent(inout)  An array descriptor with the data to be
   5221      1.1  mrg broadcasted (on @var{source_image}) or to be received (other images).
   5222      1.1  mrg @item @var{source_image} @tab intent(in)  The ID of the image from which the
   5223      1.1  mrg data should be broadcasted.
   5224      1.1  mrg @item @var{stat} @tab intent(out)  Stores the status STAT= and may be NULL.
   5225      1.1  mrg @item @var{errmsg} @tab intent(out)  When an error occurs, this will be set to
   5226      1.1  mrg an error message; may be NULL.
   5227      1.1  mrg @item @var{errmsg_len} @tab intent(in)  the buffer size of errmsg.
   5228      1.1  mrg @end multitable
   5229      1.1  mrg @end table
   5230      1.1  mrg 
   5231      1.1  mrg 
   5232      1.1  mrg 
   5233      1.1  mrg @node _gfortran_caf_co_max
   5234      1.1  mrg @subsection @code{_gfortran_caf_co_max} --- Collective maximum reduction
   5235      1.1  mrg @cindex Coarray, _gfortran_caf_co_max
   5236      1.1  mrg 
   5237      1.1  mrg @table @asis
   5238      1.1  mrg @item @emph{Description}:
   5239      1.1  mrg Calculates for each array element of the variable @var{a} the maximum
   5240      1.1  mrg value for that element in the current team; if @var{result_image} has the
   5241      1.1  mrg value 0, the result shall be stored on all images, otherwise, only on the
   5242      1.1  mrg specified image. This function operates on numeric values and character
   5243      1.1  mrg strings.
   5244      1.1  mrg 
   5245      1.1  mrg @item @emph{Syntax}:
   5246      1.1  mrg @code{void _gfortran_caf_co_max (gfc_descriptor_t *a, int result_image,
   5247      1.1  mrg int *stat, char *errmsg, int a_len, size_t errmsg_len)}
   5248      1.1  mrg 
   5249      1.1  mrg @item @emph{Arguments}:
   5250      1.1  mrg @multitable @columnfractions .15 .70
   5251      1.1  mrg @item @var{a} @tab intent(inout)  An array descriptor for the data to be
   5252      1.1  mrg processed.  On the destination image(s) the result overwrites the old content.
   5253      1.1  mrg @item @var{result_image} @tab intent(in)  The ID of the image to which the
   5254      1.1  mrg reduced value should be copied to; if zero, it has to be copied to all images.
   5255      1.1  mrg @item @var{stat} @tab intent(out)  Stores the status STAT= and may be NULL.
   5256      1.1  mrg @item @var{errmsg} @tab intent(out)  When an error occurs, this will be set to
   5257      1.1  mrg an error message; may be NULL.
   5258      1.1  mrg @item @var{a_len} @tab intent(in)  the string length of argument @var{a}
   5259      1.1  mrg @item @var{errmsg_len} @tab intent(in)  the buffer size of errmsg
   5260      1.1  mrg @end multitable
   5261      1.1  mrg 
   5262      1.1  mrg @item @emph{NOTES}
   5263      1.1  mrg If @var{result_image} is nonzero, the data in the array descriptor @var{a} on
   5264      1.1  mrg all images except of the specified one become undefined; hence, the library may
   5265      1.1  mrg make use of this.
   5266      1.1  mrg @end table
   5267      1.1  mrg 
   5268      1.1  mrg 
   5269      1.1  mrg 
   5270      1.1  mrg @node _gfortran_caf_co_min
   5271      1.1  mrg @subsection @code{_gfortran_caf_co_min} --- Collective minimum reduction
   5272      1.1  mrg @cindex Coarray, _gfortran_caf_co_min
   5273      1.1  mrg 
   5274      1.1  mrg @table @asis
   5275      1.1  mrg @item @emph{Description}:
   5276      1.1  mrg Calculates for each array element of the variable @var{a} the minimum
   5277      1.1  mrg value for that element in the current team; if @var{result_image} has the
   5278      1.1  mrg value 0, the result shall be stored on all images, otherwise, only on the
   5279      1.1  mrg specified image. This function operates on numeric values and character
   5280      1.1  mrg strings.
   5281      1.1  mrg 
   5282      1.1  mrg @item @emph{Syntax}:
   5283      1.1  mrg @code{void _gfortran_caf_co_min (gfc_descriptor_t *a, int result_image,
   5284      1.1  mrg int *stat, char *errmsg, int a_len, size_t errmsg_len)}
   5285      1.1  mrg 
   5286      1.1  mrg @item @emph{Arguments}:
   5287      1.1  mrg @multitable @columnfractions .15 .70
   5288      1.1  mrg @item @var{a} @tab intent(inout)  An array descriptor for the data to be
   5289      1.1  mrg processed.  On the destination image(s) the result overwrites the old content.
   5290      1.1  mrg @item @var{result_image} @tab intent(in)  The ID of the image to which the
   5291      1.1  mrg reduced value should be copied to; if zero, it has to be copied to all images.
   5292      1.1  mrg @item @var{stat} @tab intent(out)  Stores the status STAT= and may be NULL.
   5293      1.1  mrg @item @var{errmsg} @tab intent(out)  When an error occurs, this will be set to
   5294      1.1  mrg an error message; may be NULL.
   5295      1.1  mrg @item @var{a_len} @tab intent(in)  the string length of argument @var{a}
   5296      1.1  mrg @item @var{errmsg_len} @tab intent(in)  the buffer size of errmsg
   5297      1.1  mrg @end multitable
   5298      1.1  mrg 
   5299      1.1  mrg @item @emph{NOTES}
   5300      1.1  mrg If @var{result_image} is nonzero, the data in the array descriptor @var{a} on
   5301      1.1  mrg all images except of the specified one become undefined; hence, the library may
   5302      1.1  mrg make use of this.
   5303      1.1  mrg @end table
   5304      1.1  mrg 
   5305      1.1  mrg 
   5306      1.1  mrg 
   5307      1.1  mrg @node _gfortran_caf_co_sum
   5308      1.1  mrg @subsection @code{_gfortran_caf_co_sum} --- Collective summing reduction
   5309      1.1  mrg @cindex Coarray, _gfortran_caf_co_sum
   5310      1.1  mrg 
   5311      1.1  mrg @table @asis
   5312      1.1  mrg @item @emph{Description}:
   5313      1.1  mrg Calculates for each array element of the variable @var{a} the sum of all
   5314      1.1  mrg values for that element in the current team; if @var{result_image} has the
   5315      1.1  mrg value 0, the result shall be stored on all images, otherwise, only on the
   5316      1.1  mrg specified image.  This function operates on numeric values only.
   5317      1.1  mrg 
   5318      1.1  mrg @item @emph{Syntax}:
   5319      1.1  mrg @code{void _gfortran_caf_co_sum (gfc_descriptor_t *a, int result_image,
   5320      1.1  mrg int *stat, char *errmsg, size_t errmsg_len)}
   5321      1.1  mrg 
   5322      1.1  mrg @item @emph{Arguments}:
   5323      1.1  mrg @multitable @columnfractions .15 .70
   5324      1.1  mrg @item @var{a} @tab intent(inout)  An array descriptor with the data to be
   5325      1.1  mrg processed.  On the destination image(s) the result overwrites the old content.
   5326      1.1  mrg @item @var{result_image} @tab intent(in)  The ID of the image to which the
   5327      1.1  mrg reduced value should be copied to; if zero, it has to be copied to all images.
   5328      1.1  mrg @item @var{stat} @tab intent(out)  Stores the status STAT= and may be NULL.
   5329      1.1  mrg @item @var{errmsg} @tab intent(out)  When an error occurs, this will be set to
   5330      1.1  mrg an error message; may be NULL.
   5331      1.1  mrg @item @var{errmsg_len} @tab intent(in)  the buffer size of errmsg
   5332      1.1  mrg @end multitable
   5333      1.1  mrg 
   5334      1.1  mrg @item @emph{NOTES}
   5335      1.1  mrg If @var{result_image} is nonzero, the data in the array descriptor @var{a} on
   5336      1.1  mrg all images except of the specified one become undefined; hence, the library may
   5337      1.1  mrg make use of this.
   5338      1.1  mrg @end table
   5339      1.1  mrg 
   5340      1.1  mrg 
   5341      1.1  mrg 
   5342      1.1  mrg @node _gfortran_caf_co_reduce
   5343      1.1  mrg @subsection @code{_gfortran_caf_co_reduce} --- Generic collective reduction
   5344      1.1  mrg @cindex Coarray, _gfortran_caf_co_reduce
   5345      1.1  mrg 
   5346      1.1  mrg @table @asis
   5347      1.1  mrg @item @emph{Description}:
   5348      1.1  mrg Calculates for each array element of the variable @var{a} the reduction
   5349      1.1  mrg value for that element in the current team; if @var{result_image} has the
   5350      1.1  mrg value 0, the result shall be stored on all images, otherwise, only on the
   5351      1.1  mrg specified image.  The @var{opr} is a pure function doing a mathematically
   5352      1.1  mrg commutative and associative operation.
   5353      1.1  mrg 
   5354      1.1  mrg The @var{opr_flags} denote the following; the values are bitwise ored.
   5355      1.1  mrg @code{GFC_CAF_BYREF} (1) if the result should be returned
   5356      1.1  mrg by reference; @code{GFC_CAF_HIDDENLEN} (2) whether the result and argument
   5357      1.1  mrg string lengths shall be specified as hidden arguments;
   5358      1.1  mrg @code{GFC_CAF_ARG_VALUE} (4) whether the arguments shall be passed by value,
   5359      1.1  mrg @code{GFC_CAF_ARG_DESC} (8) whether the arguments shall be passed by descriptor.
   5360      1.1  mrg 
   5361      1.1  mrg 
   5362      1.1  mrg @item @emph{Syntax}:
   5363      1.1  mrg @code{void _gfortran_caf_co_reduce (gfc_descriptor_t *a,
   5364      1.1  mrg void * (*opr) (void *, void *), int opr_flags, int result_image,
   5365      1.1  mrg int *stat, char *errmsg, int a_len, size_t errmsg_len)}
   5366      1.1  mrg 
   5367      1.1  mrg @item @emph{Arguments}:
   5368      1.1  mrg @multitable @columnfractions .15 .70
   5369      1.1  mrg @item @var{a} @tab intent(inout)  An array descriptor with the data to be
   5370      1.1  mrg processed.  On the destination image(s) the result overwrites the old content.
   5371      1.1  mrg @item @var{opr} @tab intent(in)  Function pointer to the reduction function
   5372      1.1  mrg @item @var{opr_flags} @tab intent(in)  Flags regarding the reduction function
   5373      1.1  mrg @item @var{result_image} @tab intent(in)  The ID of the image to which the
   5374      1.1  mrg reduced value should be copied to; if zero, it has to be copied to all images.
   5375      1.1  mrg @item @var{stat} @tab intent(out)  Stores the status STAT= and may be NULL.
   5376      1.1  mrg @item @var{errmsg} @tab intent(out)  When an error occurs, this will be set to
   5377      1.1  mrg an error message; may be NULL.
   5378      1.1  mrg @item @var{a_len} @tab intent(in)  the string length of argument @var{a}
   5379      1.1  mrg @item @var{errmsg_len} @tab intent(in)  the buffer size of errmsg
   5380      1.1  mrg @end multitable
   5381      1.1  mrg 
   5382      1.1  mrg @item @emph{NOTES}
   5383      1.1  mrg If @var{result_image} is nonzero, the data in the array descriptor @var{a} on
   5384      1.1  mrg all images except of the specified one become undefined; hence, the library may
   5385      1.1  mrg make use of this.
   5386      1.1  mrg 
   5387      1.1  mrg For character arguments, the result is passed as first argument, followed
   5388      1.1  mrg by the result string length, next come the two string arguments, followed
   5389      1.1  mrg by the two hidden string length arguments.  With C binding, there are no hidden
   5390      1.1  mrg arguments and by-reference passing and either only a single character is passed
   5391      1.1  mrg or an array descriptor.
   5392      1.1  mrg @end table
   5393      1.1  mrg 
   5394      1.1  mrg 
   5395      1.1  mrg @c Intrinsic Procedures
   5396      1.1  mrg @c ---------------------------------------------------------------------
   5397      1.1  mrg 
   5398      1.1  mrg @include intrinsic.texi
   5399      1.1  mrg 
   5400      1.1  mrg 
   5401      1.1  mrg @tex
   5402      1.1  mrg \blankpart
   5403      1.1  mrg @end tex
   5404      1.1  mrg 
   5405      1.1  mrg @c ---------------------------------------------------------------------
   5406      1.1  mrg @c Contributing
   5407      1.1  mrg @c ---------------------------------------------------------------------
   5408      1.1  mrg 
   5409      1.1  mrg @node Contributing
   5410      1.1  mrg @unnumbered Contributing
   5411      1.1  mrg @cindex Contributing
   5412      1.1  mrg 
   5413      1.1  mrg Free software is only possible if people contribute to efforts
   5414      1.1  mrg to create it.
   5415      1.1  mrg We're always in need of more people helping out with ideas
   5416      1.1  mrg and comments, writing documentation and contributing code.
   5417      1.1  mrg 
   5418      1.1  mrg If you want to contribute to GNU Fortran,
   5419      1.1  mrg have a look at the long lists of projects you can take on.
   5420      1.1  mrg Some of these projects are small,
   5421      1.1  mrg some of them are large;
   5422      1.1  mrg some are completely orthogonal to the rest of what is
   5423      1.1  mrg happening on GNU Fortran,
   5424      1.1  mrg but others are ``mainstream'' projects in need of enthusiastic hackers.
   5425      1.1  mrg All of these projects are important!
   5426      1.1  mrg We will eventually get around to the things here,
   5427      1.1  mrg but they are also things doable by someone who is willing and able.
   5428      1.1  mrg 
   5429      1.1  mrg @menu
   5430      1.1  mrg * Contributors::
   5431      1.1  mrg * Projects::
   5432      1.1  mrg @end menu
   5433      1.1  mrg 
   5434      1.1  mrg 
   5435      1.1  mrg @node Contributors
   5436      1.1  mrg @section Contributors to GNU Fortran
   5437      1.1  mrg @cindex Contributors
   5438      1.1  mrg @cindex Credits
   5439      1.1  mrg @cindex Authors
   5440      1.1  mrg 
   5441      1.1  mrg Most of the parser was hand-crafted by @emph{Andy Vaught}, who is
   5442      1.1  mrg also the initiator of the whole project.  Thanks Andy!
   5443      1.1  mrg Most of the interface with GCC was written by @emph{Paul Brook}.
   5444      1.1  mrg 
   5445      1.1  mrg The following individuals have contributed code and/or
   5446      1.1  mrg ideas and significant help to the GNU Fortran project
   5447      1.1  mrg (in alphabetical order):
   5448      1.1  mrg 
   5449      1.1  mrg @itemize @minus
   5450      1.1  mrg @item Janne Blomqvist
   5451      1.1  mrg @item Steven Bosscher
   5452      1.1  mrg @item Paul Brook
   5453      1.1  mrg @item Tobias Burnus
   5454      1.1  mrg @item Fran@,{c}ois-Xavier Coudert
   5455      1.1  mrg @item Bud Davis
   5456      1.1  mrg @item Jerry DeLisle
   5457      1.1  mrg @item Erik Edelmann
   5458      1.1  mrg @item Bernhard Fischer
   5459      1.1  mrg @item Daniel Franke
   5460      1.1  mrg @item Richard Guenther
   5461      1.1  mrg @item Richard Henderson
   5462      1.1  mrg @item Katherine Holcomb
   5463      1.1  mrg @item Jakub Jelinek
   5464      1.1  mrg @item Niels Kristian Bech Jensen
   5465      1.1  mrg @item Steven Johnson
   5466      1.1  mrg @item Steven G. Kargl
   5467      1.1  mrg @item Thomas Koenig
   5468      1.1  mrg @item Asher Langton
   5469      1.1  mrg @item H. J. Lu
   5470      1.1  mrg @item Toon Moene
   5471      1.1  mrg @item Brooks Moses
   5472      1.1  mrg @item Andrew Pinski
   5473      1.1  mrg @item Tim Prince
   5474      1.1  mrg @item Christopher D. Rickett
   5475      1.1  mrg @item Richard Sandiford
   5476      1.1  mrg @item Tobias Schl@"uter
   5477      1.1  mrg @item Roger Sayle
   5478      1.1  mrg @item Paul Thomas
   5479      1.1  mrg @item Andy Vaught
   5480      1.1  mrg @item Feng Wang
   5481      1.1  mrg @item Janus Weil
   5482      1.1  mrg @item Daniel Kraft
   5483      1.1  mrg @end itemize
   5484      1.1  mrg 
   5485      1.1  mrg The following people have contributed bug reports,
   5486      1.1  mrg smaller or larger patches,
   5487      1.1  mrg and much needed feedback and encouragement for the
   5488      1.1  mrg GNU Fortran project:
   5489      1.1  mrg 
   5490      1.1  mrg @itemize @minus
   5491      1.1  mrg @item Bill Clodius
   5492      1.1  mrg @item Dominique d'Humi@`eres
   5493      1.1  mrg @item Kate Hedstrom
   5494      1.1  mrg @item Erik Schnetter
   5495  1.1.1.3  mrg @item Gerhard Steinmetz
   5496      1.1  mrg @item Joost VandeVondele
   5497      1.1  mrg @end itemize
   5498      1.1  mrg 
   5499      1.1  mrg Many other individuals have helped debug,
   5500      1.1  mrg test and improve the GNU Fortran compiler over the past few years,
   5501      1.1  mrg and we welcome you to do the same!
   5502      1.1  mrg If you already have done so,
   5503      1.1  mrg and you would like to see your name listed in the
   5504      1.1  mrg list above, please contact us.
   5505      1.1  mrg 
   5506      1.1  mrg 
   5507      1.1  mrg @node Projects
   5508      1.1  mrg @section Projects
   5509      1.1  mrg 
   5510      1.1  mrg @table @emph
   5511      1.1  mrg 
   5512      1.1  mrg @item Help build the test suite
   5513      1.1  mrg Solicit more code for donation to the test suite: the more extensive the
   5514      1.1  mrg testsuite, the smaller the risk of breaking things in the future! We can
   5515      1.1  mrg keep code private on request.
   5516      1.1  mrg 
   5517      1.1  mrg @item Bug hunting/squishing
   5518      1.1  mrg Find bugs and write more test cases! Test cases are especially very
   5519      1.1  mrg welcome, because it allows us to concentrate on fixing bugs instead of
   5520      1.1  mrg isolating them.  Going through the bugzilla database at
   5521      1.1  mrg @url{https://gcc.gnu.org/@/bugzilla/} to reduce testcases posted there and
   5522      1.1  mrg add more information (for example, for which version does the testcase
   5523      1.1  mrg work, for which versions does it fail?) is also very helpful.
   5524      1.1  mrg 
   5525  1.1.1.3  mrg @item Missing features
   5526  1.1.1.3  mrg For a larger project, consider working on the missing features required for
   5527  1.1.1.3  mrg Fortran language standards compliance (@pxref{Standards}), or contributing
   5528  1.1.1.3  mrg to the implementation of extensions such as OpenMP (@pxref{OpenMP}) or
   5529  1.1.1.3  mrg OpenACC (@pxref{OpenACC}) that are under active development.  Again,
   5530  1.1.1.3  mrg contributing test cases for these features is useful too!
   5531      1.1  mrg 
   5532  1.1.1.3  mrg @end table
   5533      1.1  mrg 
   5534      1.1  mrg 
   5535      1.1  mrg @c ---------------------------------------------------------------------
   5536      1.1  mrg @c GNU General Public License
   5537      1.1  mrg @c ---------------------------------------------------------------------
   5538      1.1  mrg 
   5539      1.1  mrg @include gpl_v3.texi
   5540      1.1  mrg 
   5541      1.1  mrg 
   5542      1.1  mrg 
   5543      1.1  mrg @c ---------------------------------------------------------------------
   5544      1.1  mrg @c GNU Free Documentation License
   5545      1.1  mrg @c ---------------------------------------------------------------------
   5546      1.1  mrg 
   5547      1.1  mrg @include fdl.texi
   5548      1.1  mrg 
   5549      1.1  mrg 
   5550      1.1  mrg 
   5551      1.1  mrg @c ---------------------------------------------------------------------
   5552      1.1  mrg @c Funding Free Software
   5553      1.1  mrg @c ---------------------------------------------------------------------
   5554      1.1  mrg 
   5555      1.1  mrg @include funding.texi
   5556      1.1  mrg 
   5557      1.1  mrg @c ---------------------------------------------------------------------
   5558      1.1  mrg @c Indices
   5559      1.1  mrg @c ---------------------------------------------------------------------
   5560      1.1  mrg 
   5561      1.1  mrg @node Option Index
   5562      1.1  mrg @unnumbered Option Index
   5563      1.1  mrg @command{gfortran}'s command line options are indexed here without any
   5564      1.1  mrg initial @samp{-} or @samp{--}.  Where an option has both positive and
   5565      1.1  mrg negative forms (such as -foption and -fno-option), relevant entries in
   5566      1.1  mrg the manual are indexed under the most appropriate form; it may sometimes
   5567      1.1  mrg be useful to look up both forms.
   5568      1.1  mrg @printindex op
   5569      1.1  mrg 
   5570      1.1  mrg @node Keyword Index
   5571      1.1  mrg @unnumbered Keyword Index
   5572      1.1  mrg @printindex cp
   5573      1.1  mrg 
   5574      1.1  mrg @bye
   5575