Mercurial > hg > cc > cirrus_home
view bin/hist @ 138:9ea12f7b304b
just barely working
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Fri, 23 Jul 2021 16:23:46 +0000 |
parents | b976a7449d41 |
children |
line wrap: on
line source
#!/bin/sh # Usage: hist file bins [-max n] [-min n] [-ll n] [-t title] [-ntile n] file=$1 shift nb=$1 shift date=`date` while case "x$1" in x-max) shift; max=$1 ;; x-ll) shift; ll=$1 ;; x-min) shift; min=$1 ;; x-t) shift; title=$1 ;; x-ntile) shift; ntile=$1 ;; x) break ;; *) echo hunh 1>&2; exit 1 ;; esac do shift done if [ \( -z "$max" -o -z "$min" \) ] then rfile=/tmp/hist$$ sort -n $file > $rfile fi perl -e " (\$max,\$min,\$nb,\$ll,\$title,\$ntile)=(${max:-`tail -1 /tmp/hist$$`}, ${min:-`head -1 /tmp/hist$$`} ,$nb,${ll:-80},\"${title:-$file}\",${ntile:-0});"' $#bins=$nb; $range=$max-$min; while (<>) { if ($_<$min) { $minn+=1; } elsif ($_>$max) { $maxn+=1; } else { $n+=1; $i=(($_-$min)/$range)*$nb; if ($i==$nb) {$bins[$i-1]+=1} else {$bins[int($i)]+=1}; }; }; $start=$min+$range/(2*$nb); $step=$range/$nb; foreach $i (0..$nb-1) { $mb=$bins[$i] if ($bins[$i]>$mb); }; $bscale=$mb/($ll-16); $bscale=1 if ($bscale<1); print "$title ",`date`,"\n"; print " n min max width maxcnt bscale"; if ($ntile) { print " ntiles tilew"; $tile=$tstep=($n/$ntile); $ntile--; } print "\n"; printf("%7d%7.3f %7.3f%7.3f%6d %7.3f",$n,$min,$max,$step,$mb,$bscale); printf("%5d %7.2f",$ntile+1,$tstep) if ($ntile); print "\n\n"; if ($minn) {printf("<%7.3f%7d\n",$min,$minn)}; foreach $i (0..$nb-1) { $n=$bins[$i]; if ($ntile) { $cum+=$n; if ($cum>=$tile) { print "-"; $tile+=$tstep; $ntile--; } else { print " "; }; } else { print " "; }; printf("%7.3f%7d ",$start+($i*$step),$bins[$i]); $nx=$bins[$i]/$bscale; $nx=1 if (($nx<1) && ($bins[$i]>0)); print "*" x $nx; print "\n"; }; if ($maxn) {printf(">%7.3f%7d\n",$max,$maxn)};' ${rfile:-$file} if [ "$rfile" ] then rm $rfile fi