简体   繁体   English

将Fortran f77代码转换/翻译为C或Matlab / Octave

[英]Convert / translate Fortran f77 code to C or Matlab / Octave

I have an old piece of Fortran f77 code that I would like to understand and edit for future reuse. 我有一段Fortran f77旧代码,我想对其进行理解和编辑以备将来使用。 For that purpose, I would like this code to be translated to either C or Matlab / Octave language. 为此,我希望将此代码翻译为C或Matlab / Octave语言。 I have found an instance of f2c exe online, but it wouldn't run because of inappropriate OS ( my OS is Win 7 x64, f2c wanted older x32 ). 我在网上找到了f2c exe实例,但是由于操作系统不正确而无法运行(我的操作系统是Win 7 x64,f2c需要较早的x32)。

My main concern is being able to understand the code. 我主要关心的是能够理解代码。 Translation in terms of execution efficiency is not of importance. 就执行效率而言,翻译并不重要。 I am open to any suggestion, apart from learning Fortran 77. I am aware of that option myself, but would do it only as a last resort. 除了学习Fortran 77外,我也乐于接受任何建议。我本人也知道该选项,但只有在万不得已时才这样做。 Thank you. 谢谢。

Just learn Fortran. 只需学习Fortran。 The output of machine-translated code may well be functionally correct and suitable for compilation and execution, but it's going to be really hard to understand and maintain. 机器翻译的代码的输出可能在功能上正确无误,适合编译和执行,但实际上很难理解和维护。 (Just look at what generated code targeting a single language, like the output of a GUI builder wizard, looks like.) In particular, while Matlab is built on Fortran, its idioms at the M-code level are different enough that it would be pretty incomprehensible. (只需看看针对一种语言生成的代码,如GUI构建器向导的输出,就可以看到。)特别是,尽管Matlab是基于Fortran构建的,但其在M代码级别的惯用法却相差甚远。相当不可理解。 If you already know C or any other Algol-like language, picking up Fortran is not that hard. 如果您已经知道C或任何其他类似Algol的语言,那么开始使用Fortran并不难。 And the idioms and features that are particular to Fortran – that is, the new stuff you'd have to learn – are probably going to be especially weird and incomprehensible when sent through a translator. Fortran特有的成语和功能(即,您必须学习的新知识)在通过翻译程序发送时可能会变得特别怪异和难以理解。

The one translator that might actually be useful is a Fortran 77 -> Fortran 90 translator. 一个实际上可能有用的翻译器是Fortran 77-> Fortran 90翻译器。 The modern '90 dialect would be easier to learn and more succinct, and since the translation is within the same language family the output probably wouldn't be too ugly. 现代的90年代方言更容易学习,也更简洁,而且由于翻译是在同一语言家族中进行的,因此输出可能不会太难看。

Since are using Octave, you can call Fortran code, there is no need to rewrite it. 由于使用的是Octave,因此可以调用Fortran代码,因此无需重写它。 You will need to write a very simple C++ wrapper to it but Octave already provides macros to do all of the hard work. 您将需要为其编写一个非常简单的C ++包装器,但是Octave已经提供了宏来完成所有艰苦的工作。 It is all documented on the manual . 全部记录在手册中 Actually, Octave itself calls on many fortran subroutines, so this is perfectly normal. 实际上,Octave本身会调用许多fortran子例程,因此这完全正常。

If you want to modify it, you should be learning Fortran then. 如果要修改它,则应该学习Fortran。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM