diff --git a/README.md b/README.md index fd86b6e..8a59e27 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # adif-pota2sig -Convert POTA fields in adif files to SIG and SIG_INFO fields \ No newline at end of file +Convert POTA fields in adif files to SIG and SIG_INFO fields + +Parse adif file, if a record has one or more POTA_REF entries (delimited by a +comma), add SIG POTA and SIG_INFO with reference. Multiply record such, that +every POTA_REF entry is a separate record with own SIG_INFO. +Extended adif file will be printed to stdout. + +Usage: +adif-pota2sig.pl logfile.adi > extended-logfile.adi diff --git a/adif-pota2sig.pl b/adif-pota2sig.pl new file mode 100755 index 0000000..c27baae --- /dev/null +++ b/adif-pota2sig.pl @@ -0,0 +1,65 @@ +#!/usr/bin/env perl +# +# SPDX-License-Identifier: Beerware +# Wolfgang DM5WK Kroener wrote this file. As long as you retain this notice you +# can do whatever you want with this stuff. If we meet some day, and you think +# this stuff is worth it, you can buy me a beer in return. +# +# modified from perlmonks - TedPride - http://www.perlmonks.org/?node_id=559222 +# modified from https://scruss.com/blog/2011/05/23/parsing-adif-with-perl/ +# +# Description: +# Parse adif file, if a contact has one or more POTA_REF entries (delimited by +# a comma), add SIG POTA and SIG_INFO with reference. Multiply contact such, +# that every POTA_REF entry is a separate contact with own SIG_INFO. +# Extendet adif file will be printed to stdout. +# +# Usage: +# adif-pota2sig.pl logfile.adi > new-logfile.adi + +use strict; +use warnings; + +# use filename.adi as parameter +open(my $FH, '<', $ARGV[0]) or die "$ARGV[0]: $!"; + +while (<$FH>) { + print; + # fast forward past header + last if m/\s+$/i; +} + +my @entry = (); +my @pota_refs = (); +while (<$FH>) { + push @entry, $_; + if (m/\s+$/i) { + # entry complete + if (scalar(@pota_refs) > 0) { + # add sig_info to each pota reference + foreach my $ref (@pota_refs) { + # print all except last + print @entry[0 .. $#entry - 1]; + # insert POTA SIG + print "POTA\n"; + print "" . $ref . "\n"; + # print last + print $entry[-1]; + } + } else { + # no park reference in this entry + print @entry; + } + # clear entry and pota refs for next entry + @entry = (); + @pota_refs = (); + } elsif (m/^ + my $val = (split(/>/))[-1]; + chomp($val); + # fill pota_refs with references + @pota_refs = split(/,/, $val); + chomp @pota_refs; + } +} +close($FH);