[轉] 批處理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號