3

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.

user1746066
  • 71
  • 1
  • 4
  • 3
    Please show a sample of the code you are struggling with. Also explain exactly what is not working: Compilation error? Linking problem? – wallyk May 02 '13 at 15:49
  • This should be very straightforward. Something is wrong beyond just FORTRAN. More details will help. – bob.sacamento May 02 '13 at 17:20
  • it should be straightforward to throw some debugging write statements into ZBESI to see why its throwing that error. – agentp May 07 '13 at 21:53

2 Answers2

3

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.
M. S. B.
  • 28,968
  • 2
  • 46
  • 73
  • I'm using Intel compiler. Now my code compiles fine by something like: ifort set_precisions.f90 ZBESI.f amos.f90 test_ZBESI.f90. As long as I put the files in right order, everything compiles fine. But the output result seems to be wrong. I'm not sure if this is due to the code itself or the compiling issue. I updated my test code in my original question. Thanks! – user1746066 May 06 '13 at 15:29
0

I came across the same issue. In my case, this was because I1MACH and D1MACH called from ZBESI.f returned a wrong answer. Using the file in https://github.com/certik/fortran-utils/blob/master/src/legacy/amos/d1mach.f90 made it work.

  • 2
    Welcome to Stack Overflow! A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](/help/deleted-answers) – Sabito stands with Ukraine Jan 15 '21 at 08:03
  • 1
    Welcome to StackOverflow. While this explanation may solve the question, including a sample code of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. I suggest you to edit your answer to add some code example, Have a look here → [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) Thanks! – Federico Baù Jan 15 '21 at 09:42