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

问题描述

我正在使用Fortran 90编写代码,现在我需要使用* amos Fotran 77库中的特殊功能()。现在我找到了这些例程的模块接口()。



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



我一直在为此奋斗一整天,但仍然无法解决这个问题。



以下是我的测试代码:

  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

调用ZBESI(zr,zi,0.0_DBL,1,n,cyr,cyi,nz,ierr)
print *,''
do i = 1 (*,10)i-1,cyr(i)
write(*,11)i-1,cyi(i)
end do
print * ,'NZ =',NZ
print *,'错误代码:',ierr
print *,''

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

结束程序TEST_ZBESI
 <$ c $ 

 

我得到的结果如下: (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
错误代码:4

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

我试图手动将ZBESI.f Fortran 77代码转换为Fortran 90代码。但代码太长了,这是一场灾难。除了极少数例外情况外,FORTRAN 77是Fortran 90/95/2003/2008的一个子组。实际上,编译器仍然支持过时的功能。使用相同的编译器编译FORTRAN 77和Fortran 90/59/2003/2008源应该生成兼容的目标模块。您可能必须单独编译两种语言版本,因为可能需要不同的编译器选项,例如,对于固定和自由格式的源布局。通过Fortran 90/95/2003/2008代码中的接口,编译器将使用兼容的调用约定。



你有什么具体问题?你需要知道FORTRAN 77的编译选项吗?你使用的编译器是什么?编辑:你必须在使用它的源代码之前编译模块。首先将FORTRAN 77编译成目标文件,然后使用编译Fortran 95的fortran命令来链接所有内容,这很方便。所以试试:

  ifort -c -fixed ZBESI.f 
ifort ZBESI.o set_precisions.f90 amos.f90 test_ZBESI .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).

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.

The following is my test code:

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

The result I got is the following:

  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.

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.

解决方案

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.

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

EDIT: 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子例程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 01:48