#!/usr/bin/gawk -f # /* vim: set filetype=awk : */ -*- awk -*- BEGIN{ BinLog=0; # if non-zero, use bin logging after rounding numbers Bins=10; FS=OFS=","; IGNORECASE=1; Inf=10**32; Stop = -1; } { sub(/[\%\#].*/,""); gsub(/[ \t]/,""); } /^$/ { next } Pass==2 { Pass=3; for(I in Numeric) { Bin[I]=(Max[I]-Min[I])/Bins; print "% attribute",Names[I],"min",Min[I],"max",Max[I],\ "bins",Bins,"steps",Bin[I]} } /^=/ && Pass==1 { print $0; defNums(); } /^=/ {next} Pass==1 { for(I in Numeric) { if ( $I ~ /?/ ) continue; if ($I > Max[I] ) Max[I]=$I; if ($I < Min[I] ) Min[I]=$I;} } Pass==3 { for(I in Numeric) { if (I > NF + Stop) continue; if ( $I ~ /?/ ) continue; $I="_"label(I,$I)}; print } function round(x) { if (x<0) {return int(x-0.5)} else {return int(x+0.5)} } function label(i,val, x) { if ( Bin[i]==0 ) return 1; x=round((val-Min[i])/Bin[i]); if (x==0) {return 1} else {return x}; } function defNums( i,str) { for(i=1;i<=NF;i++) { str=$i; if(gsub(/[\$><]/,"",str)) { Numeric[i]=1; Max[i]= -1 * Inf; Min[i]= Inf; } gsub(/\?/,"",str); Names[i]=str; }}