ND2: some fixes for incorrectly detected dimensions

Mostly this has to do with stopped acquisitions or Z values that are
recorded multiple times with different values.

Fixes #11305.