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

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

ADD script for extracting observation types from logfile

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