Read the events list Define flags array, set to 0 if fromccf then Loop on ccds Read the bad pixels for that CCD via the CAL call flagEvents call updateBadpix end Loop endif if fromfiles then Loop on bad pixels tables Read bad pixels call flagEvents call updateBadpix end Loop endif end subroutine flagEvents map = 0 if overwrite and (forcereplace or events ON_BADPIX exist) unset ON_BADPIX, CLOSE_TO_DEADPIX and CLOSE_TO_BRIGHTPIX if replaceonboard and (forcereplace or flagged events exist) unset CLOSE_TO_ONBOARD_BADPIX Loop over bad pixels map(xb,yb) = map(xb,yb) OR ON_BADPIX Loop over pixels next to (xb,yb) if dead pixel then map(x,y) = map(x,y) OR CLOSE_TO_DEADPIX else map(x,y) = map(x,y) OR CLOSE_TO_BRIGHTPIX endif end Loop end Loop Loop over events for that CCD FLAG = FLAG OR map(RAWX,RAWY) end Loop end subroutine flagEvents subroutine updateBadpix if not (overwrite and replaceonboard) then call readBadpix on BADPIXnn table for current CCD/node in events file if overwrite and (forcereplace or events ON_BADPIX exist) remove rows where BADFLAG>1 if replaceonboard and (forcereplace or flagged events exist) remove rows where BADFLAG=1 endif add list of new bad pixels at the end of the list call mergeBad to remove redundancies call writeBadpix to BADPIXnn table end subroutine updateBadpix