如何在 Fortran 90/95 中使用 Fortran 77 子例程? [英] How to use Fortran 77 subroutines in Fortran 90/95?

查看:28
本文介绍了如何在 Fortran 90/95 中使用 Fortran 77 子例程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Fortran 90 编写代码,现在我需要使用 *amos Fotran 77 库中的特殊函数(http://www.netlib.org/amos/).现在我找到了这些例程的模块接口(https://github.com/certik/fortran-utils/blob/master/src/amos.f90).

I'm writing a code with Fortran 90 and now I need to use the special functions in the*amos Fotran 77 library(http://www.netlib.org/amos/). Now I found a module interface for those routines(https://github.com/certik/fortran-utils/blob/master/src/amos.f90).

我的问题是:如何将它们组合起来并在我的 Fortran 90 程序中使用它们以及如何正确编译它们?

My question is: how can I combine them and use them in my Fortran 90 program and how to compile them correctly?

我为此苦苦挣扎了一整天,仍然无法弄清楚.

I have been struggling for this for one whole day and still could not figure it out.

以下是我的测试代码:

PROGRAM TEST_ZBESI
USE set_precisions
USE amos
IMPLICIT NONE
INTEGER :: n, i, nz, ierr
!double precision :: zr,zi, cyr(5), cyi(5)
REAL(kind=DBL) :: zr, zi, cyr(5), cyi(5)

n=5
zr=1.0_DBL
zi=2.0_DBL

call ZBESI(zr,zi,0.0_DBL,1,n,cyr,cyi,nz,ierr)
print *,' '
do i=1, n
   write(*,10) i-1, cyr(i)
   write(*,11) i-1, cyi(i)
end do
print *,' NZ=', NZ
print *,' Error code:', ierr
print *,' '

10 format('  zr(',I1,') = ',F10.6)
11 format('  zi(',I1,') = ',F10.6)

END PROGRAM TEST_ZBESI

我得到的结果如下:

  zr(0) =   0.000000
  zi(0) =   0.000000
  zr(1) =   0.000000
  zi(1) =   0.000000
  zr(2) =   0.000000
  zi(2) =   0.000000
  zr(3) =   0.000000
  zi(3) =   0.000000
  zr(4) =   0.000000
  zi(4) =   0.000000
  NZ=           0
  Error code:           4

似乎无论如何我都无法得到正确的答案.

It seems I could not get the correct answer no matter how.

我尝试手动将 ZBESI.f Fortran 77 代码转换为 Fortran 90 代码.但是代码太长了,简直是一场灾难.

I tried to convert the ZBESI.f Fortran 77 code to Fortran 90 code by hand. But the code is so long and it was a disaster.

推荐答案

除了极少数例外,FORTRAN 77 是 Fortran 90/95/2003/2008 的子集.在实践中,编译器仍然支持过时的特性.使用相同的编译器编译 FORTRAN 77 和 Fortran 90/59/2003/2008 源代码应该会生成兼容的对象模块.您可能必须分别编译这两种语言版本,因为可能需要不同的编译器选项,例如,对于固定和自由格式的源代码布局.使用 Fortan 90/95/2003/2008 代码中的接口,编译器将使用兼容的调用约定.

With extremely few exceptions, FORTRAN 77 is a subset of Fortran 90/95/2003/2008. And in practice, compilers still support the obsolete features. Compiling the FORTRAN 77 and Fortran 90/59/2003/2008 source with the same compiler should produce compatible object modules. You will likely have to compile the two language versions separately since different compiler options will probably be necessary, e.g., for fixed and free-form source layout. With the interfaces in your Fortan 90/95/2003/2008 code, the compiler will use compatible calling conventions.

您遇到了哪些具体问题?您需要了解 FORTRAN 77 的编译器选项吗?你用的是什么编译器?

What specific problems are you having? Do you need to know the compiler options for FORTRAN 77? What compiler are you using?

您必须在使用它的源代码之前编译模块.方便的是先将 FORTRAN 77 编译成目标文件,然后使用编译 Fortran 95 的 fortran 命令链接所有内容.所以试试:

You have to compile the module before the source code that uses it. It is convenient to compile the FORTRAN 77 first, into an object file, and then use the fortran command that compiles the Fortran 95 to link everything. So try:

ifort -c -fixed ZBESI.f
ifort ZBESI.o set_precisions.f90 amos.f90 test_ZBESI.f90.

这篇关于如何在 Fortran 90/95 中使用 Fortran 77 子例程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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