1.function !key :don't change the imput
real,external ::aaa !this must be written in main program
real,intrinsic ::bbb
function aaa(a,b)
real aaa
end function
2.common !功能:share 記憶體 ;讀位子,不讀名稱, 值可被改變
paragram test
real aa
commom/tt1/aa
end
subroutine s1(x,aaa) !也可傳遞函數
real a1
common/tt1/a1 !here the value of a1 = the valus of aa in paragram
real,external::aaa
retun
end subroutine
black data
real aa
commom/tt1/aa
data aa/1.d0/
end block data
3.使變數永遠活著
integer,save ::aa
4.interface
case1. :傳陣列
case2. :傳遞參數個數有改(ex:有optional)
case3. :改變 傳遞參數的位置
case4. :傳入或回傳指標
5.recursive
recursive function fact(n) result(ans)
!result(ans) 用來存function fact的計算結果
implicit none
integer n !"n" is imput. You don't set "real fact" because ans is the result what you want.
real ans !output
!set the end point ,this is very important
if (n<0) then
ans=0
write(*,*) "wrong n"
return !終止遞迴
else if (n==1) then
ans=1
return !終止遞迴
end if
ans=n*fact(n-1)
return !終止function 並回傳計算結果
end function