Using GNU Fortran
Total Page:16
File Type:pdf, Size:1020Kb
Using GNU Fortran For gcc version 7.1.0 (GCC) The gfortran team Published by the Free Software Foundation 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA Copyright c 1999-2017 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with the Invariant Sections being \Funding Free Software", the Front-Cover Texts being (a) (see below), and with the Back-Cover Texts being (b) (see below). A copy of the license is included in the section entitled \GNU Free Documentation License". (a) The FSF's Front-Cover Text is: A GNU Manual (b) The FSF's Back-Cover Text is: You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development. i Short Contents 1 Introduction ::::::::::::::::::::::::::::::::::::::::: 1 Invoking GNU Fortran 2 GNU Fortran Command Options :::::::::::::::::::::::: 7 3 Runtime: Influencing runtime behavior with environment variables ::::::::::::::::::::::::::::::::::::::::::: 29 Language Reference 4 Fortran 2003 and 2008 Status :::::::::::::::::::::::::: 35 5 Compiler Characteristics :::::::::::::::::::::::::::::: 39 6 Extensions :::::::::::::::::::::::::::::::::::::::::: 43 7 Mixed-Language Programming ::::::::::::::::::::::::: 63 8 Coarray Programming :::::::::::::::::::::::::::::::: 77 9 Intrinsic Procedures ::::::::::::::::::::::::::::::::: 101 10 Intrinsic Modules ::::::::::::::::::::::::::::::::::: 273 Contributing ::::::::::::::::::::::::::::::::::::::::::: 279 GNU General Public License :::::::::::::::::::::::::::::: 283 GNU Free Documentation License ::::::::::::::::::::::::: 295 Funding Free Software ::::::::::::::::::::::::::::::::::: 303 Option Index :::::::::::::::::::::::::::::::::::::::::: 305 Keyword Index ::::::::::::::::::::::::::::::::::::::::: 307 iii Table of Contents 1 Introduction::::::::::::::::::::::::::::::::::::: 1 1.1 About GNU Fortran ::::::::::::::::::::::::::::::::::::::::::: 1 1.2 GNU Fortran and GCC :::::::::::::::::::::::::::::::::::::::: 2 1.3 Preprocessing and conditional compilation :::::::::::::::::::::: 2 1.4 GNU Fortran and G77 ::::::::::::::::::::::::::::::::::::::::: 3 1.5 Project Status ::::::::::::::::::::::::::::::::::::::::::::::::: 3 1.6 Standards :::::::::::::::::::::::::::::::::::::::::::::::::::::: 4 1.6.1 Varying Length Character Strings ::::::::::::::::::::::::: 4 Part I: Invoking GNU Fortran :::::::::::::::::::: 5 2 GNU Fortran Command Options ::::::::::::: 7 2.1 Option summary ::::::::::::::::::::::::::::::::::::::::::::::: 7 2.2 Options controlling Fortran dialect ::::::::::::::::::::::::::::: 8 2.3 Enable and customize preprocessing ::::::::::::::::::::::::::: 12 2.4 Options to request or suppress errors and warnings :::::::::::: 15 2.5 Options for debugging your program or GNU Fortran:::::::::: 19 2.6 Options for directory search ::::::::::::::::::::::::::::::::::: 20 2.7 Influencing the linking step:::::::::::::::::::::::::::::::::::: 21 2.8 Influencing runtime behavior :::::::::::::::::::::::::::::::::: 21 2.9 Options for code generation conventions ::::::::::::::::::::::: 21 2.10 Environment variables affecting gfortran :::::::::::::::::::: 28 3 Runtime: Influencing runtime behavior with environment variables:::::::::::::::::::::::: 29 3.1 TMPDIR|Directory for scratch files :::::::::::::::::::::::::::: 29 3.2 GFORTRAN_STDIN_UNIT|Unit number for standard input :::::: 29 3.3 GFORTRAN_STDOUT_UNIT|Unit number for standard output :::: 29 3.4 GFORTRAN_STDERR_UNIT|Unit number for standard error:::::: 29 3.5 GFORTRAN_UNBUFFERED_ALL|Do not buffer I/O on all units:::: 29 3.6 GFORTRAN_UNBUFFERED_PRECONNECTED|Do not buffer I/O on preconnected units::::::::::::::::::::::::::::::::::::::::::::: 29 3.7 GFORTRAN_SHOW_LOCUS|Show location for runtime errors :::::: 29 3.8 GFORTRAN_OPTIONAL_PLUS|Print leading + where permitted :: 30 3.9 GFORTRAN_DEFAULT_RECL|Default record length for new files :: 30 3.10 GFORTRAN_LIST_SEPARATOR|Separator for list output :::::::: 30 3.11 GFORTRAN_CONVERT_UNIT|Set endianness for unformatted I/O ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 30 3.12 GFORTRAN_ERROR_BACKTRACE|Show backtrace on run-time errors ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 31 Part II: Language Reference ::::::::::::::::::::: 33 iv The GNU Fortran Compiler 4 Fortran 2003 and 2008 Status :::::::::::::::: 35 4.1 Fortran 2003 status ::::::::::::::::::::::::::::::::::::::::::: 35 4.2 Fortran 2008 status ::::::::::::::::::::::::::::::::::::::::::: 36 4.3 Technical Specification 29113 Status ::::::::::::::::::::::::::: 38 4.4 Technical Specification 18508 Status ::::::::::::::::::::::::::: 38 5 Compiler Characteristics ::::::::::::::::::::: 39 5.1 KIND Type Parameters ::::::::::::::::::::::::::::::::::::::: 39 5.2 Internal representation of LOGICAL variables ::::::::::::::::: 39 5.3 Thread-safety of the runtime library ::::::::::::::::::::::::::: 40 5.4 Data consistency and durability ::::::::::::::::::::::::::::::: 40 5.5 Files opened without an explicit ACTION= specifier :::::::::: 41 5.6 File operations on symbolic links :::::::::::::::::::::::::::::: 41 6 Extensions ::::::::::::::::::::::::::::::::::::: 43 6.1 Extensions implemented in GNU Fortran :::::::::::::::::::::: 43 6.1.1 Old-style kind specifications :::::::::::::::::::::::::::::: 43 6.1.2 Old-style variable initialization ::::::::::::::::::::::::::: 43 6.1.3 Extensions to namelist ::::::::::::::::::::::::::::::::::: 44 6.1.4 X format descriptor without count field ::::::::::::::::::: 45 6.1.5 Commas in FORMAT specifications ::::::::::::::::::::::::: 45 6.1.6 Missing period in FORMAT specifications ::::::::::::::::::: 45 6.1.7 I/O item lists :::::::::::::::::::::::::::::::::::::::::::: 45 6.1.8 Q exponent-letter ::::::::::::::::::::::::::::::::::::::::: 45 6.1.9 BOZ literal constants::::::::::::::::::::::::::::::::::::: 45 6.1.10 Real array indices ::::::::::::::::::::::::::::::::::::::: 46 6.1.11 Unary operators :::::::::::::::::::::::::::::::::::::::: 46 6.1.12 Implicitly convert LOGICAL and INTEGER values :::::::::: 46 6.1.13 Hollerith constants support:::::::::::::::::::::::::::::: 47 6.1.14 Cray pointers ::::::::::::::::::::::::::::::::::::::::::: 47 6.1.15 CONVERT specifier:::::::::::::::::::::::::::::::::::::::: 49 6.1.16 OpenMP:::::::::::::::::::::::::::::::::::::::::::::::: 50 6.1.17 OpenACC :::::::::::::::::::::::::::::::::::::::::::::: 50 6.1.18 Argument list functions %VAL, %REF and %LOC :::::::::::: 51 6.1.19 Read/Write after EOF marker :::::::::::::::::::::::::: 51 6.1.20 STRUCTURE and RECORD :::::::::::::::::::::::::::::::::: 51 6.1.21 UNION and MAP :::::::::::::::::::::::::::::::::::::::::: 54 6.1.22 Type variants for integer intrinsics::::::::::::::::::::::: 56 6.1.23 AUTOMATIC and STATIC attributes ::::::::::::::::::::::: 57 6.1.24 Extended math intrinsics :::::::::::::::::::::::::::::::: 57 6.1.25 Form feed as whitespace::::::::::::::::::::::::::::::::: 58 6.1.26 TYPE as an alias for PRINT:::::::::::::::::::::::::::: 58 6.1.27 %LOC as an rvalue ::::::::::::::::::::::::::::::::::::: 58 6.1.28 .XOR. operator ::::::::::::::::::::::::::::::::::::::::: 59 6.1.29 Bitwise logical operators :::::::::::::::::::::::::::::::: 59 6.1.30 Extended I/O specifiers ::::::::::::::::::::::::::::::::: 59 6.1.31 Legacy PARAMETER statements ::::::::::::::::::::::: 60 v 6.1.32 Default exponents ::::::::::::::::::::::::::::::::::::::: 61 6.2 Extensions not implemented in GNU Fortran :::::::::::::::::: 61 6.2.1 ENCODE and DECODE statements ::::::::::::::::::::::::::: 61 6.2.2 Variable FORMAT expressions :::::::::::::::::::::::::::::: 62 6.2.3 Alternate complex function syntax:::::::::::::::::::::::: 62 6.2.4 Volatile COMMON blocks:::::::::::::::::::::::::::::::::::: 62 6.2.5 OPEN( ... NAME=):::::::::::::::::::::::::::::::::::::::: 62 7 Mixed-Language Programming::::::::::::::: 63 7.1 Interoperability with C :::::::::::::::::::::::::::::::::::::::: 63 7.1.1 Intrinsic Types ::::::::::::::::::::::::::::::::::::::::::: 63 7.1.2 Derived Types and struct::::::::::::::::::::::::::::::::: 63 7.1.3 Interoperable Global Variables:::::::::::::::::::::::::::: 64 7.1.4 Interoperable Subroutines and Functions:::::::::::::::::: 64 7.1.5 Working with Pointers ::::::::::::::::::::::::::::::::::: 66 7.1.6 Further Interoperability of Fortran with C :::::::::::::::: 68 7.2 GNU Fortran Compiler Directives ::::::::::::::::::::::::::::: 69 7.3 Non-Fortran Main Program ::::::::::::::::::::::::::::::::::: 70 7.3.1 _gfortran_set_args | Save command-line arguments ::: 70 7.3.2 _gfortran_set_options | Set library option flags::::::: 71 7.3.3 _gfortran_set_convert | Set endian conversion :::::::: 72 7.3.4 _gfortran_set_record_marker | Set length of record markers :::::::::::::::::::::::::::::::::::::::::::::::::::: 72 7.3.5 _gfortran_set_fpe | Enable floating point exception traps :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 73 7.3.6 _gfortran_set_max_subrecord_length | Set subrecord length :::::::::::::::::::::::::::::::::::::::::::::::::::::: 73 7.4 Naming and argument-passing conventions :::::::::::::::::::: 73 7.4.1 Naming conventions :::::::::::::::::::::::::::::::::::::: 74 7.4.2 Argument passing conventions :::::::::::::::::::::::::::: 74 8 Coarray Programming :::::::::::::::::::::::: 77 8.1 Type and enum ABI Documentation :::::::::::::::::::::::::: 77 8.1.1 caf_token_t ::::::::::::::::::::::::::::::::::::::::::::: 77