source: ntrip/trunk/BNC/scripts/Bnc.pm@ 10007

Last change on this file since 10007 was 10007, checked in by stuerze, 13 months ago

ppp plot scripts updated

  • Property svn:keywords set to Header
File size: 28.6 KB
Line 
1package Bnc;
2
3# Perl utility functions for BNC
4#
5# Revision: $Header: trunk/BNC/scripts/Bnc.pm 10007 2023-03-16 14:32:28Z stuerze $
6
7use strict;
8use warnings;
9use File::Basename;
10use File::Spec::Functions qw(catfile);
11use File::Temp qw(tempfile);
12use Exporter;
13use Time::Piece 1.30;
14use PDL::Lite; # to avoid namespace pollution
15use PDL::Primitive;
16use Log::Log4perl qw(:easy);
17
18# use List::MoreUtils qw(uniq); # Prototype mismatch with PDL (uniq)
19
20# =============================================================================
21# callBnc ($bnc_ini, %$opts_ref)
22# =============================================================================
23# Call BNC
24#
25# Param : $bnc_ini [optional] The BNC config file that should be used. If not set, the default config is ised.
26# $opts_ref [required] Hash with BNC config options as key. They will overwrite the settings from the config file.
27# Return : BNC exit status
28# =============================================================================
29sub callBnc {
30 my ( $bnc, $bnc_ini, $opts ) = @_;
31
32 my $config_file = "";
33 if ( $bnc_ini && -s $bnc_ini ) {
34 $config_file = "--conf $bnc_ini";
35 }
36 else {
37 DEBUG("callBnc: Use default bnc-ini file");
38 }
39
40 my $opts_str = "";
41 if ($opts) { $opts_str = options2string($opts) }
42
43 # my @cmd = (
44 # 'xvfb-run',
45 # "--server-args='-screen 0, 1280x1024x8'", # 1024x768x24
46 # "$bnc",
47 # "--nw",
48 # $opts_str,
49 # );
50
51#my $rc = call_system("xvfb-run -a -e /home/user/xvfb.err --server-args='-screen 0 1280x1024x8' $bnc --nw $config_file $opts_str");
52 return Common::runCmd("$bnc --nw $config_file $opts_str");
53}
54
55# Converts options map to string used for calling BNC.
56sub options2string {
57 my ($opts) = shift;
58
59 my $opts_str = "";
60 if ($opts) {
61 foreach my $key ( keys %{$opts} ) {
62 $opts_str .= "--key $key" . ' "' . $opts->{$key} . '" ';
63 }
64 }
65 return $opts_str;
66}
67
68# =============================================================================
69# parseMessageTypesFromFile
70# =============================================================================
71# Parse Message-Types with repetition rate from a BNC/scanRTCM logfile
72#
73# Param : $logfile [required] Path to the BNC-logfile.
74# $caAbbr [optional] caster name or abbreviation
75#
76# Return : Message-types for each mountpoint (as Hash-Ref)
77# Hash with mp as key and the list of messTypes as value
78# Example: $VAR1 = { 'RIO10' => ['1004(1)','1006(15)','1008(15)',...],
79# 'CLIB0' => ['1004(1)','1006(10)','1008(10)',...],
80# };
81# =============================================================================
82sub parseMessageTypesFromFile {
83 my ( $logfile, $caAbbr, $mytmpPath ) = @_;
84
85 unless ( -s $logfile ) {
86 ERROR "File [$logfile] is empty or does not exist";
87 return;
88 }
89
90 my $tmp = File::Temp->new( UNLINK => 1, SUFFIX => '.messtyps' );
91 my $casterMessTypeFile = $tmp->filename;
92
93 #my $caster = $logfilename =~ s/\.log\.messtyps//r;
94 #INFO "Process caster '$caster'";
95
96 INFO "Process $logfile";
97
98 # scan beginns with that line: 16-02-18 23:58:02 WTZ37: Get data in RTCM 3.x format
99
100 # First grep for message type lines in bnc-logfile and write them to local temp. directory
101 # NOTE: 'sort -u' because Ephemeries message-types 1019 (GPS), 1020 (GLONASS), 1045 (Galileo) come
102 # for every sat. at the same time/second. This is done for getting the repetition rate
103 system ("grep \"Received message type\" $logfile | sort -u > $casterMessTypeFile") == 0
104 or ERROR "Fehler: $!";
105
106 # --------------------------------------------
107 # Get message types foreach station/mountpoint
108 # --------------------------------------------
109 my $cmd = "cat $casterMessTypeFile | awk '{print \$3, \$7}' | sort -u";
110 my @messTypes = `$cmd`; # ['DARX1: 1004\n','DARX1: 1006\n',... ]
111 if ( scalar @messTypes < 1 ) {
112 ERROR "Could not retrieve message types from file $casterMessTypeFile";
113 return;
114 }
115
116 # Note: Skip first 1500 lines because BNC is weird here, all lines with same timestamp, buffer problem?
117
118 # ------------------------------------------------------
119 # Guess repetition rate for each mountpoint/message-type
120 # ------------------------------------------------------
121 # For that get the first $minSamples appearances of mountp with same message type
122 # and build the differences between them
123 my $minSamples = 4;
124 foreach my $mpType (@messTypes) {
125 chomp $mpType; # 'AUBG3: 1004'
126 my ( $mp, $mt ) = split ( /:\s*/, $mpType );
127 my $cmd = "grep \"$mp: Received message type $mt\" $logfile";
128 my @rows = `$cmd`;
129 if ( scalar @rows < 1 ) {
130 ERROR "Could not retrieve message types for $mpType from file $casterMessTypeFile";
131 next;
132 }
133
134 if ( scalar @rows <= $minSamples ) {
135 WARN "Could not guess repetition rate for message type $mpType: only " . scalar @rows . " matches found";
136 next;
137 }
138
139 my $repRate = _computeMessTypRepetitonRate( \@rows, $caAbbr );
140 if ($repRate) {
141 $mpType .= '(' . $repRate . ')';
142 }
143 } # ----- end foreach messageType -----
144
145 #if ( unlink $casterMessTypeFile ) { TRACE "Removed file [$casterMessTypeFile]" }
146
147 # Return an HASH OF ARRAYS with mp as key and the list of messTypes as value
148 my %messTypesHash;
149 foreach (@messTypes) {
150 my @ele = split ( ': ', $_ );
151 my $mp = shift @ele;
152 push ( @{ $messTypesHash{$mp} }, shift @ele );
153 }
154
155 return \%messTypesHash;
156}
157
158# =============================================================================
159# _computeMessTypRepetitonRate
160# =============================================================================
161# Guess repetition rate of message types
162#
163# Param : $firstMatches [required] Array-Ref with first appearances of station
164# and mess type. Complete logfile lines, e.g.
165# '13-07-04 17:38:26 BRUX0: Received message type 1004 '
166# $caAbbr [optional] caster abbreviation
167# Return : repetition rate in secs, (median value)
168# =============================================================================
169sub _computeMessTypRepetitonRate {
170 my ( $rows, $caAbbr ) = @_;
171
172 my $maxGap = 600; # if gap > 10min then we guess it is a new scan
173
174 $rows->[0] =~ /.{18}([a-x0-9]+): Received message type (\d+)/i;
175 my $stat = $1;
176 my $mestp = $2;
177
178 # Create list of unix timestamps
179 my @scans;
180 my $scan = 0;
181 my ( $prevTime, $deltaT ) = ( 0, 0 );
182 foreach (@$rows) {
183 my $uxtime = date2unix( substr ( $_, 0, 17 ) );
184 if ( !$uxtime ) {
185 ERROR "Could not parse date from line $_";
186 next;
187 }
188 $deltaT = $uxtime - $prevTime;
189 next if ( $deltaT == 0 ); # e.g. eph 1019,1020 one message for each sat.
190 next if ( $deltaT <= 1 && $mestp =~ /10(19|20|42|43|44|45|46)|63/ );
191 if ( $prevTime && $deltaT > $maxGap ) {
192 $scan++;
193 }
194 push ( @{ $scans[$scan] }, $uxtime );
195 $prevTime = $uxtime;
196 }
197
198 my @repRates;
199 my $highest_nof_diffs = 0;
200 foreach (@scans) {
201 my @timestamps = @{$_};
202
203 # Compute the differences
204 my @diffs;
205 for ( my $i = 1; $i <= $#timestamps; $i++ ) {
206 push ( @diffs, $timestamps[$i] - $timestamps[ $i - 1 ] );
207 }
208 my $nof_diffs = scalar @diffs;
209
210 if ( $nof_diffs < 2 ) {
211 WARN("$stat: $mestp: only $nof_diffs diffs");
212 next;
213 }
214
215 my ( $mean, $prms, $median, $min, $max, $adev, $rms_n ) = stats( pdl \@diffs );
216 $mean = sprintf ( "%.0f", $mean );
217 $rms_n = sprintf ( "%.02f", $rms_n );
218 print $stat, ": ", $mestp, ": ", join ( ' ', @diffs ), "[Sig: $mean, $rms_n]\n";
219
220 if ( $rms_n > 10 ) {
221 WARN("$stat: $mestp: RMS too high: $rms_n");
222 next;
223 }
224
225 # get the most frequent value
226 my %counti = ();
227 $counti{$_}++ foreach (@diffs);
228 my ( $ni, $mfv ) = ( 0, 0 );
229 while ( my ( $k, $v ) = each %counti ) {
230 if ( $v > $ni ) {
231 $ni = $v;
232 $mfv = $k;
233 }
234 }
235
236 my $rounded_val = $mfv; # init
237 foreach ( ( 1, 5, 10, 15, 30, 60, 120, 150, 300 ) ) { # most likely values
238 my $mdiff = abs ( $mfv - $_ );
239 if ( $mdiff <= 2 ) {
240 $rounded_val = $_;
241 }
242 }
243 push ( @repRates, [ $rounded_val, $nof_diffs ] );
244
245 if ( $nof_diffs > $highest_nof_diffs ) {
246 $highest_nof_diffs = $nof_diffs;
247 }
248 } # ----- end foreach scan -----
249
250 my @mostLikelyRates = grep { $_->[1] == $highest_nof_diffs } @repRates;
251 my $mostLikelyRate = $mostLikelyRates[0]->[0];
252 foreach (@repRates) {
253 if ( abs ( $_->[0] - $mostLikelyRate ) > 2 ) {
254 ERROR "$stat: $caAbbr: $mestp: repetition rates from different scans differ: $mostLikelyRate $_->[0]";
255 if ( scalar @repRates == 2 ) {
256 return;
257 }
258 }
259 }
260
261 return $mostLikelyRate;
262}
263
264# =============================================================================
265# parseConfig ($confFile)
266# =============================================================================
267# Parse the BNC config file.
268#
269# Param : $confFile [required] BNC config file
270# Return : Hash with configuration on success, otherwise undef
271# Usage : $bncConf = parseConf($bncConfFile);
272# $corrMount = $bncConf->{'PPP'}->{'corrMount'};
273# =============================================================================
274sub parseConfig {
275 my ($confFile) = @_;
276
277 -s $confFile || LOGDIE "BNC config file \"$confFile\" does not exist\n";
278 TRACE "Parse BNC config file $confFile";
279 open ( my $INP, '<', $confFile ) || die "Could not open file '$confFile': $!";
280 my @confLines = <$INP>;
281 close ($INP);
282
283 my %conf;
284 my $section; # [General], [PPP]
285 foreach (@confLines) {
286 chomp;
287 s/#.*//; # entfernt Kommentare
288 s/^\s*//; # whitespace am Anfang entfernen
289 s/\s+$//; # entfernt alle whitespaces am Ende
290 next unless length;
291 if ( $_ =~ /\[(\S+)\]/ ) { $section = $1 }
292 next if ( !$section );
293 my ( $key, $val ) = split ( /\s*=\s*/, $_, 2 );
294 if ( !defined $val ) { $val = "" }
295
296 if ( $key eq "mountPoints" ) {
297
298 # Simple parsing
299 $val =~ s/^\/\///;
300 my @mpts = split ( /,\s?\/{2}/, $val );
301 $conf{$section}->{$key} = \@mpts;
302
303 # Extended parsing
304 my @mpts_def = ();
305 foreach (@mpts) {
306 # user:passwd@igs-ip.net:2101/ASPA0 RTCM_3.0 ASM -14.33 189.28 no 1
307 if ( $_ =~
308 /^([\w-]+):(.+[^@])@([\w\.-]+):(\d{3,5})\/([-\w]+) ([\w\.]+) ?(\w{3})? ([\+\-\d\.]+) ([\+\-\d\.]+) no (\w+)/i
309 )
310 {
311 push ( @mpts_def, { caster => $3, port => $4, mp => $5, ntripVers => $10 } );
312 }
313 else { ERROR "$confFile: Could not parse mountPoints string $_" }
314 }
315 $conf{$section}->{'mountPoints_parsed'} = \@mpts_def;
316 }
317 elsif ( $key eq "cmbStreams" ) {
318 my @cmbStrs = split ( /\s*,\s*/, $val );
319 foreach (@cmbStrs) {
320 s/"//g;
321 s/\s+$//; # entfernt alle whitespaces am Ende
322 }
323 $conf{$section}->{$key} = \@cmbStrs;
324 }
325 else { $conf{$section}->{$key} = $val }
326 }
327
328 my @nofPar = keys %conf;
329 if ( scalar @nofPar < 1 ) {
330 ERROR "No parameter found in BNC conf \"$confFile\"";
331 return;
332 }
333 return \%conf;
334}
335
336# =============================================================================
337# parseLogfile ($file, $sampling, $goBackSecs, $logMode )
338# =============================================================================
339# Parse BNCs' logfile
340#
341# Param : $file [required] BNC logfile
342# $sampling [optional] sampling rate for logfile
343# $logMode [optional] Flag. If set, remember the position of the file-read
344# for the next read. Default: off
345# Return : \%data
346# =============================================================================
347sub parseLogfile {
348 my $file = shift;
349 my $sampling = shift // 1;
350 my $logMode = shift // 0;
351
352 open ( my $fh, "<", $file ) || LOGDIE "Could not open file $file: $!\n";
353
354 # Goto last position from last read
355 #my $fPos = filePosition($file);
356 #TRACE "Current file pos: $fPos";
357 $logMode && seek ( $fh, filePosition($file), 0 );
358
359 #$logMode && seek ( $fh, $fPos, 0 );
360 my $ln = "";
361 my ( @hlp, @epochs, @latencies, @restarts );
362 my $rec = {};
363 while (<$fh>) {
364 chomp ( $ln = $_ );
365 $rec = {};
366
367 if ( $ln =~ /\bNEU/ ) { # NEU displacements
368 @hlp = split ( /\s+/, $ln );
369 my $tp = Time::Piece->strptime( substr ( $hlp[2], 0, 19 ), '%Y-%m-%d_%H:%M:%S' );
370
371 if ( $hlp[14] eq '-nan' || $hlp[15] eq '-nan' || $hlp[16] eq '-nan' ) {
372 WARN("$hlp[2] $hlp[3]: NEU displacements are NAN");
373 next;
374 }
375
376 #DEBUG ($tp->epoch, $hlp[3]);
377 push (
378 @epochs,
379 {
380 time => $tp->epoch,
381 site => $hlp[3],
382 dN => $hlp[14],
383 dE => $hlp[15],
384 dU => $hlp[16],
385 TRP => $hlp[18] + $hlp[19],
386 }
387 );
388 }
389 elsif ( index ( $ln, "latency", 25 ) > 1 ) {
390
391# DEBUG ($ln);
392# altes format: 15-10-06 15:29:02 POTS0: Mean latency 2.34 sec, min 1.58, max 3, rms 0.48, 43 epochs, 17 gaps
393# neu in BNC 2.12.4: 17-06-06 15:35:02 OHI37 Observations: Mean latency 1.51 sec, min 0.57, max 2.7, rms 0.5, 203 epochs, 73 gaps
394 @hlp = split ( /\s+/, $ln );
395
396 # old latency log format
397 if ( $hlp[2] =~ /:$/ ) {
398 splice @hlp, 3, 0, 'Placeholder:';
399 $hlp[2] =~ s/:$//;
400 }
401 $hlp[3] =~ s/:$//;
402
403 my $tp = Time::Piece->strptime( "$hlp[0] $hlp[1]", '%y-%m-%d %H:%M:%S' );
404 $rec = {
405 time => $tp->epoch,
406 mp => $hlp[2],
407 meanLat => $hlp[6] + 0.0,
408 epochs => int ( $hlp[14] ),
409 type => $hlp[3]
410 };
411
412 # Unter bestimmten Bedingungen werden die gaps nicht rausgeschrieben!
413 if ( $ln =~ /gaps/ ) {
414 $rec->{'gaps'} = int ( $hlp[16] );
415 }
416
417 push ( @latencies, $rec );
418 }
419 elsif ( index ( $ln, "Start BNC" ) > 1 ) {
420
421 # 17-06-13 07:06:58 ========== Start BNC v2.12.3 (LINUX) ==========
422 @hlp = split ( /\s+/, $ln );
423 my $tp = Time::Piece->strptime( "$hlp[0] $hlp[1]", '%y-%m-%d %H:%M:%S' );
424 push (
425 @restarts,
426 {
427 time => $tp->epoch,
428 bncvers => $hlp[5]
429 }
430 );
431 }
432
433 } # ----- next line -----
434
435 $logMode && filePosition( $file, tell ($fh) ); # Remember pos for next read
436 close $fh;
437
438 # Sampling must be done afterwords, for each station separated!
439 my @epochs_sampled;
440 my @sites = map { $_->{'site'} } @epochs;
441
442 #@sites = uniq @sites;
443 my %hlp1 = ();
444 @sites = grep { !$hlp1{$_}++ } @sites;
445 foreach my $s (@sites) {
446 my $epoch_selected = 0;
447 foreach my $rec (@epochs) {
448 next if ( $rec->{'site'} ne $s );
449 if ( $rec->{'time'} - $epoch_selected >= $sampling ) {
450 push ( @epochs_sampled, $rec );
451 $epoch_selected = $rec->{'time'};
452 }
453 }
454 }
455
456 my %data = (
457 EPOCHS => \@epochs_sampled,
458 LATENCIES => \@latencies,
459 RESTARTS => \@restarts
460 );
461
462 return \%data;
463}
464
465# =============================================================================
466# parsePPPLogfile ($file, $sampling, $goBackSecs, $logMode )
467# =============================================================================
468# Parse BNCs' PPP station logfile
469#
470# Param : $file [required] BNC PPP station
471# $sampling [optional] sampling rate for logfile
472# $goBackSecs [optional] go back that seconds from now in logfile
473# $logMode [optional] Flag. If set, remember the position of the file-read
474# for the next read. Default: off
475# Return : $station, \%data
476# =============================================================================
477sub parsePPPLogfile {
478 my $file = shift;
479 my $sampling = shift // 1;
480 my $goBackSecs = shift // 0;
481 my $logMode = shift // 0;
482
483 if ($logMode) { $goBackSecs = 0 }
484
485 my $startSec;
486 if ($goBackSecs) {
487 $startSec = time () - $goBackSecs;
488 }
489 my $epo;
490 my $old_epochSec = 0;
491 my $epochSec = 0;
492 my $epochDiff = 0;
493 my (
494 @hlp, @EPOCHs, @N, @E, @U,
495 %SATNUM, @TRPs,
496 @CLKs, @OFF_GLOs, @OFF_GALs, @OFF_BDSs,
497 );
498 my ( @EPOCHs_CLK, @EPOCHs_OFF_GLO, @EPOCHs_OFF_GAL, @EPOCHs_OFF_BDS );
499 my ( %AMB, %RES, %ELE, %ION, %BIA );
500 my ( $station, $lki, $sys, $sat, $amb );
501 open ( my $fh, "<", $file ) || LOGDIE "Could not open file $file: $!\n";
502
503 # Goto last position from last read
504 #my $fPos = filePosition($file);
505 #TRACE "Current file pos: $fPos";
506 $logMode && seek ( $fh, filePosition($file), 0 );
507
508 #$logMode && seek ( $fh, $fPos, 0 );
509 my $ln = "";
510 while (<$fh>) {
511 chomp ( $ln = $_ );
512
513 if ( $ln =~ /\bof Epoch\b/ ) {
514
515 # PPP of Epoch 2015-08-27_14:00:15.000
516 if ( $ln =~ /PPP of Epoch (\d{4}-\d{2}-\d{2}_\d{2}:\d{2}:\d{2})\.\d+/ ) {
517 $epo = $1; #print "$epo\n";
518 }
519 else { ERROR "strange line: \"$ln\""; next }
520
521 my $tp = Time::Piece->strptime( $epo, '%Y-%m-%d_%H:%M:%S' );
522 $epochSec = $tp->epoch();
523 $epochDiff = $epochSec - $old_epochSec;
524 next;
525 }
526
527 next if ( !$epo );
528 next if ( defined $startSec && $epochSec < $startSec );
529 next if ( $epochDiff && $epochDiff < $sampling );
530
531 @hlp = split ( /\s+/, $ln );
532
533 if ( $ln =~ /\bdN\b/ ) {
534 push ( @EPOCHs, $epochSec ); # besser $epo ?
535 $old_epochSec = $epochSec;
536
537 #2015-08-27_13:59:50.000 DIEP1 X = 3842152.9054 +- 0.0242 Y = 563402.0331 +- 0.0176 Z = 5042888.5182 +- 0.0319 dN = 0.0130 +- 0.0193 dE = -0.0032 +- 0.0178 dU = -0.0248 +- 0.0349
538 $station = $hlp[1];
539
540 if ( $hlp[19] eq '-nan' || $hlp[24] eq '-nan' || $hlp[29] eq '-nan' ) {
541 WARN("$hlp[0] $station: NEU displacements are NAN");
542 }
543
544 push @N, $hlp[19];
545 push @E, $hlp[24];
546 push @U, $hlp[29];
547 }
548 elsif ( ( $ln =~ /\bAMB\b/ ) && ( $ln !~ /RESET/ ) ) {
549 # 2015-08... AMB lIF G04 253.0000 -8.9924 +- 1.7825 el = 22.03 epo = 86
550 $lki = $hlp[2];
551 $sat = $hlp[3];
552 $sys = substr ( $sat, 0, 1 );
553 $amb = $hlp[4] + $hlp[5];
554 push @{ $AMB{$lki}{$sys}{$sat}{EPOCH} }, $epochSec;
555 push @{ $AMB{$lki}{$sys}{$sat}{DATA} }, $amb;
556 push @{ $AMB{$lki}{$sys}{$sat}{NUMEPO} }, $hlp[13];
557 push @{ $ELE{$sys}{$sat}{EPOCH} }, $epochSec;
558 push @{ $ELE{$sys}{$sat}{DATA} }, $hlp[10];
559 }
560 elsif ( $ln =~ /\bRES\b/ && $ln !~ /Neglected/ ) {
561 # 2015-08... RES lIF G30 -0.0076
562 $sat = $hlp[3];
563 $lki = $hlp[2];
564 $sys = substr ( $sat, 0, 1 );
565
566 #print "$epo $lki $sys $sat $res\n";
567 push @{ $RES{$lki}{$sys}{$sat}{EPOCH} }, $epochSec;
568 push @{ $RES{$lki}{$sys}{$sat}{DATA} }, $hlp[4];
569 }
570 elsif ( ( $ln =~ /\bION\b/ ) && ( $ln !~ /RESET/ ) ) {
571
572 # 2018-12-01_20:37:58.000 ION G02 0.0000 -0.3277 +- 2.4663
573 $sat = $hlp[2];
574 $sys = substr ( $sat, 0, 1 );
575 push @{ $ION{$sys}{$sat}{EPOCH} }, $epochSec;
576 push @{ $ION{$sys}{$sat}{DATA} }, $hlp[4];
577 }
578 elsif ( ( $ln =~ /\bBIA\b/ ) && ( $ln !~ /RESET/ ) ) {
579
580 # 2020-12-09_00:55:19.000 BIA c1 G 0.0000 +2.5149 +- 9.6543
581 $lki = $hlp[2];
582 $sys = $hlp[3];
583 push @{ $BIA{$lki}{$sys}{EPOCH} }, $epochSec;
584 push @{ $BIA{$lki}{$sys}{DATA} }, $hlp[4] + $hlp[5];
585 }
586 elsif ( $ln =~ /\bREC_CLK\b/ ) {
587 push ( @EPOCHs_CLK, $epochSec );
588 push ( @CLKs, $hlp[2] + $hlp[3] );
589 }
590 elsif ( $ln =~ /\bOFF_GLO\b/ ) { # 2015-08... OFF_GLO 52.6806 -3.8042 +- 9.0077
591 push ( @EPOCHs_OFF_GLO, $epochSec );
592 push ( @OFF_GLOs, $hlp[2] + $hlp[3] );
593 }
594 elsif ( $ln =~ /\bOFF_GAL\b/ ) { # 2015-08... OFF_GAL 52.6806 -3.8042 +- 9.0077
595 push ( @EPOCHs_OFF_GAL, $epochSec );
596 push ( @OFF_GALs, $hlp[2] + $hlp[3] );
597 }
598 elsif ( $ln =~ /\bOFF_BDS\b/ ) { # 2015-08... OFF_BDS 52.6806 -3.8042 +- 9.0077
599 push ( @EPOCHs_OFF_BDS, $epochSec );
600 push ( @OFF_BDSs, $hlp[2] + $hlp[3] );
601 }
602 elsif ( $ln =~ /\bSATNUM\b/ ) { # 2015-09... SATNUM G 8
603 push ( @{ $SATNUM{ $hlp[2] } }, $hlp[3] );
604 }
605 elsif ( $ln =~ /\bTRP\b/ ) { # 2015-08... TRP 2.3803 +0.1009 +- 0.0324
606 push ( @TRPs, $hlp[2] + $hlp[3] );
607 }
608 } # ----- next line -----
609
610 $logMode && filePosition( $file, tell ($fh) ); # Remember pos for next read
611 close $fh;
612
613 my $nof_epochs = scalar @EPOCHs;
614 DEBUG( "epochs:$nof_epochs, North displac.: "
615 . scalar @N
616 . ", East displac.: "
617 . scalar @E
618 . ", Up displac.: "
619 . scalar @U
620 . ", TRPs:"
621 . scalar @TRPs );
622 if ( $nof_epochs != scalar @N ) { LOGDIE "number of epochs and residuals not equal\n" }
623 if ( $nof_epochs != scalar @TRPs ) { LOGDIE "number of epochs and TRPs not equal\n" }
624 if ( @CLKs && scalar @EPOCHs_CLK != scalar @CLKs ) { LOGDIE "number of epochs and CLKs not equal\n" }
625 if ( @OFF_GLOs && scalar @EPOCHs_OFF_GLO != scalar @OFF_GLOs ) { LOGDIE "number of epochs and OFF_GLOs not equal\n" }
626 if ( @OFF_GALs && scalar @EPOCHs_OFF_GAL != scalar @OFF_GALs ) { LOGDIE "number of epochs and OFF_GALs not equal\n" }
627 if ( @OFF_BDSs && scalar @EPOCHs_OFF_BDS != scalar @OFF_BDSs ) { LOGDIE "number of epochs and OFF_BDSs not equal\n" }
628
629 my %data = (
630 EPOCHS => \@EPOCHs,
631 N => \@N,
632 E => \@E,
633 U => \@U,
634 SATNUM => \%SATNUM,
635 TRPs => \@TRPs,
636 CLKs => \@CLKs,
637 OFF_GLOs => \@OFF_GLOs,
638 OFF_GALs => \@OFF_GALs,
639 OFF_BDSs => \@OFF_BDSs,
640 RES => \%RES,
641 AMB => \%AMB,
642 ELE => \%ELE,
643 ION => \%ION,
644 BIA => \%BIA,
645 );
646
647 return ( $station, \%data, 0 );
648}
649
650# =============================================================================
651# BncStillWorks ($bncConfFile)
652# =============================================================================
653# Checks if BNC is still working.
654#
655# BNC Jobs can still be alive (in processlist) but are not producing any more.
656# This function checks if a BNC process is proper working.
657#
658# Param : $bncConfFile [required] path of BNC config file
659# Return : true if BNC is still working otherwise false.
660# =============================================================================
661sub BncStillWorks {
662 my ($bncConfFile) = @_;
663
664 my $timep = Time::Piece->new;
665
666 # for safety if it is exatly at 00:00, add 30 sec
667 my $min_tmp = $timep->strftime("%M");
668 if ( $min_tmp =~ /00|15|30|45/ && $timep->strftime("%S") < 15 ) {
669 $timep += 30;
670 sleep 30;
671 }
672 my $yyyy = $timep->year;
673 my $yy = $timep->yy;
674 my $doy = sprintf "%03d", $timep->yday + 1;
675 my $hh = $timep->strftime("%H");
676 my $h = uc ( chr ( 65 + $hh ) );
677 my $min = $timep->min;
678 my $startmin;
679 if ( $min < 15 ) { $startmin = "00" }
680 elsif ( $min < 30 ) { $startmin = "15" }
681 elsif ( $min < 45 ) { $startmin = "30" }
682 elsif ( $min <= 59 ) { $startmin = "45" }
683 my $bncConf = parseConf($bncConfFile);
684 my $bncLogFileStub = $bncConf->{'General'}->{'logFile'};
685
686 # BNC log file
687 # ------------
688 my $bncLogFile = "${bncLogFileStub}_" . $timep->strftime("%y%m%d"); # -> bnc.log_160425
689 unless ( -s $bncLogFile ) {
690 WARN("BNC logfile \"$bncLogFile\" is empty or does not exist");
691 return 0;
692 }
693
694 # RINEX Obs Generation
695 # --------------------
696 if ( $bncConf->{'General'}->{'rnxPath'} ) {
697 my $rnxPath = $bncConf->{'General'}->{'rnxPath'};
698 $rnxPath =~ s/\/$//;
699
700 # Write Rnx3 files (i.e. long Rnx3 filenames) 2: on ('rnxV3filenames' is deprecated since 2.12.8!!!)
701 my $writeRnxV3 = $bncConf->{'General'}->{'rnxV3'};
702 my $rnxIntr = $bncConf->{'General'}->{'rnxIntr'};
703 my $fileMask;
704
705 if ($writeRnxV3) {
706 if ( $rnxIntr eq "1 hour" ) {
707 $fileMask = "*_S_${yyyy}${doy}${hh}??_01H_30S_?O.rnx";
708 }
709 elsif ( $rnxIntr eq "15 min" ) {
710 $fileMask = "*_S_${yyyy}${doy}${hh}${startmin}_15M_01S_?O.rnx";
711 }
712 else { # daily?
713 $fileMask = "*_S_${yyyy}${doy}????_01D_30S_?O.rnx"; # HRAG00ZAF_S_20191220000_01D_30S_MO.rnx
714 }
715 }
716 else { # Rnx2
717 if ( $rnxIntr eq "1 hour" ) {
718 $fileMask = "????${doy}${h}.${yy}O";
719 }
720 elsif ( $rnxIntr eq "15 min" ) {
721 $fileMask = "????${doy}${h}${startmin}.${yy}O";
722 }
723 else { # daily?
724 $fileMask = "????${doy}*.${yy}O";
725 }
726 }
727
728 my @rnxFiles = glob "$rnxPath/$fileMask";
729 if ( scalar @rnxFiles < 1 ) {
730 ERROR("BNC does not create RINEX Obs files. (Filemask: \"$fileMask\" Path: $rnxPath)");
731
732 #return 0;
733 }
734 }
735
736 # RINEX Ephemerides Generation
737 # ----------------------------
738 if ( $bncConf->{'General'}->{'ephPath'} ) {
739 my $rnxPath = $bncConf->{'General'}->{'ephPath'};
740 $rnxPath =~ s/\/$//;
741 my $writeRnxV3 = $bncConf->{'General'}->{'ephV3'};
742 my $rnxIntr = $bncConf->{'General'}->{'ephIntr'};
743 my $fileMask;
744
745 if ($writeRnxV3) {
746 if ( $rnxIntr eq "1 hour" ) {
747 $fileMask = "BRD?00WRD_S_${yyyy}${doy}${hh}00_01H_?N.rnx";
748 }
749 elsif ( $rnxIntr eq "15 min" ) {
750 $fileMask = "BRD?00WRD_S_${yyyy}${doy}${hh}${startmin}_15M_?N.rnx"; # BRDC00WRD_S_20191220900_15M_MN.rnx
751 }
752 else { # daily?
753 $fileMask = $fileMask = "BRD?00WRD_S_${yyyy}${doy}0000_01D_?N.rnx";
754 }
755 }
756 else { # Rnx2
757 $fileMask = "BRD?${doy}*.${yy}N";
758 }
759
760 my @rnxFiles = glob "$rnxPath/$fileMask";
761 if ( scalar @rnxFiles < 1 ) {
762 ERROR("BNC does not create RINEX Nav files. (Filemask: \"$fileMask\" Path: $rnxPath)");
763
764 #return 0;
765 }
766 }
767
768 # Check jobs making PPP
769 # ---------------------
770 if ( $bncConf->{'PPP'}->{'corrMount'} && $bncConf->{'PPP'}->{'staTable'} ) {
771 my $timeOfLastCoo = `grep "NEU:" $bncLogFile | tail -1 | cut -d ' ' -f1,2`;
772 chomp $timeOfLastCoo;
773 if ( !$timeOfLastCoo ) {
774 ERROR "BNC does not compute coordinates";
775 return 0;
776 }
777
778 my $tp = Time::Piece->strptime( $timeOfLastCoo, '%y-%m-%d %H:%M:%S' );
779 my $now = Time::Piece->new;
780 my $tdiff = $now - $tp;
781 if ( $tdiff > 1200 ) {
782 ERROR( "Last computed coordinates are " . $tdiff / 60 . " min old" );
783 return 0;
784 }
785 }
786
787 # BNC works
788 return 1;
789}
790
7911; # End of Bnc
Note: See TracBrowser for help on using the repository browser.