科学 Fortran 编译错误
我正在研究科学建模程序,但尚未编译我的程序。我没有碰过我的教授坚持认为以前有效的代码,只碰过 makefile。经过多次尝试,我得到的最多的是这个错误:
Error on line 1112: Declaration error for xxmf: adjustable dimension on non-argument
upcase:
intrpl:
splin:
mtrnpr:
我的教授坚持认为这只是一个编译问题,应该有一些涉及全局变量的选项,我可以使用它来解决这个问题。我发现的最接近的是使用 makefile 中的选项
-Mipa=safeall
,但我不确定我是否将其放在正确的位置,或者它是否产生了影响,因为我仍然遇到相同的错误。
I'm working on scientific modelling program and have yet to get my program to even compile. I haven't touched the code which my professor insists previously worked, only the makefile. After many attempts, the furthest I've gotten was this error:
Error on line 1112: Declaration error for xxmf: adjustable dimension on non-argument
upcase:
intrpl:
splin:
mtrnpr:
My Professor insists that it's merely a compiling problem and that there should be some option involving global variables that I can use that'll fix this. The closest I've found is using the option
-Mipa=safeall
in the makefile, but I'm not sure if I'm putting it in the right place or if it made a difference since I still get the same error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Oof - 听起来你有一个旧代码,可以与你的主管的古老 f77 编译器的特定版本一起正常工作,但是当你慢慢地将其提高到标准以便符合标准的编译器将让你心痛一段时间时做正确的事。
可调整数组是这样的:
-- 也就是说,或多或少像在 C 中那样传递数组。Fortran90 及更高版本允许您使用 假定形状数组
更加干净,因为编译器确保传递数组的正确大小。
因此,听起来您的主管的代码在子例程中不是参数的情况下使用了这种构造,大概是作为在运行时创建特定大小的数组的一种方式。标准 Fortran77 从来不允许这样做,但一些编译器作为扩展这样做了。幸运的是,您现在可以使用可分配数组作为执行此操作的标准方法,所以我建议只需更改变量现在让你对可分配数组感到悲伤。
顺便说一句,有很多静态代码分析工具可以让您主动发现此类问题并跟踪它们。 Understand 是一个很好的商业许可证,有大约 2 周的评估许可证,可以发现很多问题。 Forcheck 虽然不那么用户友好,但非常彻底。使用这样的工具将你的主管代码拖入 2010 年代会有点困难,但这将是你时间的绝佳投资。另一套很好的工具是 eclipse + photran,但不幸的是,这已经主要假设您有很好的 fortran90 代码 - 它将是在你可以使用它之前一段时间。
(在有人开始对 Fortran 做出尖锐的评论之前——是的,是的,那里有很多旧的蹩脚的 Fortran 代码,但这并不是 Fortran 所独有的,不是吗。)
Oof -- Sounds like you have an old code which works fine with your supervisor's particular version of an ancient f77 compiler, but is going to cause heartache for you for a while as you slowly bring it up to standard so that standards-compilant compilers will do the right thing.
Adjustable arrays are things like this:
-- which is to say, passing arrays more or less the way you do in C. Fortran90 and onwards allows you to use assumed-shape arrays
which is a lot cleaner, as the compiler is ensuring the correct size of the array is being passed.
So it sounds like your supervisor's code is using this sort of construct in something that isn't an argument in a subroutine, presumably as a way of creating arrays of a particular size at runtime. Standard Fortran77 never allowed that, but several compilers did as extensions. Luckily, you can use allocatable arrays now as a standard way of doing this, so I'd suggest just changing the variable giving you grief now to an allocatable array.
Incidentally, there are a lot of static code analysis tools out there that will allow you to proactively find problems like this and track them down. Understand is a good commercial one with a ~2 week evaluation license that will find a lot of problems. Forcheck, though not nearly as user friendly, is very thorough. Using tools like these to drag your supervisors code kicking and screaming into the 2010s will be a bit of a slog, but it'll be an excellent investment of your time. Another good set of tools is eclipse + photran, but unfortunately that already mostly assumes you have nice fortran90 code -- it'll be a while before you can be using that.
(And before anyone starts making snarky comments about fortran -- yes, yes, there's a lot of old crappy fortran code out there, but that's hardly unique to fortran now, is it.)