📄 gfortran.texi
字号:
Fortran) for each file in the source code, and then calls the assemblerand linker as appropriate to produce the compiled output. In a copy ofGCC which has been compiled with Fortran language support enabled,@command{gcc} will recognize files with @file{.f}, @file{.for}, @file{.ftn},@file{.f90}, @file{.f95}, and @file{.f03} extensions as Fortran source code,and compile it accordingly. A @command{gfortran} driver program is alsoprovided, which is identical to @command{gcc} except that it automaticallylinks the Fortran runtime libraries into the compiled program.Source files with @file{.f}, @file{.for}, @file{.fpp}, @file{.ftn}, @file{.F},@file{.FOR}, @file{.FPP}, and @file{.FTN} extensions are treated as fixed form.Source files with @file{.f90}, @file{.f95}, @file{.f03}, @file{.F90}, @file{.F95}, and @file{.F03} extensions are treated as free form. Thecapitalized versions of either form are run through preprocessing. Source fileswith the lower case @file{.fpp} extension are also run through preprocessing.This manual specifically documents the Fortran front end, which handlesthe programming language's syntax and semantics. The aspects of GCCwhich relate to the optimization passes and the back-end code generationare documented in the GCC manual; see @ref{Top,,Introduction,gcc,Using the GNU Compiler Collection (GCC)}.The two manuals together provide a complete reference for the GNUFortran compiler.@c ---------------------------------------------------------------------@c Preprocessing and conditional compilation@c ---------------------------------------------------------------------@node Preprocessing and conditional compilation@section Preprocessing and conditional compilation@cindex CPP@cindex FPP@cindex Conditional compilation@cindex PreprocessingMany Fortran compilers including GNU Fortran allow passing the source codethrough a C preprocessor (CPP; sometimes also called the Fortran preprocessor,FPP) to allow for conditional compilation. In the case of GNU Fortran,this is the GNU C Preprocessor in the traditional mode. On systems withcase-preserving file names, the preprocessor is automatically invoked if thefile extension is @code{.F}, @code{.FOR}, @code{.FTN}, @code{.F90},@code{.F95} or @code{.F03}; otherwise use for fixed-format code the option@code{-x f77-cpp-input} and for free-format code @code{-x f95-cpp-input}.Invocation of the preprocessor can be suppressed using @code{-x f77} or@code{-x f95}.If the GNU Fortran invoked the preprocessor, @code{__GFORTRAN__}is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and@code{__GNUC_PATCHLEVEL__} can be used to determine the version of thecompiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details.While CPP is the de-facto standard for preprocessing Fortran code,Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) definesConditional Compilation, which is not widely used and not directlysupported by the GNU Fortran compiler. You can use the program cocoto preprocess such files (@uref{http://users.erols.com/dnagle/coco.html}).@c ---------------------------------------------------------------------@c GNU Fortran and G77@c ---------------------------------------------------------------------@node GNU Fortran and G77@section GNU Fortran and G77@cindex Fortran 77@cindex @command{g77}The GNU Fortran compiler is the successor to @command{g77}, the Fortran 77 front end included in GCC prior to version 4. It is an entirely new program that has been designed to provide Fortran 95 support and extensibility for future Fortran language standards, as well as providing backwards compatibility for Fortran 77 and nearly all of the GNU language extensions supported by @command{g77}.@c ---------------------------------------------------------------------@c Project Status@c ---------------------------------------------------------------------@node Project Status@section Project Status@quotationAs soon as @command{gfortran} can parse all of the statements correctly,it will be in the ``larva'' state.When we generate code, the ``puppa'' state.When @command{gfortran} is done,we'll see if it will be a beautiful butterfly,or just a big bug....--Andy Vaught, April 2000@end quotationThe start of the GNU Fortran 95 project was announced onthe GCC homepage in March 18, 2000(even though Andy had already been working on it for a while,of course).The GNU Fortran compiler is able to compile nearly allstandard-compliant Fortran 95, Fortran 90, and Fortran 77 programs,including a number of standard and non-standard extensions, and can beused on real-world programs. In particular, the supported extensionsinclude OpenMP, Cray-style pointers, and several Fortran 2003 featuressuch as enumeration, stream I/O, and some of the enhancements toallocatable array support from TR 15581. However, it is still underdevelopment and has a few remaining rough edges.At present, the GNU Fortran compiler passes the@uref{http://www.fortran-2000.com/ArnaudRecipes/fcvs21_f95.html, NIST Fortran 77 Test Suite}, and produces acceptable results on the@uref{http://www.netlib.org/lapack/faq.html#1.21, LAPACK Test Suite}.It also provides respectable performance on the @uref{http://www.polyhedron.com/pb05.html, Polyhedron Fortrancompiler benchmarks} and the@uref{http://www.llnl.gov/asci_benchmarks/asci/limited/lfk/README.html,Livermore Fortran Kernels test}. It has been used to compile a number oflarge real-world programs, including@uref{http://mysite.verizon.net/serveall/moene.pdf, the HIRLAMweather-forecasting code} and@uref{http://www.theochem.uwa.edu.au/tonto/, the Tonto quantum chemistry package}; see @url{http://gcc.gnu.org/wiki/GfortranApps} for anextended list.Among other things, the GNU Fortran compiler is intended as a replacementfor G77. At this point, nearly all programs that could be compiled withG77 can be compiled with GNU Fortran, although there are a few minor knownregressions.The primary work remaining to be done on GNU Fortran falls into threecategories: bug fixing (primarily regarding the treatment of invalid codeand providing useful error messages), improving the compiler optimizationsand the performance of compiled code, and extending the compiler to supportfuture standards---in particular, Fortran 2003.@c ---------------------------------------------------------------------@c Standards@c ---------------------------------------------------------------------@node Standards@section Standards@cindex StandardsThe GNU Fortran compiler implementsISO/IEC 1539:1997 (Fortran 95). As such, it can also compile essentially allstandard-compliant Fortran 90 and Fortran 77 programs. It also supportsthe ISO/IEC TR-15581 enhancements to allocatable arrays, andthe @uref{http://www.openmp.org/drupal/mp-documents/spec25.pdf,OpenMP Application Program Interface v2.5} specification.In the future, the GNU Fortran compiler may also support other standard variants of and extensions to the Fortran language. These includeISO/IEC 1539-1:2004 (Fortran 2003).@c =====================================================================@c PART I: INVOCATION REFERENCE@c =====================================================================@tex\part{I}{Invoking GNU Fortran}@end tex@c ---------------------------------------------------------------------@c Compiler Options@c ---------------------------------------------------------------------@include invoke.texi@c ---------------------------------------------------------------------@c Runtime@c ---------------------------------------------------------------------@node Runtime@chapter Runtime: Influencing runtime behavior with environment variables@cindex environment variableThe behavior of the @command{gfortran} can be influenced byenvironment variables.Malformed environment variables are silently ignored.@menu* 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_USE_STDERR:: Send library output to standard error* GFORTRAN_TMPDIR:: Directory for scratch files* GFORTRAN_UNBUFFERED_ALL:: Don't buffer I/O for all units.* GFORTRAN_UNBUFFERED_PRECONNECTED:: Don't buffer I/O for preconnected units.* GFORTRAN_SHOW_LOCUS:: Show location for runtime errors* GFORTRAN_OPTIONAL_PLUS:: Print leading + where permitted* GFORTRAN_DEFAULT_RECL:: Default record length for new files* GFORTRAN_LIST_SEPARATOR:: Separator for list output* GFORTRAN_CONVERT_UNIT:: Set endianness for unformatted I/O* GFORTRAN_ERROR_DUMPCORE:: Dump core on run-time errors* GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors@end menu@node GFORTRAN_STDIN_UNIT@section @env{GFORTRAN_STDIN_UNIT}---Unit number for standard inputThis environment variable can be used to select the unit numberpreconnected to standard input. This must be a positive integer.The default value is 5.@node GFORTRAN_STDOUT_UNIT@section @env{GFORTRAN_STDOUT_UNIT}---Unit number for standard outputThis environment variable can be used to select the unit numberpreconnected to standard output. This must be a positive integer.The default value is 6.@node GFORTRAN_STDERR_UNIT@section @env{GFORTRAN_STDERR_UNIT}---Unit number for standard errorThis environment variable can be used to select the unit numberpreconnected to standard error. This must be a positive integer.The default value is 0.@node GFORTRAN_USE_STDERR@section @env{GFORTRAN_USE_STDERR}---Send library output to standard errorThis environment variable controls where library output is sent.If the first letter is @samp{y}, @samp{Y} or @samp{1}, standarderror is used. If the first letter is @samp{n}, @samp{N} or@samp{0}, standard output is used.@node GFORTRAN_TMPDIR@section @env{GFORTRAN_TMPDIR}---Directory for scratch filesThis environment variable controls where scratch files arecreated. If this environment variable is missing,GNU Fortran searches for the environment variable @env{TMP}. Ifthis is also missing, the default is @file{/tmp}.@node GFORTRAN_UNBUFFERED_ALL@section @env{GFORTRAN_UNBUFFERED_ALL}---Don't buffer I/O on all unitsThis environment variable controls whether all I/O is unbuffered. Ifthe first letter is @samp{y}, @samp{Y} or @samp{1}, all I/O isunbuffered. This will slow down small sequential reads and writes. Ifthe first letter is @samp{n}, @samp{N} or @samp{0}, I/O is buffered.This is the default.@node GFORTRAN_UNBUFFERED_PRECONNECTED@section @env{GFORTRAN_UNBUFFERED_PRECONNECTED}---Don't buffer I/O on preconnected unitsThe environment variable named @env{GFORTRAN_UNBUFFERED_PRECONNECTED} controlswhether I/O on a preconnected unit (i.e STDOUT or STDERR) is unbuffered. If the first letter is @samp{y}, @samp{Y} or @samp{1}, I/O is unbuffered. Thiswill slow down small sequential reads and writes. If the first letteris @samp{n}, @samp{N} or @samp{0}, I/O is buffered. This is the default.@node GFORTRAN_SHOW_LOCUS@section @env{GFORTRAN_SHOW_LOCUS}---Show location for runtime errorsIf the first letter is @samp{y}, @samp{Y} or @samp{1}, filename andline numbers for runtime errors are printed. If the first letter is@samp{n}, @samp{N} or @samp{0}, don't print filename and line numbersfor runtime errors. The default is to print the location.@node GFORTRAN_OPTIONAL_PLUS@section @env{GFORTRAN_OPTIONAL_PLUS}---Print leading + where permittedIf the first letter is @samp{y}, @samp{Y} or @samp{1},a plus sign is printedwhere permitted by the Fortran standard. If the first letteris @samp{n}, @samp{N} or @samp{0}, a plus sign is not printedin most cases. Default is not to print plus signs.@node GFORTRAN_DEFAULT_RECL@section @env{GFORTRAN_DEFAULT_RECL}---Default record length for new filesThis environment variable specifies the default record length, inbytes, for files which are opened without a @code{RECL} tag in the@code{OPEN} statement. This must be a positive integer. Thedefault value is 1073741824 bytes (1 GB).@node GFORTRAN_LIST_SEPARATOR@section @env{GFORTRAN_LIST_SEPARATOR}---Separator for list outputThis environment variable specifies the separator when writinglist-directed output. It may contain any number of spaces andat most one comma. If you specify this on the command line,be sure to quote spaces, as in@smallexample$ GFORTRAN_LIST_SEPARATOR=' , ' ./a.out@end smallexamplewhen @command{a.out} is the compiled Fortran program that you want to run.Default is a single space.@node GFORTRAN_CONVERT_UNIT@section @env{GFORTRAN_CONVERT_UNIT}---Set endianness for unformatted I/OBy setting the @env{GFORTRAN_CONVERT_UNIT} variable, it is possibleto change the representation of data for unformatted files.The syntax for the @env{GFORTRAN_CONVERT_UNIT} variable is:@smallexampleGFORTRAN_CONVERT_UNIT: mode | mode ';' exception | exception ;mode: 'native' | 'swap' | 'big_endian' | 'little_endian' ;exception: mode ':' unit_list | unit_list ;unit_list: unit_spec | unit_list unit_spec ;unit_spec: INTEGER | INTEGER '-' INTEGER ;@end smallexampleThe variable consists of an optional default mode, followed bya list of optional exceptions, which are separated by semicolonsfrom the preceding default and each other. Each exception consistsof a format and a comma-separated list of units. Valid values forthe modes are the same as for the @code{CONVERT} specifier:@itemize @w{}@item @code{NATIVE} Use the native format. This is the default.@item @code{SWAP} Swap between little- and big-endian.@item @code{LITTLE_ENDIAN} Use the little-endian format for unformatted files.@item @code{BIG_ENDIAN} Use the big-endian format for unformatted files.@end itemizeA missing mode for an exception is taken to mean @code{BIG_ENDIAN}.Examples of values for @env{GFORTRAN_CONVERT_UNIT} are:@itemize @w{}@item @code{'big_endian'} Do all unformatted I/O in big_endian mode.@item @code{'little_endian;native:10-20,25'} Do all unformatted I/O in little_endian mode, except for units 10 to 20 and 25, which are innative format.@item @code{'10-20'} Units 10 to 20 are big-endian, the rest is native.@end itemizeSetting the environment variables should be done on the commandline or via the @command{export}command for @command{sh}-compatible shells and via @command{setenv}for @command{csh}-compatible shells.Example for @command{sh}:@smallexample$ gfortran foo.f90$ GFORTRAN_CONVERT_UNIT='big_endian;native:10-20' ./a.out@end smallexampleExample code for @command{csh}:@smallexample% gfortran foo.f90% setenv GFORTRAN_CONVERT_UNIT 'big_endian;native:10-20'% ./a.out@end smallexampleUsing anything but the native representation for unformatted datacarries a significant speed overhead. If speed in this area mattersto you, it is best if you use this only for data that needs to beportable.@xref{CONVERT specifier}, for an alternative way to specify thedata representation for unformatted files. @xref{Runtime Options}, forsetting a default data representation for the whole program. The@code{CONVERT} specifier overrides the @option{-fconvert} compile options.@emph{Note that the values specified via the GFORTRAN_CONVERT_UNITenvironment variable will override the CONVERT specifier in theopen statement}. This is to give control over data formats tousers who do not have the source code of their program available.@node GFORTRAN_ERROR_DUMPCORE@section @env{GFORTRAN_ERROR_DUMPCORE}---Dump core on run-time errorsIf the @env{GFORTRAN_ERROR_DUMPCORE} variable is set to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -