Add weighted averaging to dat.py for use in offsetsubtract. Moved wait statement from dat.py to engine (making sure file fully written).