Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / ntp / scripts / stats.ulrich.patches
1 \ 1\ 1\ 1\ 1
2 Received: from huey2.ee.udel.edu by mail.eecis.udel.edu id aa25207;
3           10 Dec 1997 10:39 EST
4 Received: from copland.udel.edu by huey.udel.edu id aa16958;
5           10 Dec 1997 10:39 EST
6 Received: from rrzs2.rz.uni-regensburg.de (rrzs2.rz.uni-regensburg.de [132.199.1.2]) by copland.udel.edu (8.8.5/8.7.3) with ESMTP id KAA21293 for <mills@udel.edu>; Wed, 10 Dec 1997 10:39:12 -0500 (EST)
7 Received: from ngate.ngate.uni-regensburg.de (ngate.rz.uni-regensburg.de [132.199.3.13])
8         by rrzs2.rz.uni-regensburg.de (8.8.5/8.8.5) with SMTP id QAA19974
9         for <mills@udel.edu>; Wed, 10 Dec 1997 16:38:42 +0100 (MET)
10 Received: from rkdvmks1.ngate.uni-regensburg.de by ngate.ngate.uni-regensburg.de; Wed, 10 Dec 97 16:39 MET
11 Received: from rkdvmks1.ngate.uni-regensburg.de by kgate.ngate.uni-regensburg.de; Wed, 10 Dec 97 15:38 GMT
12 Received: from RKDVMKS1/SpoolDir by rkdvmks1.ngate.uni-regensburg.de (Mercury 1.32);
13     10 Dec 97 16:38:34 +0100
14 Received: from SpoolDir by RKDVMKS1 (Mercury 1.32); 10 Dec 97 16:38:06 +0100
15 From: Ulrich Windl <ulrich.windl@rz.uni-regensburg.de>
16 Organization: Universitaet Regensburg, Klinikum
17 To: mills@udel.edu
18 Date: Wed, 10 Dec 1997 16:38:04 +0100
19 MIME-Version: 1.0
20 Content-Type: text/plain; charset=US-ASCII
21 Content-transfer-encoding: 7BIT
22 Subject: Big patch to scripts/monitoring
23 Priority: normal
24 X-mailer: Pegasus Mail for Windows (v2.53/R1)
25 Message-ID: <103AB9D209F5@rkdvmks1.ngate.uni-regensburg.de>
26
27 Dave, there's another big patch against scripts/monitoring. The Perl 
28 programs in there are rather old. As they are quite nice thogh, I 
29 decided to update them for the latest version of Perl, namely 5.004.
30
31 I'll include the description of changes and the patch.
32
33 Ulrich
34
35 Here is a description of changes made in ntploopwatch:
36
37 Corrected most warnings that PERL 5.004 might emit.  Corrected signal
38 handlers to make them work again. Corrected scaling (at least I
39 think). Supported case when output is sent to file or printer and
40 there is no X11 available. Fixed number of month in xlabels of the
41 plot.
42
43 Added the ability to specify printer for GNUplot other that
44 PostScript. Use hostname if $STATHOST is not given in configuration
45 file. Corrected verbosity level for some messages. Added ability to
46 specify a non-standard print command.
47
48 Perl 5.004_04 does no longer ignore ``-w--*-perl-*-''. Made some
49 cosmetic changes and added a timescale of 10 minutes.
50
51 (Other programs are functionally unchanged. lr.pl is a PERL module now.)
52
53
54 Index: README
55 ===================================================================
56 RCS file: /home/windl/NTP/mon-REP/monitoring/README,v
57 retrieving revision 1.1.1.1
58 retrieving revision 1.2
59 diff -u -r1.1.1.1 -r1.2
60 --- README      1993/08/24 19:29:34     1.1.1.1
61 +++ README      1997/10/23 17:51:37     1.2
62 @@ -1,14 +1,14 @@
63  This directory contains support for monitoring the local clock of xntp daemons.
64  
65 -WARNING: The scripts and routines contained in this directory are bete realease!
66 -        Do not depend on their correct operation. They are, however, in regular
67 -        use at University of Erlangen-Nuernberg. No severe problems are known
68 -        for this code.
69 +WARNING: The scripts and routines contained in this directory are beta
70 +        release!  Do not depend on their correct operation. They are,
71 +        however, in regular use at University of Erlangen-Nuernberg.
72 +        No severe problems are known for this code.
73  
74  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
75  PLEASE THINK TWICE BEFORE STARTING MONITORING REMOTE XNTP DEAMONS !!!!
76  MONITORING MAY INCREASE THE LOAD OF THE DEAMON MONITORED AND MAY
77 -INCREASE THE NETWORK LOAD SIGNIFICANTLY 
78 +INCREASE THE NETWORK LOAD SIGNIFICANTLY
79  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
80  
81  
82 @@ -23,8 +23,8 @@
83         It sends a set_trap request to each server given and dumps the
84         trap messages received. It handles refresh of set_trap.
85         Currently it handles only NTP V2, however the NTP V3 servers
86 -       also accept v2 requests. It will not interpret v3 system and peer
87 -       stati correctly.
88 +       also accept v2 requests. It will not interpret v3 system and
89 +       peer stati correctly.
90  
91         usage:
92           ntptrap [-n] [-p <port>] [-l <debug-output>] servers...
93 @@ -72,7 +72,9 @@
94         
95         if a timeout occurs the next sample is tried after delay/2 seconds
96  
97 -       The script will terminate after MAX_FAIL (currently 60) consecutive errors.
98 +       The script will terminate after MAX_FAIL (currently 60)
99 +       consecutive errors.
100 +
101         Errors are counted for:
102                 - error on send call
103                 - error on select call
104 @@ -114,10 +116,10 @@
105         command line values would be replaced by settings from the config file.
106  
107         printer:        specify printer to print plot
108 -                       BSD print systems semantics apply; if printer is omitted
109 -                       the name "ps" is used; plots are prepared using
110 -                       PostScript, thus the printer should best accept
111 -                       postscript input
112 +                       BSD print systems semantics apply; if printer
113 +                       is omitted the name "ps" is used; plots are
114 +                       prepared using PostScript, thus the printer
115 +                       should best accept postscript input
116  
117         For the following see also the comments in loopwatch.config.SAMPLE
118  
119 @@ -139,8 +141,10 @@
120         within display range
121  
122  timelocal.pl:
123 -       used during conversion of ISO_DATE_TIME values specified in loopwatch
124 -       config files to unix epoch values (seconds since 1970-01-01_00:00_00 UTC)
125 +
126 +       used during conversion of ISO_DATE_TIME values specified in
127 +       loopwatch config files to unix epoch values (seconds since
128 +       1970-01-01_00:00_00 UTC)
129  
130         A version of this file is distributed with perl-4.x, however,
131         it has a bug related to dates crossing 1970, causing endless loops..
132 Index: lr.pl
133 ===================================================================
134 RCS file: /home/windl/NTP/mon-REP/monitoring/lr.pl,v
135 retrieving revision 1.1.1.1
136 retrieving revision 1.4
137 diff -u -r1.1.1.1 -r1.4
138 --- lr.pl       1993/08/24 19:29:33     1.1.1.1
139 +++ lr.pl       1997/10/23 17:51:37     1.4
140 @@ -9,9 +9,14 @@
141  ;#  Frank Kardel, Rainer Pruy
142  ;#  Friedrich-Alexander Universitaet Erlangen-Nuernberg
143  ;#
144 +;#  Copyright (c) 1997 by
145 +;#  Ulrich Windl <Ulrich.Windl@rz.uni-regensburg.de>
146 +;#  (Converted to a PERL 5.004 package)
147  ;#
148  ;#############################################################
149  
150 +package lr;
151 +
152  ##
153  ## y = A + Bx
154  ##
155 @@ -23,123 +28,124 @@
156  ##
157  ## interface
158  ##
159 -*lr_init   = *lr'lr_init;      #';# &lr_init(tag); initialize data set for tag
160 -*lr_sample = *lr'lr_sample;    #';# &lr_sample(x,y,tag); enter sample
161 -*lr_Y      = *lr'lr_Y;         #';# &lr_Y(x,tag); compute y for given x 
162 -*lr_X      = *lr'lr_X;         #';# &lr_X(y,tag); compute x for given y
163 -*lr_r      = *lr'lr_r;         #';# &lr_r(tag);   regression coeffizient
164 -*lr_cov    = *lr'lr_cov;       #';# &lr_cov(tag); covariance
165 -*lr_A      = *lr'lr_A;         #';# &lr_A(tag);   
166 -*lr_B      = *lr'lr_B;         #';# &lr_B(tag);
167 -*lr_sigma  = *lr'lr_sigma;     #';# &lr_sigma(tag); standard deviation
168 -*lr_mean   = *lr'lr_mean;      #';# &lr_mean(tag);
169 +;# init(tag);          initialize data set for tag
170 +;# sample(x, y, tag);  enter sample
171 +;# Y(x, tag);          compute y for given x 
172 +;# X(y, tag);          compute x for given y
173 +;# r(tag);             regression coefficient
174 +;# cov(tag);           covariance
175 +;# A(tag);   
176 +;# B(tag);
177 +;# sigma(tag);         standard deviation
178 +;# mean(tag);
179  #########################
180  
181 -package lr;
182 -
183 -sub tagify
184 -{
185 -    local($tag) = @_;
186 -    if (defined($tag))
187 -    {
188 -      *lr_n   = eval "*${tag}_n";
189 -      *lr_sx  = eval "*${tag}_sx";
190 -      *lr_sx2 = eval "*${tag}_sx2";
191 -      *lr_sxy = eval "*${tag}_sxy";
192 -      *lr_sy  = eval "*${tag}_sy";
193 -      *lr_sy2 = eval "*${tag}_sy2";
194 -    }
195 -}
196 -
197 -sub lr_init
198 +sub init
199  {
200 -    &tagify($_[$[]) if defined($_[$[]);
201 +    my $self = shift;
202  
203 -    $lr_n   = 0;
204 -    $lr_sx  = 0.0;
205 -    $lr_sx2 = 0.0;
206 -    $lr_sxy = 0.0;
207 -    $lr_sy  = 0.0;
208 -    $lr_sy2 = 0.0;
209 +    $self->{n}   = 0;
210 +    $self->{sx}  = 0.0;
211 +    $self->{sx2} = 0.0;
212 +    $self->{sxy} = 0.0;
213 +    $self->{sy}  = 0.0;
214 +    $self->{sy2} = 0.0;
215  }
216  
217 -sub lr_sample
218 +sub sample($$$)
219  {
220 -    local($_x, $_y) = @_;
221 -
222 -    &tagify($_[$[+2]) if defined($_[$[+2]);
223 +    my $self = shift;
224 +    my($_x, $_y) = @_;
225  
226 -    $lr_n++;
227 -    $lr_sx  += $_x;
228 -    $lr_sy  += $_y;
229 -    $lr_sxy += $_x * $_y;
230 -    $lr_sx2 += $_x**2;
231 -    $lr_sy2 += $_y**2;
232 +    ++($self->{n});
233 +    $self->{sx}  += $_x;
234 +    $self->{sy}  += $_y;
235 +    $self->{sxy} += $_x * $_y;
236 +    $self->{sx2} += $_x**2;
237 +    $self->{sy2} += $_y**2;
238  }
239  
240 -sub lr_B
241 +sub B($)
242  {
243 -    &tagify($_[$[]) if defined($_[$[]);
244 +    my $self = shift;
245  
246 -    return 1 unless ($lr_n * $lr_sx2 - $lr_sx**2);
247 -    return ($lr_n * $lr_sxy - $lr_sx * $lr_sy) / ($lr_n * $lr_sx2 - $lr_sx**2);
248 +    return 1 unless ($self->{n} * $self->{sx2} - $self->{sx}**2);
249 +    return ($self->{n} * $self->{sxy} - $self->{sx} * $self->{sy})
250 +       / ($self->{n} * $self->{sx2} - $self->{sx}**2);
251  }
252  
253 -sub lr_A
254 +sub A($)
255  {
256 -    &tagify($_[$[]) if defined($_[$[]);
257 +    my $self = shift;
258  
259 -    return ($lr_sy - &lr_B * $lr_sx) / $lr_n;
260 +    return ($self->{sy} - B($self) * $self->{sx}) / $self->{n};
261  }
262  
263 -sub lr_Y
264 +sub Y($$)
265  {
266 -    &tagify($_[$[]) if defined($_[$[]);
267 +    my $self = shift;
268  
269 -    return &lr_A + &lr_B * $_[$[];
270 +    return A($self) + B($self) * $_[$[];
271  }
272  
273 -sub lr_X
274 +sub X($$)
275  {
276 -    &tagify($_[$[]) if defined($_[$[]);
277 +    my $self = shift;
278  
279 -    return ($_[$[] - &lr_A) / &lr_B;
280 +    return ($_[$[] - A($self)) / B($self);
281  }
282  
283 -sub lr_r
284 +sub r($)
285  {
286 -    &tagify($_[$[]) if defined($_[$[]);
287 +    my $self = shift;
288  
289 -    local($s) = ($lr_n * $lr_sx2 - $lr_sx**2) * ($lr_n * $lr_sy2 - $lr_sy**2);
290 +    my $s = ($self->{n} * $self->{sx2} - $self->{sx}**2)
291 +         * ($self->{n} * $self->{sy2} - $self->{sy}**2);
292  
293      return 1 unless $s;
294      
295 -    return ($lr_n * $lr_sxy - $lr_sx * $lr_sy) / sqrt($s);
296 +    return ($self->{n} * $self->{sxy} - $self->{sx} * $self->{sy}) / sqrt($s);
297  }
298  
299 -sub lr_cov
300 +sub cov($)
301  {
302 -    &tagify($_[$[]) if defined($_[$[]);
303 +    my $self = shift;
304  
305 -    return ($lr_sxy - $lr_sx * $lr_sy / $lr_n) / ($lr_n - 1);
306 +    return ($self->{sxy} - $self->{sx} * $self->{sy} / $self->{n})
307 +       / ($self->{n} - 1);
308  }
309  
310 -sub lr_sigma
311 +sub sigma($)
312  {
313 -    &tagify($_[$[]) if defined($_[$[]);
314 +    my $self = shift;
315  
316 -    return 0 if $lr_n <= 1;
317 -    return sqrt(($lr_sy2 - ($lr_sy * $lr_sy) / $lr_n) / ($lr_n));
318 +    return 0 if $self->{n} <= 1;
319 +    return sqrt(($self->{sy2} - ($self->{sy} * $self->{sy}) / $self->{n})
320 +               / ($self->{n}));
321  }
322  
323 -sub lr_mean
324 +sub mean($)
325  {
326 -    &tagify($_[$[]) if defined($_[$[]);
327 +    my $self = shift;
328  
329 -    return 0 if $lr_n <= 0;
330 -    return $lr_sy / $lr_n;
331 +    return 0 if $self->{n} <= 0;
332 +    return $self->{sy} / $self->{n};
333  }
334  
335 -&lr_init();
336 +sub new
337 +{
338 +    my $class = shift;
339 +    my $self = {
340 +       (n => undef,
341 +        sx => undef,
342 +        sx2 => undef,
343 +        sxy => undef,
344 +        sy => undef,
345 +        sy2 => undef)
346 +    };
347 +    bless $self, $class;
348 +    init($self);
349 +    return $self;
350 +}
351  
352  1;
353 Index: ntp.pl
354 ===================================================================
355 RCS file: /home/windl/NTP/mon-REP/monitoring/ntp.pl,v
356 retrieving revision 1.1.1.1
357 retrieving revision 1.3
358 diff -u -r1.1.1.1 -r1.3
359 --- ntp.pl      1993/08/24 19:29:34     1.1.1.1
360 +++ ntp.pl      1997/10/23 18:19:41     1.3
361 @@ -1,4 +1,4 @@
362 -#!/local/bin/perl
363 +#!/usr/bin/perl -w
364  ;#
365  ;# ntp.pl,v 3.1 1993/07/06 01:09:09 jbj Exp
366  ;#
367 @@ -43,7 +43,7 @@
368      ;#  N  key
369      ;#  N2 checksum
370      
371 -;# first bye of packet
372 +;# first byte of packet
373  sub pkt_LI   { return ($_[$[] >> 6) & 0x3; }
374  sub pkt_VN   { return ($_[$[] >> 3) & 0x7; }
375  sub pkt_MODE { return ($_[$[]     ) & 0x7; }
376 @@ -223,6 +223,7 @@
377  {
378      &getval(&psw_PSel($_[$[]),*PeerSelection);
379  }
380 +
381  sub PeerEvent
382  {
383      &getval(&psw_PCode($_[$[]),*PeerEvent);
384 @@ -394,14 +395,14 @@
385         $lastseen = 1 if !&pkt_M($r_e_m_op);
386         if (!defined(%FRAGS))
387         {
388 -           (&pkt_M($r_e_m_op) ? " more" : "")."\n";
389 +           print((&pkt_M($r_e_m_op) ? " more" : "")."\n");
390             $FRAGS{$offset} = $data;
391             ;# save other info
392             @FRAGS = ($status,$associd,&pkt_OP($r_e_m_op),$seq,$auth_keyid,$r_e_m_op);
393         }
394         else
395         {
396 -           (&pkt_M($r_e_m_op) ? " more" : "")."\n";
397 +           print((&pkt_M($r_e_m_op) ? " more" : "")."\n");
398             ;# add frag to previous - combine on the fly
399             if (defined($FRAGS{$offset}))
400             {
401 Index: ntploopstat
402 ===================================================================
403 RCS file: /home/windl/NTP/mon-REP/monitoring/ntploopstat,v
404 retrieving revision 1.1.1.1
405 retrieving revision 1.3
406 diff -u -r1.1.1.1 -r1.3
407 --- ntploopstat 1993/08/24 19:29:32     1.1.1.1
408 +++ ntploopstat 1997/11/23 19:07:12     1.3
409 @@ -1,4 +1,5 @@
410 -#!/local/bin/perl -w--*-perl-*-
411 +#!/usr/bin/perl -w
412 +# --*-perl-*-
413  ;#
414  ;# ntploopstat,v 3.1 1993/07/06 01:09:11 jbj Exp
415  ;# 
416 @@ -22,7 +23,7 @@
417  ;#              (Should have implemented &gettimeofday()..)
418  ;#
419  
420 -$0 =~ s!^.*/([^/]+)$!\1!;              # beautify script name
421 +$0 =~ s!^.*/([^/]+)$!$1!;              # beautify script name
422  
423  $ntpserver = 'localhost';              # default host to poll
424  $delay = 60;                           # default sampling rate
425 Index: ntploopwatch
426 ===================================================================
427 RCS file: /home/windl/NTP/mon-REP/monitoring/ntploopwatch,v
428 retrieving revision 1.1.1.1
429 retrieving revision 1.14
430 diff -u -r1.1.1.1 -r1.14
431 --- ntploopwatch        1993/10/22 14:28:18     1.1.1.1
432 +++ ntploopwatch        1997/12/07 17:06:36     1.14
433 @@ -1,4 +1,5 @@
434 -#!/local/bin/perl -w--*-perl-*-
435 +#!/usr/bin/perl -w
436 +#--*-perl-*-
437  ;#
438  ;# ntploopwatch,v 3.1 1993/07/06 01:09:13 jbj Exp
439  ;#
440 @@ -9,12 +10,17 @@
441  ;#  Copyright (c) 1992 
442  ;#  Rainer Pruy Friedrich-Alexander Universitaet Erlangen-Nuernberg
443  ;#
444 +;#  Copyright (c) 1997
445 +;#  Ulrich Windl <Ulrich.Windl@rz.uni-regensburg.de>
446 +;#  (Corrections for Perl5 and other fixes)
447  ;#
448  ;#############################################################
449 -$0 =~ s!^.*/([^/]+)$!\1!;
450 +$0 =~ s!^.*/([^/]+)$!$1!;
451  $F = ' ' x length($0);
452  $|=1;
453  
454 +use 5.004;     # require 5.004
455 +
456  $ENV{'SHELL'} = '/bin/sh'; # use bourne shell
457  
458  undef($config);
459 @@ -23,17 +29,17 @@
460  undef($samples);
461  undef($StartTime);
462  undef($EndTime);
463 -($a,$b) if 0;                  # keep -w happy
464 +
465  $usage = <<"E-O-P";
466  usage:
467 -  to watch statistics permanently:
468 +  to watch statistics periodically:
469       $0 [-v[<level>]] [-c <config-file>] [-d <working-dir>]
470       $F [-h <hostname>]
471  
472    to get a single print out specify also
473 -     $F -P[<printer>] [-s<samples>]
474 -     $F               [-S <start-time>] [-E <end-time>]
475 -     $F               [-Y <MaxOffs>] [-y <MinOffs>]
476 +     $F -P[[<term_type:>]<printer>]
477 +     $F [-s<samples>] [-S <start-time>] [-E <end-time>]
478 +     $F [-Y <MaxOffs>] [-y <MinOffs>]
479  
480  If You like long option names, You can use:
481      -help
482 @@ -41,21 +47,28 @@
483      -d    +directory
484      -h    +host
485      -v    +verbose[=<level>]
486 -    -P    +printer[=<printer>]
487 +    -P    +printer[=[<term_type>:]<printer>[:<print_cmd>]]
488      -s    +samples[=<samples>]
489      -S    +starttime
490      -E    +endtime
491      -Y    +maxy
492      -y    +miny
493  
494 +If <printer> is prefixed with a <term_type> and a colon, the <term_type>
495 +given is used as terminal fpr gnuplot.
496  If <printer> contains a '/' (slash character) output is directed to 
497  a file of this name instead of delivered to a printer.
498 +If suffix :<print_cmd> is given, the suffix is used as the print command,
499 +and <printer> is ignored.  If blanks are needed inside <term_type> or
500 +<print_cmd>, just use underscores instead.
501  E-O-P
502  
503  ;# add directory to look for lr.pl and timelocal.pl (in front of current list)
504  unshift(@INC,"/src/NTP/v3/xntp/monitoring");
505  
506  require "lr.pl";       # linear regresion routines
507 +my $lr_offs = new lr;
508 +my $lr_freq = new lr;
509  
510  $MJD_1970 = 40587;             # from ntp.h (V3)
511  $RecordSize = 48;              # usually a line fits into 42 bytes
512 @@ -171,16 +184,20 @@
513  
514  ;# configuration file
515  $config = "loopwatch.config" unless defined($config);
516 -($STATHOST = $config) =~ s!.*loopwatch\.config.([^/\.]*)$!\1!
517 +($STATHOST = $config) =~ s!.*loopwatch\.config.([^/\.]+)$!$1!
518      unless defined($STATHOST);
519 -($STATTAG = $STATHOST) =~ s/^([^\.\*\s]+)\..*$/\1/;
520 +if ($STATHOST eq $config) {
521 +    require "hostname.pl";
522 +    $STATHOST = hostname();
523 +}
524 +($STATTAG = $STATHOST) =~ s/^([^\.\*\s]+)\..*$/$1/;
525  
526  $srcprefix =~ s/\$STATHOST/$STATHOST/g;
527  
528  ;# plot command 
529 -@plotcmd=("gnuplot",
530 -         '-title', "Ntp loop filter statistics $STATHOST",
531 -         '-name', "NtpLoopWatch_$STATTAG");
532 +@plotcmd=("gnuplot");
533 +push(@plotcmd, '-title', "NTP loop filter statistics for $STATHOST",
534 +     '-name', "NtpLoopWatch_$STATTAG") unless $PrintIt;
535  $tmpfile = "/tmp/ntpstat.$$";
536  
537  ;# other variables
538 @@ -211,9 +228,8 @@
539                $?>>8,$? & 0xff)) if $?;
540    exit(1) if $? && defined($Plotpid) && $pid == $Plotpid;
541  }
542 -&sigchld if 0;
543 -$SIG{'CHLD'} = "sigchld";
544 -$SIG{'CLD'} = "sigchld";
545 +$SIG{'CHLD'} = \&sigchld;
546 +$SIG{'CLD'} = \&sigchld;
547  
548  sub abort
549  {
550 @@ -221,8 +237,7 @@
551    defined($Plotpid) && kill('TERM',$Plotpid);
552    die("$0: received signal SIG$_[$[] - exiting\n");
553  }
554 -&abort if 0;   # make -w happy - &abort IS used
555 -$SIG{'INT'} = $SIG{'HUP'} = $SIG{'QUIT'} = $SIG{'TERM'} = $SIG{'PIPE'} = "abort";
556 +$SIG{'INT'} = $SIG{'HUP'} = $SIG{'QUIT'} = $SIG{'TERM'} = $SIG{'PIPE'} = \&abort;
557  
558  ;#
559  sub abs
560 @@ -248,7 +263,7 @@
561     open(STDOUT,">&STDERR") ||
562         die("$0: failed to redirect STDOUT of plot command: $!\n");
563     
564 -   print STDOUT "plot command running as $$\n";
565 +   print STDOUT "plot command has PID $$\n";
566  
567     exec @plotcmd;
568     die("$0: failed to exec (@plotcmd): $!\n");
569 @@ -275,128 +290,83 @@
570      s/^([^\#]*[^\#\s]?)\s*\#.*$//;
571      next if /^\s*$/;
572  
573 -    s/^\s*([^=\s]*)\s*=\s*(.*\S)\s*$/\1=\2/;
574 +    s/^\s*([^=\s]*)\s*=\s*(.*\S)\s*$/$1=$2/;
575  
576 -    ($c,$v) = split(/=/,$_,2);
577 +    ($c,$v) = ($1, $2);
578      print "processing \"$c=$v\"\n" if $verbose > 3;
579 -    ($c eq "delay") && ($delay = $v,1) && next;
580 -    ($c eq 'samples') && (!defined($PrintIt) || !defined($samples)) &&
581 -       ($samples = $v,1) && next;
582 -    ($c eq 'srcprefix') && (($srcprefix=$v)=~s/\$STATHOST/$STATHOST/g,1)
583 -       && next;
584 -    ($c eq 'showoffs') &&
585 -       ($showoffs = ($v eq 'yes' || $v eq 'y' || $v != 0),1) && next;
586 -    ($c eq 'showfreq') &&
587 -       ($showfreq = ($v eq 'yes' || $v eq 'y' || $v != 0),1) && next;
588 -    ($c eq 'showcmpl') &&
589 -       ($showcmpl = ($v eq 'yes' || $v eq 'y' || $v != 0),1) && next;
590 -    ($c eq 'showoreg') &&
591 -       ($showoreg = ($v eq 'yes' || $v eq 'y' || $v != 0),1) && next;
592 -    ($c eq 'showfreg') &&
593 -       ($showfreg = ($v eq 'yes' || $v eq 'y' || $v != 0),1) && next;
594 -
595 -    ($c eq 'exit') && (unlink($tmpfile),die("$0: exit by config request\n"));
596 -
597 -    ($c eq 'freqbase' ||
598 -     $c eq 'cmplscale') &&
599 -       do {
600 -           if (! defined($v) || $v eq "" || $v eq 'dynamic')
601 -           {
602 -             eval "undef(\$$c);";
603 -           }
604 -           else
605 -           {
606 -             eval "\$$c = \$v;";
607 -           }
608 -           next;
609 -       };
610 -    ($c eq 'timebase') &&
611 -       do {
612 -           if (! defined($v) || $v eq "" || $v eq "dynamic")
613 -           {
614 -             undef($timebase);
615 -           }
616 -           else
617 -           {
618 -             $timebase=&date_time_spec2seconds($v);
619 -           }
620 -       };
621 -    ($c eq 'EndTime') &&
622 -       do {
623 -           next if defined($EndTime) && defined($PrintIt);
624 -           if (! defined($v) || $v eq "" || $v eq "none")
625 -           {
626 -             undef($EndTime);
627 -           }
628 -           else
629 -           {
630 -             $EndTime=&date_time_spec2seconds($v);
631 -           }
632 -       };
633 -    ($c eq 'StartTime') &&
634 -       do {
635 -           next if defined($StartTime) && defined($PrintIt);
636 -           if (! defined($v) || $v eq "" || $v eq "none")
637 -           {
638 -             undef($StartTime);
639 -           }
640 -           else
641 -           {
642 -             $StartTime=&date_time_spec2seconds($v);
643 -           }
644 -       };
645 -
646 -    ($c eq 'MaxY') &&
647 -       do {
648 -           next if defined($MaxY) && defined($PrintIt);
649 -           if (! defined($v) || $v eq "" || $v eq "none")
650 -           {
651 -             undef($MaxY);
652 -           }
653 -           else
654 -           {
655 -             $MaxY=$v;
656 -           }
657 -       };
658 -
659 -    ($c eq 'MinY') &&
660 -       do {
661 -           next if defined($MinY) && defined($PrintIt);
662 -           if (! defined($v) || $v eq "" || $v eq "none")
663 -           {
664 -             undef($MinY);
665 -           }
666 -           else
667 -           {
668 -             $MinY=$v;
669 -           }
670 -       };
671 -
672 -    ($c eq 'deltaT') &&
673 -       do {
674 -           if (!defined($v) || $v eq "")
675 -           {
676 -             undef($deltaT);
677 -           }
678 -           else
679 -           {
680 -             $deltaT = $v;
681 -           }
682 -           next;
683 -       };
684 -    ($c eq 'verbose') && ! defined($PrintIt) &&
685 -       do {
686 -            if (!defined($v) || $v == 0)
687 -            {
688 -              $verbose = 0;
689 -            }
690 -            else
691 -            {
692 -              $verbose = $v;
693 -            }
694 -            next;
695 -       };
696 -    ;# otherwise: silently ignore unrecognized config line
697 +    if ($c eq "delay") {
698 +       $delay = $v;
699 +    } elsif ($c eq 'samples') {
700 +       $samples = $v if (!defined($PrintIt) || !defined($samples));
701 +    } elsif ($c eq 'srcprefix') {
702 +       ($srcprefix = $v) =~ s/\$STATHOST/$STATHOST/g;
703 +    } elsif ($c eq 'showoffs') {
704 +       $showoffs = ($v =~ /^yes$|^y$|^1$/);
705 +    } elsif ($c eq 'showfreq') {
706 +       $showfreq = ($v =~ /^yes$|^y$|^1$/);
707 +    } elsif ($c eq 'showcmpl') {
708 +       $showcmpl = ($v =~ /^yes$|^y$|^1$/);
709 +    } elsif ($c eq 'showoreg') {
710 +       $showoreg = ($v =~ /^yes$|^y$|^1$/);
711 +    } elsif ($c eq 'showfreg') {
712 +       $showfreg = ($v =~ /^yes$|^y$|^1$/);
713 +    } elsif ($c eq 'exit') {
714 +       unlink($tmpfile); die("$0: exit by config request\n");
715 +    } elsif ($c eq 'freqbase' || $c eq 'cmplscale') {
716 +       if (! defined($v) || $v eq "" || $v eq 'dynamic') {
717 +           eval "undef(\$$c);";
718 +       } else {
719 +           eval "\$$c = \$v;";
720 +       }
721 +    } elsif ($c eq 'timebase') {
722 +       if (! defined($v) || $v eq "" || $v eq "dynamic") {
723 +           undef($timebase);
724 +       } else {
725 +           $timebase=&date_time_spec2seconds($v);
726 +       }
727 +    } elsif ($c eq 'EndTime') {
728 +       next if defined($EndTime) && defined($PrintIt);
729 +       if (! defined($v) || $v eq "" || $v eq "none") {
730 +           undef($EndTime);
731 +       } else {
732 +           $EndTime=&date_time_spec2seconds($v);
733 +       }
734 +    } elsif ($c eq 'StartTime') {
735 +       next if defined($StartTime) && defined($PrintIt);
736 +       if (! defined($v) || $v eq "" || $v eq "none") {
737 +           undef($StartTime);
738 +       } else {
739 +           $StartTime=&date_time_spec2seconds($v);
740 +       }
741 +    } elsif ($c eq 'MaxY') {
742 +       next if defined($MaxY) && defined($PrintIt);
743 +       if (! defined($v) || $v eq "" || $v eq "none") {
744 +           undef($MaxY);
745 +       } else {
746 +           $MaxY=$v;
747 +       }
748 +    } elsif ($c eq 'MinY') {
749 +       next if defined($MinY) && defined($PrintIt);
750 +       if (! defined($v) || $v eq "" || $v eq "none") {
751 +           undef($MinY);
752 +       } else {
753 +           $MinY=$v;
754 +       }
755 +    } elsif ($c eq 'deltaT') {
756 +       if (!defined($v) || $v eq "") {
757 +           undef($deltaT);
758 +       } else {
759 +           $deltaT = $v;
760 +       }
761 +    } elsif ($c eq 'verbose' && ! defined($PrintIt)) {
762 +       if (!defined($v) || $v == 0) {
763 +           $verbose = 0;
764 +       } else {
765 +           $verbose = $v;
766 +       }
767 +    } else {
768 +       ;# otherwise: silently ignore unrecognized config line
769 +    }
770    }
771    close(CF);
772    ;# set show defaults when nothing selected
773 @@ -413,16 +383,16 @@
774      print  "   showcmpl\t= $showcmpl\n";
775      print  "   showoreg\t= $showoreg\n";
776      print  "   showfreg\t= $showfreg\n";
777 -    printf "   timebase\t= %s",defined($timebase)?&ctime($timebase):"dynamic\n";
778 -    printf "   freqbase\t= %s\n",defined($freqbase)  ?"$freqbase":"dynamic";
779 -    printf "   cmplscale\t= %s\n",defined($cmplscale)?"$cmplscale":"dynamic";
780 -    printf "   StartTime\t= %s",defined($StartTime)?&ctime($StartTime):"none\n";
781 -    printf "   EndTime\t= %s",  defined($EndTime) ?  &ctime($EndTime):"none\n";
782 -    printf "   MaxY\t= %s",defined($MaxY)? $MaxY      :"none\n";
783 -    printf "   MinY\t= %s",defined($MinY)? $MinY      :"none\n";
784 +    printf "   timebase\t= %s", defined($timebase) ? &ctime($timebase) : "dynamic\n";
785 +    printf "   freqbase\t= %s\n", defined($freqbase) ? "$freqbase" : "dynamic";
786 +    printf "   cmplscale\t= %s\n", defined($cmplscale) ? "$cmplscale" : "dynamic";
787 +    printf "   StartTime\t= %s", defined($StartTime) ? &ctime($StartTime) : "none\n";
788 +    printf "   EndTime\t= %s", defined($EndTime) ? &ctime($EndTime):"none\n";
789 +    printf "   MaxY\t= %s", defined($MaxY) ? $MaxY : "none\n";
790 +    printf "   MinY\t= %s", defined($MinY) ? $MinY : "none\n";
791      print  "   verbose\t= $verbose\n";
792    }
793 -print "configuration file read\n" if $verbose > 2;
794 +  print "configuration file read\n" if $verbose > 2;
795  }
796  
797  sub make_doplot
798 @@ -443,10 +413,9 @@
799      ;# number of integral seconds to get at least 12 tic marks on x axis
800      $t = int(($maxtime - $mintime) / 12 + 0.5);
801      $t = 1 unless $t;          # prevent $t to be zero
802 -    foreach $i (30,
803 -               60,5*60,15*60,30*60,
804 -               60*60,2*60*60,6*60*60,12*60*60,
805 -               24*60*60,48*60*60)
806 +    foreach $i (30, 60,
807 +               5*60, 10*60, 15*60, 30*60, 60*60,
808 +               2*60*60, 6*60*60, 12*60*60, 24*60*60, 48*60*60)
809      {
810         last if $t < $i;
811         $t = $t - ($t % $i);
812 @@ -458,31 +427,30 @@
813          $i <= $maxtime + $t;
814          $i += $t, $c=",")
815      {
816 +       my ($sec, $min, $hour, $mday, $mon, $year, $wday) = localtime($i);
817 +
818         $s .= $c;
819         ((int($i / $t) % 2) &&
820          ($s .= sprintf("'' %lf",($i - $LastTimeBase)/3600))) ||
821              (($t <= 60) &&
822               ($s .= sprintf("'%d:%02d:%02d' %lf",
823 -                            (localtime($i))[$[+2,$[+1,$[+0],
824 -                            ($i - $LastTimeBase)/3600))) 
825 +                            $hour, $min, $sec, ($i - $LastTimeBase) / 3600))) 
826                  || (($t <= 2*60*60) &&
827                      ($s .= sprintf("'%d:%02d' %lf",
828 -                                   (localtime($i))[$[+2,$[+1],
829 -                                   ($i - $LastTimeBase)/3600)))
830 +                                   $hour, $min, ($i - $LastTimeBase) / 3600)))
831                      || (($t <= 12*60*60) &&
832                          ($s .= sprintf("'%s %d:00' %lf",
833 -                                       $Day[(localtime($i))[$[+6]],
834 -                                       (localtime($i))[$[+2],
835 -                                       ($i - $LastTimeBase)/3600)))
836 +                                       $Day[$wday], $hour,
837 +                                       ($i - $LastTimeBase) / 3600)))
838                          || ($s .= sprintf("'%d.%d-%d:00' %lf",
839 -                                          (localtime($i))[$[+3,$[+4,$[+2],
840 -                                          ($i - $LastTimeBase)/3600));
841 +                                          $mday, $mon + 1, $hour,
842 +                                          ($i - $LastTimeBase) / 3600));
843      }
844      $doplot .= "set xtics ($s)\n";
845      
846      chop($xts = &ctime($mintime));
847      chop($xte = &ctime($maxtime));
848 -    $doplot .= "set xlabel 'Start:  $xts    --   Time Scale   --    End:  $xte'\n";
849 +    $doplot .= "set xlabel 'Start: $xts   -- Time Scale --   End: $xte'\n";
850      $doplot .= "set yrange [" ;
851      $doplot .= defined($MinY) ? sprintf("%lf", $MinY) : $miny;
852      $doplot .= ':';
853 @@ -518,22 +486,22 @@
854          $c = ",");
855      $showoreg && $showoffs &&
856         ($doplot .= sprintf($regfmt, $c,
857 -                           &lr_B('offs'),&lr_A('offs'),
858 -                           "offset   ",
859 -                           &lr_B('offs'),
860 -                           ((&lr_A('offs')) < 0 ? '-' : '+'),
861 -                           &abs(&lr_A('offs')), &lr_r('offs'),
862 +                           $lr_offs->B(),$lr_offs->A(),
863 +                           "offset",
864 +                           $lr_offs->B(),
865 +                           (($lr_offs->A()) < 0 ? '-' : '+'),
866 +                           &abs($lr_offs->A()), $lr_offs->r(),
867                             "[ms]"),
868          $c = ",");
869      $showfreg && $showfreq &&
870         ($doplot .= sprintf($regfmt, $c,
871 -                           &lr_B('freq') * $FreqScale,
872 -                           (&lr_A('freq') + $minfreq) * $FreqScale - $LastFreqBase,
873 +                           $lr_freq->B() * $FreqScale,
874 +                           ($lr_freq->A() + $minfreq) * $FreqScale - $LastFreqBase,
875                             "frequency",
876 -                           &lr_B('freq') * $FreqScale,
877 -                           ((&lr_A('freq') + $minfreq) * $FreqScale - $LastFreqBase) < 0 ? '-' : '+',
878 -                           &abs((&lr_A('freq') + $minfreq) * $FreqScale - $LastFreqBase),
879 -                           &lr_r('freq'),
880 +                           $lr_freq->B() * $FreqScale,
881 +                           (($lr_freq->A() + $minfreq) * $FreqScale - $LastFreqBase) < 0 ? '-' : '+',
882 +                           &abs(($lr_freq->A() + $minfreq) * $FreqScale - $LastFreqBase),
883 +                           $lr_freq->r(),
884                             "[${FreqScaleInv}ppm]"),
885          $c = ",");
886      $doplot .= "\n";
887 @@ -583,7 +551,7 @@
888      $#loffset = $[ - 1;
889      $#filekey = $[ - 1;
890      print "memory allocation ready\n" if $verbose > 2;
891 -    sleep(3) if $verbose > 1;
892 +    sleep(3) if $verbose > 2;
893  
894      if (index($in,"/") < $[)
895      {
896 @@ -606,7 +574,6 @@
897         ;# rescan directory on changes
898         $Lsdir = $sdir;
899         $Ltime = (stat($sdir))[$[+9];
900 -       </X{> if 0;             # dummy line - calm down my formatter
901         local(@newfiles) = < ${in}*[0-9] >;
902         local($st_dev,$st_ino,$st_mtime,$st_size,$name,$key,$modified);
903  
904 @@ -626,7 +593,7 @@
905                 $F_key{$name} = $key;
906                 $modified++;
907             }
908 -           if (!defined($F_name{$key}) || $F_name{$key} != $name)
909 +           if (!defined($F_name{$key}) || $F_name{$key} ne $name)
910             {
911                 $F_name{$key} = $name;
912                 $modified++;
913 @@ -643,9 +610,9 @@
914             }
915             if ($modified)
916             {
917 -               print "new data \"$name\" key: $key;\n" if $verbose > 1;
918 +               print "new data \"$name\" key: $key;\n" if $verbose > 2;
919                 print "             size: $st_size; mtime: $st_mtime;\n"
920 -                   if $verbose > 1;
921 +                   if $verbose > 2;
922                 $F_last{$key} = $F_first{$key} = $st_mtime;
923                 $F_first{$key}--; # prevent zero divide later on
924                 ;# now compute derivated attributes
925 @@ -692,7 +659,7 @@
926                 }
927                 close(IN);
928                 print("             first: ",$F_first{$key},
929 -                     " last: ",$F_last{$key},"\n") if $verbose > 1;
930 +                     " last: ",$F_last{$key},"\n") if $verbose > 2;
931             }
932         }
933         ;# now reclaim memory used for files no longer referenced ...
934 @@ -739,7 +706,7 @@
935         }
936         ;# create list sorted by time
937         @F_files = sort {$F_first{$a} <=> $F_first{$b}; } keys(%F_name);
938 -       if ($verbose > 1)
939 +       if ($verbose > 2)
940         {
941             print "Resulting file list:\n";
942             foreach (@F_files)
943 @@ -797,7 +764,7 @@
944             print "guess start according to StartTime ($StartTime)\n"
945                 if $verbose > 3;
946  
947 -           if ($fpos[$[] eq 'start')
948 +           if (defined $fpos[$[] && $fpos[$[] eq 'start')
949             {
950                 if (grep($_ eq $fpos[$[+1],@f))
951                 {
952 @@ -1001,9 +968,9 @@
953             $t += $F[$[+1];     # add seconds + fraction
954             
955             ;# multiply offset by 1000 to get ms - try to avoid float op
956 -           (($F[$[+2] =~ s/(\d*)\.(\d{3})(\d*)/\1\2.\3/) &&
957 +           (($F[$[+2] =~ s/(\d*)\.(\d{3})(\d*)/$1$2.$3/) &&
958              $F[$[+2] =~ s/0+([\d\.])/($1 eq '.') ? '0.' : $1/e) # strip leading zeros
959 -               || $F[$[+2] *= 1000;
960 +               || ($F[$[+2] *= 1000);
961  
962             
963             ;# skip samples out of specified time range
964 @@ -1036,8 +1003,8 @@
965      print "input scanned ($l lines/",scalar(@time)," samples)\n"
966         if $verbose > 1;
967      
968 -    &lr_init('offs');
969 -    &lr_init('freq');
970 +    $lr_offs->init();
971 +    $lr_freq->init();
972      
973      if (@time)
974      {
975 @@ -1047,17 +1014,17 @@
976         local($freqbase) unless defined($freqbase);
977         local($cmplscale) unless defined($cmplscale);
978         
979 -       undef($mintime,$maxtime,$minoffs,$maxoffs,
980 -             $minfreq,$maxfreq,$mincmpl,$maxcmpl,
981 -             $miny,$maxy);
982 +       undef $mintime; undef $maxtime; undef $minoffs; undef $maxoffs;
983 +       undef $minfreq; undef $maxfreq; undef $mincmpl; undef $maxcmpl;
984 +       undef $miny; undef $maxy;
985         
986         print "computing ranges\n" if $verbose > 2;
987         
988         $LastCnt = @time;
989  
990         ;# @time is in ascending order (;-)
991 -       $mintime = @time[$[];
992 -       $maxtime = @time[$#time];
993 +       $mintime = $time[$[];
994 +       $maxtime = $time[$#time];
995         unless (defined($timebase))
996         {
997             local($time,@X) = (time);
998 @@ -1081,24 +1048,24 @@
999             ;# (otherwise a (shift(@a1),shift(a2)) would do),
1000             ;# I dont like to make copies of these arrays as they may be huge
1001             $i = $[;
1002 -           &lr_sample(($time[$i]-$timebase)/3600,$offs[$
1003 \ 1\ 1\ 1\ 1