writing mdwf function.