#! /usr/bin/gawk -f
# Last edited on 1998-09-15 23:44:20 by stolfi

# Reads a list of pairs  SECX.FNUMX SECY.FNUMY  where each SEC is a 
# section tag and each FNUM is a page f-number.
# The pairs must be sorted by SECX.
# Prints the count of pairs (SECX, SECY) in tabular format.

BEGIN{
  nsc = 0; 
  split("", sct); split("", scs); split("", tb);
  ps = "";
}

/./ {
  x = $1; gsub(/[.].*$/, "", x);
  if (! (x in sct)) { sct[x]=1; nsc++; scs[nsc]=x; }
  y = $2; gsub(/[.].*$/, "", y);
  tb[x,y]++;
}

END { 
  for (i=1;i<=nsc;i++)
    { x=scs[i]; printf "%-6s", x;
      for (j=1;j<=nsc;j++) 
        { y=scs[j];  n=tb[x,y]; 
          # hack to correct for duplication of same-section pairs: 
          if (x == y) { n /= 2; }
          printf " %2s", (n == 0 ? "." : n );
        }
      printf "\n";
    }
}