annotate bin/hist @ 178:e1bc9d8d688c

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