libtime++: Date and time calculation

◆ time_sub()

subroutine time_sub ( integer, dimension(7)  date1,
integer, dimension(7)  date2,
integer, dimension(7)  date3 
)

Definition at line 31 of file time_sub.f.

References time_copy(), and time_norm().

31 c
32 c date3=abs(date1-date2)
33 c
34 c This routine will only return the absolute value of the result.
35 c We do not handle signs. Therefore in any case the smaller time
36 c value will be subtracted from the larger one.
37 c
38 c relative - relative -> relative case 1
39 c absolute - relative -> absolute case 2
40 c absolute - absolute -> relative case 3
41 c
42 c NOTICE: This version of time_sub disregards leap-seconds!
43 c
44 c input:
45 c date1: date record
46 c date2: date record
47 c output:
48 c date3: fully qualified and regularized absolute difference between
49 c input date values (maybe rælative or absolute - see above)
50 c
51 c last change: V2.00 (05/08/2000)
52 c
53  integer date1(7), date2(7), date3(7)
54 cE
55  integer i, larger(7), smaller(7), case, time_compare
56  logical time_isleapyear
57 c
58  call time_norm(date1)
59  call time_norm(date2)
60 c find out case and set larger and smaller
61  if ((date1(1).eq.0).or.(date2(1).eq.0)) then
62  if (date1(1).eq.date2(1)) then
63  case=1
64  else
65  case=2
66  if (date1(1).eq.0) then
67  call time_copy(date2, larger)
68  call time_copy(date1, smaller)
69  else
70  call time_copy(date1, larger)
71  call time_copy(date2, smaller)
72  endif
73  endif
74  else
75  case=3
76  endif
77 c
78  if (case.ne.2) then
79  if (time_compare(date1, date2).gt.0) then
80  call time_copy(date1, larger)
81  call time_copy(date2, smaller)
82  else
83  call time_copy(date2, larger)
84  call time_copy(date1, smaller)
85  endif
86  endif
87 c handle year boundaries of absolute times
88  if (case.eq.3) then
89  1 if (larger(1).eq.smaller(1)) goto 2
90  larger(1)=larger(1)-1
91  larger(2)=larger(2)+365
92  if (time_isleapyear(larger(1))) larger(2)=larger(2)+1
93  goto 1
94  2 continue
95  endif
96 c build difference
97  do i=1,7
98  date3(i)=larger(i)-smaller(i)
99  enddo
100  call time_norm(date3)
101  return
integer time_isleapyear(timeint year)
void time_copy(time_Ts Date1, time_Ts *Pdate2)
Definition: ctime_copy.c:33
void time_norm(time_Ts *Pdate)
Definition: ctime_norm.c:33
integer time_compare(time_Ts Date1, time_Ts Date2)
Definition: ctime_compare.c:35
Here is the call graph for this function: