たまにはソースを.完全に以下のサイトのパクリですが.
http://www.nag-j.co.jp/fortran/tips/tips_PortableWayToTime.html
MODULE RecordTime IMPLICIT NONE INTEGER(4), PRIVATE :: t1, t2, t_rate, t_max, diff REAL(8), PRIVATE :: cput1, cput2 PUBLIC RecordTime_Start, RecordTime_End CONTAINS SUBROUTINE RecordTime_Start CALL system_clock(t1) CALL cpu_time(cput1) END SUBROUTINE RecordTime_Start SUBROUTINE RecordTime_End CALL system_clock(t2, t_rate, t_max) IF ( t2 < t1 ) THEN diff = (t_max - t1) + t2 + 1 ELSE diff = t2 - t1 END IF CALL cpu_time(cput2) OPEN(20,FILE="Cal_Time.txt",STATUS='REPLACE') WRITE(20, "(A, F10.3)"), "time it took was(sec):", diff/DBLE(t_rate) WRITE(20, "(A, F10.3)"), "cpu time(sec):", cput2-cput1 CLOSE(20) END SUBROUTINE RecordTime_End END MODULE RecordTime
計算開始時に
CALL RecordTime_Start
終了時に
CALL RecordTime_End
で
OKです.
書いていて思いましたが,もうちょっと複雑なもので,
MODULE文,INTERFACE文の総称,CONTAINS文を使えば,
FORTRANでもカプセル化とかポリモーフィズムが書けますね.