90999 发表于 2014-7-28 16:09:11

G77 简易 Fortran 编译器 FOR WIN

释放到任意位置,然后修改g77setup.bat里的G77PATH = d:\G77 为你自己释放的路径,运行g77setup.bat 写入系统路径。

然后用记事本什么的IDE写代码,用g77 代码名 -o 文件名.exe 编译, 不加-o 输出a.exe ,没有优化等级。 程序在WIN7下测试通过。





简单说明
----------------------------------------------------------------------------
1. What is g77?
----------------------------------------------------------------------------

G77 is a Fortran compiler from the Free Software Foundation (GNU). The g77
compiler is designed to be portable, and there are implementationson a
wide variety of systems including Linux, other Unixes, OS/2, MS-DOS and
Windows 95/98/Me and Windows NT4/2000/XP.

The g77 compiler supports the whole of the (now obsolete) Fortran77
Standard plus many commonly-used extensions.

Typographical note: in this introduction Fortran keywords and code are
shown in UPPER CASE merely to make them stand out; g77 is equally happy
with Fortran in lower-case.



----------------------------------------------------------------------------
4. How to use the compiler.
----------------------------------------------------------------------------

The command G77 will compile and link your program and produce an
executable that can only be run under Windows 95/98/Me or Windows
NT4/2000/XP, not under DOS (nor in a DOS box of Windows 3.1x)
There are various command options (see below) which need to be specified
before the name of the program file(s).A simple demonstration program
called MYTEST1.F is included in the package.To compile this just use:

G77 MYTEST1.F

This generates a file A.EXE, which can be executed simply using

A

The compiler by default names the produced executable file as "A.EXE".
If one wishes to override this default behavior, then one can specify
the desired name of the produced executable, using the "-o" compiler
option.E.g., to produce an executable with the name MYTEST1.EXE
the above command should be:

G77 MYTEST1.F -o MYTEST1.EXE

It is good practice to get the compiler to warn you of unused and
undeclared variables, the switch to do this is "-Wall" which can be used
like this:

G77 -Wall MYTEST1.F

Note that the switches are case-sensitive: -WALL will not work.

The g77 compiler has a large number of other command switches - a few of
the most useful are shown here:

-c               Compile-only: produces .OBJ files.
-ffree-form      Selects free-format source code
-fpedantic       Warns of non-portable/non-standard code.
-fno-automatic   Static storage for all variables, like universal SAVE
-fno-backslash   Interprets "\" as a normal character in strings
-fvxt            Use VAX Fortran interpretation of certain syntax
-g               Produces debugging information.
-Idirectory      Specifies directory to search for INCLUDE files
-O               Optimise code generation
-Wimplicit       Warns of any names with no explicit data type
-WuninitialisedWarns of some cases of unset variables (if -O also set).
-Wall            Warns of both of above cases.

Any number of source-code files can be used on the command-line, and
wild-cards (*) are supported in file-names.The command-line can also
contain compiled object modules (these have the .O extension) and library
files (called "archives" in Unix-speak) which have .A as the extension.
File-names are, of course, NOT case-sensitive under Windows 95/98/Me/NT4/2000/XP,
so file abcde.f is the same as file ABCDE.F and file aBcDe.F


NOTE:        How To Capture Errors Produced By The Compiler In a File:
      ---------------------------------------------------------
        The command shell of Windows 95/98/Me does not provide for re-direction
      of the standard error output.So, if a user wishes to capture the
        output of the compiler in a file, then a possible solution is by
      using a utility like "etime" (available as:
         
        http://www.geocities.com/Athens/Olympus/5564/etime.zip
       
        or as:
       
        http://kkourakis.tripod.com/etime.zip)
       
        for this purpose.In this case, running the compiler as:

                ETIME -2ERRFILE G77 MYFILE.F

        will capture all the errors in the file ERRFILE.

        Under Windows NT4/2000/XP the command shell supports Unix-like
        redirection of the standard error output, so a user only needs
        to enter:

                G77 MYFILE.F 2>ERRFILE

        in order to capture the compiler output in the file ERRFILE.

----------------------------------------------------------------------------
5. Extensions to g77 compatible with Fortran90:
----------------------------------------------------------------------------

The g77 compiler conforms fully only to the Fortran77 Standard.Although
this is technically obsolete, the vast majority of Fortran programs in the
world were written (more or less) to this Standard.The new standard,
Fortran90, has many more advanced features.The g77 compiler already
supports some features of Fortran90, the most notable of these being:

IMPLICIT NONE (to flag non-explicit data types in a program unit).
INCLUDE 'filename'
Automatic arrays (a form of dynamic storage within subprograms).
Free-format input (if the switch -ffree-form is used)
Multiple statements on a line (with ";" as the separator).
Symbolic names can be up to 31-characters long, can contain lower-case
letters (equivalent to upper-case) and underscores.
End-of-line comments may be used starting with ! (but ! must not be
in column 6 with fixed-format source-code).
Relational operators > >= < <= == /= can be used instead of .GT. etc.
Character constants can use "double" or 'single' quotes.
Program unit names permitted on END, e.g. END SUBROUTINE MYSUB.
DO without labels and END DO are permitted, also indefinite DO (but a
conditional EXIT or STOP is obviously needed in such loops).
DO WHILE(logical expression) with END DO is permitted.
EXIT and CYCLE are allowed in DO loops.
SELECT CASE structure is supported but only with integer/logical selectors.
Construct names are allowed with IF/DO/CYCLE/EXIT/SELECT CASE.
Zero-length strings are valid.
Substrings of character constants are permitted.
Character intrinsic functions ACHAR, IACHAR, and LEN_TRIM are provided.
Bit-wise integer functions BTEST, IAND, IBCLR, IBITS, IBSET, IEOR, IOR,
ISHFT, ISHFT, MVBITS, NOT (the MIL-STD 1753 intrinsics) are provided.
OPEN with STATUS='REPLACE' is supported.
NAMELIST input/output is also supported.
Type declarations may use KIND values (but this is of limited use because
kind-selection functions are not yet provided).

----------------------------------------------------------------------------
6. Other g77 extensions (NOT compatible with Fortran90)
----------------------------------------------------------------------------

Many extensions to the official Fortran77 Standard were introduced by
companies which produced Fortran compilers for sale, but not all of these
were incorporated into Fortran90.You may find that existing "Fortran77"
code makes use of some of these non-standard features.Fortunately g77
supports some of the more common extensions, especially those of VAX
Fortran.The most important ones are listed below.They make it possible
to use "legacy" code with a minimum of alteration, but are NOT recommended
if you are writing new code.

Data types BYTE, INTEGER*1, INTEGER*2, INTEGER*4 (default), INTEGER*8,
REAL*4 (default), REAL*8, DOUBLE COMPLEX, COMPLEX*8 (default), COMPLEX*16,
LOGICAL*1, LOGICAL*2, LOGICAL*4 (default) are supported.
DATA statements may be intermixed with specifications statements.
Arguments of procedure calls may use %VAL, %REF, %LOC, %DESCR functions.
Additional intrinsic functions: LOC, AND, OR, LSHIFT, RSHIFT, XOR,
CDABS, CDCOS, CDEXP, CDLOG, CDSIN, CDSQRT, DCMPLX, DCONJG, DFLOAT,
DIMAG, DREAL, IMAG, ZABS, ZCOS, ZEXP, ZLOG, ZSIN, and ZSQRT supported.
Any number of continuations lines may be used.
Symbolic names may include "$" if -fdollar-ok switch is specified..
Integer constants may be specified in other number bases: e.g. B'01',
O'01234567', X'01EF', Z'FFFF' etc.; in addition "typeless" constantsmay
be given in a similar form but with the letter following the string of
digits.
FORMAT specifications may include $ to suppress the final carriage-return.
Debug lines starting "D" or "d" are treated as comments.

----------------------------------------------------------------------------
7. Notes on Input/Output
----------------------------------------------------------------------------

I/O unit numbers must be in the range 0 to 99, with 0 and 6 pre-connected to
the screen, 5 to the keyboard (but best to use UNIT=* for both).
Unformatted direct-access files have bytes as units of record length.
Output to the screen does not count as "printing" in Fortran terms, so
the first character of each record is never removed for carriage-control.
Output to unit N is sent to file "FORT.N" if no file was opened for it.


----------------------------------------------------------------------------
8. The Fortran Library
----------------------------------------------------------------------------

G77 supports, even under Windows 95/98/Me/NT4/2000/XP, most of the routines
commonly used to access system services on Unix.These include: ABORT, GETARG,
IARGC, EXIT, CTIME, DATE, DTIME, ETIME, FDATE, GMTIME, LTIME, IDATE, ITIME,
MCLOCK, SECNDS, SECOND, SYSTEM, TIME,ERF, DERF, ERFC, DERFC, IRAND, RAND,
SRAND, ACCESS, CHDIR, CHMOD, GETCWD, FSTAT, SSTAT, LSTAT, RENAME, UMASK,
UNLINK, GERROR, IERRNO, PERROR, GETENV, FGETC, GFET, FPUTC, FPUT, FLUSH,
FNUM, FSEEK, FTELL, ISATTY, TTYNAM, SLEEP.

Note that I have not checked all of these.HOSTNM and GETLOG arenot
supported, and SYSTEM (which executes an operating system command line)
seems to work in a DOS-box under Windows 95/98/Me/NT4/2000/XP

For details of the calling sequences see the g77 documentation.


----------------------------------------------------------------------------
9. How to use object libraries
----------------------------------------------------------------------------

A version of the standard Unix library manager, unhelpfully called AR
(for "archiver") is provided.It manages what it calls "archives"
which are just collections of object modules.These libraries have ".A"
as their filename extension and the prefix "LIB" to their name.
E.g., the library with the "basic" name SLATEC will be stored
in the file LIBSLATEC.A
To create a library you need to compile the source files with the -c switch
to produce one or more object files (.O).These can be put in a library
like this:

AR -rLIBMYLIB.AFILE1.O FILE2.O ...etc(note the prefix "LIB")

or, even:

AR -rLIBMYLIB.A*.O

To list the contents of an archive use

AR -t LIBMYLIB.A

More details regarding the usage of the librarian utility "AR" are
given in the text file \G77\AR.DOC.
The generated libraries are best placed in the same directory where
all the G77 libraries were placed during installation (\G77\LIB\).
This directory is pointed at by the environment variable LIB_PATH
as set by the setup file G77SETUP.BAT   Then, the libraries can be
referenced in a G77 command line by the "-l" option followed (without
a space) with the library _basic_ name without the extension ".A",
_nor_ the prefix "LIB".E.g., a library file LIBMYLIB.A that exists
in \G77\LIB\ has the _basic_ library name "MYLIB".Then if one
specifies -lMYLIB on the G77 command-line, it will be searched during
the linking phaseand link only those modules which are called
directly or indirectly, e.g.,

G77 MYFILE.F -o MYFILE.EXE -lMYLIB   (note: this is "el", not "one")

Alternatively, one can specify the _full_ pathname of a library file
on the command line.E.g., to link with the modules contained with
the library file LIBXYZ.A which exists in the directory E:\QWERTY,
one can write:

G77 MYFILE.F -o MYFILE.EXE E:\QWERTY\LIBXYZ.A

If the library file is present in the current directory then one
can write:

G77 MYFILE.F -o MYFILE.EXE LIBXYZ.A

In general, libraries that are not to be used temporarily are best
placed in \G77\LIB and referenced as explained above with the "-l"
option, using only the basic library name.
       



90999 发表于 2014-7-28 16:10:22

本帖最后由 90999 于 2014-7-28 18:19 编辑

FORTRAN77语法概述/简单教程(G77)

FORTRAN是世界上最早出现的高级编程语言,是工程界最常用的编程语言,它在科学计算中(如航空航天、地质勘探、天气预报和建筑工程等领域)发挥着极其重要的作用。经过40多年的发展,伴随着FORTRAN语言多次版本的更新及相应开发系统的出现,其功能不断完善,最新版本的开发系统几乎具备了VC、VB的所有特点,如图形界面编程、数据库等。目前,工科院校开设的计算机编程语言课首选仍然是FORTRAN :<

说实话,从科技发展的趋势来说这不是好事。您可以设想一下,如果需要用鹅毛笔抄写大量的古籍是什么感受!
强烈建议阅读《发掘C#特性赋予科学计算项目以威力》
1 FORTRAN77四则运算符

+ – * / ** (其中**表示乘方)
在表达式中按优先级次序由低到高为: +或-→*或/→**→函数→()
2 FORTRAN77变量类型
2.1 隐含约定:I-N规则

凡是以字母I,J,K,L,M,N六个字母开头的,即认为是整型变量,其它为实型变量。
2.2 用类型说明语句确定变量类型:可以改变I-N规则INTEGER        整型
REAL        实型
DOUBLE PRECISION        双精度实型
COMPLEX        复型,赋值形式为(实部,虚部),如D=(8.76E+0.5,-67.8E-3),C=(3.0,6.3),如果含表达式则用CMPLX,如C=CMPLX(3.0*A,6.0+B)
LOGICAL        逻辑型,逻辑常量有“T”和“F”,“T”表示“.TRUE.”,“F”表示“.FALSE.”
CHARACTER*N        字符型,N为字符串长度,可以在变量名称后重新指定长度,如CHARACTER*8 STR1,STR2*10 ,赋值形式为STR2=’I”M A BOY.’

2.3 用IMPLICIT语句将某一字母开头的全部变量指定为所需类型

如 IMPLICIT REAL (I,J)
三种定义的优先级别由低到高顺序为:I-N规则→IMPLICIT语句→类型说明语句,因此,在程序中IMPLICIT语句应放在类型说明语句之前。

2.4 数组的说明与使用

使用I-N规则时用DIMENSION说明数组,也可在定义变量类型同时说明数组,说明格式为:数组名(下标下界,下标上界),也可省略下标下界,此时默认为1,例:
DIMENSION IA(0:9),ND(80:99),W(3,2),NUM(-1:0),A(0:2,0:1,0:3)
REAL IA(10),ND(80:99)使用隐含DO循环进行数组输入输出操作:例如
WRITE(*,10) (‘I=’,I,’A=’,A(I),I=1,10,2)
10FORMAT(1X,5(A2,I2,1X,A2,I4))
2.5 使用DATA语句给数组赋初值

变量表中可出现变量名,数组名,数组元素名,隐含DO循环,但不许出现任何形式的表达式:例如
DATA A,B,C/-1.0,-1.0,-1.0/
DATA A/-1.0/,B/-1.0/,C/-1.0/
DATA A,B,C/3*-1.0/CHARACTER*6 CHN(10)
DATA CHN/10*’   ‘/INTEGER NUM(1000)
DATA (NUM(I),I=1,500)/500*0/,(NUM(I),I=501,1000)/500*1/
3 FORTRAN77程序书写规则
程序中的变量名,不分大小写;
变量名称是以字母开头再加上1到5位字母或数字构成,即变更名字串中只有前6位有效;
一行只能写一个语句;
程序的第一个语句固定为PROGRAM 程序名称字符串
某行的第1个字符至第5个字符位为标号区,只能书写语句标号或空着或注释内容;
某行的第1个字符为C或*号时,则表示该行为注释行,其后面的内容为注释内容;
某行的第6个字符位为非空格和非0字符时,则该行为上一行的续行,一个语句最多可有19个续行;
某行的第7至72字符位为语句区,语句区内可以任加空格以求美观;
某行的第73至80字符位为注释区,80字符位以后不能有内容。
4 FORTRAN77关系运算符

.GT. 大于
.GE. 天于或等于
.LT. 小于
.LE. 小于或等于
.EQ. 等于
.NE. 不等于 .AND. 逻辑与
.OR. 逻辑或
.NOT. 逻辑非
.EQV. 逻辑等
.NEQV. 逻辑不等
运算符优先级由高到低顺序为:()→**→*或/→+或-→.GT.或.GE.或.LT.或.LE.或.EQ.或.NE.→.NOT.→.AND.→.OR.→.EQV.或.NEQV
5 FORTRAN77语句语句        说明        备注
WRITE(*,*) X1,X2        输出语句        第一个*号是指输入输出文件设备号或其它设备,如果不指定则是指显示器或打印机,第二个*号是指表控格式语句的行号,如不指定则用默认格式
PRINT *,X1,X2        输出语句        *号是指表控格式语句的行号,如不指定则用默认格式
READ *,X1,X2        输入语句        *号是指表控格式语句的行号,如不指定则用默认格式
FORMAT(格式符)        请见附录一。        请见附录二。
END        结束程序或子程序       
STOP         结束程序并输出信息        为数字或字符串信息
PAUSE         暂停程序执行并输出信息,输入回车后继续执行        为数字或字符串信息
PARAMETER (PI=3.14)        参数语句,用来定义常量,在程序中应放在类型说明语句之后       
EQUIVALENCE (变量表)        等价语句,()内变量共用一个存储单元。        EQUIVALENCE(X1,X2,…XN),(X1,X2,…XN),…
COMMON X1,……        公用语句,其后变量相等,用来在程序单位间传递数据,同时可以用来说明数组。程序中可有一个无名公用区和多个有名公用区。        无名公用区:在主程序各子程序中相同,均在可执行语句之前,如
COMMON A(5),I
有名公用区:名称放在两个“/”之间,如
COMMON //X1,X2,X3/C1/X4,X5,X6
OPEN (说明项1)        打开旧文件或创建新文件        说明项1中内容:UNIT=N, FILE=NAM, STATUS=STR1, ACCESS=STR2, FORM=STR3, RECL=C, BLANK=STR4, ERR=BH, IOSTAT=M
其中:
1.N=1~99;
2.NAM为文件名,可以是字符常量或变量;
3.STR1=’NEW’时新建文件;’OLD’时打开文件;’SCRATCH’时表示临时文件,关闭时自动删除,且不能与FILE=NAM项共存;’UNKNOWN’时由计算机系统规定文件状态;
4.STR2为文件存取方式,’SEQUENTIAL’表示顺序存取,’DIRECT’表示直接存取,省略此项时表示按顺序存取;
5.STR3为记录格式说明,’FORMATTED’表示记录按有格式形式存放, ‘UNFORMATTED’表示记录按无格式形式存放。省略此项时,对于顺序文件是有格式的,对于直接存取文件是无格式的;
6.C表示记录长度,以字节为单位,直接存取文件必指定,顺序文件必省略;
7.STR4表示数字值格式输入字段中空格含意,’NULL’时表示忽略不计,’ZERO’时表示按0计。省略此项时按0计;
8.BH表示出错时处理语句行标号,可以省略此项;
9.M为整数,出错时返回该整数,可以省略此项。
CLOSE (说明项2)        关闭已打开文件        说明项2中内容:UNIT=N,STATUS=STR5,ERR=BH,IOSTAT=M
其中STR5为文件关闭状态,’KEEP’时保留,’DELETE’删除,省略此项时为保留;
ERR=BH,IOSTAT=M可以省略。
REWIND (说明项3)        将文件读写指针置于文件开头        说明项3中内容:UNIT=N,ERR=BH,IOSTAT=M
ERR=BH,IOSTAT=M可以省略
BACKSPACE (说明项3)        将文件读写指针回退一行       

6 FORTRAN77选择判断语句
6.1 逻辑IF语句

IF (逻辑表达式) 程序语句
6.2 无ELSE块

IF (逻辑表达式) THEN
程序块
END IF
6.3 标准选择

IF (逻辑表达式) THEN
程序块1
ELSE
程序块2
END IF
6.4 多重选择块

IF (逻辑表达式1) THEN
程序块1
ELSE IF (逻辑表达式2) THEN
程序块2
ELSE IF (逻辑表达式2) THEN
程序块2
……
ELSE IF (逻辑表达式N) THEN
程序块N
ELSE
程序块N+1
END IF
7 FORTRAN77循环语句
7.1 GO TO语句

标号程序行
程序块
GO TO 标号
7.2 DO语句

DO 标号,记数变量=起始值,终止值,步距”语句,如
DO 标号,N=1,100,1
程序块
标号CONTINUE
7.3 DO WHILE 语句

DO 标号,WHILE(PI.EQ.3.14159)
程序块
标号CONTINUE
7.4 DO UNTIL语句

DO 标号,UNTIL (逻辑表达式)”语句,如
DO 标号,UNTIL(PI.GT.3.14159)
程序块
标号CONTINUE
8 FORTRAN77内部函数INT(X)        将数字串或数值X转换为整型数
REAL(X)        将数字串或数值X转换为实型数
DBEL(X)        将数字串或数值X转换为双精度型数
CMPLX(X)        将数字串或数值X转换为复型数
CHAR(X)        将数值X转换为字符(0≤X≤255)
ICHAR(X)        将字符X转换为整数
AINT(X)        截去X的小数部分
ANINT(X)        将X舍入到最接近的整数
NINT(X)        将X舍入到最接近的整型数
ABS(X)        返回X的绝对值
MOD(X1,X2)        返回X1/X2的余数
SIGN(X1,X2)        取X2的符号,取X1的绝对值
DIM(X1,X2)        当X1>X2时,等于X1-X2,当X1≤X2时,等于0
DPROD(X1,X2)        双精度乘(X1,X2均为实数)
AIMAG(X)        返回字符串X的虚部
CONJG(X)        返回字符串X的共轭
MAX(X1,X2,X3,…,XN)        返回X1,X2,X3,…,XN中最大值
MIN(X1,X2,X3,…,XN)        返回X1,X2,X3,…,XN中最小值
SQRT(X)        返回X的平方根(X≥0)
EXP(X)        返回E的X次方
LOG(X)        返回以E为底的X的对数即自然对数(X>0)
LOG10(X)        返回以10为底的X的对数即常用对数(X>0)
SIN(X)        返回弧度值X的正弦值
COS(X)        返回弧度值X的余弦值
TAN(X)        返回弧度值X的正切值
ASIN(X)        返回弧度值X的反正弦值
ACOS(X)        返回弧度值X的反余弦值
ATAN(X)        返回弧度值X的反正切值
SINH(X)        返回X的双曲正弦值
COSH(X)        返回X的双曲余弦值
TANH(X)        返回X的双曲正切值
LEN(X)        返回字符串X的长度
INDEX(X1,X2)        返回字符串X2在字符串X1中的位置,不包含时返回0
LGE(X1,X2)        如果字符串X1≥X2则等于.TRUE.,否则等于.FALSE.
LGT(X1,X2)        如果字符串X1>X2则等于.TRUE.,否则等于.FALSE.
LLE(X1,X2)        如果字符串X1≤X2则等于.TRUE.,否则等于.FALSE.
LLT(X1,X2)        如果字符串X1<X2则等于.TRUE.,否则等于.FALSE.
       

9 FORTRAN77函数与子程序
9.1 FORTRAN77语句函数
当函数十分简单,用一条语句足以定义时(允许使用继续行)才用;
应该放在所有可执行语句之前和有关类型说明语句之后,是非执行语句;
只在其所在程序单位中有意义;
语句函数中的虚参就是变量名,不能是常量、表达式或数组元素等;
语句函数定义语句中的表达式可以包含已经定义过的语句函数、外部函数或内部函数。
语句函数通过表达式得一个函数值,此数值类型必须与函数名的类型一致。语句函数的使用同内部函数相同。
语句函数例子:
YMJ(R)=3.14159265*R*R
ZMJ=YMJ(5)

9.2 FORTRAN77自定义函数

定义格式:
类型说明 FUNCTION 函数名(虚拟参数1,虚拟参数2,……,虚拟参数N)
程序块(可以含有RETURN)
函数名=函数值
END
调用格式与内部函数相同。
9.3 FORTRAN77子程序

定义格式:
SUBROUTINE 子程序名(虚拟参数1,虚拟参数2,……,虚拟参数N)
程序块(可以含有RETURN)
END
调用格式:
CALL 子程序名(实在参数1,实在参数2,……,实在参数N)
数据块子程序:只是用来给有名公用区中的变量赋初值,格式如下:
BLOCK DATA 子程序名
DATA语句块
END

附录一、FORTRAN77控制输入输出格式
1.在打印输出时,每一行第1个字符不显示,用来控制纵向走纸或显示行。第1个字符        作用
空格        正常回车换行
0        回车并跳过1行
1        换页
+        只回车不换行
其它        通常是回车换行


2.输入小数时,自带小数点优先。
3.输出字段宽度不够时用*号填充。

附录二、FORTRAN77控制输入输出格式语句1        IW或IW.M        整数型        W为字段宽度,M为最少数字位数
2        FW.D        实数型        D为小数位数
3        EW.D或EW.DEE        指数实数型        E为指数位数,通常为3或4
4        GW.M        自动实数型       
5        DW.D        双精度型       
6        LW        逻辑型       
7        A或AW        字符型        不指定W时自动
8        ‘字符串’        插入字符串        两个’表示一个字符’
9        NH字符串        插入长度为N的字符串       
10        NX        插入N个空格       
11        RIW,R(NX,IW.M)        R个IW,R个(NX,IW.M)        R为重复系数
12        /        换行       
13        ,$        禁止换行


7.2.5 使用硬件设备

在Fortran中标准的输入设备是键盘,标准的输出设备是显示器(控制台)。—般的输入输出语句都是针对标准设备进行操作的,如果想对除键盘和显示器以外的其他的物理设备进行读写操作,就应该把物理设备名描述为文件名,这样就可以像操作文件一样对其进行操作,绝大多数设备名没有扩展名。以下是WinNT/9x下的一些设备名。

设备
描述
CON
控制台(即屏幕,标准输出设备)
PRN
打印机
COMl
1#串行通信口
COM2
2#串行通信口
COM3
3#串行通信口
COM4
4#串行通信口
LPTl
1#并行通信口
LPT2
2#并行通信口
LPT3
3#并行通信口
LPT4
4#并行通信口
NUL
空(NLTLL)设备。放弃输出,不包含任何输入
AUX
1#串行通信口
LINE1
1#串行通信口
USER1
标准输出
ERRl
标准错误
CONOUT$
标准输出
CONIN$
标准输入
如果使用了这些名字的扩展名,例如LPT1.TXT,Fortran将会写入一个文件而不是相应的设备。下面是打开物理设备作为单元的例子:
例:OPEN(UNIT=4,FILE=’PRN’)
例:OPEN(UNIT=7,FILE=’COM2’,ERR=100)

aozima 发表于 2014-7-28 16:29:58

    考古!
页: [1]
查看完整版本: G77 简易 Fortran 编译器 FOR WIN