G95 使用详解

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-checkCheck array and substring bounds at runtime
-fcase-upperMake all public symbols uppercase
-fleading-underscoreAdd a leading underscore to public names
-fonetripExecute DO-loops at least once. (Buggy fortran 66)
-fpack-derivedTry to layout derived types as compact as possible. Requires less memory, but may be slower
-fqkind=nSet the kind for a real with the 'q' exponent to n
-fsecond-underscoreAppend a second trailing underscore in names having an underscore (default). Use -fno-second-underscore to suppress.
-fshort-circuitCause the .AND. and .OR. operators to not compute the second operand if the value of the expression is known from the first operand.
-fsloppy-charSuppress errors when writing non-character data to character descriptors
-fstaticPut 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'.
-funderscoringAppend a trailing underscore in global names (default). Use -fno-underscoring to suppress.
-max-frame-size=nHow large a single stack frame will get before arrays are allocated dynamically
-finteger=nInitialize 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.
-fzeroInitialize 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_UNITIntegerUnit number that will be preconnected to standard input. No preconnection if negative, default is 5.
G95_STDOUT_UNITIntegerUnit number that will be preconnected to standard output. No preconnection if negative, default is 6.
G95_STDERR_UNITIntegerUnit number that will be preconnected to standard error. No preconnection if negative, default is 0.
G95_USE_STDERRBooleanSends library output to standard error instead of standard output. Default is Yes.
G95_ENDIANStringEndian format to use for I/O of unformatted data. Values are BIG, LITTLE or NATIVE. Default is NATIVE.
G95_CRBooleanOutput carriage returns for formatted sequential records. Default true on windows, false elsewhere.
G95_IGNORE_CRBooleanTreat a carriage return-linefeed as a record marker instead of just a linefeed. Default true.
G95_IGNORE_ENDFILEBooleanIgnore attempts to read past the ENDFILE record in sequential access mode. Default false
G95_TMPDIRStringDirectory for scratch files. Overrides the TMP environment variable. If TMP is not set /var/tmp is used. No default
G95_UNBUFFERED_ALLBooleanIf 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_LOCUSBooleanIf TRUE, print filename and line number where runtime errors happen. Default is Yes.
G95_OPTIONAL_PLUSBooleanPrint optional plus signs in numbers where permitted. Default FALSE.
G95_DEFAULT_RECLIntegerDefault maximum record length for sequential files. Most useful for adjusting line length of preconnected units. Default is 50000000.
G95_LIST_SEPARATORStringSeparator to use when writing list output. May contain any number of spaces and at most one comma. Default is a single space.
G95_LIST_EXPIntegerLast power of ten which does not use exponential format for list output. Default 6.
G95_COMMABooleanUse a comma character as the default decimal point for I/O. Default false.
G95_EXPAND_UNPRINTABLEBooleanFor formatted output, print otherwise unprintable characters with /-sequences. Default No.
G95_QUIETBooleanSuppress bell characters (/a) in formatted output. Default No.
G95_SYSTEM_CLOCKIntegerNumber of ticks per second reported by the SYSTEM_CLOCK() intrinsic in microseconds. Zero disables the clock. Default 100000.
G95_SEED_RNGBooleanIf true, seeds the random number generator with a new seed when the program is run. Default false.
G95_MINUS_ZEROBooleanIf true, prints minus zero without a minus sign in formatted (non-list) output, contrary to the standard. Default FALSE.
G95_ABORTBooleanIf true, dumps core on abnormal program end. Useful for finding the locus of the problem. Default FALSE.
G95_MEM_INITStringHow 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_SEGMENTSIntegerMaximum 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_MAXALLOCBooleanIf true, shows the maximum number of bytes allocated in user memory during the program run. Default No.
G95_MEM_MXFASTIntegerMaximum request size for handing requests in from fastbins. Fastbins are quicker but fragment more easily. Default 64 bytes.
G95_MEM_TRIM_THRESHOLDIntegerAmount 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_PADIntegerExtra space to allocate when getting memory from the OS. Can speed up future requests. Default 0.
G95_SIGHUPStringWhether the program will IGNORE, ABORT or SUSPEND on SIGHUP. Default ABORT.
G95_SIGINTStringWhether the program will IGNORE or ABORT or SUSPEND on SIGINT. Default ABORT
G95_FPU_ROUNDStringSet floating point rounding mode. Values are NEAREST, UP, DOWN, ZERO. Default is NEAREST.
G95_FPU_PRECISIONStringPrecision of intermediate results. Value can be 24, 53 and 64. Default 64. Only available on x86 and IA64 compatibles.
G95_FPU_DENORMALBooleanRaise a floating point exception when denormal numbers are encountered. Default no.
G95_FPU_INVALIDBooleanRaise a floating point exception on an invalid operation. Default No.
G95_FPU_ZERODIVBooleanRaise a floating point exception when dividing by zero. Default No.
G95_FPU_OVERFLOWBooleanRaise a floating point exception on overflow. Default No.
G95_FPU_UNDERFLOWBooleanRaise a floating point exception on underflow. Default No.
G95_FPU_INEXACTBooleanRaise a floating point exception on precision loss. Default No
G95_FPU_EXCEPTIONSBooleanWhether masked floating point exceptions should be shown after the program ends. Default No
G95_UNIT_xStringOverrides the default unit name for unit x.
G95_UNBUFFERED_xBooleanIf true, unit x is unbuffered
G95_UNIT_ENDIAN_xStringSets 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值