如何使用翻译器 f2c 编译单个 fortran 对象?
我有以下问题:我想模拟一些控制工程系统。由于它相当复杂,我使用计算机导出了一些(复杂的)方程,这些方程只能导出为 fortran77 代码。在我的开发电脑上这没有问题(Linux 机器)。
不,我想在硬件中完成它,但这里我必须使用 Windows 操作系统。不幸的是,matlab 不支持 Windows 上的 gfortran。因此我无法编译该盒子上的 fortran 文件。
我现在的想法是转换为 C,因为 win 上的 matlab 提供了 C 编译器。还有其他(更好)的选择吗?
我有几个子程序,其方式如下。
SUBROUTINE sys_rhs (x, v, dx, param)
REAL*8 x(6)
C code is coming here
RETURN
END SUBROUTINE
在用 C 编写的接口函数中使用函数 sys_rhs__
是一种好的做法吗? 问题是,我无法测试它,因为我没有大量访问 Windows 机器的权限。因此,如果我尝试一下,它应该会起作用,而且我不需要进行很多实验。
另外,我在 Windows 上需要什么库?我在哪里可以得到它们?
谢谢 基督教
I have the following problem: I want to simulate some control engineering system. As it is quite complicated I used the computer to derive some (complicated) equations which can only be exported to fortran77 code. On my development pc this is no problem (linux machine).
No I want to do it in hardware and here I have to use a windows OS. Unfortunately matlab does not support gfortran on windows. Therefore I can not compile the fortran files on that box.
My idea was now to translate to C as a C compiler is available at matlab on win. Any other (better) options?
I have several SUBROUTINES in the manner of the following.
SUBROUTINE sys_rhs (x, v, dx, param)
REAL*8 x(6)
C code is coming here
RETURN
END SUBROUTINE
Is it good practice and does it work to use the function sys_rhs__
in the interface function written in C?
The problem is, that I can not test it as I do not have massive access to the windows machine. So it should work if I try it and I should not need to experiment a lot.
Also what lib's do I need on windows? Where can I get them?
Thanks
Christian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Intel 销售了一款相当不错的 Fortran 编译器 (http://software.intel.com/ en-us/articles/fortran-compilers/) 他们曾经免费赠送用于测试...;-)
PS 不,我与这家公司没有任何联系!
Intel sells a pretty good fortran compiler (http://software.intel.com/en-us/articles/fortran-compilers/) which they used to give away for free for testing ... ;-)
PS No, Im not linked to this company in any way!
您可能想检查 gnumex 项目,该项目允许使用 GNU GCC 编译器套件编译 MEX 文件(使用MinGW或Cygwin),能够使用g77编译Fortran程序。
You might wanna check the gnumex project, which allows to compile MEX-files using the GNU GCC compiler suite (using either MinGW or Cygwin), with the ability to use g77 to compile Fortran programs.
答案很简单:我的 Fortran 代码中有一些语法错误。
gfortran
没有进行如此严格的语法检查,因此可以正确解释 fortran 代码。删除错别字后,我成功使用 f2c 进行转码。谢谢
The answer was quite simple: I had some syntax errors in my fortran code.
gfortran
does no such strict syntax checking and therefor interpreted the fortran code correctly. After removing the typos I succceded transcoding with f2c.Thanks
对于这一切有一个更好的解决方案
使用你的linux机器或windows机器用c/c++实现该功能,然后生成一个dll文件。
在 matlab 中,您可以加载 DLL 并调用其中的函数。
这是一个简单的教程,展示如何使用 matlab 调用 dll。
http ://www.mathworks.com/matlabcentral/fileexchange/15065-example-of-loading-c-dll-and-performance-comparison
there is a better solution to all this
use your linux machine or your windows machine to implement the function in c/c++ and then generate a dll file.
In matlab you can load the DLL and make a call to the functions inside it.
here is a simple tutorial that show how to call the dll with matlab.
http://www.mathworks.com/matlabcentral/fileexchange/15065-example-of-loading-c-dll-and-performance-comparison