Detailed simulation of morphodynamics: 3. Ripples and dunes