Incidentally, I wrote a program that calculates read coverage from a sam file (number of reads mapped to each sequence, average depth, median depth, standard deviation, fraction of bases covered, etc).
pileup.sh in=mapped.sam out=coverage.txt
It has a toggle for including or ignoring secondary alignments; secondary=false or secondary=true (default).