#!/usr/bin/perl # This script reads in a file with two columns # of numbers. The first number is a bond length, and # the second is an error. It finds the min and max # errors (within the user-specified interval) and # computes their difference (the "nonparallelity error") # # Arteum Bochevarov, 2006 print "Enter the start of the interval: \n"; chomp($start=); print "Enter the end of the interval: \n"; chomp($end=); if($ARGV[0]=~/--/){ $arg=1; } else { $arg=0; } open(IN,$ARGV[$arg]); @input=; close(IN); $c1=0; foreach $line (@input) { chomp $line; @tmp=split / +/, $line; $bg[$c1]=$tmp[0]; $en[$c1]=$tmp[1]; $c1++; } # We determine the first element we're going to start with # in order to assign $minel and $maxel to this first element for($i=0;$i<@bg;$i++){ if($bg[$i]<$start){ next; } $firstelt=$i; last; } $minel=$en[$firstelt]; $maxel=$en[$firstelt]; for($i=0;$i<@bg;$i++){ if($bg[$i]<$start || $bg[$i]>$end){ next; } if($en[$i]<=$minel){ $minel=$en[$i]; } if($en[$i]>=$maxel){ $maxel=$en[$i]; } } print "minel = ",$minel,"\n"; print "maxel = ",$maxel,"\n"; print "Diff = ",$maxel-$minel,"\n";