[转] 批处理fortran77转fortran90格式
(转载时的话:现在很多浏览器都已经不支持ftp功能了,看网盘存档吧。如果网盘失效了可以邮件发给您)
由于f77不支持可变数组,导致想添加的功能不能实现,于是想把整个工程从77转成90。有同学推荐,直接在f77的模式下强行把f90的功能加进去(比如可变数组,module等),然后用gfortran编译也能通过运行。我自己做了小测试发现可变数组确实可以运行,但是不推荐,毕竟不规范!
说回正题,f77转f90倒是有一个比较好的网站可以转,而且还能在线转,网址:http://quill.fcode.cn/ 。但是网上转有一点不方便,不能批量转换,对文件大小也有限制。所以就上google上找了,主要找到了以下几个:
-
f77tof90, a Bourne shell script for dealing with non-standard F77 code. It converts Record and Structure F77 extensions into F90 Type statements. It also converts C-preprocessed #include statements into Fortran INCLUDE statements. Written by Jack Scheible.
网址:www.soton.ac.uk/~fortran/tools/f77tof90/f77tof90.html -
convert.f90, written by Mike Metcalf.
网址:ftp://ftp.numerical.rl.ac.uk/pub/MandR/convert.f90
https://hepd.pnpi.spb.ru/docs_html/Fortran90/WWW/f90/convert.f90
3.to_f90.f90, written by Alan Miller.
网址:users.bigpond.net.au/amiller/to_f90.f90
https://github.com/jbdv-no/to_f90
4.ftof90.c, for converting comments and continuation lines, written by Michael Olagnon.
网址:ftp://ftp.ifremer.fr/ifremer/ditigo/fortran90/ftof90.c.gz
5.f2f is a Perl script which does much of the tedious work of converting Fortran 77 source code into Fortran 90/95 form. There seems to be a lot of Fortran hate in the world, and I think this comes from people who have been forced to use Fortran 77 at some time or another. Hopefully, this program will make you a less hateful person.
网址:https://bitbucket.org/lemonlab/f2f/
- fortran_tools-master,一个python的项目
项目主页:https://github.com/arktools/fortran_tools
这六个我都试了一下,大部分的效果都不太理想(可能不同程序效果不一样,大家踊跃尝试)。其中第4个算是比较稳定的,因为它好像修改的部分最少,仅对换行符,注释符进行了修改,不改变程序原有的goto语句。所以我选用了第四个,但是目前除了python那个是批处理的,其他都不是,没办法,只能自己动手。使用的方法说明如下:
1). 将ftof90.c的源文件与read.bat的源文件放在同一个目录
2). 编译ftof90.c,注意生成的可执行文件名一定要是ftof90.exe
3). 把所有要转换的.f文件都复制到本目录下,!!!不能保证每个程序的转换效果,因此一定要留.f备份
4). 双击read.bat(windows下),会生成一个新的run.bat
5). 执行run.bat,大功告成!
以上所有提到的源程序都打包传到了网盘,
地址:https://pan.baidu.com/s/1chZotASV344iWohMKVJayg 密码:vx5i
转自汪卓的新浪博客 https://blog.sina.com.cn/s/blog_94d357c90102w8r8.html
延伸阅读:f77改写成f90时动态数组的处理,以及common的特点 http://bbs.fcode.cn/thread-3147-1-1.html

浙公网安备 33010602011771号