// An highlighted block
!module 不是函式,是封裝模塊,用來把具有一定功能的子例程subroutine或者子程式function,
!或者變數封裝起來,便于后面的直接呼叫,如果把子例程subroutine用module封裝起來,后面在主程
!序中呼叫子例程,便可以省略顯示介面interface,但是本文主要講如何呼叫module中的function函式
module date
contains
function plus(a,b) result(ans)
real::ans
real::a,b
ans=a+b
end function plus
end module date
!首先用module封裝了一個函式,注意,在module中定義子例程或者子程式時,必須寫contains,然后換行開始寫函式
!在這兒自定義函式plus,并且使用了resul函式,用ans在子程式中接收輸出結果,
!因此在子程式中需要宣告 ans的型別,不必宣告function name的資料型別
program main
use date
implicit none
real::a1,b1
parameter(a1=1.0,b1=2.3)
print*,plus(a1,b1)
end program main
!在主程式中需要呼叫模塊里面的內容,方法 use+模塊名
!呼叫plus函式,原本在呼叫函式時需要宣告呼叫函式的資料型別,但是我們這兒呼叫了date 模塊,由于我們在模塊中已經定義了函式結果ans的資料型別,因此在主程式中不需要再定義plus的資料型別,
比如在主程式中定義plus的資料型別
program main
use date
implicit none
real,external::plus
real::a1,b1
parameter(a1=1.0,b1=2.3)
print*,plus(a1,b1)
end program main
!報錯:錯誤 1 error #6401: The attributes of this name conflict with those made accessible by a USE statement.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/262102.html
標籤:區塊鏈
