Mercurial > hg > cc > cirrus_home
comparison bin/hist @ 17:b976a7449d41
sic
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Thu, 27 Feb 2020 13:24:19 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
16:47ef882acbec | 17:b976a7449d41 |
---|---|
1 #!/bin/sh | |
2 # Usage: hist file bins [-max n] [-min n] [-ll n] [-t title] [-ntile n] | |
3 file=$1 | |
4 shift | |
5 nb=$1 | |
6 shift | |
7 date=`date` | |
8 while | |
9 case "x$1" in | |
10 x-max) shift; max=$1 ;; | |
11 x-ll) shift; ll=$1 ;; | |
12 x-min) shift; min=$1 ;; | |
13 x-t) shift; title=$1 ;; | |
14 x-ntile) shift; ntile=$1 ;; | |
15 x) break ;; | |
16 *) echo hunh 1>&2; exit 1 ;; | |
17 esac | |
18 do | |
19 shift | |
20 done | |
21 if [ \( -z "$max" -o -z "$min" \) ] | |
22 then | |
23 rfile=/tmp/hist$$ | |
24 sort -n $file > $rfile | |
25 fi | |
26 perl -e " | |
27 (\$max,\$min,\$nb,\$ll,\$title,\$ntile)=(${max:-`tail -1 /tmp/hist$$`}, | |
28 ${min:-`head -1 /tmp/hist$$`} | |
29 ,$nb,${ll:-80},\"${title:-$file}\",${ntile:-0});"' | |
30 $#bins=$nb; | |
31 $range=$max-$min; | |
32 while (<>) { | |
33 if ($_<$min) { | |
34 $minn+=1; | |
35 } | |
36 elsif ($_>$max) { | |
37 $maxn+=1; | |
38 } | |
39 else { | |
40 $n+=1; | |
41 $i=(($_-$min)/$range)*$nb; | |
42 if ($i==$nb) {$bins[$i-1]+=1} else {$bins[int($i)]+=1}; | |
43 }; | |
44 }; | |
45 $start=$min+$range/(2*$nb); | |
46 $step=$range/$nb; | |
47 foreach $i (0..$nb-1) { | |
48 $mb=$bins[$i] if ($bins[$i]>$mb); | |
49 }; | |
50 $bscale=$mb/($ll-16); | |
51 $bscale=1 if ($bscale<1); | |
52 print "$title ",`date`,"\n"; | |
53 print " n min max width maxcnt bscale"; | |
54 if ($ntile) { | |
55 print " ntiles tilew"; | |
56 $tile=$tstep=($n/$ntile); | |
57 $ntile--; | |
58 } | |
59 print "\n"; | |
60 printf("%7d%7.3f %7.3f%7.3f%6d %7.3f",$n,$min,$max,$step,$mb,$bscale); | |
61 printf("%5d %7.2f",$ntile+1,$tstep) if ($ntile); | |
62 print "\n\n"; | |
63 if ($minn) {printf("<%7.3f%7d\n",$min,$minn)}; | |
64 foreach $i (0..$nb-1) { | |
65 $n=$bins[$i]; | |
66 if ($ntile) { | |
67 $cum+=$n; | |
68 if ($cum>=$tile) { | |
69 print "-"; $tile+=$tstep; $ntile--; | |
70 } | |
71 else { | |
72 print " "; | |
73 }; | |
74 } | |
75 else { | |
76 print " "; | |
77 }; | |
78 printf("%7.3f%7d ",$start+($i*$step),$bins[$i]); | |
79 $nx=$bins[$i]/$bscale; | |
80 $nx=1 if (($nx<1) && ($bins[$i]>0)); | |
81 print "*" x $nx; print "\n"; | |
82 }; | |
83 if ($maxn) {printf(">%7.3f%7d\n",$max,$maxn)};' ${rfile:-$file} | |
84 if [ "$rfile" ] | |
85 then | |
86 rm $rfile | |
87 fi | |
88 |