#!/usr/local/bin/perl # usage: # ranger.p col=3 < b_ans.dat # Finds the range of a distribution, from 5th to 95th percentile. $col = 0; # How to override min and max values with command line eval "\$$1=\$2" while $ARGV[0]=~ /^(\w+)=(.*)/ && shift; sub bynumber { $a <=> $b; } $j=0; $tot=0; while (<>) { @fields = split (' '); @data[$j] = @fields[$col] ; $tot+=@fields[$col]; $j++; } @sorted= sort bynumber @data; $jmin = int(0.05*$j); $jmax = int( $j - 1 -$jmin); printf STDERR "Range from %d to %d (out of %d. Min = %f Max = %f. Range = %f)\n", $jmin, $jmax, $j,@sorted[0],@sorted[$j-1],@sorted[$j-1]-@sorted[0]; printf STDERR "lower percentile = %f. upper = %f. Range = %f\n", @sorted[$jmin], @sorted[$jmax] , @sorted[$jmax] - @sorted[$jmin] ; printf STDERR "mean of all %d = %f \n", $j, $tot/$j ;