Implementation and related tests

Addresses https://bugs.launchpad.net/openquake/+bug/1081934