|
87楼
发表于 2007-10-24 08:57:56
|
只看该作者
来自:北京
module time_mod
implicit none
type time_type
integer hour
integer minute
integer second
end type
interface operator(+)
module procedure ta
end interface
interface operator(-)
module procedure tb
end interface
contains
function ta(x,y)
type(time_type),intent(in):: x
type(time_type),intent(in)::y
type(time_type) ta
ta%hour=x%hour+y%hour
ta%minute=x%minute+y%minute
ta%second=x%second+y%second
if ((x%second+y%second)>60) then
ta%second=ta%second-60
ta%minute=ta%minute+1
endif
if((x%hour+y%hour)>60) then
ta%minute=ta%minute-60
ta%hour=ta%hour+1
endif
end function
function tb(x,y)
type(time_type),intent(in)::x
type(time_type),intent(in)::y
type(time_type) tb
tb%hour=x%hour-y%hour
tb%minute=x%minute-y%minute
tb%second=x%second-y%second
if ((x%second-y%second)<60) then
tb%second=tb%second+60
tb%minute=tb%minute-1
endif
if((x%hour-y%hour)<60) then
tb%minute=tb%minute+60
tb%hour=tb%hour-1
endif
end function
end module
program t
use time_mod
implicit none
type(time_type) ::t1,t2
type(time_type) ::ti1=time_type(3,5,8)
type(time_type) ::ti2=time_type(2,57,32)
t1=ti1+ti2
t2=ti1-ti2
print*,'(3hours,3minutes,8seconds)+(2hours,57minutes,32seconds)=',t1
print*,'(3hours,3minutes,8seconds)-(2hours,57minutes,32seconds)=',t2
end |
|