The GNU Fortran Compiler#
This manual documents the use of gfortran, the GNU Fortran compiler. You can find in this manual how to invoke gfortran, as well as its features and incompatibilities.
Warning
This document, and the compiler it describes, are still under development. While efforts are made to keep it up-to-date, it might not accurately reflect the status of the most recent GNU Fortran compiler.
Part I: Invoking GNU Fortran#
- GNU Fortran Command Options
- Description
- Option summary
- Options controlling Fortran dialect
- Enable and customize preprocessing
- Options to request or suppress errors and warnings
- Options for debugging your program or GNU Fortran
- Options for directory search
- Influencing the linking step
- Influencing runtime behavior
- Options for code generation conventions
- Options for interoperability with other languages
- Environment variables affecting gfortran
- Runtime: Influencing runtime behavior with environment variables
- TMPDIR—Directory for scratch files
- GFORTRAN_STDIN_UNIT—Unit number for standard input
- GFORTRAN_STDOUT_UNIT—Unit number for standard output
- GFORTRAN_STDERR_UNIT—Unit number for standard error
- GFORTRAN_UNBUFFERED_ALL—Do not buffer I/O on all units
- GFORTRAN_UNBUFFERED_PRECONNECTED—Do not buffer I/O on preconnected units
- GFORTRAN_SHOW_LOCUS—Show location for runtime errors
- GFORTRAN_OPTIONAL_PLUS—Print leading + where permitted
- GFORTRAN_LIST_SEPARATOR—Separator for list output
- GFORTRAN_CONVERT_UNIT—Set conversion for unformatted I/O
- GFORTRAN_ERROR_BACKTRACE—Show backtrace on run-time errors
- GFORTRAN_FORMATTED_BUFFER_SIZE—Set buffer size for formatted I/O
- GFORTRAN_UNFORMATTED_BUFFER_SIZE—Set buffer size for unformatted I/O
Part II: Language Reference#
- Compiler Characteristics
- KIND Type Parameters
- Internal representation of LOGICAL variables
- Evaluation of logical expressions
- MAX and MIN intrinsics with REAL NaN arguments
- Thread-safety of the runtime library
- Data consistency and durability
- Files opened without an explicit ACTION= specifier
- File operations on symbolic links
- File format of unformatted sequential files
- Asynchronous I/O
- Extensions
- Extensions implemented in GNU Fortran
- Old-style kind specifications
- Old-style variable initialization
- Extensions to namelist
- X format descriptor without count field
- Commas in FORMAT specifications
- Missing period in FORMAT specifications
- Default widths for F, G and I format descriptors
- I/O item lists
- Q exponent-letter
- BOZ literal constants
- Real array indices
- Unary operators
- Implicitly convert LOGICAL and INTEGER values
- Hollerith constants support
- Character conversion
- Cray pointers
- CONVERT specifier
- OpenMP
- OpenACC
- Argument list functions %VAL, %REF and %LOC
- Read/Write after EOF marker
- STRUCTURE and RECORD
- UNION and MAP
- Type variants for integer intrinsics
- AUTOMATIC and STATIC attributes
- Extended math intrinsics
- Form feed as whitespace
- TYPE as an alias for PRINT
- %LOC as an rvalue
- .XOR. operator
- Bitwise logical operators
- Extended I/O specifiers
- Legacy PARAMETER statements
- Default exponents
- Extensions not implemented in GNU Fortran
- Extensions implemented in GNU Fortran
- Mixed-Language Programming
- Interoperability with C
- GNU Fortran Compiler Directives
- Non-Fortran Main Program
- _gfortran_set_args — Save command-line arguments
- _gfortran_set_options — Set library option flags
- _gfortran_set_convert — Set endian conversion
- _gfortran_set_record_marker — Set length of record markers
- _gfortran_set_fpe — Enable floating point exception traps
- _gfortran_set_max_subrecord_length — Set subrecord length
- Naming and argument-passing conventions
- Coarray Programming
- Type and enum ABI Documentation
- Function ABI Documentation
- _gfortran_caf_init — Initialiation function
- _gfortran_caf_finish — Finalization function
- _gfortran_caf_this_image — Querying the image number
- _gfortran_caf_num_images — Querying the maximal number of images
- _gfortran_caf_image_status — Query the status of an image
- _gfortran_caf_failed_images — Get an array of the indexes of the failed images
- _gfortran_caf_stopped_images — Get an array of the indexes of the stopped images
- _gfortran_caf_register — Registering coarrays
- _gfortran_caf_deregister — Deregistering coarrays
- _gfortran_caf_is_present — Query whether an allocatable or pointer component in a derived type coarray is allocated
- _gfortran_caf_send — Sending data from a local image to a remote image
- _gfortran_caf_get — Getting data from a remote image
- _gfortran_caf_sendget — Sending data between remote images
- _gfortran_caf_send_by_ref — Sending data from a local image to a remote image with enhanced referencing options
- _gfortran_caf_get_by_ref — Getting data from a remote image using enhanced references
- _gfortran_caf_sendget_by_ref — Sending data between remote images using enhanced references on both sides
- _gfortran_caf_lock — Locking a lock variable
- _gfortran_caf_lock — Unlocking a lock variable
- _gfortran_caf_event_post — Post an event
- _gfortran_caf_event_wait — Wait that an event occurred
- _gfortran_caf_event_query — Query event count
- _gfortran_caf_sync_all — All-image barrier
- _gfortran_caf_sync_images — Barrier for selected images
- _gfortran_caf_sync_memory — Wait for completion of segment-memory operations
- _gfortran_caf_error_stop — Error termination with exit code
- _gfortran_caf_error_stop_str — Error termination with string
- _gfortran_caf_fail_image — Mark the image failed and end its execution
- _gfortran_caf_atomic_define — Atomic variable assignment
- _gfortran_caf_atomic_ref — Atomic variable reference
- _gfortran_caf_atomic_cas — Atomic compare and swap
- _gfortran_caf_atomic_op — Atomic operation
- _gfortran_caf_co_broadcast — Sending data to all images
- _gfortran_caf_co_max — Collective maximum reduction
- _gfortran_caf_co_min — Collective minimum reduction
- _gfortran_caf_co_sum — Collective summing reduction
- _gfortran_caf_co_reduce — Generic collective reduction
- Intrinsic Procedures
- Introduction to intrinsic procedures
- ABORT — Abort the program
- ABS — Absolute value
- ACCESS — Checks file access modes
- ACHAR — Character in ASCII collating sequence
- ACOS — Arccosine function
- ACOSD — Arccosine function, degrees
- ACOSH — Inverse hyperbolic cosine function
- ADJUSTL — Left adjust a string
- ADJUSTR — Right adjust a string
- AIMAG — Imaginary part of complex number
- AINT — Truncate to a whole number
- ALARM — Execute a routine after a given delay
- ALL — All values in MASK along DIM are true
- ALLOCATED — Status of an allocatable entity
- AND — Bitwise logical AND
- ANINT — Nearest whole number
- ANY — Any value in MASK along DIM is true
- ASIN — Arcsine function
- ASIND — Arcsine function, degrees
- ASINH — Inverse hyperbolic sine function
- ASSOCIATED — Status of a pointer or pointer/target pair
- ATAN — Arctangent function
- ATAND — Arctangent function, degrees
- ATAN2 — Arctangent function
- ATAN2D — Arctangent function, degrees
- ATANH — Inverse hyperbolic tangent function
- ATOMIC_ADD — Atomic ADD operation
- ATOMIC_AND — Atomic bitwise AND operation
- ATOMIC_CAS — Atomic compare and swap
- ATOMIC_DEFINE — Setting a variable atomically
- ATOMIC_FETCH_ADD — Atomic ADD operation with prior fetch
- ATOMIC_FETCH_AND — Atomic bitwise AND operation with prior fetch
- ATOMIC_FETCH_OR — Atomic bitwise OR operation with prior fetch
- ATOMIC_FETCH_XOR — Atomic bitwise XOR operation with prior fetch
- ATOMIC_OR — Atomic bitwise OR operation
- ATOMIC_REF — Obtaining the value of a variable atomically
- ATOMIC_XOR — Atomic bitwise OR operation
- BACKTRACE — Show a backtrace
- BESSEL_J0 — Bessel function of the first kind of order 0
- BESSEL_J1 — Bessel function of the first kind of order 1
- BESSEL_JN — Bessel function of the first kind
- BESSEL_Y0 — Bessel function of the second kind of order 0
- BESSEL_Y1 — Bessel function of the second kind of order 1
- BESSEL_YN — Bessel function of the second kind
- BGE — Bitwise greater than or equal to
- BGT — Bitwise greater than
- BIT_SIZE — Bit size inquiry function
- BLE — Bitwise less than or equal to
- BLT — Bitwise less than
- BTEST — Bit test function
- C_ASSOCIATED — Status of a C pointer
- C_F_POINTER — Convert C into Fortran pointer
- C_F_PROCPOINTER — Convert C into Fortran procedure pointer
- C_FUNLOC — Obtain the C address of a procedure
- C_LOC — Obtain the C address of an object
- C_SIZEOF — Size in bytes of an expression
- CEILING — Integer ceiling function
- CHAR — Character conversion function
- CHDIR — Change working directory
- CHMOD — Change access permissions of files
- CMPLX — Complex conversion function
- CO_BROADCAST — Copy a value to all images the current set of images
- CO_MAX — Maximal value on the current set of images
- CO_MIN — Minimal value on the current set of images
- CO_REDUCE — Reduction of values on the current set of images
- CO_SUM — Sum of values on the current set of images
- COMMAND_ARGUMENT_COUNT — Get number of command line arguments
- COMPILER_OPTIONS — Options passed to the compiler
- COMPILER_VERSION — Compiler version string
- COMPLEX — Complex conversion function
- CONJG — Complex conjugate function
- COS — Cosine function
- COSD — Cosine function, degrees
- COSH — Hyperbolic cosine function
- COTAN — Cotangent function
- COTAND — Cotangent function, degrees
- COUNT — Count function
- CPU_TIME — CPU elapsed time in seconds
- CSHIFT — Circular shift elements of an array
- CTIME — Convert a time into a string
- DATE_AND_TIME — Date and time subroutine
- DBLE — Double conversion function
- DCMPLX — Double complex conversion function
- DIGITS — Significant binary digits function
- DIM — Positive difference
- DOT_PRODUCT — Dot product function
- DPROD — Double product function
- DREAL — Double real part function
- DSHIFTL — Combined left shift
- DSHIFTR — Combined right shift
- DTIME — Execution time subroutine (or function)
- EOSHIFT — End-off shift elements of an array
- EPSILON — Epsilon function
- ERF — Error function
- ERFC — Error function
- ERFC_SCALED — Error function
- ETIME — Execution time subroutine (or function)
- EVENT_QUERY — Query whether a coarray event has occurred
- EXECUTE_COMMAND_LINE — Execute a shell command
- EXIT — Exit the program with status.
- EXP — Exponential function
- EXPONENT — Exponent function
- EXTENDS_TYPE_OF — Query dynamic type for extension
- FDATE — Get the current time as a string
- FGET — Read a single character in stream mode from stdin
- FGETC — Read a single character in stream mode
- FINDLOC — Search an array for a value
- FLOOR — Integer floor function
- FLUSH — Flush I/O unit(s)
- FNUM — File number function
- FPUT — Write a single character in stream mode to stdout
- FPUTC — Write a single character in stream mode
- FRACTION — Fractional part of the model representation
- FREE — Frees memory
- FSEEK — Low level file positioning subroutine
- FSTAT — Get file status
- FTELL — Current stream position
- GAMMA — Gamma function
- GERROR — Get last system error message
- GETARG — Get command line arguments
- GET_COMMAND — Get the entire command line
- GET_COMMAND_ARGUMENT — Get command line arguments
- GETCWD — Get current working directory
- GETENV — Get an environmental variable
- GET_ENVIRONMENT_VARIABLE — Get an environmental variable
- GETGID — Group ID function
- GETLOG — Get login name
- GETPID — Process ID function
- GETUID — User ID function
- GMTIME — Convert time to GMT info
- HOSTNM — Get system host name
- HUGE — Largest number of a kind
- HYPOT — Euclidean distance function
- IACHAR — Code in ASCII collating sequence
- IALL — Bitwise AND of array elements
- IAND — Bitwise logical and
- IANY — Bitwise OR of array elements
- IARGC — Get the number of command line arguments
- IBCLR — Clear bit
- IBITS — Bit extraction
- IBSET — Set bit
- ICHAR — Character-to-integer conversion function
- IDATE — Get current local time subroutine (day/month/year)
- IEOR — Bitwise logical exclusive or
- IERRNO — Get the last system error number
- IMAGE_INDEX — Function that converts a cosubscript to an image index
- INDEX — Position of a substring within a string
- INT — Convert to integer type
- INT2 — Convert to 16-bit integer type
- INT8 — Convert to 64-bit integer type
- IOR — Bitwise logical or
- IPARITY — Bitwise XOR of array elements
- IRAND — Integer pseudo-random number
- IS_CONTIGUOUS — Test whether an array is contiguous
- IS_IOSTAT_END — Test for end-of-file value
- IS_IOSTAT_EOR — Test for end-of-record value
- ISATTY — Whether a unit is a terminal device
- ISHFT — Shift bits
- ISHFTC — Shift bits circularly
- ISNAN — Test for a NaN
- ITIME — Get current local time subroutine (hour/minutes/seconds)
- KILL — Send a signal to a process
- KIND — Kind of an entity
- LBOUND — Lower dimension bounds of an array
- LCOBOUND — Lower codimension bounds of an array
- LEADZ — Number of leading zero bits of an integer
- LEN — Length of a character entity
- LEN_TRIM — Length of a character entity without trailing blank characters
- LGE — Lexical greater than or equal
- LGT — Lexical greater than
- LINK — Create a hard link
- LLE — Lexical less than or equal
- LLT — Lexical less than
- LNBLNK — Index of the last non-blank character in a string
- LOC — Returns the address of a variable
- LOG — Natural logarithm function
- LOG10 — Base 10 logarithm function
- LOG_GAMMA — Logarithm of the Gamma function
- LOGICAL — Convert to logical type
- LSHIFT — Left shift bits
- LSTAT — Get file status
- LTIME — Convert time to local time info
- MALLOC — Allocate dynamic memory
- MASKL — Left justified mask
- MASKR — Right justified mask
- MATMUL — matrix multiplication
- MAX — Maximum value of an argument list
- MAXEXPONENT — Maximum exponent of a real kind
- MAXLOC — Location of the maximum value within an array
- MAXVAL — Maximum value of an array
- MCLOCK — Time function
- MCLOCK8 — Time function (64-bit)
- MERGE — Merge variables
- MERGE_BITS — Merge of bits under mask
- MIN — Minimum value of an argument list
- MINEXPONENT — Minimum exponent of a real kind
- MINLOC — Location of the minimum value within an array
- MINVAL — Minimum value of an array
- MOD — Remainder function
- MODULO — Modulo function
- MOVE_ALLOC — Move allocation from one object to another
- MVBITS — Move bits from one integer to another
- NEAREST — Nearest representable number
- NEW_LINE — New line character
- NINT — Nearest whole number
- NORM2 — Euclidean vector norms
- NOT — Logical negation
- NULL — Function that returns an disassociated pointer
- NUM_IMAGES — Function that returns the number of images
- OR — Bitwise logical OR
- PACK — Pack an array into an array of rank one
- PARITY — Reduction with exclusive OR
- PERROR — Print system error message
- POPCNT — Number of bits set
- POPPAR — Parity of the number of bits set
- PRECISION — Decimal precision of a real kind
- PRESENT — Determine whether an optional dummy argument is specified
- PRODUCT — Product of array elements
- RADIX — Base of a model number
- RAN — Real pseudo-random number
- RAND — Real pseudo-random number
- RANDOM_INIT — Initialize a pseudo-random number generator
- RANDOM_NUMBER — Pseudo-random number
- RANDOM_SEED — Initialize a pseudo-random number sequence
- RANGE — Decimal exponent range
- RANK — Rank of a data object
- REAL — Convert to real type
- RENAME — Rename a file
- REPEAT — Repeated string concatenation
- RESHAPE — Function to reshape an array
- RRSPACING — Reciprocal of the relative spacing
- RSHIFT — Right shift bits
- SAME_TYPE_AS — Query dynamic types for equality
- SCALE — Scale a real value
- SCAN — Scan a string for the presence of a set of characters
- SECNDS — Time function
- SECOND — CPU time function
- SELECTED_CHAR_KIND — Choose character kind
- SELECTED_INT_KIND — Choose integer kind
- SELECTED_REAL_KIND — Choose real kind
- SET_EXPONENT — Set the exponent of the model
- SHAPE — Determine the shape of an array
- SHIFTA — Right shift with fill
- SHIFTL — Left shift
- SHIFTR — Right shift
- SIGN — Sign copying function
- SIGNAL — Signal handling subroutine (or function)
- SIN — Sine function
- SIND — Sine function, degrees
- SINH — Hyperbolic sine function
- SIZE — Determine the size of an array
- SIZEOF — Size in bytes of an expression
- SLEEP — Sleep for the specified number of seconds
- SPACING — Smallest distance between two numbers of a given type
- SPREAD — Add a dimension to an array
- SQRT — Square-root function
- SRAND — Reinitialize the random number generator
- STAT — Get file status
- STORAGE_SIZE — Storage size in bits
- SUM — Sum of array elements
- SYMLNK — Create a symbolic link
- SYSTEM — Execute a shell command
- SYSTEM_CLOCK — Time function
- TAN — Tangent function
- TAND — Tangent function, degrees
- TANH — Hyperbolic tangent function
- THIS_IMAGE — Function that returns the cosubscript index of this image
- TIME — Time function
- TIME8 — Time function (64-bit)
- TINY — Smallest positive number of a real kind
- TRAILZ — Number of trailing zero bits of an integer
- TRANSFER — Transfer bit patterns
- TRANSPOSE — Transpose an array of rank two
- TRIM — Remove trailing blank characters of a string
- TTYNAM — Get the name of a terminal device
- UBOUND — Upper dimension bounds of an array
- UCOBOUND — Upper codimension bounds of an array
- UMASK — Set the file creation mask
- UNLINK — Remove a file from the file system
- UNPACK — Unpack an array of rank one into an array
- VERIFY — Scan a string for characters not a given set
- XOR — Bitwise logical exclusive OR
- Intrinsic Modules
- Contributing
- GNU GENERAL PUBLIC LICENSE
- Preamble
- TERMS AND CONDITIONS
- 0. Definitions.
- 1. Source Code.
- 2. Basic Permissions.
- 3. Protecting Users’ Legal Rights From Anti-Circumvention Law.
- 4. Conveying Verbatim Copies.
- 5. Conveying Modified Source Versions.
- 6. Conveying Non-Source Forms.
- 7. Additional Terms.
- 8. Termination.
- 9. Acceptance Not Required for Having Copies.
- 10. Automatic Licensing of Downstream Recipients.
- 11. Patents.
- 12. No Surrender of Others’ Freedom.
- 13. Use with the GNU Affero General Public License.
- 14. Revised Versions of this License.
- 15. Disclaimer of Warranty.
- 16. Limitation of Liability.
- 17. Interpretation of Sections 15 and 16.
- How to Apply These Terms to Your New Programs
- GNU Free Documentation License
- Preamble
- 1. APPLICABILITY AND DEFINITIONS
- 2. VERBATIM COPYING
- 3. COPYING IN QUANTITY
- 4. MODIFICATIONS
- 5. COMBINING DOCUMENTS
- 6. COLLECTIONS OF DOCUMENTS
- 7. AGGREGATION WITH INDEPENDENT WORKS
- 8. TRANSLATION
- 9. TERMINATION
- 10. FUTURE REVISIONS OF THIS LICENSE
- 11. RELICENSING
- ADDENDUM: How to use this License for your documents
- Funding Free Software
- Indexes and tables