Reputation: 2181
I have a third-part code in fortran 77, and I have written a subroutine in fortran 90 that I would like to interface to this code. I have found that the variables are not passed correctly from one subroutine to the other. I think the reason is that the definitions of double precision in the two programs is not compatible.
I want that the variable returned to f77 is a double precision
. Which real definition shall I use in f90? I am using selected_real_kind(p=15,r=307)
EDIT:
I have changed the declaration to double precision
in f90, and I have verified that double precision
variables are passed correctly. The problem arises when I am passing allocatable arrays from f90 to f77
The arrays are originally allocated in code f77. then I allocate some allocatable arrays in f90 and then pass them to f77, but this is not working
f77 code:
program oldprog
double precision da(100)
call sub(da)
end
subroutine sub(da)
double precision da(*)
call mynewsub(da)
end
f90 code:
subroutine mynewsub(da)
implicit none
double precision, allocatable:: da(:)
allocate(da(100))
da = 1.0
end subroutine mynewsub
I was thinking to skip the allocation in mynewsub, but then I get SIGSEGV
Upvotes: 0
Views: 311
Reputation: 60018
Your mynewsub
accepts the array as allocatable argument.
That requires explicit interface in Fortran 95, and is impossible in Fortran 90, not even speaking about FORTRAN 77 which does not have allocatable
at all.
You cannot do this.
And in your main program
program oldprog
double precision da(100)
the array is static. It cannot be reallocated in any way in any version of Fortran, it is fixed forever.
You should think about making it allocatable everywhere an update relevant parts of your code to Fortran 95.
Upvotes: 1