Free Fortran Compilers
来源:互联网 发布:centos安装snmp服务 编辑:程序博客网 时间:2024/05/17 01:42
Free Fortran Compilers
There are a number of free Fortran 77 and 90 compilers availableon the net. The one Ihave been using in my Fortran courses at Yorkis GNU, whichimplements Fortran 77 and adds several Fortran 90 features. Thanks to Prof.Clive Page (Dept of Physics & Astronomy, University of Leicester, UK)for providing the compiler and for valuable advice on Fortran in general.
Youcan download the 1999 version of this compiler (version 2.95 of gcc
) along with the SLATEC library (Version 4.1,July 1993), from this page. The package runs under all (32-bit) versions ofWindows, including XP
. All the needed filesare packed in one zipped file (Fort99.zip
) of about6MB.
(Iffor some reason you need the older DOS/EMX
version, which does notinclude a library and does not run under Windows XP
, then you can download it from my old page.)
DOWNLOAD
- Create the directory
\F
The new folder must be immediately under the root of your hard disk. You can do this by double-clicking MyComputer, then double-clicking your hard drive (usuallyC:
), and then selecting New Folder from the File menu and calling the folderF
. - Download the file
Fort99.zip
(5,820,239 bytes).
You can do this by right-clicking the mouse on the above link, and choosing Save Target As.... In the Save As window that appears, locate theF
folder, and save the file in it. - Unzip the downloaded file into
\F
.
Yon can do this by locating the file (starting from MyComputer) and simply double-clicking it to launch the zip/unzip program. Specify that all files should be extracted to theF
folder with their path names preserved (this is usually the default). If you don't have a zip/unzip program, download one from the Internet. - Set
LIBRARY_PATH
to\F\G77\lib
and include\F\G77\bin
in yourpath
. How these two environment variables are set varies from one version of Windows to another:- For the Windows 95/98/Me line: These variables are set in the
autoexec.bat
file, which is stored in the root directory of your hard disk; i.e.\
. Hence, you need to edit this file and add to the two lines:
- For the Windows 95/98/Me line: These variables are set in the
o PATH=\F\G77\bin;%PATH%
SET LIBRARY_PATH=\F\G77\lib
You can do this by opening this file in Notepad or any othereditor, adding the two lines at the end, and then saving the changes.
- For the Windows NT/2000/XP line: These variables can be set by going to the
Control Panel
, selectingSystem
, and then locating theenvironment
(or advanced, environment) section. You need to add a new variable with nameLIBRARY_PATH
and set its value to\F\G77\lib
. Similarly add a new variable namedPATH
and set its value to\F\G77\bin
or append;\F\G77\bin
to its value if it already exists.
Finally, restart your computer to allow the environment changes totake effect.
USAGE
You store your programs in the \F\York
directory, compile themusing: f2exe
, and createlibrary object files using f2lib
. Here is avery short program to test the compiler and the configuration:
program Convert
implicit none
! -----------------------------------------------Declare
real*4 tempC, tempF, FACTOR
integer*2 ZERO_SHIFT
parameter (ZERO_SHIFT = 32, FACTOR = 5./9.)
! -----------------------------------------------Input
print*, "Enter the temperature in Fahrenheit ..."
read*, tempF
! -----------------------------------------------Compute
tempC = FACTOR * (tempF - ZERO_SHIFT)
! -----------------------------------------------Output
print*, "The corresponding Centigrade temperature is "
print*, tempC, " degrees."
end
Use any editor to create this program (simply copy and paste) andsave it as a text file in the \F\York
directory under thename test.for
. You can,of course, use any editor you like as long as you can save the file in textformat and with the extension you want. Notepad, for example, uses text butinsists on using the txt
extension (unless youoverride by double-quoting) while MS-Word insists on its propriety format(unless you explicitly override). I highly recommend using the Crimson
editor, which can bedownloaded from the on-line Lab-1 (see below).
Compileand run your program from the DOS command prompt by typing:
cd \F\York
f2exe test
test
If the first command returned an error then the directory was notcreated (or named) correctly. If the second command was not recognized, orcomplained that a library is missing, then the environment variables were notset correctly (you can issue the set
command to inspect allenvironment variables).
Moreinformation on using the compiler can be found in the on-line Labs at the Fortran@York site.
LANGUAGE
The \F\G77\doc
directory has adetailed reference to the language, which is largly ANSI Fortran-77 but with someFortran-90 features added (see below).
Theabove Fortran@York site contains a quick reference guide,lab, and SLATEC usage examples. If you are already familiar with Fortran thenthe following points may be all you need to know about this compiler:
1. ControlStructures
You can use either the old (goto-based) or the new (structured) control flow(or mix them in the same program). Support of the "ugly goto" ismeant for existing code only, and any new development should avoid it.
2. Style
You can write your source using either the old style code (column 7) or thenewer free-form.
3. CompilationCommand
The above f2exe
command is just a batchfile that invokes g77
, the"real" compilation command. The command:
g77 -ffree-form prog.for -oprog.exe
directs the compiler to compile the file prog.for
and stores the outputin the file prog.exe
. The -ffree-form
switch indicatesfree-form style (remove it if you are using the old style).
4. Comments
In free-form style, use ! for both full-line and in-line comments. In the oldstyle, use a "C" in column-1.
5. StatementContinuation
In free-form style, you can continue a statement on the next line by ending itwith an ampersand "&". In the old style, put a character incolumn-6.
6. PathSeparator
When referring to files (e.g. in the file=' ' parameter of the OPEN statement)use a forward slash "/" or two consecutive backslashes "\\"rather than a backslash to delimit directories. This is because the backslash"\" denotes an escape sequence in strings.
7. I/O UnitNumbers
Not all unit numbers are allowed in the OPEN statement. In particular, unit 5is "pre-connected" to the keyboard. Units 10 through 99 seem to workwell with disk files.
8. Fortran-90Features
These include: Automatic arrays in subprograms, zero length strings, characterconstants may be enclosed in double quotes ("
) as well as singlequotes,cycle
and exit
, the DOUBLE COMPLEX
type, DO WHILE
, the END
decoration, KIND
, IMPLICIT NONE
, INCLUDE
statements,list-directed and namelist I/O on internal files, binary, octal, and hexconstants, `O' and `Z' edit descriptors, NAMELIST
, OPEN
specifiers STATUS='REPLACE'
, the FILE=
specifier may beomitted in an OPEN
statement if STATUS='SCRATCH'
is supplied, relationaloperators <
, <=
, ==
, /=
, >
and >=
may be used instead of .LT.
, .LE.
, .EQ.
, .NE.
, .GT.
and .GE.
respectively, SELECT CASE
(but not for charactertypes).
9. SeparateCompilation of Subprograms
Your main program is recognized by the program
statement, as in the Convert
program above. Thesubprograms (functions and subroutines) can be included in the same file as themain program (in which case you can compile everything in one shot) or can bestored in separate file(s). It is recommended that you store general reusablesubprograms in separate files so that you can reuse them (without recompilingthem) in future projects. To compile a file that contains only subprograms (no program
statement), use the f2lib
command, whichgenerates object files, one per sub, in the mine
directory, e.g.
f2lib util
will compile (without linking) the subprogram in util.for
and store the output(an object file) in the file util.o
. f2lib
is just a batch filethat invokes the g77
command with the -c
(compile-only) switch,viz.
g77 -c -ffree-form util.for -o..\mine\util.o
A program that uses pre-compiled object files can be compiled (andlinked to them) by simply referring to them in the compilation command:
g77 -ffree-form prog.for -oprog.exe ..\mine\*.o
The above command searches all object files in mine
to resolve any missingreference in prog.for
.
10. SeparateCompilation of Subprograms, automated
The supplied f2exe
and f2lib
batch files take careof separate compilation and delayed linking with object files and with theSLATEC subprograms. You don't have to directly issue the g77
command unless you usethe old columnar style or you want to change one of the switches ordirectories.
11. AssemblyListing
The -S
(capital S) switchallows you to see a listing of the generated assembly code.
F@Y/HR/S03 URL
- Free Fortran Compilers
- Free C, C++ Compilers
- compilers
- Fortran
- fortran
- fortran
- GNU compilers
- Introduce some c++ compilers
- 4.7 Scene Graph Compilers
- List of compilers
- free.
- free
- free()
- free
- free
- free
- free
- free()
- 随机生成测试数据(rand(),srand())
- C++可变参数
- 【剑指Offer学习】【面试题34:丑数】
- 黑马程序员-----正则表达式
- Linux转发性能评估与优化-转发瓶颈分析与解决方案(补遗)
- Free Fortran Compilers
- Thking in Java---数组详解
- 根据排队论阐述路由器和高速公路的拥堵以及拥堵缓解问题(二)
- 一道CTF
- android 杀不死的服务
- 近一个月的面试总结
- 驱动编程 配置内核树
- 将mysql数据从Windows迁移到Linux中
- oc错误:control reaches end of non-void function