Measurement of the deuteron spin structure function g1d(x) for 1 (GeV/c)2<Q2<40 (GeV/c)2