usr bin perl -w copyright Sergeyev Roman RN9RQ ex RA9QCE 2009 licence

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl -w
#copyright Sergeyev Roman, RN9RQ ex RA9QCE, 2009
#licence: GPL v3 or later, see more on gnu.org
# Скрипт вписывает данные в adif формат о регионе и RDA районе.
# Кидаем в папку IN файл с названием adif.adi запускаем скрипт и забираем готовый файл из папки OUT
# в папке table лежит набор данных с сайта http://rdaward.org/ в формате csv
sub convert ()
{
$time=localtime();
print "start convert $file \n started in $time \n";
open(ADIFFILE, "< ./in/$file") or die "can't open adif-file";
open(NEWADIFFILE, "> ./out/$file") or die "can't create adif-file";
while($line=<ADIFFILE>)
{
if($line=~m/\<CALL\:/o)
{
$b=$`;
$ser=$&;
$after=$';
$num=substr $',0,2;
$num1=substr $num,1,1;
if($num1 eq "\>"){$num=substr $num, 0,1;$call=substr $',2,$num;}
else{$call=substr $',3,$num;};
$rda="";
if((($call=~m/^R.+/o)||($call=~m/^U[A-Ia-i].+/o))&&(!($after=~m/\<CNTY\:5/o)))
{
if(exists($hash{$call}))
{
$rda=$hash{$call};
$qt=substr $rda,0,2;
$after=~s/^$num\>$call//;
$string=join "",$b,$ser,$num,">",$call," ","<STATE:2>$qt <CNTY:5>$rda",$after;
$line=$string;
};
};
};
print NEWADIFFILE $line;
};
close ADIFFILE;
close NEWADIFFILE;
$time=localtime();
print "stop convert $file \n stoped in $time \n";
};
$time=localtime();
print "program start in $time \n";
open(CSVFILE, "< ./table/rda.csv") or die "can't open csv-file";
@table=<CSVFILE>;
close CSVFILE;
%hash = ();
foreach $i (@table)
{
$i=~s/"//g;
if($i=~m/\,/)
{
$hcall=$`;
$hrda=substr $',0,5;
$hash{$hcall} = $hrda;
};
};
opendir(INDIR, "./in/") or die "can't open ./in directory";
while ($file = readdir(INDIR))
{
if ($file=~m/.+\.adi/){&convert;};
};
closedir INDIR;