AlanRominger
Technical User
I found a sweet syntax that was really helpful to simplify a lot of code. Problem is, I discovered this is a Fortran 2003 feature. It works like this:
interface
subroutine name_in_interface(a)
real, dimension), intent(in) :: a
end subroutine name_in_interface
end interface
procedure (name_in_interface) :: actual_procedure_name
With this, you can use the same interface type for multiple functions. Again, the problem is, this doesn't seem to be a 95 feature. I want to ask if there is any way to have the following code made cleaner using only Fortran 95 features. This does not compile, for instance, in g95. Do Fortran coders who don't use a modern compiler have no choice but to copy the interface over and over again no matter how large their project is (because you must use interfaces if there are assumed size arrays)? Thanks.
And someone, please please let me know how to properly quote code in these forums. I looked for a while and couldn't find anything (although I see where other people did it).
module routine_interfaces
implicit none
interface
subroutine one_array(array)
real, dimension), intent(in) :: array
end subroutine one_array
end interface
end module routine_interfaces
program main
use routine_interfaces
implicit none
real, dimension(3) :: a
procedure(one_array) :: sum_array, div_array, sd_array
a = 2.
call sum_array(a)
call div_array(a)
call sd_array(a)
end program main
subroutine sum_array(a)
implicit none
real, dimension), intent(in) :: a
write(*,*) ' sum= ',sum(a)
end subroutine sum_array
subroutine div_array(a)
implicit none
real, dimension), intent(in) :: a
write(*,*) ' sum= ',sum(1./a)
end subroutine div_array
subroutine sd_array(a)
implicit none
real, dimension), intent(in) :: a
write(*,*) ' sum= ',sum(a+1./a)
end subroutine sd_array
interface
subroutine name_in_interface(a)
real, dimension), intent(in) :: a
end subroutine name_in_interface
end interface
procedure (name_in_interface) :: actual_procedure_name
With this, you can use the same interface type for multiple functions. Again, the problem is, this doesn't seem to be a 95 feature. I want to ask if there is any way to have the following code made cleaner using only Fortran 95 features. This does not compile, for instance, in g95. Do Fortran coders who don't use a modern compiler have no choice but to copy the interface over and over again no matter how large their project is (because you must use interfaces if there are assumed size arrays)? Thanks.
And someone, please please let me know how to properly quote code in these forums. I looked for a while and couldn't find anything (although I see where other people did it).
module routine_interfaces
implicit none
interface
subroutine one_array(array)
real, dimension), intent(in) :: array
end subroutine one_array
end interface
end module routine_interfaces
program main
use routine_interfaces
implicit none
real, dimension(3) :: a
procedure(one_array) :: sum_array, div_array, sd_array
a = 2.
call sum_array(a)
call div_array(a)
call sd_array(a)
end program main
subroutine sum_array(a)
implicit none
real, dimension), intent(in) :: a
write(*,*) ' sum= ',sum(a)
end subroutine sum_array
subroutine div_array(a)
implicit none
real, dimension), intent(in) :: a
write(*,*) ' sum= ',sum(1./a)
end subroutine div_array
subroutine sd_array(a)
implicit none
real, dimension), intent(in) :: a
write(*,*) ' sum= ',sum(a+1./a)
end subroutine sd_array