Gfortran Manual

Embed Size (px)

Citation preview

  • 7/31/2019 Gfortran Manual

    1/262

    Using GNU FortranFor gcc version 4.6.2

    (GCC)

    The gfortran team

  • 7/31/2019 Gfortran Manual

    2/262

    Published by the Free Sotware Foundation51 Franklin Street, Fith FloorBoston, MA 02110-1301, USA

    Copyright c 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011Free Sotware Foundation, Inc.

    Permission is granted to copy, distribute and/or modiy this document under the terms othe GNU Free Documentation License, Version 1.3 or any later version published by theFree Sotware Foundation; with the Invariant Sections being Funding Free Sotware, theFront-Cover Texts being (a) (see below), and with the Back-Cover Texts being (b) (seebelow). A copy o the license is included in the section entitled GNU Free DocumentationLicense.

    (a) The FSFs Front-Cover Text is:

    A GNU Manual

    (b) The FSFs Back-Cover Text is:

    You have reedom to copy and modiy this GNU Manual, like GNU sotware. Copiespublished by the Free Sotware Foundation raise unds or GNU development.

  • 7/31/2019 Gfortran Manual

    3/262

    i

    Short Contents

    1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    Part I: Invoking GNU Fortran. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    5

    2 GNU Fortran Command Options . . . . . . . . . . . . . . . . . . . . . . . . 7

    3 Runtime: Infuencing runtime behavior with environment

    variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    Part II: Language Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

    4 Fortran 2003 and 2008 Status . . . . . . . . . . . . . . . . . . . . . . . . . . 31

    5 Compiler Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

    6 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

    7 Mixed-Language Programming. . . . . . . . . . . . . . . . . . . . . . . . .

    498 Intrinsic Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

    9 Intrinsic Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207

    Contributing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211

    GNU General Public License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215

    GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . . . . 227

    Funding Free Sotware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235

    Option Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

    Keyword Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239

  • 7/31/2019 Gfortran Manual

    4/262

  • 7/31/2019 Gfortran Manual

    5/262

    iii

    Table o Contents

    1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.1 About GNU Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 GNU Fortran and GCC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.3 Preprocessing and conditional compilation . . . . . . . . . . . . . . . . . . . . . . 21.4 GNU Fortran and G77 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.5 Project Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.6 Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    1.6.1 Varying Length Character Strings . . . . . . . . . . . . . . . . . . . . . . . . . 4

    Part I: Invoking GNU Fortran . . . . . . . . . . . . . . . . . . . . 5

    2 GNU Fortran Command Options. . . . . . . . . . . . .

    72.1 Option summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.2 Options controlling Fortran dialect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.3 Enable and customize preprocessing . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.4 Options to request or suppress errors and warnings . . . . . . . . . . . . 132.5 Options or debugging your program or GNU Fortran. . . . . . . . . . 162.6 Options or directory search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172.7 Inuencing the linking step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182.8 Inuencing runtime behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182.9 Options or code generation conventions . . . . . . . . . . . . . . . . . . . . . . . 192.10 Environment variables afecting gfortran . . . . . . . . . . . . . . . . . . . . 24

    3 Runtime: Inuencing runtime behavior withenvironment variables . . . . . . . . . . . . . . . . . . . . . . . . 25

    3.1 GFORTRAN_STDIN_UNITUnit number or standard input . . . . . . 253.2 GFORTRAN_STDOUT_UNITUnit number or standard output . . . . 253.3 GFORTRAN_STDERR_UNITUnit number or standard error . . . . . . 253.4 GFORTRAN_USE_STDERRSend library output to standard error

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253.5 GFORTRAN_TMPDIRDirectory or scratch les . . . . . . . . . . . . . . . . . . 253.6 GFORTRAN_UNBUFFERED_ALLDont bufer I/O on all units . . . . . 253.7 GFORTRAN_UNBUFFERED_PRECONNECTEDDont bufer I/O on

    preconnected units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253.8 GFORTRAN_SHOW_LOCUSShow location or runtime errors . . . . . . 253.9 GFORTRAN_OPTIONAL_PLUSPrint leading + where permitted . . 263.10 GFORTRAN_DEFAULT_RECLDeault record length or new les

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263.11 GFORTRAN_LIST_SEPARATORSeparator or list output . . . . . . . . 263.12 GFORTRAN_CONVERT_UNITSet endianness or unormatted I/O

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263.13 GFORTRAN_ERROR_DUMPCOREDump core on run-time errors . . 27

  • 7/31/2019 Gfortran Manual

    6/262

    iv The GNU Fortran Compiler

    3.14 GFORTRAN_ERROR_BACKTRACEShow backtrace on run-time errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

    Part II: Language Reerence . . . . . . . . . . . . . . . . . . . . . 29

    4 Fortran 2003 and 2008 Status. . . . . . . . . . . . . . . .

    314.1 Fortran 2003 status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.2 Fortran 2008 status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

    5 Compiler Characteristics . . . . . . . . . . . . . . . . . . . . . 355.1 KIND Type Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355.2 Internal representation o LOGICAL variables . . . . . . . . . . . . . . . . . 355.3 Thread-saety o the runtime library . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

    6 Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

    6.1 Extensions implemented in GNU Fortran . . . . . . . . . . . . . . . . . . . . . . 376.1.1 Old-style kind specications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376.1.2 Old-style variable initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . 376.1.3 Extensions to namelist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386.1.4 X ormat descriptor without count eld . . . . . . . . . . . . . . . . . . . 396.1.5 Commas in FORMAT specications . . . . . . . . . . . . . . . . . . . . . . . . . 396.1.6 Missing period in FORMAT specications . . . . . . . . . . . . . . . . . . . 396.1.7 I/O item lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396.1.8 Q exponent-letter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396.1.9 BOZ literal constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396.1.10 Real array indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406.1.11 Unary operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

    6.1.12 Implicitly convert LOGICAL and INTEGER values . . . . . . . . . . 406.1.13 Hollerith constants support. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406.1.14 Cray pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416.1.15 CONVERT specier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436.1.16 OpenMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436.1.17 Argument list unctions %VAL, %REF and %LOC . . . . . . . . . . . . 44

    6.2 Extensions not implemented in GNU Fortran . . . . . . . . . . . . . . . . . . 456.2.1 STRUCTURE and RECORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456.2.2 ENCODE and DECODE statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 466.2.3 Variable FORMAT expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476.2.4 Alternate complex unction syntax. . . . . . . . . . . . . . . . . . . . . . . . 47

  • 7/31/2019 Gfortran Manual

    7/262

    v

    7 Mixed-Language Programming. . . . . . . . . . . . . . . 497.1 Interoperability with C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

    7.1.1 Intrinsic Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497.1.2 Derived Types and struct. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497.1.3 Interoperable Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

    7.1.4 Interoperable Subroutines and Functions . . . . . . . . . . . . . . . . . . 507.1.5 Working with Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517.1.6 Further Interoperability o Fortran with C . . . . . . . . . . . . . . . . 53

    7.2 GNU Fortran Compiler Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547.3 Non-Fortran Main Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

    7.3.1 _gfortran_set_args Save command-line arguments . . . 557.3.2 _gfortran_set_options Set library option ags . . . . . . . 557.3.3 _gfortran_set_convert Set endian conversion . . . . . . . . 567.3.4 _gfortran_set_record_marker Set length o record

    markers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577.3.5 _gfortran_set_fpe Set when a Floating Point Exception

    should be raised . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

    7.3.6 _gfortran_set_max_subrecord_length Set subrecordlength . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

    8 Intrinsic Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 598.1 Introduction to intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . 598.2 ABORT Abort the program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598.3 ABS Absolute value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608.4 ACCESS Checks le access modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608.5 ACHAR Character in ASCII collating sequence . . . . . . . . . . . . . . . . 618.6 ACOS Arccosine unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628.7 ACOSH Inverse hyperbolic cosine unction . . . . . . . . . . . . . . . . . . . . 62

    8.8 ADJUSTL Let adjust a string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638.9 ADJUSTR Right adjust a string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638.10 AIMAG Imaginary part o complex number . . . . . . . . . . . . . . . . . 648.11 AINT Truncate to a whole number . . . . . . . . . . . . . . . . . . . . . . . . . 658.12 ALARM Execute a routine ater a given delay . . . . . . . . . . . . . . . 658.13 ALL All values in MASK along DIM are true . . . . . . . . . . . . . . 668.14 ALLOCATED Status o an allocatable entity . . . . . . . . . . . . . . . . . 678.15 AND Bitwise logical AND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678.16 ANINT Nearest whole number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688.17 ANY Any value in MASK along DIM is true . . . . . . . . . . . . . . . 698.18 ASIN Arcsine unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708.19 ASINH Inverse hyperbolic sine unction . . . . . . . . . . . . . . . . . . . . . 70

    8.20 ASSOCIATED Status o a pointer or pointer/target pair . . . . . 718.21 ATAN Arctangent unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728.22 ATAN2 Arctangent unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 738.23 ATANH Inverse hyperbolic tangent unction . . . . . . . . . . . . . . . . . 738.24 BESSEL_J0 Bessel unction o the rst kind o order 0 . . . . . . 748.25 BESSEL_J1 Bessel unction o the rst kind o order 1 . . . . . . 748.26 BESSEL_JN Bessel unction o the rst kind . . . . . . . . . . . . . . . . 758.27 BESSEL_Y0 Bessel unction o the second kind o order 0 . . . 76

  • 7/31/2019 Gfortran Manual

    8/262

    vi The GNU Fortran Compiler

    8.28 BESSEL_Y1 Bessel unction o the second kind o order 1 . . . 768.29 BESSEL_YN Bessel unction o the second kind . . . . . . . . . . . . . 778.30 BGE Bitwise greater than or equal to . . . . . . . . . . . . . . . . . . . . . . . 788.31 BGT Bitwise greater than . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788.32 BIT_SIZE Bit size inquiry unction . . . . . . . . . . . . . . . . . . . . . . . . 788.33 BLE Bitwise less than or equal to . . . . . . . . . . . . . . . . . . . . . . . . . . 798.34 BLT Bitwise less than . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798.35 BTEST Bit test unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808.36 C_ASSOCIATED Status o a C pointer . . . . . . . . . . . . . . . . . . . . . . . 808.37 C_FUNLOC Obtain the C address o a procedure . . . . . . . . . . . . 818.38 C_F_PROCPOINTER Convert C into Fortran procedure pointer

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818.39 C_F_POINTER Convert C into Fortran pointer . . . . . . . . . . . . . . 828.40 C_LOC Obtain the C address o an object . . . . . . . . . . . . . . . . . . 838.41 C_SIZEOF Size in bytes o an expression . . . . . . . . . . . . . . . . . . . 838.42 CEILING Integer ceiling unction . . . . . . . . . . . . . . . . . . . . . . . . . . . 848.43 CHAR Character conversion unction . . . . . . . . . . . . . . . . . . . . . . . 85

    8.44 CHDIR Change working directory . . . . . . . . . . . . . . . . . . . . . . . . . . 858.45 CHMOD Change access permissions o les . . . . . . . . . . . . . . . . . . . 868.46 CMPLX Complex conversion unction . . . . . . . . . . . . . . . . . . . . . . . 878.47 COMMAND_ARGUMENT_COUNT Get number o command line

    arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 878.48 COMPILER_OPTIONS Options passed to the compiler . . . . . . . . 888.49 COMPILER_VERSION Compiler version string . . . . . . . . . . . . . . . . 888.50 COMPLEX Complex conversion unction . . . . . . . . . . . . . . . . . . . . . 898.51 CONJG Complex conjugate unction . . . . . . . . . . . . . . . . . . . . . . . . 908.52 COS Cosine unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 908.53 COSH Hyperbolic cosine unction . . . . . . . . . . . . . . . . . . . . . . . . . . . 918.54 COUNT Count unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

    8.55 CPU_TIME CPU elapsed time in seconds . . . . . . . . . . . . . . . . . . . . 928.56 CSHIFT Circular shit elements o an array . . . . . . . . . . . . . . . . . 938.57 CTIME Convert a time into a string . . . . . . . . . . . . . . . . . . . . . . . . 948.58 DATE_AND_TIME Date and time subroutine . . . . . . . . . . . . . . . . . 948.59 DBLE Double conversion unction . . . . . . . . . . . . . . . . . . . . . . . . . . 958.60 DCMPLX Double complex conversion unction . . . . . . . . . . . . . . . 968.61 DIGITS Signicant binary digits unction . . . . . . . . . . . . . . . . . . 968.62 DIM Positive diference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 978.63 DOT_PRODUCT Dot product unction . . . . . . . . . . . . . . . . . . . . . . . . 988.64 DPROD Double product unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 988.65 DREAL Double real part unction . . . . . . . . . . . . . . . . . . . . . . . . . . . 998.66 DSHIFTL Combined let shit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 998.67 DSHIFTR Combined right shit . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1008.68 DTIME Execution time subroutine (or unction) . . . . . . . . . . . 1008.69 EOSHIFT End-of shit elements o an array . . . . . . . . . . . . . . . 1018.70 EPSILON Epsilon unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1028.71 ERF Error unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1038.72 ERFC Error unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1038.73 ERFC_SCALED Error unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

  • 7/31/2019 Gfortran Manual

    9/262

    vii

    8.74 ETIME Execution time subroutine (or unction) . . . . . . . . . . . 1048.75 EXECUTE_COMMAND_LINE Execute a shell command . . . . . . . . 1058.76 EXIT Exit the program with status. . . . . . . . . . . . . . . . . . . . . . . 1068.77 EXP Exponential unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1068.78 EXPONENT Exponent unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1078.79 EXTENDS_TYPE_OF Query dynamic type or extension . . . . . 1088.80 FDATE Get the current time as a string . . . . . . . . . . . . . . . . . . . 1088.81 FGET Read a single character in stream mode rom stdin . . 1098.82 FGETC Read a single character in stream mode . . . . . . . . . . . . 1108.83 FLOOR Integer oor unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1108.84 FLUSH Flush I/O unit(s) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1118.85 FNUM File number unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1128.86 FPUT Write a single character in stream mode to stdout . . . 1128.87 FPUTC Write a single character in stream mode . . . . . . . . . . . 1138.88 FRACTION Fractional part o the model representation . . . . 1148.89 FREE Frees memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1148.90 FSEEK Low level le positioning subroutine . . . . . . . . . . . . . . . 115

    8.91 FSTAT Get le status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1168.92 FTELL Current stream position . . . . . . . . . . . . . . . . . . . . . . . . . . . 1168.93 GAMMA Gamma unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1178.94 GERROR Get last system error message . . . . . . . . . . . . . . . . . . . . 1188.95 GETARG Get command line arguments . . . . . . . . . . . . . . . . . . . . 1188.96 GET_COMMAND Get the entire command line . . . . . . . . . . . . . . . 1198.97 GET_COMMAND_ARGUMENT Get command line arguments . . . . 1198.98 GETCWD Get current working directory . . . . . . . . . . . . . . . . . . . . 1208.99 GETENV Get an environmental variable . . . . . . . . . . . . . . . . . . . . 1218.100 GET_ENVIRONMENT_VARIABLE Get an environmental variable

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1228.101 GETGID Group ID unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

    8.102 GETLOG Get login name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1238.103 GETPID Process ID unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1238.104 GETUID User ID unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1248.105 GMTIME Convert time to GMT ino . . . . . . . . . . . . . . . . . . . . . . 1248.106 HOSTNM Get system host name . . . . . . . . . . . . . . . . . . . . . . . . . . 1258.107 HUGE Largest number o a kind . . . . . . . . . . . . . . . . . . . . . . . . . . 1258.108 HYPOT Euclidean distance unction . . . . . . . . . . . . . . . . . . . . . . 1258.109 IACHAR Code in ASCII collating sequence . . . . . . . . . . . . . . . . 1268.110 IALL Bitwise AND o array elements . . . . . . . . . . . . . . . . . . . . 1268.111 IAND Bitwise logical and . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1278.112 IANY Bitwise OR o array elements . . . . . . . . . . . . . . . . . . . . . . 1288.113 IARGC Get the number o command line arguments . . . . . . 1298.114 IBCLR Clear bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1298.115 IBITS Bit extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1308.116 IBSET Set bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1308.117 ICHAR Character-to-integer conversion unction . . . . . . . . . . 1308.118 IDATE Get current local time subroutine (day/month/year)

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1318.119 IEOR Bitwise logical exclusive or . . . . . . . . . . . . . . . . . . . . . . . . 132

  • 7/31/2019 Gfortran Manual

    10/262

    viii The GNU Fortran Compiler

    8.120 IERRNO Get the last system error number . . . . . . . . . . . . . . . 1328.121 IMAGE_INDEX Function that converts a cosubscript to an

    image index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1338.122 INDEX Position o a substring within a string . . . . . . . . . . . . 1338.123 INT Convert to integer type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1348.124 INT2 Convert to 16-bit integer type . . . . . . . . . . . . . . . . . . . . . 1358.125 INT8 Convert to 64-bit integer type . . . . . . . . . . . . . . . . . . . . . 1358.126 IOR Bitwise logical or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1358.127 IPARITY Bitwise XOR o array elements . . . . . . . . . . . . . . . . . 1368.128 IRAND Integer pseudo-random number . . . . . . . . . . . . . . . . . . . 1378.129 IS_IOSTAT_END Test or end-o-le value . . . . . . . . . . . . . . . . 1378.130 IS_IOSTAT_EOR Test or end-o-record value . . . . . . . . . . . . . 1388.131 ISATTY Whether a unit is a terminal device. . . . . . . . . . . . . . 1388.132 ISHFT Shit bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1398.133 ISHFTC Shit bits circularly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1398.134 ISNAN Test or a NaN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1408.135 ITIME Get current local time subroutine

    (hour/minutes/seconds) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1408.136 KILL Send a signal to a process . . . . . . . . . . . . . . . . . . . . . . . . . 1418.137 KIND Kind o an entity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1418.138 LBOUND Lower dimension bounds o an array . . . . . . . . . . . . 1428.139 LCOBOUND Lower codimension bounds o an array . . . . . . . . 1428.140 LEADZ Number o leading zero bits o an integer . . . . . . . . . 1438.141 LEN Length o a character entity . . . . . . . . . . . . . . . . . . . . . . . . 1438.142 LEN_TRIM Length o a character entity without trailing blank

    characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1448.143 LGE Lexical greater than or equal . . . . . . . . . . . . . . . . . . . . . . . 1448.144 LGT Lexical greater than . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1458.145 LINK Create a hard link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

    8.146 LLE Lexical less than or equal . . . . . . . . . . . . . . . . . . . . . . . . . . . 1468.147 LLT Lexical less than . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1468.148 LNBLNK Index o the last non-blank character in a string . . 1478.149 LOC Returns the address o a variable . . . . . . . . . . . . . . . . . . . 1488.150 LOG Natural logarithm unction . . . . . . . . . . . . . . . . . . . . . . . . . 1488.151 LOG10 Base 10 logarithm unction . . . . . . . . . . . . . . . . . . . . . . . 1498.152 LOG_GAMMA Logarithm o the Gamma unction . . . . . . . . . . . 1498.153 LOGICAL Convert to logical type . . . . . . . . . . . . . . . . . . . . . . . . . 1508.154 LONG Convert to integer type . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1508.155 LSHIFT Let shit bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1518.156 LSTAT Get le status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1518.157 LTIME Convert time to local time ino . . . . . . . . . . . . . . . . . . . 1528.158 MALLOC Allocate dynamic memory . . . . . . . . . . . . . . . . . . . . . . 1528.159 MASKL Let justied mask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1538.160 MASKR Right justied mask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1548.161 MATMUL matrix multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . 1548.162 MAX Maximum value o an argument list . . . . . . . . . . . . . . . . . 1548.163 MAXEXPONENT Maximum exponent o a real kind . . . . . . . . . 1558.164 MAXLOC Location o the maximum value within an array . . 155

  • 7/31/2019 Gfortran Manual

    11/262

    ix

    8.165 MAXVAL Maximum value o an array . . . . . . . . . . . . . . . . . . . . . 1568.166 MCLOCK Time unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1578.167 MCLOCK8 Time unction (64-bit) . . . . . . . . . . . . . . . . . . . . . . . . . 1578.168 MERGE Merge variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1588.169 MERGE_BITS Merge o bits under mask . . . . . . . . . . . . . . . . . . 1588.170 MIN Minimum value o an argument list . . . . . . . . . . . . . . . . . 1598.171 MINEXPONENT Minimum exponent o a real kind . . . . . . . . . 1598.172 MINLOC Location o the minimum value within an array . . 1598.173 MINVAL Minimum value o an array . . . . . . . . . . . . . . . . . . . . . 1608.174 MOD Remainder unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1618.175 MODULO Modulo unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1628.176 MOVE_ALLOC Move allocation rom one object to another

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1628.177 MVBITS Move bits rom one integer to another . . . . . . . . . . . 1638.178 NEAREST Nearest representable number . . . . . . . . . . . . . . . . . . 1638.179 NEW_LINE New line character . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1648.180 NINT Nearest whole number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

    8.181 NORM2 Euclidean vector norms . . . . . . . . . . . . . . . . . . . . . . . . . . 1658.182 NOT Logical negation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1668.183 NULL Function that returns an disassociated pointer . . . . . 1668.184 NUM_IMAGES Function that returns the number o images

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1668.185 OR Bitwise logical OR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1678.186 PACK Pack an array into an array o rank one . . . . . . . . . . . . 1688.187 PARITY Reduction with exclusive OR . . . . . . . . . . . . . . . . . . . . 1688.188 PERROR Print system error message . . . . . . . . . . . . . . . . . . . . . . 1698.189 PRECISION Decimal precision o a real kind . . . . . . . . . . . . . . 1698.190 POPCNT Number o bits set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1708.191 POPPAR Parity o the number o bits set . . . . . . . . . . . . . . . . . 170

    8.192 PRESENT Determine whether an optional dummy argument isspecied . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

    8.193 PRODUCT Product o array elements . . . . . . . . . . . . . . . . . . . . . . 1718.194 RADIX Base o a model number . . . . . . . . . . . . . . . . . . . . . . . . . . 1728.195 RAN Real pseudo-random number . . . . . . . . . . . . . . . . . . . . . . . . 1728.196 RAND Real pseudo-random number . . . . . . . . . . . . . . . . . . . . . . 1738.197 RANDOM_NUMBER Pseudo-random number . . . . . . . . . . . . . . . . . 1738.198 RANDOM_SEED Initialize a pseudo-random number sequence

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1748.199 RANGE Decimal exponent range . . . . . . . . . . . . . . . . . . . . . . . . . . 1758.200 REAL Convert to real type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1758.201 RENAME Rename a le . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1768.202 REPEAT Repeated string concatenation . . . . . . . . . . . . . . . . . . 1778.203 RESHAPE Function to reshape an array . . . . . . . . . . . . . . . . . . . 1778.204 RRSPACING Reciprocal o the relative spacing . . . . . . . . . . . . 1788.205 RSHIFT Right shit bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1788.206 SAME_TYPE_AS Query dynamic types or equality . . . . . . . . 1788.207 SCALE Scale a real value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

  • 7/31/2019 Gfortran Manual

    12/262

    x The GNU Fortran Compiler

    8.208 SCAN Scan a string or the presence o a set o characters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

    8.209 SECNDS Time unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1808.210 SECOND CPU time unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1818.211 SELECTED_CHAR_KIND Choose character kind . . . . . . . . . . . . 1818.212 SELECTED_INT_KIND Choose integer kind . . . . . . . . . . . . . . . . 1828.213 SELECTED_REAL_KIND Choose real kind . . . . . . . . . . . . . . . . . . 1828.214 SET_EXPONENT Set the exponent o the model . . . . . . . . . . . 1838.215 SHAPE Determine the shape o an array . . . . . . . . . . . . . . . . . . 1848.216 SHIFTA Right shit with ll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1848.217 SHIFTL Let shit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1858.218 SHIFTR Right shit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1858.219 SIGN Sign copying unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1868.220 SIGNAL Signal handling subroutine (or unction) . . . . . . . . . 1868.221 SIN Sine unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1878.222 SINH Hyperbolic sine unction . . . . . . . . . . . . . . . . . . . . . . . . . . . 1888.223 SIZE Determine the size o an array . . . . . . . . . . . . . . . . . . . . . 188

    8.224 SIZEOF Size in bytes o an expression . . . . . . . . . . . . . . . . . . . 1898.225 SLEEP Sleep or the specied number o seconds . . . . . . . . . 1898.226 SPACING Smallest distance between two numbers o a given

    type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1908.227 SPREAD Add a dimension to an array . . . . . . . . . . . . . . . . . . . . 1908.228 SQRT Square-root unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1918.229 SRAND Reinitialize the random number generator . . . . . . . . 1918.230 STAT Get le status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1928.231 STORAGE_SIZE Storage size in bits . . . . . . . . . . . . . . . . . . . . . . . 1938.232 SUM Sum o array elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1948.233 SYMLNK Create a symbolic link . . . . . . . . . . . . . . . . . . . . . . . . . . 1948.234 SYSTEM Execute a shell command . . . . . . . . . . . . . . . . . . . . . . . 195

    8.235 SYSTEM_CLOCK Time unction . . . . . . . . . . . . . . . . . . . . . . . . . . . 1958.236 TAN Tangent unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1968.237 TANH Hyperbolic tangent unction . . . . . . . . . . . . . . . . . . . . . . . 1978.238 THIS_IMAGE Function that returns the cosubscript index o

    this image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1978.239 TIME Time unction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1988.240 TIME8 Time unction (64-bit) . . . . . . . . . . . . . . . . . . . . . . . . . . . 1998.241 TINY Smallest positive number o a real kind . . . . . . . . . . . . 1998.242 TRAILZ Number o trailing zero bits o an integer . . . . . . . . 1998.243 TRANSFER Transer bit patterns . . . . . . . . . . . . . . . . . . . . . . . . . 2008.244 TRANSPOSE Transpose an array o rank two . . . . . . . . . . . . . . 2018.245 TRIM Remove trailing blank characters o a string . . . . . . . 2018.246 TTYNAM Get the name o a terminal device. . . . . . . . . . . . . . . 2018.247 UBOUND Upper dimension bounds o an array . . . . . . . . . . . . 2028.248 UCOBOUND Upper codimension bounds o an array . . . . . . . . 2038.249 UMASK Set the le creation mask . . . . . . . . . . . . . . . . . . . . . . . . 2038.250 UNLINK Remove a le rom the le system . . . . . . . . . . . . . . . 2038.251 UNPACK Unpack an array o rank one into an array . . . . . . 2048.252 VERIFY Scan a string or characters not a given set . . . . . . 204

  • 7/31/2019 Gfortran Manual

    13/262

    xi

    8.253 XOR Bitwise logical exclusive OR . . . . . . . . . . . . . . . . . . . . . . . . 205

    9 Intrinsic Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2079.1 ISO_FORTRAN_ENV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2079.2 ISO_C_BINDING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208

    9.3 OpenMP Modules OMP_LIB and OMP_LIB_KINDS . . . . . . . . . . . . . . 210

    Contributing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211Contributors to GNU Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212Proposed Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212

    Compiler extensions: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212Environment Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213

    GNU General Public License . . . . . . . . . . . . . . . . . . . 215

    GNU Free Documentation License. . . . . . . . . . . . .

    227ADDENDUM: How to use this License or your documents . . . . . . . . 234

    Funding Free Sotware . . . . . . . . . . . . . . . . . . . . . . . . . . . 235

    Option Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

    Keyword Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239

  • 7/31/2019 Gfortran Manual

    14/262

  • 7/31/2019 Gfortran Manual

    15/262

    Chapter 1: Introduction 1

    1 Introduction

    This manual documents the use o gfortran, the GNU Fortran compiler. You can nd inthis manual how to invoke gfortran, as well as its eatures and incompatibilities.

    The GNU Fortran compiler ront end was designed initially as a ree replacement or, oralternative to, the unix f95 command; gfortran is the command youll use to invoke thecompiler.

    1.1 About GNU Fortran

    The GNU Fortran compiler supports the Fortran 77, 90 and 95 standards completely, partso the Fortran 2003 and Fortran 2008 standards, and several vendor extensions. The devel-opment goal is to provide the ollowing eatures:

    Read a users program, stored in a le and containing instructions written in Fortran77, Fortran 90, Fortran 95, Fortran 2003 or Fortran 2008. This le contains source

    code. Translate the users program into instructions a computer can carry out more quicklythan it takes to translate the instructions in the rst place. The result ater compilationo a program is machine code, code designed to be eciently translated and processedby a machine such as your computer. Humans usually arent as good writing machinecode as they are at writing Fortran (or C++, Ada, or Java), because it is easy to maketiny mistakes writing machine code.

    Provide the user with inormation about the reasons why the compiler is unable tocreate a binary rom the source code. Usually this will be the case i the source codeis awed. The Fortran 90 standard requires that the compiler can point out mistakesto the user. An incorrect usage o the language causes an error message.

    The compiler will also attempt to diagnose cases where the users program contains acorrect usage o the language, but instructs the computer to do something questionable.This kind o diagnostics message is called a warning message.

    Provide optional inormation about the translation passes rom the source code tomachine code. This can help a user o the compiler to nd the cause o certain bugswhich may not be obvious in the source code, but may be more easily ound at a lowerlevel compiler output. It also helps developers to nd bugs in the compiler itsel.

    Provide inormation in the generated machine code that can make it easier to nd bugsin the program (using a debugging tool, called a debugger, such as the GNU Debuggergdb).

    Locate and gather machine code already generated to perorm actions requested bystatements in the users program. This machine code is organized into modules and islocated and linked to the user program.

    The GNU Fortran compiler consists o several components:

    A version o the gcc command (which also might be installed as the systems cc com-mand) that also understands and accepts Fortran source code. The gcc command isthe driver program or all the languages in the GNU Compiler Collection (GCC); Withgcc, you can compile the source code o any language or which a ront end is availablein GCC.

  • 7/31/2019 Gfortran Manual

    16/262

    2 The GNU Fortran Compiler

    The gfortran command itsel, which also might be installed as the systems f95 com-mand. gfortran is just another driver program, but specically or the Fortran com-piler only. The diference with gcc is that gfortran will automatically link the correctlibraries to your program.

    A collection o run-time libraries. These libraries contain the machine code neededto support capabilities o the Fortran language that are not directly provided by themachine code generated by the gfortran compilation phase, such as intrinsic unctionsand subroutines, and routines or interaction with les and the operating system.

    The Fortran compiler itsel, (f951). This is the GNU Fortran parser and code generator,linked to and interaced with the GCC backend library. f951 translates the sourcecode to assembler code. You would typically not use this program directly; instead,the gcc or gfortran driver programs will call it or you.

    1.2 GNU Fortran and GCC

    GNU Fortran is a part o GCC, the GNU Compiler Collection. GCC consists o a collec-tion o ront ends or various languages, which translate the source code into a language-independent orm called GENERIC. This is then processed by a common middle end whichprovides optimization, and then passed to one o a collection o back ends which generatecode or diferent computer architectures and operating systems.

    Functionally, this is implemented with a driver program (gcc) which provides thecommand-line interace or the compiler. It calls the relevant compiler ront-end program(e.g., f951 or Fortran) or each le in the source code, and then calls the assembler andlinker as appropriate to produce the compiled output. In a copy o GCC which has beencompiled with Fortran language support enabled, gcc will recognize les with .f, .for,.ftn, .f90, .f95, .f03 and .f08 extensions as Fortran source code, and compile it

    accordingly. A gfortran driver program is also provided, which is identical to gcc exceptthat it automatically links the Fortran runtime libraries into the compiled program.

    Source les with .f, .for, .fpp, .ftn, .F, .FOR, .FPP, and .FTN extensionsare treated as xed orm. Source les with .f90, .f95, .f03, .f08, .F90, .F95,.F03 and .F08 extensions are treated as ree orm. The capitalized versions o eitherorm are run through preprocessing. Source les with the lower case .fpp extension arealso run through preprocessing.

    This manual specically documents the Fortran ront end, which handles the program-ming languages syntax and semantics. The aspects o GCC which relate to the optimizationpasses and the back-end code generation are documented in the GCC manual; see SectionIntroduction in Using the GNU Compiler Collection (GCC). The two manuals together

    provide a complete reerence or the GNU Fortran compiler.

    1.3 Preprocessing and conditional compilation

    Many Fortran compilers including GNU Fortran allow passing the source code through aC preprocessor (CPP; sometimes also called the Fortran preprocessor, FPP) to allow orconditional compilation. In the case o GNU Fortran, this is the GNU C Preprocessorin the traditional mode. On systems with case-preserving le names, the preprocessor isautomatically invoked i the lename extension is .F, .FOR, .FTN, .fpp, .FPP, .F90,

    http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/
  • 7/31/2019 Gfortran Manual

    17/262

    Chapter 1: Introduction 3

    .F95, .F03 or .F08. To manually invoke the preprocessor on any le, use -cpp, todisable preprocessing on les where the preprocessor is run automatically, use -nocpp.

    I a preprocessed le includes another le with the Fortran INCLUDE statement, the in-cluded le is not preprocessed. To preprocess included les, use the equivalent preprocessorstatement #include.

    I GNU Fortran invokes the preprocessor, __GFORTRAN__ is dened and __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ can be used to determine the version o thecompiler. See Section Overview in The C Preprocessor or details.

    While CPP is the de-acto standard or preprocessing Fortran code, Part 3 o the Fortran95 standard (ISO/IEC 1539-3:1998) denes Conditional Compilation, which is not widelyused and not directly supported by the GNU Fortran compiler. You can use the programcoco to preprocess such les (http://www.daniellnagle.com/coco.html).

    1.4 GNU Fortran and G77

    The GNU Fortran compiler is the successor to g77, the Fortran 77 ront end included in GCCprior to version 4. It is an entirely new program that has been designed to provide Fortran95 support and extensibility or uture Fortran language standards, as well as providingbackwards compatibility or Fortran 77 and nearly all o the GNU language extensionssupported by g77.

    1.5 Project Status

    As soon as gfortran can parse all o the statements correctly, it will be in thelarva state. When we generate code, the puppa state. When gfortran isdone, well see i it will be a beautiul buttery, or just a big bug....

    Andy Vaught, April 2000

    The start o the GNU Fortran 95 project was announced on the GCC homepage in March18, 2000 (even though Andy had already been working on it or a while, o course).

    The GNU Fortran compiler is able to compile nearly all standard-compliant Fortran 95,Fortran 90, and Fortran 77 programs, including a number o standard and non-standardextensions, and can be used on real-world programs. In particular, the supported extensionsinclude OpenMP, Cray-style pointers, and several Fortran 2003 and Fortran 2008 eatures,including TR 15581. However, it is still under development and has a ew remaining roughedges.

    At present, the GNU Fortran compiler passes the NIST Fortran 77 Test Suite, andproduces acceptable results on the LAPACK Test Suite. It also provides respectable per-ormance on the Polyhedron Fortran compiler benchmarks and the Livermore Fortran Ker-

    nels test. It has been used to compile a number o large real-world programs, includingthe HIRLAM weather-orecasting code and the Tonto quantum chemistry package; seehttp://gcc.gnu.org/wiki/GfortranApps or an extended list.

    Among other things, the GNU Fortran compiler is intended as a replacement or G77.At this point, nearly all programs that could be compiled with G77 can be compiled withGNU Fortran, although there are a ew minor known regressions.

    The primary work remaining to be done on GNU Fortran alls into three categories:bug xing (primarily regarding the treatment o invalid code and providing useul error

    http://cpp.pdf/http://cpp.pdf/http://www.daniellnagle.com/coco.htmlhttp://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.htmlhttp://www.netlib.org/lapack/faq.html#1.21http://www.polyhedron.com/pb05.htmlhttp://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.htmlhttp://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.htmlhttp://mysite.verizon.net/serveall/moene.pdfhttp://www.theochem.uwa.edu.au/tonto/http://gcc.gnu.org/wiki/GfortranAppshttp://gcc.gnu.org/wiki/GfortranAppshttp://www.theochem.uwa.edu.au/tonto/http://mysite.verizon.net/serveall/moene.pdfhttp://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.htmlhttp://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.htmlhttp://www.polyhedron.com/pb05.htmlhttp://www.netlib.org/lapack/faq.html#1.21http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.htmlhttp://www.daniellnagle.com/coco.htmlhttp://cpp.pdf/
  • 7/31/2019 Gfortran Manual

    18/262

    4 The GNU Fortran Compiler

    messages), improving the compiler optimizations and the perormance o compiled code,and extending the compiler to support uture standardsin particular, Fortran 2003 andFortran 2008.

    1.6 StandardsThe GNU Fortran compiler implements ISO/IEC 1539:1997 (Fortran 95). As such, it canalso compile essentially all standard-compliant Fortran 90 and Fortran 77 programs. It alsosupports the ISO/IEC TR-15581 enhancements to allocatable arrays.

    In the uture, the GNU Fortran compiler will also support ISO/IEC 1539-1:2004 (Fortran2003), ISO/IEC 1539-1:2010 (Fortran 2008) and uture Fortran standards. Partial supporto the Fortran 2003 and Fortran 2008 standard is already provided; the current status othe support is reported in the Section 4.1 [Fortran 2003 status], page 31 and Section 4.2[Fortran 2008 status], page 32 sections o the documentation.

    Additionally, the GNU Fortran compilers supports the OpenMP specication (version

    3.0, http://openmp.org/wp/openmp-specifications/).

    1.6.1 Varying Length Character Strings

    The Fortran 95 standard species in Part 2 (ISO/IEC 1539-2:2000) varying length characterstrings. While GNU Fortran currently does not support such strings directly, there existtwo Fortran implementations or them, which work with GNU Fortran. They can be oundat http://www.fortran.com/iso_varying_string.f95 and at ftp://ftp.nag.co.uk/sc22wg5/ISO_VARYING_STRING/.

    http://openmp.org/wp/openmp-specifications/http://www.fortran.com/iso_varying_string.f95ftp://ftp.nag.co.uk/sc22wg5/ISO_VARYING_STRING/ftp://ftp.nag.co.uk/sc22wg5/ISO_VARYING_STRING/ftp://ftp.nag.co.uk/sc22wg5/ISO_VARYING_STRING/ftp://ftp.nag.co.uk/sc22wg5/ISO_VARYING_STRING/http://www.fortran.com/iso_varying_string.f95http://openmp.org/wp/openmp-specifications/
  • 7/31/2019 Gfortran Manual

    19/262

    Chapter 1: Introduction 5

    Part I: Invoking GNU Fortran

  • 7/31/2019 Gfortran Manual

    20/262

  • 7/31/2019 Gfortran Manual

    21/262

    Chapter 2: GNU Fortran Command Options 7

    2 GNU Fortran Command Options

    The gfortran command supports all the options supported by the gcc command. Onlyoptions specic to GNU Fortran are documented here.

    See Section GCC Command Options in Using the GNU Compiler Collection (GCC),or inormation on the non-Fortran-specic aspects o the gcc command (and, thereore,the gfortran command).

    All GCC and GNU Fortran options are accepted both by gfortran and by gcc (as wellas any other drivers built at the same time, such as g++), since adding GNU Fortran to theGCC distribution enables acceptance o GNU Fortran options by all o the relevant drivers.

    In some cases, options have positive and negative orms; the negative orm o -ffoowould be -fno-foo. This manual documents only one o these two orms, whichever oneis not the deault.

    2.1 Option summary

    Here is a summary o all the options specic to GNU Fortran, grouped by type. Explanationsare in the ollowing sections.

    Fortran Language OptionsSee Section 2.2 [Options controlling Fortran dialect], page 8.

    -fall-intrinsics -ffree-form -fno-fixed-form-fdollar-ok -fimplicit-none -fmax-identifier-length-std=std -fd-lines-as-code -fd-lines-as-comments

    -ffixed-line-length-n -ffixed-line-length-none-ffree-line-length-n -ffree-line-length-none-fdefault-double-8 -fdefault-integer-8 -fdefault-real-8-fcray-pointer -fopenmp -fno-range-check -fbackslash -fmodule-private

    Preprocessing OptionsSee Section 2.3 [Enable and customize preprocessing], page 10.

    -cpp -dD -dI -dM -dN -dU -fworking-directory-imultilib dir -iprefix file -isysroot dir-iquote -isystem dir -nocpp -nostdinc -undef-Aquestion=answer -A-question[=answer]-C -CC -Dmacro [=defn ] -Umacro -H -P

    Error and Warning OptionsSee Section 2.4 [Options to request or suppress errors and warnings], page 13.

    -fmax-errors=n-fsyntax-only -pedantic -pedantic-errors

    -Wall -Waliasing -Wampersand -Warray-bounds -Wcharacter-truncation-Wconversion -Wimplicit-interface -Wimplicit-procedure -Wline-truncation

    -Wintrinsics-std -Wsurprising -Wno-tabs -Wunderflow -Wunused-parameter-Wintrinsic-shadow -Wno-align-commons

    Debugging OptionsSee Section 2.5 [Options or debugging your program or GNU Fortran], page 16.

    -fdump-fortran-original -fdump-fortran-optimized-ffpe-trap=list -fdump-core -fbacktrace -fdump-parse-tree

    Directory OptionsSee Section 2.6 [Options or directory search], page 17.

    http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/
  • 7/31/2019 Gfortran Manual

    22/262

    8 The GNU Fortran Compiler

    -Idir -Jdir -fintrinsic-modules-path dir

    Link OptionsSee Section 2.7 [Options or inuencing the linking step], page 18.

    -static-libgfortran

    Runtime OptionsSee Section 2.8 [Options or inuencing runtime behavior], page 18.

    -fconvert=conversion -fno-range-check -frecord-marker=length-fmax-subrecord-length=length -fsign-zero

    Code Generation OptionsSee Section 2.9 [Options or code generation conventions], page 19.

    -fno-automatic -ff2c -fno-underscoring-fno-whole-file -fsecond-underscore-fbounds-check -fcheck-array-temporaries -fmax-array-constructor =n-fcheck=

    -fcoarray= -fmax-stack-var-size=n

    -fpack-derived -frepack-arrays -fshort-enums -fexternal-blas-fblas-matmul-limit=n -frecursive -finit-local-zero-finit-integer=n -finit-real=-finit-logical= -finit-character=n-fno-align-commons -fno-protect-parens -frealloc-lhs

    2.2 Options controlling Fortran dialect

    The ollowing options control the details o the Fortran dialect accepted by the compiler:

    -ffree-form

    -ffixed-form

    Speciy the layout used by the source le. The ree orm layout was introduced

    in Fortran 90. Fixed orm was traditionally used in older Fortran programs.When neither option is specied, the source orm is determined by the leextension.

    -fall-intrinsics

    This option causes all intrinsic procedures (including the GNU-specic exten-sions) to be accepted. This can be useul with -std=f95 to orce standard-compliance but get access to the ull range o intrinsics available with gfortran.As a consequence, -Wintrinsics-std will be ignored and no user-dened pro-cedure with the same name as any intrinsic will be called except when it isexplicitly declared EXTERNAL.

    -fd-lines-as-code

    -fd-lines-as-commentsEnable special treatment or lines beginning with d or D in xed orm sources. Ithe -fd-lines-as-code option is given they are treated as i the rst columncontained a blank. I the -fd-lines-as-comments option is given, they aretreated as comment lines.

    -fdefault-double-8

    Set the DOUBLE PRECISION type to an 8 byte wide type. I -fdefault-real-8is given, DOUBLE PRECISION would instead be promoted to 16 bytes i possible,

  • 7/31/2019 Gfortran Manual

    23/262

    Chapter 2: GNU Fortran Command Options 9

    and -fdefault-double-8 can be used to prevent this. The kind o real con-stants like 1.d0 will not be changed by -fdefault-real-8 though, so also-fdefault-double-8 does not afect it.

    -fdefault-integer-8Set the deault integer and logical types to an 8 byte wide type. Do nothing ithis is already the deault. This option also afects the kind o integer constantslike 42.

    -fdefault-real-8

    Set the deault real type to an 8 byte wide type. Do nothing i this is alreadythe deault. This option also afects the kind o non-double real constants like1.0, and does promote the deault width o DOUBLE PRECISION to 16 bytes ipossible, unless -fdefault-double-8 is given, too.

    -fdollar-ok

    Allow $ as a valid non-rst character in a symbol name. Symbols that start

    with $ are rejected since it is unclear which rules to apply to implicit typing asdiferent vendors implement diferent rules. Using $ in IMPLICIT statementsis also rejected.

    -fbackslash

    Change the interpretation o backslashes in string literals rom a single back-slash character to C-style escape characters. The ollowing combinations areexpanded \a, \b, \f, \n, \r, \t, \v, \\, and \0 to the ASCII characters alert,backspace, orm eed, newline, carriage return, horizontal tab, vertical tab,backslash, and NUL, respectively. Additionally, \xnn, \unnnn and \Unnnnnnnn(where each n is a hexadecimal digit) are translated into the Unicode charac-ters corresponding to the specied code points. All other combinations o a

    character preceded by \ are unexpanded.-fmodule-private

    Set the deault accessibility o module entities to PRIVATE. Use-associated en-tities will not be accessible unless they are explicitly declared as PUBLIC.

    -ffixed-line-length-n

    Set column ater which characters are ignored in typical xed-orm lines in thesource le, and through which spaces are assumed (as i padded to that length)ater the ends o short xed-orm lines.

    Popular values or n include 72 (the standard and the deault), 80 (card im-age), and 132 (corresponding to extended-source options in some popularcompilers). n may also be none, meaning that the entire line is meaningul

    and that continued character constants never have implicit spaces appended tothem to ll out the line. -ffixed-line-length-0 means the same thing as-ffixed-line-length-none.

    -ffree-line-length-n

    Set column ater which characters are ignored in typical ree-orm lines in thesource le. The deault value is 132. n may be none, meaning that theentire line is meaningul. -ffree-line-length-0 means the same thing as-ffree-line-length-none.

  • 7/31/2019 Gfortran Manual

    24/262

    10 The GNU Fortran Compiler

    -fmax-identifier-length=n

    Speciy the maximum allowed identier length. Typical values are 31 (Fortran95) and 63 (Fortran 2003 and Fortran 2008).

    -fimplicit-noneSpeciy that no implicit typing is allowed, unless overridden by explicitIMPLICIT statements. This is the equivalent o adding implicit none to thestart o every procedure.

    -fcray-pointer

    Enable the Cray pointer extension, which provides C-like pointer unctionality.

    -fopenmp Enable the OpenMP extensions. This includes OpenMP !$omp directives inree orm and c$omp, *$omp and !$omp directives in xed orm, !$ conditionalcompilation sentinels in ree orm and c$, *$ and !$ sentinels in xed orm, andwhen linking arranges or the OpenMP runtime library to be linked in. Theoption -fopenmp implies -frecursive.

    -fno-range-checkDisable range checking on results o simplication o constant expressions duringcompilation. For example, GNU Fortran will give an error at compile time whensimpliying a = 1. / 0. With this option, no error will be given and a will beassigned the value +Infinity. I an expression evaluates to a value outside othe relevant range o [-HUGE():HUGE()], then the expression will be replaced by-Inf or +Inf as appropriate. Similarly, DATA i/ZFFFFFFFF/ will result in aninteger overow on most systems, but with -fno-range-check the value willwrap around and i will be initialized to 1 instead.

    -std=std Speciy the standard to which the program is expected to conorm, which maybe one o f95, f2003, f2008, gnu, or legacy. The deault value or std

    is gnu, which species a superset o the Fortran 95 standard that includes allo the extensions supported by GNU Fortran, although warnings will be givenor obsolete extensions not recommended or use in new code. The legacyvalue is equivalent but without the warnings or obsolete extensions, and maybe useul or old non-standard programs. The f95, f2003 and f2008 valuesspeciy strict conormance to the Fortran 95, Fortran 2003 and Fortran 2008standards, respectively; errors are given or all extensions beyond the relevantlanguage standard, and warnings are given or the Fortran 77 eatures that arepermitted but obsolescent in later standards.

    2.3 Enable and customize preprocessing

    Preprocessor related options. See section Section 1.3 [Preprocessing and conditional com-pilation], page 2 or more detailed inormation on preprocessing in gfortran.

    -cpp

    -nocpp Enable preprocessing. The preprocessor is automatically invoked i the leextension is .fpp, .FPP, .F, .FOR, .FTN, .F90, .F95, .F03 or .F08.Use this option to manually enable preprocessing o any kind o Fortran le.

    To disable preprocessing o les with any o the above listed extensions, use thenegative orm: -nocpp.

  • 7/31/2019 Gfortran Manual

    25/262

    Chapter 2: GNU Fortran Command Options 11

    The preprocessor is run in traditional mode. Any restrictions o the le-ormat, especially the limits on line length, apply or preprocessed outputas well, so it might be advisable to use the -ffree-line-length-none or-ffixed-line-length-none options.

    -dM Instead o the normal output, generate a list o #define directives or all themacros dened during the execution o the preprocessor, including predenedmacros. This gives you a way o nding out what is predened in your versiono the preprocessor. Assuming you have no le foo.f90, the command

    touch foo.f90; gfortran -cpp -E -dM foo.f90

    will show all the predened macros.

    -dD Like -dM except in two respects: it does not include the predened macros, andit outputs both the #define directives and the result o preprocessing. Bothkinds o output go to the standard output le.

    -dN Like -dD, but emit only the macro names, not their expansions.

    -dU Like dD except that only macros that are expanded, or whose denedness istested in preprocessor directives, are output; the output is delayed until the useor test o the macro; and #undef directives are also output or macros testedbut undened at the time.

    -dI Output #include directives in addition to the result o preprocessing.

    -fworking-directory

    Enable generation o linemarkers in the preprocessor output that will let thecompiler know the current working directory at the time o preprocessing.When this option is enabled, the preprocessor will emit, ater the initial line-marker, a second linemarker with the current working directory ollowed by

    two slashes. GCC will use this directory, when its present in the prepro-cessed input, as the directory emitted as the current working directory in somedebugging inormation ormats. This option is implicitly enabled i debug-ging inormation is enabled, but this can be inhibited with the negated orm-fno-working-directory. I the -P ag is present in the command line,this option has no efect, since no #line directives are emitted whatsoever.

    -idirafter dir

    Search dir or include les, but do it ater all directories specied with -Iand the standard system directories have been exhausted. dir is treated as asystem include directory. I dir begins with =, then the = will be replaced bythe sysroot prex; see --sysroot and -isysroot.

    -imultilib dirUse diras a subdirectory o the directory containing target-specic C++ headers.

    -iprefix prefix

    Speciy prefxas the prex or subsequent -iwithprefix options. I the prefxrepresents a directory, you should include the nal /.

    -isysroot dir

    This option is like the --sysroot option, but applies only to header les. Seethe --sysroot option or more inormation.

  • 7/31/2019 Gfortran Manual

    26/262

    12 The GNU Fortran Compiler

    -iquote dir

    Search dir only or header les requested with #include "file"; they are notsearched or #include , beore all directories specied by -I and beorethe standard system directories. Idir begins with =, then the = will be replacedby the sysroot prex; see --sysroot and -isysroot.

    -isystem dir

    Search dir or header les, ater all directories specied by -I but beore thestandard system directories. Mark it as a system directory, so that it gets thesame special treatment as is applied to the standard system directories. I dirbegins with =, then the = will be replaced by the sysroot prex; see --sysrootand -isysroot.

    -nostdinc

    Do not search the standard system directories or header les. Only the direc-tories you have specied with -I options (and the directory o the current le,

    i appropriate) are searched.-undef Do not predene any system-specic or GCC-specic macros. The standard

    predened macros remain dened.

    -Apredicate =answer

    Make an assertion with the predicate predicate and answer answer. This ormis preerred to the older orm -A predicate(answer), which is still supported,because it does not use shell special characters.

    -A-predicate =answer

    Cancel an assertion with the predicate predicate and answer answer.

    -C Do not discard comments. All comments are passed through to the output le,

    except or comments in processed directives, which are deleted along with thedirective.

    You should be prepared or side efects when using -C; it causes the prepro-cessor to treat comments as tokens in their own right. For example, commentsappearing at the start o what would be a directive line have the efect o turn-ing that line into an ordinary source line, since the rst token on the line is nolonger a #.

    Warning: this currently handles C-Style comments only. The preprocessor doesnot yet recognize Fortran-style comments.

    -CC Do not discard comments, including during macro expansion. This is like -C,except that comments contained within macros are also passed through to the

    output le where the macro is expanded.In addition to the side-efects o the -C option, the -CC option causes allC++-style comments inside a macro to be converted to C-style comments. Thisis to prevent later use o that macro rom inadvertently commenting out theremainder o the source line. The -CC option is generally used to support lintcomments.

    Warning: this currently handles C- and C++-Style comments only. The prepro-cessor does not yet recognize Fortran-style comments.

  • 7/31/2019 Gfortran Manual

    27/262

    Chapter 2: GNU Fortran Command Options 13

    -Dname Predene name as a macro, with denition 1.

    -Dname =definition

    The contents o defnition are tokenized and processed as i they appeared

    during translation phase three in a #define directive. In particular, thedenition will be truncated by embedded newline characters.

    I you are invoking the preprocessor rom a shell or shell-like program you mayneed to use the shells quoting syntax to protect characters such as spaces thathave a meaning in the shell syntax.

    I you wish to dene a unction-like macro on the command line, write itsargument list with surrounding parentheses beore the equals sign (i any).Parentheses are meaningul to most shells, so you will need to quote the option.With sh and csh, -Dname(args...)=definition works.

    -D and -U options are processed in the order they are given on the commandline. All -imacros le and -include le options are processed ater all -D and -U

    options.

    -H Print the name o each header le used, in addition to other normal activities.Each name is indented to show how deep in the #include stack it is.

    -P Inhibit generation o linemarkers in the output rom the preprocessor. Thismight be useul when running the preprocessor on something that is not C code,and will be sent to a program which might be conused by the linemarkers.

    -Uname Cancel any previous denition o name, either built in or provided with a -Doption.

    2.4 Options to request or suppress errors and warnings

    Errors are diagnostic messages that report that the GNU Fortran compiler cannot compilethe relevant piece o source code. The compiler will continue to process the program in anattempt to report urther errors to aid in debugging, but will not produce any compiledoutput.

    Warnings are diagnostic messages that report constructions which are not inherentlyerroneous but which are risky or suggest there is likely to be a bug in the program. Unless-Werror is specied, they do not prevent compilation o the program.

    You can request many specic warnings with options beginning -W, or example-Wimplicit to request warnings on implicit declarations. Each o these specic warningoptions also has a negative orm beginning -Wno- to turn of warnings; or example,

    -Wno-implicit. This manual lists only one o the two orms, whichever is not thedeault.

    These options control the amount and kinds o errors and warnings produced by GNUFortran:

    -fmax-errors=n

    Limits the maximum number o error messages to n, at which point GNUFortran bails out rather than attempting to continue processing the sourcecode. In is 0, there is no limit on the number o error messages produced.

  • 7/31/2019 Gfortran Manual

    28/262

    14 The GNU Fortran Compiler

    -fsyntax-only

    Check the code or syntax errors, but dont actually compile it. This willgenerate module les or each module present in the code, but no other outputle.

    -pedantic

    Issue warnings or uses o extensions to Fortran 95. -pedantic also applies toC-language constructs where they occur in GNU Fortran source les, such asuse o \e in a character constant within a directive like #include.

    Valid Fortran 95 programs should compile properly with or without this option.However, without this option, certain GNU extensions and traditional Fortraneatures are supported as well. With this option, many o them are rejected.

    Some users try to use -pedantic to check programs or conormance. Theysoon nd that it does not do quite what they wantit nds some nonstandardpractices, but not all. However, improvements to GNU Fortran in this area are

    welcome.This should be used in conjunction with -std=f95, -std=f2003 or-std=f2008.

    -pedantic-errors

    Like -pedantic, except that errors are produced rather than warnings.

    -Wall Enables commonly used warning options pertaining to usage that werecommend avoiding and that we believe are easy to avoid. Thiscurrently includes -Waliasing, -Wampersand, -Wconversion,-Wsurprising, -Wintrinsics-std, -Wno-tabs, -Wintrinsic-shadow,-Wline-truncation, -Wreal-q-constant and -Wunused.

    -Waliasing

    Warn about possible aliasing o dummy arguments. Specically, it warns i thesame actual argument is associated with a dummy argument with INTENT(IN)and a dummy argument with INTENT(OUT) in a call with an explicit interace.

    The ollowing example will trigger the warning.

    interfacesubroutine bar(a,b)

    integer, intent(in) :: ainteger, intent(out) :: b

    end subroutineend interfaceinteger :: a

    call bar(a,a)

    -Wampersand

    Warn about missing ampersand in continued character constants. Thewarning is given with -Wampersand, -pedantic, -std=f95, -std=f2003and -std=f2008. Note: With no ampersand given in a continued characterconstant, GNU Fortran assumes continuation at the rst non-comment,non-whitespace character ater the ampersand that initiated the continuation.

  • 7/31/2019 Gfortran Manual

    29/262

    Chapter 2: GNU Fortran Command Options 15

    -Warray-temporaries

    Warn about array temporaries generated by the compiler. The inormationgenerated by this warning is sometimes useul in optimization, in order to avoidsuch temporaries.

    -Wcharacter-truncation

    Warn when a character assignment will truncate the assigned string.

    -Wline-truncation

    Warn when a source code line will be truncated.

    -Wconversion

    Warn about implicit conversions that are likely to change the value o theexpression ater conversion. Implied by -Wall.

    -Wconversion-extra

    Warn about implicit conversions between diferent types and kinds.

    -Wimplicit-interfaceWarn i a procedure is called without an explicit interace. Note this onlychecks that an explicit interace is present. It does not check that the declaredinteraces are consistent across program units.

    -Wimplicit-procedure

    Warn i a procedure is called that has neither an explicit interace nor has beendeclared as EXTERNAL.

    -Wintrinsics-std

    Warn i gfortran nds a procedure named like an intrinsic not available in thecurrently selected standard (with -std) and treats it as EXTERNAL procedurebecause o this. -fall-intrinsics can be used to never trigger this behavior

    and always link to the intrinsic regardless o the selected standard.-Wreal-q-constant

    Produce a warning i a real-literal-constant contains a q exponent-letter.

    -Wsurprising

    Produce a warning when suspicious code constructs are encountered. Whiletechnically legal these usually indicate that an error has been made.

    This currently produces a warning under the ollowing circumstances:

    An INTEGER SELECT construct has a CASE that can never be matchedas its lower value is greater than its upper value.

    A LOGICAL SELECT construct has three CASE statements.

    A TRANSFER species a source that is shorter than the destination. The type o a unction result is declared more than once with the sametype. I -pedantic or standard-conorming mode is enabled, this is anerror.

    A CHARACTER variable is declared with negative length.-Wtabs By deault, tabs are accepted as whitespace, but tabs are not members o the

    Fortran Character Set. For continuation lines, a tab ollowed by a digit be-tween 1 and 9 is supported. -Wno-tabs will cause a warning to be issued i

  • 7/31/2019 Gfortran Manual

    30/262

    16 The GNU Fortran Compiler

    a tab is encountered. Note, -Wno-tabs is active or -pedantic, -std=f95,-std=f2003, -std=f2008 and -Wall.

    -Wunderflow

    Produce a warning when numerical constant expressions are encountered, whichyield an UNDERFLOW during compilation.

    -Wintrinsic-shadow

    Warn i a user-dened procedure or module procedure has the same nameas an intrinsic; in this case, an explicit interace or EXTERNAL or INTRINSICdeclaration might be needed to get calls later resolved to the desired intrin-sic/procedure.

    -Wunused-dummy-argument

    Warn about unused dummy arguments. This option is implied by -Wall.

    -Wunused-parameter

    Contrary to gccs meaning o -Wunused-parameter, gfortrans imple-mentation o this option does not warn about unused dummy arguments(see -Wunused-dummy-argument), but about unused PARAMETER values.-Wunused-parameter is not included in -Wall but is implied by -Wall-Wextra.

    -Walign-commons

    By deault, gfortran warns about any occasion o variables being padded orproper alignment inside a COMMON block. This warning can be turned of via-Wno-align-commons. See also -falign-commons.

    -Werror Turns all warnings into errors.

    See Section Options to Request or Suppress Errors and Warnings in Using the GNUCompiler Collection (GCC), or inormation on more options ofered by the GBE shared bygfortran, gcc and other GNU compilers.

    Some o these have no efect when compiling programs written in Fortran.

    2.5 Options or debugging your program or GNU Fortran

    GNU Fortran has various special options that are used or debugging either your programor the GNU Fortran compiler.

    -fdump-fortran-original

    Output the internal parse tree ater translating the source program into internal

    representation. Only really useul or debugging the GNU Fortran compileritsel.

    -fdump-optimized-tree

    Output the parse tree ater ront-end optimization. Only really useul or de-bugging the GNU Fortran compiler itsel.

    Output the internal parse tree ater translating the source program into internalrepresentation. Only really useul or debugging the GNU Fortran compileritsel. This option is deprecated; use -fdump-fortran-original instead.

    http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/
  • 7/31/2019 Gfortran Manual

    31/262

    Chapter 2: GNU Fortran Command Options 17

    -ffpe-trap=list

    Speciy a list o IEEE exceptions when a Floating Point Exception (FPE) shouldbe raised. On most systems, this will result in a SIGFPE signal being sent andthe program being interrupted, producing a core le useul or debugging. listis a (possibly empty) comma-separated list o the ollowing IEEE exceptions:invalid (invalid oating point operation, such as SQRT(-1.0)), zero (divi-sion by zero), overflow (overow in a oating point operation), underflow(underow in a oating point operation), precision (loss o precision duringoperation) and denormal (operation produced a denormal value).

    Some o the routines in the Fortran runtime library, like CPU_TIME, are likelyto trigger oating point exceptions when ffpe-trap=precision is used. Forthis reason, the use o ffpe-trap=precision is not recommended.

    -fbacktrace

    Speciy that, when a runtime error is encountered or a deadly signal is emitted(segmentation ault, illegal instruction, bus error or oating-point exception),

    the Fortran runtime library should output a backtrace o the error. This optiononly has inuence or compilation o the Fortran main program.

    -fdump-core

    Request that a core-dump le is written to disk when a runtime error is en-countered on systems that support core dumps. This option is only efectiveor the compilation o the Fortran main program.

    See Section Options or Debugging Your Program or GCC in Using the GNU CompilerCollection (GCC), or more inormation on debugging options.

    2.6 Options or directory search

    These options afect how GNU Fortran searches or les specied by the INCLUDE directiveand where it searches or previously compiled modules.

    It also afects the search paths used by cpp when used to preprocess Fortran source.

    -Idir These afect interpretation o the INCLUDE directive (as well as o the #includedirective o the cpp preprocessor).

    Also note that the general behavior o -I and INCLUDE is pretty much thesame as o -I with #include in the cpp preprocessor, with regard to lookingor header.gcc les and other such things.

    This path is also used to search or .mod les when previously compiled mod-ules are required by a USE statement.

    See Section Options or Directory Search in Using the GNU Compiler Col-lection (GCC), or inormation on the -I option.

    -Jdir This option species where to put .mod les or compiled modules. It is alsoadded to the list o directories to searched by an USE statement.

    The deault is the current directory.

    -fintrinsic-modules-path dir

    This option species the location o pre-compiled intrinsic modules, i they arenot in the deault location expected by the compiler.

    http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/http://gcc.pdf/
  • 7/31/2019 Gfortran Manual

    32/262

    18 The GNU Fortran Compiler

    2.7 Inuencing the linking step

    These options come into play when the compiler links object les into an executable outputle. They are meaningless i the compiler is not doing a link step.

    -static-libgfortran

    On systems that provide libgfortran as a shared and a static library, thisoption orces the use o the static version. I no shared version o libgfortranwas built when the compiler was congured, this option has no efect.

    2.8 Inuencing runtime behavior

    These options afect the runtime behavior o programs compiled with GNU Fortran.

    -fconvert=conversion

    Speciy the representation o data or unormatted les. Valid values

    or conversion are: native, the deault; swap, swap between big- andlittle-endian; big-endian, use big-endian representation or unormattedles; little-endian, use little-endian representation or unormatted les.

    This option has an efect only when used in the main program. The CONVERTspecier and the GFORTRAN CONVERT UNIT environment variable over-ride the deault specied by -fconvert.

    -fno-range-check

    Disable range checking o input values during integer READ operations. Forexample, GNU Fortran will give an error i an input value is outside o the rele-vant range o [-HUGE():HUGE()]. In other words, with INTEGER (kind=4) :: i ,

    attempting to read 2147483648 will give an error unless -fno-range-checkis given.-frecord-marker=length

    Speciy the length o record markers or unormatted les. Valid values orlength are 4 and 8. Deault is 4. This is diferent rom previous versions ogfortran, which specied a deault record marker length o 8 on most systems.I you want to read or write les compatible with earlier versions o gfortran,use -frecord-marker=8.

    -fmax-subrecord-length=length

    Speciy the maximum length or a subrecord. The maximum permitted valueor length is 2147483639, which is also the deault. Only really useul or useby the gortran testsuite.

    -fsign-zero

    When enabled, oating point numbers o value zero with the sign bit set arewritten as negative number in ormatted output and treated as negative in theSIGN intrinsic. fno-sign-zero does not print the negative sign o zero valuesand regards zero as positive number in the SIGN intrinsic or compatibility withF77. Deault behavior is to show the negative sign.

  • 7/31/2019 Gfortran Manual

    33/262

    Chapter 2: GNU Fortran Command Options 19

    2.9 Options or code generation conventions

    These machine-independent options control the interace conventions used in code genera-tion.

    Most o them have both positive and negative orms; the negative orm o -ffoo wouldbe -fno-foo. In the table below, only one o the orms is listedthe one which is not thedeault. You can gure out the other orm by either removing no- or adding it.

    -fno-automatic

    Treat each program unit (except those marked as RECURSIVE) as i theSAVE statement were specied or every local variable and array reerencedin it. Does not afect common blocks. (Some Fortran compilers providethis option under the name -static o r -save.) The deault, which is-fautomatic, uses the stack or local variables smaller than the value givenby -fmax-stack-var-size. Use the option -frecursive to use no staticmemory.

    -ff2c Generate code designed to be compatible with code generated by g77 and f2c.

    The calling conventions used by g77 (originally implemented in f2c) requireunctions that return type deault REAL to actually return the C type double,and unctions that return type COMPLEX to return the values via an extraargument in the calling sequence that points to where to store the returnvalue. Under the deault GNU calling conventions, such unctions simply re-turn their results as they would in GNU Cdeault REAL unctions returnthe C type float, and COMPLEX unctions return the GNU C type complex.Additionally, this option implies the -fsecond-underscore option, unless-fno-second-underscore is explicitly requested.

    This does not afect the generation o code that interaces with the libgfortranlibrary.

    Caution: It is not a good idea to mix Fortran code compiled with -ff2cwith code compiled with the deault -fno-f2c calling conventions as, callingCOMPLEX or deault REAL unctions between program parts which were compiledwith diferent calling conventions will break at execution time.

    Caution: This will break code which passes intrinsic unctions o type deaultREAL or COMPLEX as actual arguments, as the library implementations use the-fno-f2c calling conventions.

    -fno-underscoring

    Do not transorm names o entities specied in the Fortran source le by ap-pending underscores to them.

    With -funderscoring in efect, GNU Fortran appends one underscore toexternal names with no underscores. This is done to ensure compatibility withcode produced by many UNIX Fortran compilers.

    Caution: The deault behavior o GNU Fortran is incompatible with f2c andg77, please use the -ff2c option i you want object les compiled with GNUFortran to be compatible with object code created with these tools.

  • 7/31/2019 Gfortran Manual

    34/262

    20 The GNU Fortran Compiler

    Use o -fno-underscoring is not recommended unless you are experimentingwith issues such as integration o GNU Fortran into existing system environ-ments (vis-a-vis existing libraries, tools, and so on).

    For example, with -funderscoring

    , and assuming other deaults like-fcase-lower and that j() and max_count() are external unctions whilemy_var and lvar are local variables, a statement like

    I = J() + MAX_COUNT (MY_VAR, LVAR)

    is implemented as something akin to:i = j_() + max_count__(&my_var__, &lvar);

    With -fno-underscoring, the same statement is implemented as:i = j() + max_count(&my_var, &lvar);

    Use o -fno-underscoring allows direct specication o user-dened nameswhile debugging and when interacing GNU Fortran code with other languages.

    Note that just because the names match does not mean that the interace

    implemented by GNU Fortran or an external name matches the interace im-plemented by some other language or that same name. That is, getting codeproduced by GNU Fortran to link to code produced by some other compilerusing this or any other method can be only a small part o the overall solutiongetting the code generated by both compilers to agree on issues other thannaming can require signicant efort, and, unlike naming disagreements, linkersnormally cannot detect disagreements in these other areas.

    Also, note that with -fno-underscoring, the lack o appended underscores in-troduces the very real possibility that a user-dened external name will conictwith a name in a system library, which could make nding unresolved-reerencebugs quite dicult in some casesthey might occur at program run time, andshow up only as buggy behavior at run time.

    In uture versions o GNU Fortran we hope to improve naming and linkingissues so that debugging always involves using the names as they appear in thesource, even i the names as seen by the linker are mangled to prevent accidentallinking between procedures with incompatible interaces.

    -fno-whole-file

    This ag causes the compiler to resolve and translate each procedure in a leseparately.

    By deault, the whole le is parsed and placed in a single ront-end tree. Duringresolution, in addition to all the usual checks and xups, reerences to externalprocedures that are in the same le efect resolution o that procedure, i not

    already done, and a check o the interaces. The dependences are resolvedby changing the order in which the le is translated into the backend tree.Thus, a procedure that is reerenced is translated beore the reerence and theduplication o backend tree declarations eliminated.

    The -fno-whole-file option is deprecated and may lead to wrong code.

    -fsecond-underscore

    By deault, GNU Fortran appends an underscore to external names. I thisoption is used GNU Fortran appends two underscores to names with underscores

  • 7/31/2019 Gfortran Manual

    35/262

    Chapter 2: GNU Fortran Command Options 21

    and one underscore to external names with no underscores. GNU Fortran alsoappends two underscores to internal names with underscores to avoid namingcollisions with external names.

    This option has no efect i -fno-underscoring is in efect. It is implied bythe -ff2c option.

    Otherwise, with this option, an external name such as MAX_COUNT is imple-mented as a reerence to the link-time external symbol max_count__, insteado max_count_. This is required or compatibility with g77 and f2c, and isimplied by use o the -ff2c option.

    -fcoarray=

    none Disable coarray support; using coarray declarations and image-control statements will produce a compile-time error. (Deault)

    single Single-image mode, i.e. num_images() is always one.

    -fcheck=

    Enable the generation o run-time checks; the argument shall be a comma-delimited list o the ollowing keywords.

    all Enable all run-time test o -fcheck.

    array-tempsWarns at run time when or passing an actual argument a tempo-rary array had to be generated. The inormation generated by thiswarning is sometimes useul in optimization, in order to avoid suchtemporaries.

    Note: The warning is only printed once per location.

    bounds Enable generation o run-time checks or array subscripts and

    against the declared minimum and maximum values. It alsochecks array indices or assumed and deerred shape arrays againstthe actual allocated bounds and ensures that all string lengthsare equal or character array constructors without an explicittypespec.

    Some checks require that -fcheck=bounds is set or the compila-tion o the main program.

    Note: In the uture this may also include other orms o checking,e.g., checking substring reerences.

    do Enable generation o run-time checks or invalid modication oloop iteration variables.

    mem Enable generation o run-time checks or memory allocation. Note:This option does not afect explicit allocations using the ALLOCATEstatement, which will be always checked.

    pointer Enable generation o run-time checks or pointers and allocatables.

    recursionEnable generation o run-time checks or recursively called sub-routines and unctions which are not marked as recursive. See

  • 7/31/2019 Gfortran Manual

    36/262

    22 The GNU Fortran Compiler

    also -frecursive. Note: This check does not work or OpenMPprograms and is disabled i used together with -frecursive and-fopenmp.

    -fbounds-checkDeprecated alias or -fcheck=bounds.

    -fcheck-array-temporaries

    Deprecated alias or -fcheck=array-temps.

    -fmax