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

问题描述

我正在研究一些主要是F77的科学代码,但也有一些F95。在某些地方,我需要在我的F95代码中包含F77代码。有没有办法让这个代码在我的代码中使用特定的编译器标志或其他东西很好地播放?我正在使用gfortran,偶尔也会使用。我可以修改遗留代码,但我需要以一种明智的方式做到这一点,以保持与其他F77代码的向后兼容性,同时也可以向前兼容F95代码。



我收到以下错误:

  cstruc:16.12:
包含在mod_op.f90中:6:

REAL * 8
1
错误:(1)
中的名称无效字符cstruc:17.6:
包含在mod_op.f90中:6:

& RH,RH1,! ln rho
1
错误:名称中的无效字符(1)
cstruc:18.6:
包含在mod_op.f90中:6:

& amp ; RHP,RHP1,! d ln rho / d ln p
1
错误:(1)
名称中的字符无效cstruc:19.6:
包含在mod_op.f90:6:

& RHT,RHT1,! (1)


$ b中的无效字符$ b

cstruc看起来像这样:

  REAL * 8 
& RH,RH1,!在rho
& RHP,RHP1,! d ln rho / d ln p
& RHT,RHT1,! d ln rho / d ln T
& PSI,!在Lambda(对于退化气体)
& 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在J1
& TONI! T在J1

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

解决方案

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



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

可以将自由格式和固定格式的代码结合到一个最终对象中(每个单独编译),但是一个好的然而,如果您尝试使用 include ,那么您可能会遇到以下问题: code>来创建一个模块来替换一个通用块,那么没有理由不能使用固定格式的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.

I get errors like:

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 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!

解决方案

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.

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.

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.

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

07-30 01:48