结合 F77 和 F95 fortran 代码 [英] Combining F77 and F95 fortran code

查看:12
本文介绍了结合 F77 和 F95 fortran 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些科学代码,主要是 F77,但也有一些 F95.在某些地方,我需要将 F77 代码包含到我的 F95 代码中.有没有办法通过使用特定的编译器标志或其他东西让这段代码在我的代码中很好地发挥作用?我正在使用 gfortran,偶尔使用 ifort.我可以修改遗留代码,但我需要以一种合理的方式进行修改,以保持与其他 F77 代码的向后兼容性,同时还要向前兼容 F95 代码.

I'm working on some scientific code that is mostly F77 but also some F95. In places, I need to include F77 code into my F95 code. Is there a way to get this code to play nicely within my code by using a particular compiler flag or something? I'm using gfortran and occasionally ifort. It is possible for me to modify the legacy code but I would need to do it in a sensible way to maintain backwards compatibility with other F77 code while also being forwards compatible with F95 code.

我收到如下错误:

cstruc:16.12:
    Included at mod_op.f90:6:

      REAL*8
            1
Error: Invalid character in name at (1)
cstruc:17.6:
    Included at mod_op.f90:6:

     &       RH, RH1,      ! ln rho
      1
Error: Invalid character in name at (1)
cstruc:18.6:
    Included at mod_op.f90:6:

     &       RHP, RHP1,    ! d ln rho / d ln p
      1
Error: Invalid character in name at (1)
cstruc:19.6:
    Included at mod_op.f90:6:

     &       RHT, RHT1,    ! d ln rho / d ln T
      1
Error: Invalid character in name at (1)

cstruc 看起来像这样:

cstruc looks like this:

  REAL*8
 &       RH, RH1,      ! ln rho
 &       RHP, RHP1,    ! d ln rho / d ln p
 &       RHT, RHT1,    ! d ln rho / d ln T
 &       PSI,          ! ln Lambda (for degenerate gas)
 &       RHPSI,        ! d ln rho / d PSI
 &       RHPSIP,       ! d2 ln rho / d PSI d ln P
 &       RHPSIT,       ! d2 ln rho / d PSI d ln T
 &       PL,           ! P at J1
 &       TONI          ! T at J1

非常感谢任何帮助.谢谢!

Any help is much appreciated. Thanks!

推荐答案

除了一些例外,Fortran 77 代码是 Fortran 95 代码.我猜您的错误来自您试图将固定格式的源代码(您在 cstruc 中的 F77 代码)include 到一个自由格式的源代码文件 mod_op.f90 中.这不太可能结束.

With some exceptions, Fortran 77 code is Fortran 95 code. I guess that your errors come from that you are attempting to include fixed-form source code (your F77 code in cstruc) into a free-form source code file mod_op.f90. This is unlikely to end well.

大多数编译器会假定以.f90"结尾的文件是自由格式的,因此如果您确实使用的是固定格式,那么您将需要一个编译器标志来覆盖该假设.

Most compilers will assume a file ending in ".f90" is free-form, so if you really are using fixed-form then you will need a compiler flag to override the assumption.

可以将自由格式和固定格式的代码组合成一个最终对象(每个单独编译),但是关于如何解决您遇到的问题的好建议只能提供更详细的信息.

It is possible to combine free- and fixed-form code into a final object (each compiled separately), but a good suggestion as to how to resolve the problems you are seeing can come only with more detail.

但是,如果您尝试使用 include 创建一个模块来替换公共块,那么您没有理由不能使用 F95 功能和固定格式.只需有选择地执行此操作即可.

However, if you are attempting with your include to create a module to replace a common block, then there is no reason why you can't use the F95 feature with fixed-form. Just do that selectively.

或者,您可以查看 Vladimir F 的答案,其中解释了如何编写既免费又有效的源代码- 形式和固定形式的来源.您可以使用它来修改 Fortran 77 固定格式代码,使其能够被 Fortran 90 自由格式代码 include,同时仍可编译为固定格式(但不是有效的 Fortran 77).

Alternatively, you can see the answer by Vladimir F which explains how to write source code that is valid as both free-form and fixed-form source. You can use this to modify the Fortran 77 fixed-form code to be include-able by the Fortran 90 free-form code while still being compilable as fixed-form (but not valid Fortran 77).

这篇关于结合 F77 和 F95 fortran 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆