[Fortran] 纯文本查看 复制代码
program Test
implicit none
integer::iorder
real(8)::xv1(2),abcd
real(8),external::GaussInteg_Tri
iorder=1
xv1=(/0.0_8,0.0_8/)
abcd=GaussInteg_Tri( fun,xv1 )
write(*,*)abcd
contains
real(8) function fun(xy)
real(8) :: xy(2),x,y
select case(iorder)
case(1)
fun= xy(1)
case(2)
fun= xy(2)
case default
write(*,*) 'error in iorder!',iorder; stop
end select
return
end function
end program Test
function GaussInteg_Tri( fun,xv1 )
real(8) :: GaussInteg_Tri, xv1(2)
real(8) ,external :: fun
GaussInteg_Tri = fun(xv1)
write(*,*)GaussInteg_Tri
return
end function
[Fortran] 纯文本查看 复制代码
Module testMod
implicit none
integer :: iorder = 1
contains
real(8) function fun(xy)
real(8) :: xy(2)
if(iorder<1.or.iorder>size(xy)) then
write(*,*) 'error in iorder!' , iorder
stop
end if
fun= xy(iorder)
end function
real(8) function GaussInteg_Tri( fun,xv1 )
real(8) :: xv1(2)
real(8) ,external :: fun
GaussInteg_Tri = fun(xv1)
write(*,*) GaussInteg_Tri
end function
End Module testMod
program Test
use testMod
implicit none
real(8)::xv1(2)=[11.0_8,22.0_8]
write(*,*) GaussInteg_Tri( fun , xv1 )
end program Test