我正在尝试使用过程指针(Fortran 2003中的新功能)指向元素函数,但它不起作用.我真的需要函数,ELEMENTAL并需要一个指向它的指针.在Fortran中指向元素函数真的不可能吗?
module elemfunc
implicit none
contains
elemental function fun111(x) result(y)
real*8, intent(in) :: x
real*8 :: y
y = x**2+1
end function fun111
end module elemfunc
program testptr
use elemfunc
implicit none
interface
elemental function func (z)
real*8 :: func
real*8, intent (in) :: z
end function func
end interface
procedure (func), pointer :: ptr
ptr => fun111
print *, ptr( (/1.0d0,2.0d0/) )
end program testptr
Run Code Online (Sandbox Code Playgroud)
错误信息:
main.f90:12.7:ptr=>fun111
1
Nonintrinstic elemental procedure pointer 'func111' is invalid in …Run Code Online (Sandbox Code Playgroud) 我试图在Vim中将:%s/&=/=&/g
'&='替换为'=&',但命令将'&='替换为'=&='.
为什么会这样?我应该使用什么命令?
我想知道如何在FORTRAN中实现内置函数sin(),因为我尝试编写可以接收标量和数组作为其输入变量的函数,其效果可以在sin()中找到,即sin (0)返回0和sin(a),其中数组a =(/ 0,3.14 ...),返回一个数组(0,0).
我希望我要编写的所有数学函数都具有这种灵活性和优势.有人可以帮我一个忙吗?
如何在Fortran中实现这一目标?
do i = 1, n Except n/2
Run Code Online (Sandbox Code Playgroud)
有没有方便的方法而不是在循环中使用'if'?
fortran ×3
function ×2
loops ×1
pointers ×1
procedure ×1
substitution ×1
trigonometry ×1
vim ×1