libtime++: Date and time calculation
time_nfit.f
Go to the documentation of this file.
1 c this is <time_nfit.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 fill time span with given sampling interval
24 c
25 c REVISIONS and CHANGES
26 c 05/08/2000 V1.0 Thomas Forbriger
27 c V2.0 use language specific fatal error handler
28 c 24/04/2023 V2.1 capture cases exceeding integer value range
29 c
30 c ============================================================================
31 cS
32  subroutine time_nfit(date1, date2, n, full)
33 c
34 c Evaluate how many (n) samples of length date2 fit into the
35 c time span date1 at best.
36 c
37 c full=n*date2
38 c
39 c The difference abs(date1-full) will be less or equal
40 c the half of date2.
41 c
42 c input:
43 c date1: given time span (relative time record)
44 c date2: given sampling interval (relative time record)
45 c output:
46 c n: number of intervals date2 that fit at best in date1
47 c full: the full time span that would be covered by n intervals
48 c of length date2 (regularized relative time record)
49 c
50 c last change: V2.00 (05/08/2000)
51 c
52  integer date1(7), date2(7), n, full(7)
53 cE
54  double precision d1, d2
55  integer limit(7), i, time_compare, c, dif(7), dhalf(7), rest
56  data limit/-1,-1,24,60,60,1000,1000/
57 c
58  if ((date1(1).ne.0).or.(date2(1).ne.0)) then
59  call time_util_fatal('time_nfit','no absolute times allowed')
60  else
61 c for our convenience we will first use floating point arithmetics
62 c for an estimation
63  d1=float(date1(2))
64  d2=float(date2(2))
65  do i=3,7
66  d1=d1*float(limit(i))+float(date1(i))
67  d2=d2*float(limit(i))+float(date2(i))
68  enddo
69  if (d1.gt.(d2*2.**31)) then
70  call time_util_fatal('time_nfit',
71  & 'ratio exceeds integer value range')
72  endif
73  n=int(d1/d2)
74 c get half of sampling interval
75  call time_div(date2, dhalf, 2, rest)
76  dhalf(7)=dhalf(7)+rest
77  call time_norm(dhalf)
78 c now go and fit result stepwise
79  1 call time_mul(date2, full, n)
80  c=time_compare(date1, full)
81  call time_sub(date1, full, dif)
82 c next step if difference exceeds half of sampling rate
83  if (time_compare(dif, dhalf).gt.0) then
84  if (c.gt.0) then
85  n=n+1
86  else
87  n=n-1
88  endif
89  goto 1
90  endif
91  endif
92  return
93  end
94 c
95 c ----- END OF <time_nfit.f> -----
void time_div(time_Ts Date1, time_Ts *Pdate2, timeint n, timeint *rest)
Definition: ctime_div.c:36
subroutine time_util_fatal(caller, text)
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
void time_nfit(time_Ts Date1, time_Ts Date2, timeint *n, time_Ts *Pfull)
Definition: ctime_nfit.c:36
void time_mul(time_Ts Date1, time_Ts *Pdate2, integer n)
Definition: ctime_mul.c:35