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

Last change on this file since 10686 was 10686, checked in by wiese, 2 months ago

CHANGE: naming of old 4char mountpoint names

  • Property svn:executable set to *
  • Property svn:keywords set to Header
File size: 3.5 KB
RevLine 
[9672]1#!/usr/bin/env perl
2
3#
[9679]4# sot.pl - parse BNC logfile(s) and create *.sot files that contain the observation types for each GNSS in RINEX header format
[9672]5#
[9679]6# Revision: $Header: trunk/BNC/scripts/sot.pl 10686 2025-07-02 14:59:26Z wiese $
[9672]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} : "";
[9679]21if ( scalar @ARGV < 1 ) {
[9672]22 warn "usage error: no BNC logfile given\n";
23 HELP_MESSAGE();
24}
[9679]25my @logFiles = @ARGV;
[9672]26
27my %obsTyps_of;
28
[9679]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
[10686]49 if ( $satSys eq "G" ) { # GPS see #65
[9679]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 }
[9672]54 }
55 }
56 }
57 }
[9679]58 close ($inp);
[9672]59}
60
61# Write .sot files
62foreach my $mp ( keys %obsTyps_of ) {
63 my $obstypes = obsTypes2str( $obsTyps_of{$mp} );
64 next unless ($obstypes);
[10686]65
66 # names should be 5 or 10 char long, w/o extension.
67 if ( len($mp) == 4 ) { $mp .= "0" }
68 my $fname = "${mp}.sot";
69
70 writeSOT( $fname, $obstypes, $caster );
[9672]71}
72
73sub obsTypes2str {
74 my ($obsTypes) = @_;
75
76 my $obstypes_str = "";
77 foreach my $sys (qw(G R E J C I S)) {
78 next unless ( exists $obsTypes->{$sys} );
79 my @obsTypes = @{ $obsTypes->{$sys} };
80 my $nof_obsTypes = scalar @obsTypes;
81 my @currentTypes = splice ( @obsTypes, 0, 13 );
82 my $types_str = join ( ' ', @currentTypes );
83 $obstypes_str .=
84 sprintf ( "%-1s %3s %-53.53s%-19s\n", $sys, $nof_obsTypes, $types_str, 'SYS / # / OBS TYPES' );
85 while (@obsTypes) { # we need a new line
86 $types_str = join ( ' ', @obsTypes );
87 $obstypes_str .= sprintf ( " %-52.52s %-20s\n", $types_str, 'SYS / # / OBS TYPES' );
88 @currentTypes = splice ( @obsTypes, 0, 13 );
89 }
90 }
91 return $obstypes_str;
92}
93
94# Write the sotfile. If option -n is set, write the file into a directory with the name of the caster.
95sub writeSOT {
96 my ( $filename, $obsTypes, $caster ) = @_;
97
98 if ($caster) {
99 if ( !-d $caster ) {
100 eval { mkpath($caster) };
101 if ($@) {
102 warn ("could not create path [$caster]: $@");
103 return;
104 }
105 }
106 $filename = $caster . "/" . $filename;
107 }
108
109 my $fh;
110 if ( !open ( $fh, '>', $filename ) ) {
111 warn "could not open file '$filename' for writing: $!";
112 return;
113 }
114 print $fh $obsTypes;
115 close ($fh);
116}
117
118sub HELP_MESSAGE {
119 print <<EOI_HILFE;
[9679]120$prog - parse observation types from BNC's logfile(s) and write them as *.sot files
[9672]121
122USAGE:
[9679]123 $prog [OPTIONS] <bnc-logfiles>
[9672]124
125OPTIONS:
126 -n name or address of the scanned caster (optional)
127 -h, --help show this help
128
129EXAMPLES:
[9747]130 $prog -n euref-ip.net /home/user/log/bnc.log*
[9672]131
132EOI_HILFE
133 exit;
134}
135
Note: See TracBrowser for help on using the repository browser.