Excitation and decay of flows in the magnetosphere-ionosphere system due to magnetic reconnection at the dayside magnetopause and in the geomagnetic tail