您的位置:首页 > 其它

f2c / f77 安装指导手册以及使用方法,无瑕纯洁版

2015-03-18 22:41 381 查看
March 18, 2015

f2c / f77 Installation Instructions for Linux

[code]f2c / f77 background
f2c is a fortran77-to-c source code translator. Because f2c is written in c and its ouput is c, both of which can be compiled natively on unix operating systems, f2c offers a very transportable compiler solution for compiling fortran programs. f2c also offers a means of converting large fortran libraries, such as LAPACK, into c. f2c is still actively maintained and is available at http://www.netlib.org/f2c/. 
The original f77 program, which was written in c, was the first complete fortran77 compiler. The original f77 program is no longer available for current computer architectures. However, f2c is based on the original f77 program, and the f2c distribution contains a f77 wrapper script that combines the f2c translation and c compilation steps. The f77 script also supports many command line options commonly associated with fortran compilers. Since the f77 script calls f2c, which in turn is based upon the original f77 program, the f77 script within the f2c distribution represents the most current implementation of the original f77 program.
Download installation script
Download install_f2c_linux.csh which is the following script

#! /bin/csh
setenv INSTALL /usr/local
curl "http://netlib.sandia.gov/cgi-bin/netlib/netlibfiles.tar?filename=netlib/f2c" -o "f2c.tar"
tar -xvf f2c.tar
gunzip -rf f2c/*
cd f2c
mkdir libf2c
mv libf2c.zip libf2c
cd libf2c
unzip libf2c.zip
cp makefile.u Makefile
make
cp f2c.h $INSTALL/include
cp libf2c.a $INSTALL/lib
cd ../src
cp makefile.u Makefile
make
cp f2c $INSTALL/bin
cd ..
mkdir -p $INSTALL/man/man1
cp f2c.1t $INSTALL/man/man1
cp fc $INSTALL/bin/f77
chmod +x $INSTALL/bin/f77
cd ..
rm -rf f2c
echo "==================SUMMARY=================="
echo $0 " has built and installed:"
find $INSTALL -name '*f2c*' -mmin -5
find $INSTALL -name '*f77*' -mmin -5

Run installation script
    # chmod +x install_f2c_linux.csh
    # ./install_f2c_linux.csh
which will produce the following files:
    /usr/local/bin/f2c
    /usr/local/include/f2c.h
    /usr/local/lib/libf2c.a
    /usr/local/man/man1/f2c.1t
    /usr/local/bin/f77
Translate, compile, link, and run a program
    $ f2c hello.f
    $ gcc -c hello.c
    $ gcc -o hello hello.o -lf2c -lm
    $ ./hello
Or combine these into a single command
    $ f77 -o hello hello.f


http://www.webmo.net/support/f2c_linux.html

安装过程中会出现

[root@yutong src]# make

./xsum Notice README cds.c data.c defines.h defs.h equiv.c error.c exec.c expr.c f2c.1 f2c.1t f2c.h format.c format.h formatdata.c ftypes.h gram.c gram.dcl gram.exec gram.expr gram.head gram.io init.c intr.c io.c iob.h lex.c machdefs.h main.c makefile.u makefile.vc malloc.c mem.c memset.c misc.c names.c names.h niceprintf.c niceprintf.h output.c output.h p1defs.h p1output.c parse.h parse_args.c pccdefs.h pread.c proc.c put.c putpcc.c sysdep.c sysdep.h sysdeptest.c tokens usignal.h vax.c version.c xsum.c >xsum1.out

/bin/sh: ./xsum: Permission denied

make: * [xsum.out] Error 126

[root@yutong src]# LS

bash: LS: command not found…

Similar command is: ‘ls’

[root@yutong src]# vim Makefile

[root@yutong src]# ls

cds.c expr.c gram.c init.c makefile.u names.c p1defs.h putpcc.c usignal.h

data.c f2c.1 gram.dcl intr.c makefile.vc names.h p1output.c readme vax.c

defines.h f2c.1t gram.exec iob.h malloc.c niceprintf.c parse_args.c README version.c

defs.h f2c.h gram.expr io.c MD5 niceprintf.h parse.h sysdep.c xsum

directory format.c gram.head lex.c mem.c notice pccdefs.h sysdep.h xsum0.out

equiv.c formatdata.c gram.io machdefs.h memset.c Notice pread.c sysdeptest.c xsum1.out

error.c format.h index main.c misc.c output.c proc.c tokdefs.h xsum.c

exec.c ftypes.h index.html Makefile mkfile.plan9 output.h put.c tokens

[root@yutong src]# ls -al xsum

-rw-r–r– 1 52842 37288 7394 Aug 15 2011 xsum

[root@yutong src]# chmod +x xsum

[root@yutong src]# make

./xsum Notice README cds.c data.c defines.h defs.h equiv.c error.c exec.c expr.c f2c.1 f2c.1t f2c.h format.c format.h formatdata.c ftypes.h gram.c gram.dcl gram.exec gram.expr gram.head gram.io init.c intr.c io.c iob.h lex.c machdefs.h main.c makefile.u makefile.vc malloc.c mem.c memset.c misc.c names.c names.h niceprintf.c niceprintf.h output.c output.h p1defs.h p1output.c parse.h parse_args.c pccdefs.h pread.c proc.c put.c putpcc.c sysdep.c sysdep.h sysdeptest.c tokens usignal.h vax.c version.c xsum.c >xsum1.out

/bin/sh: ./xsum: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

make: * [xsum.out] Error 126

这是因为64位系统中安装了32位程序

解决方法:

yum install glibc.i686

重新安装以后还有如下类系错误 再继续安装包

error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

yum install libstdc++.so.6

使用

f2c是一个不带图形界面的命令行程序。它提供了众多程序参数,下面的表格给出了其中一些比较重要的参数说明。

参数 说明

-A 生成ANSI C代码,如不指定此参数则默认生成K&R形式代码。

-a 将函数定义中的变量设定为自动类型(automatic)而不是静态类型(static)。建议使用此参数。

-C++ 生成C++代码。如果你的项目开发语言是C++而不是C的话,建议使用此参数。实际上f2c在代码中加入如下预编译宏:

ifdef __cplusplus

extern “C” {

endif



ifdef __cplusplus

}

endif

如果使用该参数,最好把生成文件的扩展名从.c改为.cpp。

-c 将原Fortran代码作为注释放到C源代码文件中。

-P 对每一个输入Fortran源代码文件file.f,将函数定义的原型(ANSI C prototype)写入file.P文件中。可以将file.P改名为file.h以便导出函数定义。

-r8 将单精度浮点型变量提升为双精度浮点型。

f2c支持Unix命令参数标准,因此下面两种形式是等价的。

f2c−P−A−a−c−r8∗.f f2c -P -A -a -c -r8 *.f
f2c -PAacr8 *.f

此外,利用Unix的管道(pipe)功能,可以把多个Fortran源代码文件转换为一个C源代码文件。

$ cat *.f | f2c > mystuff.c

f2c生成的函数定义原型文件的扩展名是.P,在Linux下面可以
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: