Added ability for distance calc script to handle (i.e. ignore) nan/inf