This page is translated from http://www.g95.org/docs.html
— 本页面翻译自G95官方网站:http://www.g95.org/
快速链接:
开始:
下载并安装G95 for windows:
win 9x用户,http://ftp.g95.org/g95-MinGW.exe
win 2x,xp用户,http://ftp.g95.org/g95-MinGW-41.exe
装好之后,即可使用了。
运行 G95
基本选项:
-c | 只编译, 不运行链接器. |
-o | 输出文件的命名, 对于目标文件*.o或者可执行文件*.exe. |
多个源文件和目标文件的编译可以一次执行。Fortran 文件的格式由其扩展名决定,例如 ".f", ".F", ".for", ".FOR", ".f90", ".F90", ".f95", ".F95", ".f03" 和 ".F03"。 多个源文件可以由此指明格式,目标文件也可以被具体指明,并一起链接成一个可执行文件。
大写的文件扩展名经过C预处理器分析(默认),小写的扩展名不被C预处理器分析。
文件扩展名为 ".f", ".F", ".for", 和 ".FOR" 被认作固定格式,与老的f77文件兼容。文件扩展名为 ".f90", ".F90", ".f95", ".F95", ".f03" 和 ".F03" 被认作自由格式书写的源文件。
简单的例子:
g95 -c hello.f90 | 把 hello.f 编译成目标文件,命名为 hello.o. |
g95 hello.f90 | 编译 hello.f90 并链接生成可执行文件a.out(Unix)或者a.exe(Windows) |
g95 -c h1.f90 h2.f90 h3.f90 | 编译多个源文件。如果顺利,生成目标文件 h1.o, h2.o 和 h3.o |
g95 -o hello h1.f90 h2.f90 h3.f90 | 编译多个源文件,并把它们链接生成一个可执行文件,命名为 'hello'. |
预处理选项
G95 可以处理包含C预处理器结构的文件can handle files that contain C preprocessor constructs.-cpp | 强制用C预处理器运行输入文件 |
-no-cpp | 防止输入文件被处理 |
-Dname[=value] | 定义一个预处理宏 |
-Uname | 取消一个预处理宏的定义 |
-E | 只显示预处理源程序 |
-Idirectory | 添加 '目录' 搜索包括的模块文件。文件一下面的方式搜索:主源文件的木留,当前的目录,-I 特定的目录,在G95_INCLUDE_PATH environment 变量特定的目录,最后是系统目录。 |
-traditional | 执行传统的C预处理(默认) |
-nontraditional | 执行现代的C预处理 |
Fortran 选项
-Wall | 允许大多数的警告信息 |
-Werror | 把警告变成错误。 |
-Wextra | 允许 -Wall 中不允许的警告 |
-Wglobals | 交叉检查同一个源文件里的使用和定义。 默认情况下,用 -Wno-globals 禁止. |
-Wimplicit-none | 同 -fimplicit-none |
-Wimplicit-interface | 警告使用一个默认的借口 |
-Wline-truncation | 警告语句行被删节 |
-Wmissing-intent | 警告缺少变量的意向 intent |
-Wobsolescent | 警告没有使用的结构 |
-Wno=numbers | 取消逗号分隔的警告数字列表 |
-Wuninitialized | 警告变量使用前没有初始化。需要 -O2 |
-Wunused-vars | 警告没有使用的变量 |
-Wunused-types | 警告没有使用的模块类型。没有由 -Wall 默认。 |
-Wunset-vars | 警告没有设置的变量。 |
-Wunused-module-vars | 警告没有使用的模块变量,对有 Only 语句有用。 |
-Wunused-module-procs | 警告没有使用的模块程序。对有 Only 语句有用。 |
-Wunused-parameter | 警告没有使用的常量系数。没有由 -Wall 默认。 |
-Wprecision-loss | 警告精度损失,在默认的类型转换时 |
-fbackslash | 解释反斜线符号/ 作为字符常量的结束代码。用 -fno-backslash 把反斜线符号当作一个字。 |
-fd-comment | 让D行可执行的指令,用固定格式书写 |
-fdollar-ok | 允许用美元符号$命名实体 |
-fendian= | 强制字节顺序,对非格式的读写。值必须是'big' 或者 'little'. 而不管环境变量. |
-ffixed-form | 假定源文件是固定格式 |
-ffixed-line-length-132 | 固定格式书写长度为132字符 |
-ffixed-line-length-80 | 固定格式书写长度为80字符 |
-ffree-form | 假定源文件是自由格式 |
-ffree-line-length-huge | 允许大于10K的源文件 |
-fimplicit-none | 指定允许非默认类型, 除非有显示的默认类型说明指令。 |
-fintrinsic-extensions | 允许 g95- 特殊内部程序,即使在 -std= 模式 |
-fintrinsic-extensions=proc1,proc2,... | 包括选择的内部程序,即使在 -std= 模式. 列表以逗号分开 |
-fmod=directory | 把模块文件放入文件夹 directory |
-fmodule-private | 设置模块的实体属性默认为 PRIVATE |
-fmultiple-save | 允许SAVE 属性多次被指定 |
-fone-error | 强制在第一个错误后,停止编译 |
-ftr15581 | 允许 TR15581 可变数组扩充,即使在-std=F或-std=f95 模式下 |
-M | 在标准输出文件上生成一个编写文件的行 |
-std=F | 警告 非-F 的特征 |
-std=f2003 | 严格 fortran 2003 检查 |
-std=f95 | 严格 fortran 95 检查 |
-i4 | 设置Integer的种类说明为kind=4 (32位机)。默认的种类不改变。 |
-i8 | 设置Integer的种类说明为kind=8 (65位机)。默认的种类不改变。 |
-r8 | 设置实数的种类为双精度,未作特定说明的话。 |
-d8 | 默认为 -i8 和-r8. |
编码整体选项
-fbounds-check | Check array and substring bounds at runtime |
-fcase-upper | Make all public symbols uppercase |
-fleading-underscore | Add a leading underscore to public names |
-fonetrip | Execute DO-loops at least once. (Buggy fortran 66) |
-fpack-derived | Try to layout derived types as compact as possible. Requires less memory, but may be slower |
-fqkind=n | Set the kind for a real with the 'q' exponent to n |
-fsecond-underscore | Append a second trailing underscore in names having an underscore (default). Use -fno-second-underscore to suppress. |
-fshort-circuit | Cause the .AND. and .OR. operators to not compute the second operand if the value of the expression is known from the first operand. |
-fsloppy-char | Suppress errors when writing non-character data to character descriptors |
-fstatic | Put local variables in static memory where possible. This is not the same as linking things statically (-static). |
-ftrace | '-ftrace=frame' will insert code to allow stack tracebacks on abnormal end of program. This will slow down your program. '-ftrace=full' additionally allows finding the line number of arithmetic exceptions (slower). Default is '-ftrace=none'. |
-funderscoring | Append a trailing underscore in global names (default). Use -fno-underscoring to suppress. |
-max-frame-size=n | How large a single stack frame will get before arrays are allocated dynamically |
-finteger=n | Initialize uninitialized scalar integer variables to n |
-flogical= | Initialize uninitialized scalar logical variables. Legal values are none, true and false. |
-freal= | Initialize uninitialized scalar real and complex variables. Legal values are none, zero, nan, inf, +inf and -inf. |
-fpointer= | Initialize scalar pointers. Legal values are none, null and invalid. |
-fround= | Controls compile-time rounding. Legal values are nearest, plus, minus and zero. Default is round to nearest, plus is round to plus infinity, minus is minus infinity, zero is towards zero. |
-fzero | Initialize numeric types to zero, logical values to false and pointers to null. The other initialization options override this one. |
运行g95程序
G95 的运行环境提供了多种选项,在运行的时候来引导你的程序。它们可以通过环境变量来控制。用--g95选项来运行g95编译程序,就可以拷贝标准选项输出文件。
可变变量的值总是字符串,但是该字符串可以被认为证书或者布尔变量".true."。只有布尔变量第一个字符检查的时候必须为 't', 'f', 'y', 'n', '1' 或 '0' (大写的OK也算)。如果值是错误的,并且没有出现错误,就使用缺省值。
G95_STDIN_UNIT | Integer | Unit number that will be preconnected to standard input. No preconnection if negative, default is 5. |
G95_STDOUT_UNIT | Integer | Unit number that will be preconnected to standard output. No preconnection if negative, default is 6. |
G95_STDERR_UNIT | Integer | Unit number that will be preconnected to standard error. No preconnection if negative, default is 0. |
G95_USE_STDERR | Boolean | Sends library output to standard error instead of standard output. Default is Yes. |
G95_ENDIAN | String | Endian format to use for I/O of unformatted data. Values are BIG, LITTLE or NATIVE. Default is NATIVE. |
G95_CR | Boolean | Output carriage returns for formatted sequential records. Default true on windows, false elsewhere. |
G95_IGNORE_CR | Boolean | Treat a carriage return-linefeed as a record marker instead of just a linefeed. Default true. |
G95_IGNORE_ENDFILE | Boolean | Ignore attempts to read past the ENDFILE record in sequential access mode. Default false |
G95_TMPDIR | String | Directory for scratch files. Overrides the TMP environment variable. If TMP is not set /var/tmp is used. No default |
G95_UNBUFFERED_ALL | Boolean | If TRUE, all output is unbuffered. This will slow down large writes but can be useful for forcing data to be displayed immediately. Default is False. |
G95_SHOW_LOCUS | Boolean | If TRUE, print filename and line number where runtime errors happen. Default is Yes. |
G95_OPTIONAL_PLUS | Boolean | Print optional plus signs in numbers where permitted. Default FALSE. |
G95_DEFAULT_RECL | Integer | Default maximum record length for sequential files. Most useful for adjusting line length of preconnected units. Default is 50000000. |
G95_LIST_SEPARATOR | String | Separator to use when writing list output. May contain any number of spaces and at most one comma. Default is a single space. |
G95_LIST_EXP | Integer | Last power of ten which does not use exponential format for list output. Default 6. |
G95_COMMA | Boolean | Use a comma character as the default decimal point for I/O. Default false. |
G95_EXPAND_UNPRINTABLE | Boolean | For formatted output, print otherwise unprintable characters with /-sequences. Default No. |
G95_QUIET | Boolean | Suppress bell characters (/a) in formatted output. Default No. |
G95_SYSTEM_CLOCK | Integer | Number of ticks per second reported by the SYSTEM_CLOCK() intrinsic in microseconds. Zero disables the clock. Default 100000. |
G95_SEED_RNG | Boolean | If true, seeds the random number generator with a new seed when the program is run. Default false. |
G95_MINUS_ZERO | Boolean | If true, prints minus zero without a minus sign in formatted (non-list) output, contrary to the standard. Default FALSE. |
G95_ABORT | Boolean | If true, dumps core on abnormal program end. Useful for finding the locus of the problem. Default FALSE. |
G95_MEM_INIT | String | How to initialize allocated memory. Default value is NONE for no initialization (faster), NAN for a Not-a-Number with the mantissa 0x40f95 or a custom hexadecimal value. |
G95_MEM_SEGMENTS | Integer | Maximum number of still-allocated memory segments to display when program ends. 0 means show none, less than 0 means show all. Default 25 |
G95_MEM_MAXALLOC | Boolean | If true, shows the maximum number of bytes allocated in user memory during the program run. Default No. |
G95_MEM_MXFAST | Integer | Maximum request size for handing requests in from fastbins. Fastbins are quicker but fragment more easily. Default 64 bytes. |
G95_MEM_TRIM_THRESHOLD | Integer | Amount of top-most memory to keep around until it is returned to the operating system. -1 prevents returning memory to the system. Useful in long-lived programs. Default 262144. |
G95_MEM_TOP_PAD | Integer | Extra space to allocate when getting memory from the OS. Can speed up future requests. Default 0. |
G95_SIGHUP | String | Whether the program will IGNORE, ABORT or SUSPEND on SIGHUP. Default ABORT. |
G95_SIGINT | String | Whether the program will IGNORE or ABORT or SUSPEND on SIGINT. Default ABORT |
G95_FPU_ROUND | String | Set floating point rounding mode. Values are NEAREST, UP, DOWN, ZERO. Default is NEAREST. |
G95_FPU_PRECISION | String | Precision of intermediate results. Value can be 24, 53 and 64. Default 64. Only available on x86 and IA64 compatibles. |
G95_FPU_DENORMAL | Boolean | Raise a floating point exception when denormal numbers are encountered. Default no. |
G95_FPU_INVALID | Boolean | Raise a floating point exception on an invalid operation. Default No. |
G95_FPU_ZERODIV | Boolean | Raise a floating point exception when dividing by zero. Default No. |
G95_FPU_OVERFLOW | Boolean | Raise a floating point exception on overflow. Default No. |
G95_FPU_UNDERFLOW | Boolean | Raise a floating point exception on underflow. Default No. |
G95_FPU_INEXACT | Boolean | Raise a floating point exception on precision loss. Default No |
G95_FPU_EXCEPTIONS | Boolean | Whether masked floating point exceptions should be shown after the program ends. Default No |
G95_UNIT_x | String | Overrides the default unit name for unit x. |
G95_UNBUFFERED_x | Boolean | If true, unit x is unbuffered |
G95_UNIT_ENDIAN_x | String | Sets the endianness of an individual unit. The value can be "big" or "little". Takes precedence over G95_ENDIAN |
运行时的错误代码
-2 | 记录的结束 |
-1 | 文件的结束 |
0 | 成功返回 |
操作系统错误代码 (1 - 199) | |
200 | 冲突的指令选项 |
201 | 错误的指令选项 |
202 | 缺少指令选项 |
203 | 文件已经通过别的设备号打开 |
204 | 无隶属的单元 |
205 | 格式错误 |
206 | 执行错误的指令 |
207 | 读过ENDFILE记录 |
208 | 读到错误的值 |
209 | 读的时候,数值溢出 |
210 | 内存不足 |
211 | 数组已经被分配 |
212 | 取消分配一个错误的指针 |
214 | 在无格式顺序直接文件中的错误 |
215 | 读取数据多余记录长度 (RECL) |
216 | 写入数据多余记录长度 (RECL) |
对g95程序的接口
因为g95程序可独立运行,偶尔需要与其他的程序接口,通常是C语言。第一个困难就是多语言编程要面对的公共符号。G95 根据f2c调用规则对公共的名称加以下划线,或者双下划线,如果还包括一个下划线(这里指子程序的意思)。选项 -fno-second-underscore 和 -fno-underscoring 用于强迫g95来生成与C编译器相兼容的名字。
用 'nm' 程序来看两个编译器生成的目标文件.o。
G95 folds public names to lowercase as well, unless -fupper-case is given, in which case everything will be upper case. Module names are represented as module-name_MP_name.
After linking, there are two main cases: Fortran calling C subroutines and C calling fortran subroutines.
For C calling fortran subroutines, the fortran subroutines will often call fortran library subroutines that expect the heap to be initialized in some way. To force a manual initialization from C, call g95_runtime_start() to initialize the fortran library and g95_runtime_stop() when done. The prototype of the g95_runtime_start() is:
void g95_runtime_start(int argc, char *argv[]);The library has to be able to process command-line options. If this is awkward to do and your program doesn't have a need for command-line arguments, pass argc=0 and argv=NULL.
On OSX/Tiger, include '-lSystemStubs' when using g95 to run the linker and linking objects files compiled by gcc.
Information on OpenGL binding can be found at Nick Yasko's G95/OpenGL page .
© 2004 Free Software Foundation