#!/usr/bin/perl # ignore commented (#) and empty lines, # and compute square difference of columns 2,3,.. # provided that data in column 1 are the same (otherwise ignore) # version 1.0 - by Nicola Manini - Jan 2003 if($#ARGV == 1) { $InputFile1=shift(@ARGV); $InputFile2=shift(@ARGV); open(I1, $InputFile1); open(I2, $InputFile2); while ($line1 = ){ if($line1 !~/^\#/ && $line1 !~/^\s*$/){ # print "QUII 1: ".$line1; $nl1++; while ($line2 = ){ if($line2 !~/^\#/ && $line2 !~/^\s*$/){ # print "QUII 2: ".$line2; $nl2++; @li1=split(/\s+/,$line1);@li2=split(/\s+/,$line2); if($li1[0]==$li2[0]){ $nlp++; printf "%21.16g",shift(@li1); shift(@li2); while($#li1>=0 && $#li2>=0){ printf " %21.16g",(shift(@li1) - shift(@li2))**2; } print "\n"; } last; # jump out of the loop and get next $line1 } } } } close(I1);close(I2); # print "QUAA ".$nl1." ".$nl2."\n"; if($nl1 != $nl2){print STDERR "squarediff warning: \# lines in ".$InputFile1." and ".$InputFile2. " do not match\n";} elsif($nlp == 0 ){print STDERR "squarediff warning: no lines matching\n";} elsif($nlp/$nl1<0.01 || $nl1/$nl2<0.01){print STDERR "squarediff warning: very few lines in output\n";} } else { print STDERR "usage: squarediff file1 file2 [file1/2 can be - for stdin]\n"; }