function bfpack,badflag
; This routine packs the contents of the badflag(7,nstar) array into
; a single short integer array bfp(nstar) by setting the corresponding
; bits in a 7-bit binary number according as the corresponding entry
; in badflag is zero or anything else.

pows=[1,2,4,8,16,32,64]

sz=size(badflag)
nst=sz(2)
bb=intarr(7,nst)
s=where(badflag ne 0,ns)
if(ns gt 0) then bb(s)=1
prod=rebin(pows,7,nst)*bb
out=fix(total(prod,1))

return,out
end