#!/usr/bin/perl # cleanup of data files $version="1.4"; $date="18 Feb 2020"; # by Nick Manini sub print_help { print STDERR <0 or die "there is no point setting a threshold <=0\n"; next; } if($p eq "-h"){ # print help print_help; exit; } print STDERR "Error: invalid option $p\n "; print_help; exit; } if ($#FILELIST==-1) { push(@FILELIST,"-"); # adds stdio for lack of arguments } while ($filename=shift(@FILELIST)){ # loop on filenames $xmax=-$BIG; $ymax=-$BIG; $xmin=$BIG; $ymin=$BIG; $xkeep=$BIG; $ykeep=$BIG; open(INF, $filename); # Open for input while (){ # compute the max & min for x and y: s/^\s+//; @data=split(/[()\s]+/); $x=$data[0]+0.; $y=$data[1]+0.; if($x<$xmin){$xmin=$x;} if($y<$ymin){$ymin=$y;} if($x>$xmax){$xmax=$x;} if($y>$ymax){$ymax=$y;} } close(INF); $xrange=$xmax-$xmin; $yrange=$ymax-$ymin; $xcheck=$xrange+$TINY; $ycheck=$yrange+$TINY; print "# pruned with ",$xcheck," ",$ycheck,"\n"; open(INF, $filename); # re-open for input while (){ # loop on lines in the file s/^\s+//; @data=split(/[()\s]+/); $xnext=$data[0]+0.; $ynext=$data[1]+0.; $lnext=$_; $xratio=abs($x-$xkeep)/$xcheck; $yratio=abs($y-$ykeep)/$ycheck; if( # sufficient displacement: (0.99*$xratio+0.01*$yratio > $thresh && 0.01*$xratio+0.99*$yratio > $thresh) || # a local max or minimum: ($y-$ykeep)*($y-$ynext)>0 ){ # print $x," ",$y,"\n"; print $l; $xkeep=$x; $ykeep=$y; } $x=$xnext; $y=$ynext; $l=$lnext; } close(INF); if($x!=$xkeep){ # print $x," ",$y,"\n"; print $l; } # print last point anyway }