Alright, alright. Settle down. The script:
#!/usr/bin/perl #-----------------------------pointset1---------------------- $points=$ARGV[0]; $cnt=0; open(PTS,"<$points"); while(<PTS>) { #X,Y,Z,Time,Amplitude ++$cnt; if(!/X/) { ($x,$y,$z,$ts,$a)=split ','; ($date,$time)=split ' ',$ts; $ts="$date $time"; ($h,$m,$s)=split ':', $time; ($d,$mon,$yr)=split '-', $date; $date="$d-$mon-$yr"; $t=($h*3600)+($m*60)+$s;#convert to seconds push(@ts,$t); push(@as,$a); push(@lines,$_); #$data[$cnt][0]=$t; #$data[$cnt][1]=$a; #$data[$cnt][2]=$_; #print STDERR "\n$_"; #print STDERR "Event #: $cnt\n"; #print STDERR "Seconds: $t\n"; #print STDERR "Amplitude: $a\n"; } } close(PTS); while (@ts != 0) { $t0=pop(@ts); $a0=pop(@as); $line0=pop(@lines); # sort by amplitude smallest to largest #@data=sort {$a->[1]<=>$b->[1];} @data; #($t0,$a0,$line0) = pop(@data); #print STDERR "T0=$t0\n"; #print STDERR "A0=$a0\n"; #print STDERR "$line0\n"; # sort by time difference smallest to largest #@data=sort {abs($t0-$data[$a][0])<=>abs($t0-$data[$b][0])} @data; $flag=0; for ($i=0;$i<@ts;$i++){ $test = abs($t0-$ts[$i]); #print "NEXT Time= $ts[$i]\n"; #print "NEXT Amp= $as[$i]\n"; #print "Time Difference= $test\n"; #if ($test < 0.3 && $a0 < $as[$i]){print "TIME: $test is l +ess than 0.3\n"; #print "AMPLITUDE:$a0 is less than $as[$i]\n"} if( $test < 0.3 && $a0 < $as[$i]){$flag=1} #print "FLAG= $flag\n"; } if ($flag==0) {unshift(@keepers,$line0)}; #push(@keepers,$line0); } open(OUT,">out_file.txt"); print OUT "X,Y,Z,Time,Amplitude\n"; print OUT (@keepers); close (OUT);
The input file:
X,Y,Z,Time,Amplitude 2550,531,66,10-12-2007 07:03:08.069,2 2549,529,62,10-12-2007 07:03:08.151,1 2550,531,66,10-12-2007 07:03:09.069,1 2549,529,62,10-12-2007 07:03:09.151,2
Current results:
X,Y,Z,Time,Amplitude 2550,531,66,10-12-2007 07:03:08.069,2 2550,531,66,10-12-2007 07:03:09.069,1 2549,529,62,10-12-2007 07:03:09.151,2
The current script only works if the largest amplitude appears first in time(default sort of the data). An attempt to get a bit more sophisticated (commented lines)wasn't working either. -honyok

In reply to Re^2: Compare fields in a file by honyok
in thread Compare fields in a file by honyok

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.