comparison 2.4/src/direction_filter.pl @ 16:8eb7d93f7e58 draft

Uploaded
author plus91-technologies-pvt-ltd
date Sat, 31 May 2014 11:23:36 -0400
parents e3609c8714fb
children
comparison
equal deleted inserted replaced
15:da93b6f4d684 16:8eb7d93f7e58
1 use Getopt::Long;
2 my ($v);
3
4 GetOptions ("v|verbose" => \$v); # flag
5
6
7
8 open (FILE,"$ARGV[0]") or die "Cant find file\n\n";
9 my $dist=0;
10 my $pos=0;
11 my @max=0;
12 my @events=0;
13
14 while(<FILE>){
15 $dist=0;
16 @first=split(/\s+/,$_);
17 $numEvents=($_=~tr/\|//)+1;
18 $dist=$first[1]-$pos;
19 push(@max,$_);
20 push(@events,$numEvents);
21 #print "STARTING_POS=$pos\n";
22 if(($dist<500)||eof()){
23 until (($dist>500)||eof()){
24 $newline=<FILE>;
25 @second=split(/\s+/,$newline);
26 $numEvents=($newline=~tr/\|//)+1;
27 push(@max,$newline);
28 push(@events,$numEvents);
29 if($v){print "DIST=$dist\nSEC1=@second[1] POS1=$pos;\n";}
30 my $tmp=$pos;
31 $pos=@second[1];
32 $dist=@second[1]-$tmp;
33 }
34 }
35 if ($v){print "Corrected dist= $dist\n" if ($v)};
36 #Get the last values since they don't count
37 $NL=pop(@max);
38 $NE=pop(@events);
39 my $idxMax = 0;
40 #Get the index of the largest value in array
41 if ($v){print "Picking from events:\n"};
42 $events[$idxMax] > $events[$_] or $idxMax = $_ for 1 .. $#events;
43
44 my $val=@max[$idxMax];
45 print "$val" unless ($val=~/^0$/) ;
46
47
48 @max=$NL;
49 @events=$NE;
50 my @tmp=split(/\s+/,$NL);
51 $pos=$tmp[1];
52 }
53
54 close FILE;
55