在现代时代学习FORTRAN [英] Learning FORTRAN In the Modern Era
问题描述
你必须得到一个感觉,让程序员必须在当天做些什么。我工作的绝大多数代码都比我年长,并且在我父母上高中的时候在新机器上运行。
常见的FORTRAN-isms我处理,伤害可读性:
$ b
- 常见块
- 隐式变量
- 具有共享CONTINUE语句的两个或三个DO循环
- GOTO代替DO循环
- 算术IF语句 >
- 计算GOTO的
- 在一些公共块等价REAL / INTEGER /其他
解决这些问题的策略包括:
如果你有更多关于如何完成一些可读性任务的具体问题,我可以给出建议。我有一个由几十万行Fortran代码组成的代码库,这个代码库在40年的时间里我写了一篇文章,这是我在某种程度上负责的,所以我可能遇到了你可能发现的任何问题。
I've recently come to maintain a large amount of scientific calculation-intensive FORTRAN code. I'm having difficulties getting a handle on all of the, say, nuances, of a forty year old language, despite google & two introductory level books. The code is rife with "performance enhancing improvements". Does anyone have any guides or practical advice for de-optimizing FORTRAN into CS 101 levels? Does anyone have knowledge of how FORTRAN code optimization operated? Are there any typical FORTRAN 'gotchas' that might not occur to a Java/C++/.NET raised developer taking over a FORTRAN 77/90 codebase?
You kind of have to get a "feel" for what programmers had to do back in the day. The vast majority of the code I work with is older than I am and ran on machines that were "new" when my parents were in high school.
Common FORTRAN-isms I deal with, that hurt readability are:
- Common blocks
- Implicit variables
- Two or three DO loops with shared CONTINUE statements
- GOTO's in place of DO loops
- Arithmetic IF statements
- Computed GOTO's
- Equivalence REAL/INTEGER/other in some common block
Strategies for solving these involve:
- Get Spag / plusFORT, worth the money, it solves a lot of them automatically and Bug Free(tm)
- Move to Fortran 90 if at all possible, if not move to free-format Fortran 77
- Add IMPLICIT NONE to each subroutine and then fix every compile error, time consuming but ultimately necessary, some programs can do this for you automatically (or you can script it)
- Moving all COMMON blocks to MODULEs, low hanging fruit, worth it
- Convert arithmetic IF statements to IF..ELSEIF..ELSE blocks
- Convert computed GOTOs to SELECT CASE blocks
Convert all DO loops to the newer F90 syntax
myloop: do ii = 1, nloops ! do something enddo myloop
Convert equivalenced common block members to either ALLOCATABLE memory allocated in a module, or to their true character routines if it is Hollerith being stored in a REAL
If you had more specific questions as to how to accomplish some readability tasks, I can give advice. I have a code base of a few hundred thousand lines of Fortran which was written over the span of 40 years that I am in some way responsible for, so I've probably run across any "problems" you may have found.
这篇关于在现代时代学习FORTRAN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!