I don’t know what kind of shape the loaded data has and how the indexing works, so could you please check the intermediate values used in calDist and e.g. calStepLoc and make sure the indexing is correct?