libtime++: Date and time calculation
time_norm.f
Go to the documentation of this file.
1 c this is <time_norm.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 regularize any time record (relative or absolute)
24 c
25 c REVISIONS and CHANGES
26 c 05/08/2000 V2.0 Thomas Forbriger
27 c 07/11/2017 V2.1 fix bug, negative values were not normalized
28 c correctly in cases where they were integer
29 c multiples of the limit values; this cause
30 c problems, when calling time_compare with the
31 c result from time_sub when the result of
32 c time_sub was not properly normalized
33 c
34 c ============================================================================
35 cS
36  subroutine time_norm(date)
37 c
38 c Regularize any time record (relative or absolute)
39 c (i.e. set all fields to correct value range)
40 c
41 c input/output:
42 c date: date record to be regularized
43 c
44 c last change: V2.10 (05/08/2000)
45 c
46  integer date(7)
47 cE
48  integer carry, i, diy
49  integer limit(7)
50  logical time_isleapyear
51  data limit/-1,-1,24,60,60,1000,1000/
52 c
53 c set linear value ranges (from hours on)
54  do i=7,3,-1
55  carry=int(date(i)/limit(i))
56  if (date(i).lt.0) carry=int((date(i)+1)/limit(i))-1
57  date(i)=date(i)-carry*limit(i)
58  date(i-1)=date(i-1)+carry
59  enddo
60 c work on date if not relative
61  if (date(1).gt.0) then
62 c set full 4 digit year
63  call time_fullyear(date(1))
64  if (date(2).gt.0) then
65  if (time_isleapyear(date(1))) then
66  diy=366
67  else
68  diy=365
69  endif
70  1 if (date(2).le.diy) goto 2
71  date(2)=date(2)-diy
72  date(1)=date(1)+1
73  if (time_isleapyear(date(1))) then
74  diy=366
75  else
76  diy=365
77  endif
78  goto 1
79  2 continue
80  else
81  3 if (date(2).gt.0) goto 4
82  date(1)=date(1)-1
83  if (time_isleapyear(date(1))) then
84  diy=366
85  else
86  diy=365
87  endif
88  date(2)=date(2)+diy
89  goto 3
90  4 continue
91  endif
92  endif
93  return
94  end
95 c
96 c ----- END OF <time_norm.f> -----
void time_norm(time_Ts *Pdate)
Definition: ctime_norm.c:33
void time_fullyear(timeint *year)