source: ntrip/trunk/misc/createRnx3Aliases.pl @ 8229

Last change on this file since 8229 was 8229, checked in by wiese, 21 months ago

ADD: script

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 10.5 KB
Line 
1#!/usr/bin/env perl
2
3# ========================================================================
4# createRnx3Aliases.pl
5# ========================================================================
6#
7# Purpose : Helps to create Rnx3 alias mountpoints for a existing
8#           BKG NtripCaster installation. See help for details.
9#
10# Revision: $Id:$
11# ========================================================================
12
13# Uses
14use strict;
15use warnings;
16
17# Arguments
18my ($confDir) = @ARGV;
19if ( !defined $confDir || $confDir =~ /-h|--help/ ) {
20    print <<EOI_HLP;
21
22createRnx3Aliases.pl - Helps to create Rnx3 alias mountpoints for a existing
23    BKG NtripCaster installation.
24
25    See White Paper URL???
26    For NtripCaster admins.
27    The output contains the alias records for the ntripcaster.conf file.
28    Creates a new sourcetable file with alias records included.
29
30USAGE:
31  $0 <ntripcaster-conf-dir>
32
33EXAMPLES:
34   $0 /home/rt/eurefcaster/conf
35
36Authors:
37   Erwin Wiesensarter <Erwin.Wiesensarter\@bkg.bund.de>
38
39EOI_HLP
40    exit;
41}
42
43my $ntripcaster_conf = $confDir . '/ntripcaster.conf';
44my $sourcetable_dat  = $confDir . '/sourcetable.dat';
45
46my @igsLongNames = <DATA>;
47chomp $_ for (@igsLongNames);
48
49my @existing_mpts;
50my %st_streams = parseSourcetable($sourcetable_dat);
51
52# Create alias names for each stream
53# ----------------------------------
54my @alias;
55my $rnx3Name = "";
56while ( my ( $fourCharId, $rows ) = each %st_streams ) {
57
58    # RAW streams
59    my @raw = grep ( $_->[3] =~ /RAW/i, @$rows );
60    if (@raw) {
61        if ( scalar @raw > 1 ) {
62            warn "WARN: more than one RAW stream for $fourCharId\n";
63        }
64        my $i = 0;
65        foreach (@raw) {
66            if ( $i == 0 ) {
67                $rnx3Name = $fourCharId . "00" . $_->[8] . 9;
68                if ( grep { $rnx3Name eq $_ } @existing_mpts ) {
69                    print "$rnx3Name already exists - skip";
70                    next;
71                }
72                printf "%-5s  %-8s  %-6s %-9s\n", $_->[1], $_->[3], $_->[4], $rnx3Name;
73                push ( @alias, [ $_->[1], $rnx3Name ] );
74            }
75            else {
76                printf "%-5s  %-8s  %-6s %-9s\n", $_->[1], $_->[3], $_->[4], "skipped";
77            }
78
79            $i++;
80        }
81    }
82
83    # RTCM streams
84    my @rtcm = map { $_->[0] }
85      sort { $b->[2] <=> $a->[2] }
86      map { [ $_, split ( /\s+/, $_->[3], 2 ) ] }
87      grep { $_->[3] =~ /RTCM/i } @$rows;
88
89    my $i = 0;
90    foreach (@rtcm) {
91        $rnx3Name = $fourCharId . "00" . $_->[8] . $i++;
92        if ( grep { $rnx3Name eq $_ } @existing_mpts ) {
93            print "$rnx3Name already exists - skip";
94            next;
95        }
96        printf "%-5s  %-15s  %-9s\n", $_->[1], $_->[3], $rnx3Name;
97        push ( @alias, [ $_->[1], $rnx3Name ] );
98    }
99
100    print "\n";
101}
102
103print "===================== Alias ===================== (insert in $ntripcaster_conf)\n";
104foreach ( sort { ( $a->[1] ) cmp ( $b->[1] ) } @alias ) {
105    print "alias /$_->[1] /$_->[0]\n";
106}
107print "\n";
108
109writeNewSourcetable($sourcetable_dat);
110
111###############################################################################
112sub parseSourcetable {
113    my ($sourcetableFil) = @_;
114
115    my %st;
116    open ( my $ST, '<', $sourcetableFil ) || die "Could not open file '$sourcetableFil': $!\n";
117    while (<$ST>) {
118        chomp;
119        next if ( $_ =~ /^#/ );
120        $_ =~ /^(CAS|NET|STR);.+/ || die "Weird sourcetable line: [$_]";
121        if ( $_ =~ /^STR;/ ) {
122            my @fields = split ';', $_;
123            push ( @existing_mpts, $fields[1] );
124            scalar @fields >= 18 || die "Not enough fields in line: [$_]\nsee http://software.rtcm-ntrip.org/wiki/STR";
125            if ( $fields[1] =~ /^CLK|EPH$/i ) {
126                print "INFO: skip $fields[1]\n";
127                next;
128            }
129
130            # Consider only mountpoint names with length 5
131            if ( length ( $fields[1] ) == 5 ) {
132                my $fourCharId = substr ( $fields[1], 0, 4 );
133
134                # Compare country code with official IGS station list (IGS Network.csv 21.12.2017 from
135                # http://www.igs.org/network)
136                my @igs_found = grep ( $fourCharId eq substr ( $_, 0, 4 ), @igsLongNames );
137                if (@igs_found) {
138                    my $rnx3Name = $fourCharId . "00" . $fields[8];
139                    $rnx3Name eq $igs_found[0]
140                      || warn
141                      "ERROR: wrong country code \"$fields[8]\" for sourcetable stream $fields[1] (IGS: $igs_found[0])\n"
142                      ;    # die
143                }
144                push ( @{ $st{$fourCharId} }, \@fields );
145            }
146        }
147    }
148    close ($ST);
149    return %st;
150}
151
152sub writeNewSourcetable {
153    my ($sourcetable_orig) = @_;
154
155    my $sourcetable_new = $sourcetable_orig . '.new';
156
157    open ( my $ORIG, '<', $sourcetable_orig ) || die "Could not open file '$sourcetable_orig': $!\n";
158    open ( my $NEW,  '>', $sourcetable_new )  || die "Could not open file '$sourcetable_new': $!\n";
159    while (<$ORIG>) {
160        print $NEW $_;
161        my @fields = split ( ';', $_ );
162        if ( @fields && $fields[0] eq "STR" ) {
163            my @found = grep ( $_->[0] eq $fields[1], @alias );    # search for mountpoint
164            if (@found) {
165                $fields[1]  = $found[0]->[1];
166                $fields[18] = $found[0]->[0];
167                my $alias_rc = join ( ';', @fields );
168                print $NEW "$alias_rc\n";
169            }
170        }
171    }
172    close ($ORIG) || die "Could not close file $sourcetable_orig: $!";
173    close ($NEW)  || die "Could not close file $sourcetable_new: $!";
174
175    print "INFO: New sourcetable $sourcetable_new created\n";
176}
177
178__DATA__
179ABMF00GLP
180ABPO00MDG
181ADIS00ETH
182AGGO00ARG
183AIRA00JPN
184AJAC00FRA
185ALBH00CAN
186ALGO00CAN
187ALIC00AUS
188ALRT00CAN
189AMC200USA
190ANKR00TUR
191ANMG00MYS
192ANTC00CHL
193AREG00PER
194AREQ00PER
195ARTU00RUS
196ARUC00ARM
197ASCG00SHN
198ASPA00USA
199AUCK00NZL
200AZU100USA
201BADG00RUS
202BAIE00CAN
203BAKE00CAN
204BAKO00IDN
205BAMF00CAN
206BARH00USA
207BHR300BHR
208BHR400BHR
209BIK000KGZ
210BILL00USA
211BJCO00BEN
212BJFS00CHN
213BJNM00CHN
214BLYT00USA
215BNOA00IDN
216BOGI00POL
217BOGT00COL
218BOR100POL
219BRAZ00BRA
220BREW00USA
221BRFT00BRA
222BRMU00GBR
223BRST00FRA
224BRUN00BRN
225BRUX00BEL
226BSHM00ISR
227BTNG00IDN
228BUCU00ROU
229BZRG00ITA
230CAGS00CAN
231CAS100ATA
232CCJ200JPN
233CEBR00ESP
234CEDU00AUS
235CGGN00NGA
236CHAN00CHN
237CHIL00USA
238CHOF00JPN
239CHPG00BRA
240CHPI00BRA
241CHTI00NZL
242CHUM00KAZ
243CHUR00CAN
244CHWK00CAN
245CIT100USA
246CKIS00COK
247CKSV00TWN
248CLAR00USA
249CMP900USA
250CMUM00THA
251CNMR00USA
252COCO00AUS
253CORD00ARG
254COSO00USA
255COTE00ATA
256COYQ00CHL
257CPNM00THA
258CPVG00CPV
259CRAO00UKR
260CRFP00USA
261CRO100VIR
262CUSV00THA
263CUT000AUS
264CUUT00THA
265CZTG00ATF
266DAE200KOR
267DAEJ00KOR
268DAKR00SEN
269DARW00AUS
270DAV100ATA
271DEAR00ZAF
272DGAR00GBR
273DHLG00USA
274DJIG00DJI
275DLF100NLD
276DLTV00VNM
277DRAG00ISR
278DRAO00CAN
279DUBO00CAN
280DUM100ATA
281DUND00NZL
282DYNG00GRC
283EBRE00ESP
284EIL300USA
285EIL400USA
286EPRT00USA
287ESCU00CAN
288EUSM00MYS
289FAA100PYF
290FAIR00USA
291FALE00WSM
292FALK00FLK
293FFMJ00DEU
294FLIN00CAN
295FLRS00PRT
296FRDN00CAN
297FTNA00WLF
298FUNC00PRT
299GAMB00PYF
300GAMG00KOR
301GANP00SVK
302GCGO00USA
303GENO00ITA
304GLPS00ECU
305GLSV00UKR
306GMSD00JPN
307GODE00USA
308GODN00USA
309GODS00USA
310GODZ00USA
311GOL200USA
312GOLD00USA
313GOP600CZE
314GOP700CZE
315GOPE00CZE
316GOUG00SHN
317GRAC00FRA
318GRAS00FRA
319GRAZ00AUT
320GUAM00GUM
321GUAO00CHN
322GUAT00GTM
323GUUG00GUM
324HALY00SAU
325HAMD00IRN
326HARB00ZAF
327HARV00USA
328HERS00GBR
329HERT00GBR
330HKSL00HKG
331HKWS00HKG
332HLFX00CAN
333HNLC00USA
334HNPT00USA
335HNUS00ZAF
336HOB200AUS
337HOFN00ISL
338HOLB00CAN
339HOLM00CAN
340HOLP00USA
341HRAG00ZAF
342HRAO00ZAF
343HUEG00DEU
344HYDE00IND
345IENG00ITA
346IISC00IND
347INEG00MEX
348INVK00CAN
349IQAL00CAN
350IQQE00CHL
351IRKJ00RUS
352IRKM00RUS
353IRKT00RUS
354ISBA00IRQ
355ISPA00CHL
356ISTA00TUR
357IZMI00TUR
358JCTW00ZAF
359JFNG00CHN
360JNAV00VNM
361JOG200IDN
362JOZ200POL
363JOZE00POL
364JPLM00USA
365JPRE00ZAF
366KARR00AUS
367KAT100AUS
368KELY00GRL
369KERG00ATF
370KGNI00JPN
371KHAR00UKR
372KIR000SWE
373KIR800SWE
374KIRI00KIR
375KIRU00SWE
376KIT300UZB
377KITG00UZB
378KMNM00TWN
379KOKB00USA
380KOKV00USA
381KOS100NLD
382KOUC00NCL
383KOUG00GUF
384KOUR00GUF
385KRGG00ATF
386KRS100TUR
387KSMV00JPN
388KUNM00CHN
389KUUJ00CAN
390KZN200RUS
391LAE100PNG
392LAMA00POL
393LAUT00FJI
394LBCH00USA
395LCK300IND
396LCK400IND
397LEIJ00DEU
398LHAZ00CHN
399LLAG00ESP
400LMMF00MTQ
401LPAL00ESP
402LPGS00ARG
403LROC00FRA
404M0SE00ITA
405MAC100AUS
406MAD200ESP
407MADR00ESP
408MAG000RUS
409MAJU00MHL
410MAL200KEN
411MANA00NIC
412MAR600SWE
413MAR700SWE
414MARS00FRA
415MAS100ESP
416MAT100ITA
417MATE00ITA
418MATG00ITA
419MAUI00USA
420MAW100ATA
421MAYG00MYT
422MBAR00UGA
423MCHL00AUS
424MCIL00JPN
425MCM400ATA
426MDO100USA
427MDVJ00RUS
428MEDI00ITA
429MELI00ESP
430MERS00TUR
431MET300FIN
432METG00FIN
433METS00FIN
434MFKG00ZAF
435MGUE00ARG
436MIKL00UKR
437MIZU00JPN
438MKEA00USA
439MOBJ00RUS
440MOBK00RUS
441MOBN00RUS
442MOBS00AUS
443MOIU00KEN
444MONP00USA
445MORP00GBR
446MQZG00NZL
447MRL100NZL
448MRL200NZL
449MRO100AUS
450MTKA00JPN
451MTV100URY
452MTV200URY
453NAIN00CAN
454NAMA00SAU
455NANO00CAN
456NAUR00NRU
457NCKU00TWN
458NICO00CYP
459NIST00USA
460NIUM00NIU
461NKLG00GAB
462NLIB00USA
463NNOR00AUS
464NOT100ITA
465NOVM00RUS
466NRC100CAN
467NRIL00RUS
468NRL100USA
469NRMD00NCL
470NTUS00SGP
471NURK00RWA
472NVSK00RUS
473NYA100NOR
474NYA200NOR
475NYAL00NOR
476OAK100GBR
477OAK200GBR
478OBE400DEU
479OHI200ATA
480OHI300ATA
481ONS100SWE
482ONSA00SWE
483OPMT00FRA
484ORID00MKD
485OSN300KOR
486OSN400KOR
487OUS200NZL
488OWMG00NZL
489PADO00ITA
490PALM00ATA
491PARC00CHL
492PARK00AUS
493PBRI00IND
494PDEL00PRT
495PEN200HUN
496PENC00HUN
497PERT00AUS
498PETS00RUS
499PGEN00PHL
500PICL00CAN
501PIE100USA
502PIMO00PHL
503PIN100USA
504PNGM00PNG
505POHN00FSM
506POL200KGZ
507POLV00UKR
508POTS00DEU
509POVE00BRA
510PPPC00PHL
511PRDS00CAN
512PRE300ZAF
513PRE400ZAF
514PTAG00PHL
515PTBB00DEU
516PTGG00PHL
517PTVL00VUT
518QAQ100GRL
519QIKI00CAN
520QUI300ECU
521QUI400ECU
522QUIN00USA
523RABT00MAR
524RAEG00PRT
525RAMO00ISR
526RBAY00ZAF
527RCMN00KEN
528RDSD00DOM
529RECF00BRA
530REDU00BEL
531RESO00CAN
532REUN00REU
533REYK00ISL
534RGDG00ARG
535RIGA00LVA
536RIO200ARG
537RIOP00ECU
538ROAP00ESP
539ROCK00USA
540ROTH00ATA
541SALU00BRA
542SAMO00WSM
543SANT00CHL
544SASK00CAN
545SASS00DEU
546SAVO00BRA
547SBOK00ZAF
548SCH200CAN
549SCIP00USA
550SCOR00GRL
551SCRZ00BOL
552SCTB00ATA
553SCUB00CUB
554SEJN00KOR
555SEY200SYC
556SEYG00SYC
557SFDM00USA
558SFER00ESP
559SGOC00LKA
560SHAO00CHN
561SHE200CAN
562SIMO00ZAF
563SIN100SGP
564SMST00JPN
565SNI100USA
566SOD300FIN
567SOFI00BGR
568SOLA00SAU
569SOLO00SLB
570SPK100USA
571SPT000SWE
572SPTU00BRA
573SSIA00SLV
574STFU00USA
575STHL00GBR
576STJ300CAN
577STJO00CAN
578STK200JPN
579STR100AUS
580STR200AUS
581SULP00UKR
582SUTH00ZAF
583SUTM00ZAF
584SUWN00KOR
585SVTL00RUS
586SYDN00AUS
587SYOG00ATA
588TABL00USA
589TANA00ETH
590TASH00UZB
591TCMS00TWN
592TDOU00ZAF
593TEHN00IRN
594THTG00PYF
595THTI00PYF
596THU200GRL
597THU300GRL
598TID100AUS
599TIDB00AUS
600TIT200DEU
601TIXI00RUS
602TLSE00FRA
603TLSG00FRA
604TNML00TWN
605TONG00TON
606TORP00USA
607TOW200AUS
608TRAK00USA
609TRO100NOR
610TSK200JPN
611TSKB00JPN
612TUBI00TUR
613TUVA00TUV
614TWTF00TWN
615UCAL00CAN
616UCLP00USA
617UCLU00CAN
618UFPR00BRA
619ULAB00MNG
620ULDI00ZAF
621UNB300CAN
622UNBD00CAN
623UNBJ00CAN
624UNBN00CAN
625UNSA00ARG
626UNX200AUS
627UNX300AUS
628URUM00CHN
629USN700USA
630USN800USA
631USN900USA
632USNO00USA
633USUD00JPN
634UZHL00UKR
635VACS00MUS
636VALD00CAN
637VESL00ATA
638VILL00ESP
639VIS000SWE
640VNDP00USA
641VOIM00MDG
642WAB200CHE
643WARK00NZL
644WARN00DEU
645WDC500USA
646WDC600USA
647WES200USA
648WGTN00NZL
649WHC100USA
650WHIT00CAN
651WIDC00USA
652WILL00CAN
653WIND00NAM
654WLSN00USA
655WROC00POL
656WSRT00NLD
657WTZ300DEU
658WTZA00DEU
659WTZR00DEU
660WTZS00DEU
661WTZZ00DEU
662WUH200CHN
663WUHN00CHN
664XIAN00CHN
665XMIS00AUS
666YAKT00RUS
667YAR200AUS
668YAR300AUS
669YARR00AUS
670YEBE00ESP
671YEL200CAN
672YELL00CAN
673YIBL00OMN
674YKRO00CIV
675YONS00KOR
676YSSK00RUS
677ZAMB00ZMB
678ZECK00RUS
679ZIM200CHE
680ZIM300CHE
681ZIMJ00CHE
682ZIMM00CHE
683ZWE200RUS
684
Note: See TracBrowser for help on using the repository browser.