|
使用重载(看彭国伦书module那章):
- module m
- implicit none
- interface sub
- module procedure :: sub_sp
- module procedure :: sub_dp
- end interface
- contains
- subroutine sub_sp(array)
- ! single precision
- real, dimension(:) :: array
- integer :: i
- do i = 1, size(array)
- array(i) = array(i) + i * 2.0
- end do
- end subroutine
- subroutine sub_dp(array)
- ! double precision
- real(kind=8), dimension(:) :: array
- integer :: i
- do i = 1, size(array)
- array(i) = array(i) + i * 2.0D0
- end do
- end subroutine
- end module
- program main
- use m
- implicit none
- integer :: i
- real, dimension(5) :: a = [(i,i=1,5)]
- real(kind=8), dimension(5) :: b = [(i,i=1,5)]
- call sub(a)
- call sub(b)
- write(*,*) a
- write(*,*) b
- end program
复制代码
运行结果:
- 3.00000000 6.00000000 9.00000000 12.0000000 15.0000000
- 3.0000000000000000 6.0000000000000000 9.0000000000000000 12.000000000000000 15.000000000000000
复制代码
|
评分 Rate
-
查看全部评分 View all ratings
|