libtime++: Date and time calculation
time_sub.f
Go to the documentation of this file.
1 c this is <time_sub.f> (extracted from ../libtime.f)
2 c automatically generated by "SPLITF.PL V1.0 SPLIT Fortran source code"
3 c----------------------------------------------------------------------
4 c
5 c Copyright 2000 by Thomas Forbriger (IfG Stuttgart)
6 c
7 c ----
8 c libtime is free software; you can redistribute it and/or modify
9 c it under the terms of the GNU General Public License as published by
10 c the Free Software Foundation; either version 2 of the License, or
11 c (at your option) any later version.
12 c
13 c This program is distributed in the hope that it will be useful,
14 c but WITHOUT ANY WARRANTY; without even the implied warranty of
15 c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 c GNU General Public License for more details.
17 c
18 c You should have received a copy of the GNU General Public License
19 c along with this program; if not, write to the Free Software
20 c Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 c ----
22 c
23 c calculate difference between time records
24 c
25 c REVISIONS and CHANGES
26 c 05/08/2000 V2.0 Thomas Forbriger
27 c
28 c ============================================================================
29 cS
30  subroutine time_sub(date1, date2, date3)
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
102  end
103 c
104 c ----- END OF <time_sub.f> -----
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
void time_sub(time_Ts Date1, time_Ts Date2, time_Ts *Pdate3)
Definition: ctime_sub.c:33