Add support for writing to subsets of datasets

I had a go at implementing this, mostly copying from your getindex code. It seems to work OK for some preliminary tests.