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

Last change on this file since 8330 was 8230, checked in by wiese, 7 years ago

CHANGE: die if wrong country code

  • 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: createRnx3Aliases.pl 8230 2018-01-03 14:40:27Z wiese $
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 || die
141 "wrong country code \"$fields[8]\" for sourcetable stream $fields[1] (IGS: $igs_found[0])\n";
142 }
143 push ( @{ $st{$fourCharId} }, \@fields );
144 }
145 }
146 }
147 close ($ST);
148 return %st;
149}
150
151sub writeNewSourcetable {
152 my ($sourcetable_orig) = @_;
153
154 my $sourcetable_new = $sourcetable_orig . '.new';
155
156 open ( my $ORIG, '<', $sourcetable_orig ) || die "Could not open file '$sourcetable_orig': $!\n";
157 open ( my $NEW, '>', $sourcetable_new ) || die "Could not open file '$sourcetable_new': $!\n";
158 while (<$ORIG>) {
159 print $NEW $_;
160 my @fields = split ( ';', $_ );
161 if ( @fields && $fields[0] eq "STR" ) {
162 my @found = grep ( $_->[0] eq $fields[1], @alias ); # search for mountpoint
163 if (@found) {
164 $fields[1] = $found[0]->[1];
165 $fields[18] = $found[0]->[0];
166 my $alias_rc = join ( ';', @fields );
167 print $NEW "$alias_rc\n";
168 }
169 }
170 }
171 close ($ORIG) || die "Could not close file $sourcetable_orig: $!";
172 close ($NEW) || die "Could not close file $sourcetable_new: $!";
173
174 print "INFO: New sourcetable $sourcetable_new created\n";
175}
176
177__DATA__
178ABMF00GLP
179ABPO00MDG
180ADIS00ETH
181AGGO00ARG
182AIRA00JPN
183AJAC00FRA
184ALBH00CAN
185ALGO00CAN
186ALIC00AUS
187ALRT00CAN
188AMC200USA
189ANKR00TUR
190ANMG00MYS
191ANTC00CHL
192AREG00PER
193AREQ00PER
194ARTU00RUS
195ARUC00ARM
196ASCG00SHN
197ASPA00USA
198AUCK00NZL
199AZU100USA
200BADG00RUS
201BAIE00CAN
202BAKE00CAN
203BAKO00IDN
204BAMF00CAN
205BARH00USA
206BHR300BHR
207BHR400BHR
208BIK000KGZ
209BILL00USA
210BJCO00BEN
211BJFS00CHN
212BJNM00CHN
213BLYT00USA
214BNOA00IDN
215BOGI00POL
216BOGT00COL
217BOR100POL
218BRAZ00BRA
219BREW00USA
220BRFT00BRA
221BRMU00GBR
222BRST00FRA
223BRUN00BRN
224BRUX00BEL
225BSHM00ISR
226BTNG00IDN
227BUCU00ROU
228BZRG00ITA
229CAGS00CAN
230CAS100ATA
231CCJ200JPN
232CEBR00ESP
233CEDU00AUS
234CGGN00NGA
235CHAN00CHN
236CHIL00USA
237CHOF00JPN
238CHPG00BRA
239CHPI00BRA
240CHTI00NZL
241CHUM00KAZ
242CHUR00CAN
243CHWK00CAN
244CIT100USA
245CKIS00COK
246CKSV00TWN
247CLAR00USA
248CMP900USA
249CMUM00THA
250CNMR00USA
251COCO00AUS
252CORD00ARG
253COSO00USA
254COTE00ATA
255COYQ00CHL
256CPNM00THA
257CPVG00CPV
258CRAO00UKR
259CRFP00USA
260CRO100VIR
261CUSV00THA
262CUT000AUS
263CUUT00THA
264CZTG00ATF
265DAE200KOR
266DAEJ00KOR
267DAKR00SEN
268DARW00AUS
269DAV100ATA
270DEAR00ZAF
271DGAR00GBR
272DHLG00USA
273DJIG00DJI
274DLF100NLD
275DLTV00VNM
276DRAG00ISR
277DRAO00CAN
278DUBO00CAN
279DUM100ATA
280DUND00NZL
281DYNG00GRC
282EBRE00ESP
283EIL300USA
284EIL400USA
285EPRT00USA
286ESCU00CAN
287EUSM00MYS
288FAA100PYF
289FAIR00USA
290FALE00WSM
291FALK00FLK
292FFMJ00DEU
293FLIN00CAN
294FLRS00PRT
295FRDN00CAN
296FTNA00WLF
297FUNC00PRT
298GAMB00PYF
299GAMG00KOR
300GANP00SVK
301GCGO00USA
302GENO00ITA
303GLPS00ECU
304GLSV00UKR
305GMSD00JPN
306GODE00USA
307GODN00USA
308GODS00USA
309GODZ00USA
310GOL200USA
311GOLD00USA
312GOP600CZE
313GOP700CZE
314GOPE00CZE
315GOUG00SHN
316GRAC00FRA
317GRAS00FRA
318GRAZ00AUT
319GUAM00GUM
320GUAO00CHN
321GUAT00GTM
322GUUG00GUM
323HALY00SAU
324HAMD00IRN
325HARB00ZAF
326HARV00USA
327HERS00GBR
328HERT00GBR
329HKSL00HKG
330HKWS00HKG
331HLFX00CAN
332HNLC00USA
333HNPT00USA
334HNUS00ZAF
335HOB200AUS
336HOFN00ISL
337HOLB00CAN
338HOLM00CAN
339HOLP00USA
340HRAG00ZAF
341HRAO00ZAF
342HUEG00DEU
343HYDE00IND
344IENG00ITA
345IISC00IND
346INEG00MEX
347INVK00CAN
348IQAL00CAN
349IQQE00CHL
350IRKJ00RUS
351IRKM00RUS
352IRKT00RUS
353ISBA00IRQ
354ISPA00CHL
355ISTA00TUR
356IZMI00TUR
357JCTW00ZAF
358JFNG00CHN
359JNAV00VNM
360JOG200IDN
361JOZ200POL
362JOZE00POL
363JPLM00USA
364JPRE00ZAF
365KARR00AUS
366KAT100AUS
367KELY00GRL
368KERG00ATF
369KGNI00JPN
370KHAR00UKR
371KIR000SWE
372KIR800SWE
373KIRI00KIR
374KIRU00SWE
375KIT300UZB
376KITG00UZB
377KMNM00TWN
378KOKB00USA
379KOKV00USA
380KOS100NLD
381KOUC00NCL
382KOUG00GUF
383KOUR00GUF
384KRGG00ATF
385KRS100TUR
386KSMV00JPN
387KUNM00CHN
388KUUJ00CAN
389KZN200RUS
390LAE100PNG
391LAMA00POL
392LAUT00FJI
393LBCH00USA
394LCK300IND
395LCK400IND
396LEIJ00DEU
397LHAZ00CHN
398LLAG00ESP
399LMMF00MTQ
400LPAL00ESP
401LPGS00ARG
402LROC00FRA
403M0SE00ITA
404MAC100AUS
405MAD200ESP
406MADR00ESP
407MAG000RUS
408MAJU00MHL
409MAL200KEN
410MANA00NIC
411MAR600SWE
412MAR700SWE
413MARS00FRA
414MAS100ESP
415MAT100ITA
416MATE00ITA
417MATG00ITA
418MAUI00USA
419MAW100ATA
420MAYG00MYT
421MBAR00UGA
422MCHL00AUS
423MCIL00JPN
424MCM400ATA
425MDO100USA
426MDVJ00RUS
427MEDI00ITA
428MELI00ESP
429MERS00TUR
430MET300FIN
431METG00FIN
432METS00FIN
433MFKG00ZAF
434MGUE00ARG
435MIKL00UKR
436MIZU00JPN
437MKEA00USA
438MOBJ00RUS
439MOBK00RUS
440MOBN00RUS
441MOBS00AUS
442MOIU00KEN
443MONP00USA
444MORP00GBR
445MQZG00NZL
446MRL100NZL
447MRL200NZL
448MRO100AUS
449MTKA00JPN
450MTV100URY
451MTV200URY
452NAIN00CAN
453NAMA00SAU
454NANO00CAN
455NAUR00NRU
456NCKU00TWN
457NICO00CYP
458NIST00USA
459NIUM00NIU
460NKLG00GAB
461NLIB00USA
462NNOR00AUS
463NOT100ITA
464NOVM00RUS
465NRC100CAN
466NRIL00RUS
467NRL100USA
468NRMD00NCL
469NTUS00SGP
470NURK00RWA
471NVSK00RUS
472NYA100NOR
473NYA200NOR
474NYAL00NOR
475OAK100GBR
476OAK200GBR
477OBE400DEU
478OHI200ATA
479OHI300ATA
480ONS100SWE
481ONSA00SWE
482OPMT00FRA
483ORID00MKD
484OSN300KOR
485OSN400KOR
486OUS200NZL
487OWMG00NZL
488PADO00ITA
489PALM00ATA
490PARC00CHL
491PARK00AUS
492PBRI00IND
493PDEL00PRT
494PEN200HUN
495PENC00HUN
496PERT00AUS
497PETS00RUS
498PGEN00PHL
499PICL00CAN
500PIE100USA
501PIMO00PHL
502PIN100USA
503PNGM00PNG
504POHN00FSM
505POL200KGZ
506POLV00UKR
507POTS00DEU
508POVE00BRA
509PPPC00PHL
510PRDS00CAN
511PRE300ZAF
512PRE400ZAF
513PTAG00PHL
514PTBB00DEU
515PTGG00PHL
516PTVL00VUT
517QAQ100GRL
518QIKI00CAN
519QUI300ECU
520QUI400ECU
521QUIN00USA
522RABT00MAR
523RAEG00PRT
524RAMO00ISR
525RBAY00ZAF
526RCMN00KEN
527RDSD00DOM
528RECF00BRA
529REDU00BEL
530RESO00CAN
531REUN00REU
532REYK00ISL
533RGDG00ARG
534RIGA00LVA
535RIO200ARG
536RIOP00ECU
537ROAP00ESP
538ROCK00USA
539ROTH00ATA
540SALU00BRA
541SAMO00WSM
542SANT00CHL
543SASK00CAN
544SASS00DEU
545SAVO00BRA
546SBOK00ZAF
547SCH200CAN
548SCIP00USA
549SCOR00GRL
550SCRZ00BOL
551SCTB00ATA
552SCUB00CUB
553SEJN00KOR
554SEY200SYC
555SEYG00SYC
556SFDM00USA
557SFER00ESP
558SGOC00LKA
559SHAO00CHN
560SHE200CAN
561SIMO00ZAF
562SIN100SGP
563SMST00JPN
564SNI100USA
565SOD300FIN
566SOFI00BGR
567SOLA00SAU
568SOLO00SLB
569SPK100USA
570SPT000SWE
571SPTU00BRA
572SSIA00SLV
573STFU00USA
574STHL00GBR
575STJ300CAN
576STJO00CAN
577STK200JPN
578STR100AUS
579STR200AUS
580SULP00UKR
581SUTH00ZAF
582SUTM00ZAF
583SUWN00KOR
584SVTL00RUS
585SYDN00AUS
586SYOG00ATA
587TABL00USA
588TANA00ETH
589TASH00UZB
590TCMS00TWN
591TDOU00ZAF
592TEHN00IRN
593THTG00PYF
594THTI00PYF
595THU200GRL
596THU300GRL
597TID100AUS
598TIDB00AUS
599TIT200DEU
600TIXI00RUS
601TLSE00FRA
602TLSG00FRA
603TNML00TWN
604TONG00TON
605TORP00USA
606TOW200AUS
607TRAK00USA
608TRO100NOR
609TSK200JPN
610TSKB00JPN
611TUBI00TUR
612TUVA00TUV
613TWTF00TWN
614UCAL00CAN
615UCLP00USA
616UCLU00CAN
617UFPR00BRA
618ULAB00MNG
619ULDI00ZAF
620UNB300CAN
621UNBD00CAN
622UNBJ00CAN
623UNBN00CAN
624UNSA00ARG
625UNX200AUS
626UNX300AUS
627URUM00CHN
628USN700USA
629USN800USA
630USN900USA
631USNO00USA
632USUD00JPN
633UZHL00UKR
634VACS00MUS
635VALD00CAN
636VESL00ATA
637VILL00ESP
638VIS000SWE
639VNDP00USA
640VOIM00MDG
641WAB200CHE
642WARK00NZL
643WARN00DEU
644WDC500USA
645WDC600USA
646WES200USA
647WGTN00NZL
648WHC100USA
649WHIT00CAN
650WIDC00USA
651WILL00CAN
652WIND00NAM
653WLSN00USA
654WROC00POL
655WSRT00NLD
656WTZ300DEU
657WTZA00DEU
658WTZR00DEU
659WTZS00DEU
660WTZZ00DEU
661WUH200CHN
662WUHN00CHN
663XIAN00CHN
664XMIS00AUS
665YAKT00RUS
666YAR200AUS
667YAR300AUS
668YARR00AUS
669YEBE00ESP
670YEL200CAN
671YELL00CAN
672YIBL00OMN
673YKRO00CIV
674YONS00KOR
675YSSK00RUS
676ZAMB00ZMB
677ZECK00RUS
678ZIM200CHE
679ZIM300CHE
680ZIMJ00CHE
681ZIMM00CHE
682ZWE200RUS
683
Note: See TracBrowser for help on using the repository browser.