fortran2003新特性:可分配函数
程序员文章站
2022-03-09 09:57:36
...
Module testMod
implicit none
contains
function testfunc( a ) result( res )
implicit none
real, allocatable :: res(:)
integer :: i
real :: a(:)
if ( allocated( res ) ) then
write( *,'(1x,a)' ) 'the distributable function is allocated!'
deallocate( res )
!.. reallocate
allocate( res(size(a)) )
else
write( *,'(1x,a)' ) 'the distributable function is not allocated!'
allocate( res(size(a)) )
end if
forall ( i = 1:size(res) )
res(i) = a(i) * 10.0
end forall
end function testfunc
End module testMod
Program main
use testMod
implicit none
real :: a(5)
call random_seed
call random_number( a )
write( *,'(*(g0,3x))' ) testfunc(a)
End program main
上一篇: 工作n年,技术积累传授何人?
下一篇: 字符串的方法