source: ntrip/trunk/BNC/scripts/sot.pl@ 10083

Last change on this file since 10083 was 9747, checked in by wiese, 2 years ago

ADD: minor in helper scripts

  • Property svn:executable set to *
  • Property svn:keywords set to Header
File size: 3.4 KB
Line 
1#!/usr/bin/env perl
2
3#
4# sot.pl - parse BNC logfile(s) and create *.sot files that contain the observation types for each GNSS in RINEX header format
5#
6# Revision: $Header: trunk/BNC/scripts/sot.pl 9747 2022-06-01 09:45:39Z wiese $
7#
8
9use strict;
10use warnings;
11use File::Basename;
12use File::Path;
13use Getopt::Std;
14
15my $prog = basename($0);
16
17# Arguments
18getopts( "hn:", \my %opts );
19$opts{h} && HELP_MESSAGE();
20my $caster = $opts{n} ? $opts{n} : "";
21if ( scalar @ARGV < 1 ) {
22 warn "usage error: no BNC logfile given\n";
23 HELP_MESSAGE();
24}
25my @logFiles = @ARGV;
26
27my %obsTyps_of;
28
29# Parse each logfile
30foreach my $logfile (@logFiles) {
31 my $inp;
32 if ( !open ( $inp, '<', $logfile ) ) {
33 warn "could not open file '$logfile': $!";
34 next;
35 }
36 while (<$inp>) {
37
38 # # 16-03-21 10:25:38 MARS0: Observation Types: R 6 C1C L1C S1C C2P L2P S2P
39 if ( $_ =~ /Observation Types:/ ) {
40 chomp;
41 my @fields = split ( /\s+/, $_ );
42 my $mp = $fields[2];
43 $mp =~ s/:$//;
44 my $satSys = $fields[5];
45 my @obsTyps = @fields[ 7 .. $#fields ];
46 $obsTyps_of{$mp}->{$satSys} = \@obsTyps;
47
48 # Check obs types
49 if ( $satSys eq "G" ) { # GPS see #65
50 foreach my $otp (@obsTyps) {
51 if ( $otp eq "L2P" || $otp eq "C2P" ) {
52 warn ("$_: Observation Types 'L2P' and/or 'C2P' are not reasonable for GPS\n");
53 }
54 }
55 }
56 }
57 }
58 close ($inp);
59}
60
61# Write .sot files
62foreach my $mp ( keys %obsTyps_of ) {
63 my $obstypes = obsTypes2str( $obsTyps_of{$mp} );
64 next unless ($obstypes);
65 writeSOT( "${mp}.sot", $obstypes, $caster );
66}
67
68sub obsTypes2str {
69 my ($obsTypes) = @_;
70
71 my $obstypes_str = "";
72 foreach my $sys (qw(G R E J C I S)) {
73 next unless ( exists $obsTypes->{$sys} );
74 my @obsTypes = @{ $obsTypes->{$sys} };
75 my $nof_obsTypes = scalar @obsTypes;
76 my @currentTypes = splice ( @obsTypes, 0, 13 );
77 my $types_str = join ( ' ', @currentTypes );
78 $obstypes_str .=
79 sprintf ( "%-1s %3s %-53.53s%-19s\n", $sys, $nof_obsTypes, $types_str, 'SYS / # / OBS TYPES' );
80 while (@obsTypes) { # we need a new line
81 $types_str = join ( ' ', @obsTypes );
82 $obstypes_str .= sprintf ( " %-52.52s %-20s\n", $types_str, 'SYS / # / OBS TYPES' );
83 @currentTypes = splice ( @obsTypes, 0, 13 );
84 }
85 }
86 return $obstypes_str;
87}
88
89# Write the sotfile. If option -n is set, write the file into a directory with the name of the caster.
90sub writeSOT {
91 my ( $filename, $obsTypes, $caster ) = @_;
92
93 if ($caster) {
94 if ( !-d $caster ) {
95 eval { mkpath($caster) };
96 if ($@) {
97 warn ("could not create path [$caster]: $@");
98 return;
99 }
100 }
101 $filename = $caster . "/" . $filename;
102 }
103
104 my $fh;
105 if ( !open ( $fh, '>', $filename ) ) {
106 warn "could not open file '$filename' for writing: $!";
107 return;
108 }
109 print $fh $obsTypes;
110 close ($fh);
111}
112
113sub HELP_MESSAGE {
114 print <<EOI_HILFE;
115$prog - parse observation types from BNC's logfile(s) and write them as *.sot files
116
117USAGE:
118 $prog [OPTIONS] <bnc-logfiles>
119
120OPTIONS:
121 -n name or address of the scanned caster (optional)
122 -h, --help show this help
123
124EXAMPLES:
125 $prog -n euref-ip.net /home/user/log/bnc.log*
126
127EOI_HILFE
128 exit;
129}
130
Note: See TracBrowser for help on using the repository browser.