Index: src/Jobs/Grid/SamplingGrid.cpp
===================================================================
--- src/Jobs/Grid/SamplingGrid.cpp	(revision c6355f2a2d0b8d1942a82247a03b8c3193315bb1)
+++ src/Jobs/Grid/SamplingGrid.cpp	(revision 64bafe0d0cd15e6cd2e50cb7a27b730cfec01778)
@@ -233,4 +233,30 @@
 }
 
+double SamplingGrid::getNearestLowerGridPoint(
+    const double value, const size_t axis) const
+{
+  const double length = end[axis] - begin[axis];
+  if ((fabs(length) < std::numeric_limits<double>::epsilon()) || (getGridPointsPerAxis() == 0)) {
+    return 0.;
+  } else {
+    const double offset = value - begin[axis];
+    const double factor = floor((double)getGridPointsPerAxis()*(offset/length));
+    return factor*(length/(double)getGridPointsPerAxis());
+  }
+}
+
+double SamplingGrid::getNearestHigherGridPoint(
+    const double value, const size_t axis) const
+{
+  const double length = end[axis] - begin[axis];
+  if ((fabs(length) < std::numeric_limits<double>::epsilon()) || (getGridPointsPerAxis() == 0)) {
+    return 0.;
+  } else {
+    const double offset = value - begin[axis];
+    const double factor = ceil((double)getGridPointsPerAxis()*(offset/length));
+    return factor*(length/(double)getGridPointsPerAxis());
+  }
+}
+
 void SamplingGrid::setWindowSize(
     const double _begin_window[3],
@@ -238,12 +264,12 @@
 {
   for (size_t index=0;index<3;++index) {
-    ASSERT( _begin_window[index] >= begin[index],
+    begin_window[index] = getNearestLowerGridPoint(_begin_window[index], index);
+    ASSERT( begin_window[index] >= begin[index],
         "SamplingGrid::setWindowSize() - window starts earlier than domain on "
         +toString(index)+"th component.");
-    begin_window[index] = _begin_window[index];
-    ASSERT( _end_window[index] <= end[index],
+    end_window[index] = getNearestHigherGridPoint(_end_window[index], index);
+    ASSERT( end_window[index] <= end[index],
         "SamplingGrid::setWindowSize() - window ends later than domain on "
         +toString(index)+"th component.");
-    end_window[index] = _end_window[index];
   }
 }
@@ -339,13 +365,23 @@
   size_t length[3];
   size_t total[3];
+  const double round_offset =
+      (std::numeric_limits<size_t>::round_style == std::round_toward_zero) ?
+          0.5 : 0.; // need offset to get to round_toward_nearest behavior
   for(size_t index=0;index<3;++index) {
-    pre_offset[index] = (_begin_window[index] - begin_window[index])*gridpoints_axis;
-    length[index] = (_end_window[index] - _begin_window[index])*gridpoints_axis;
-    post_offset[index] = (end_window[index] - _end_window[index])*gridpoints_axis;
-    total[index] = (end_window[index] - begin_window[index])*gridpoints_axis;
+    // we refrain from using floor/ceil as the window's starts and ends,
+    // the grids have to be compatible (equal level), should always be on
+    // discrete grid point locations.
+    const double delta = (double)gridpoints_axis/(end[index] - begin[index]);
+    // delta is conversion factor from box length to discrete length, i.e. number of points
+    pre_offset[index] = delta*(_begin_window[index] - begin_window[index])+round_offset;
+    length[index] = delta*(_end_window[index] - _begin_window[index])+round_offset;
+    post_offset[index] = delta*(end_window[index] - _end_window[index])+round_offset;
+    total[index] = delta*(end_window[index] - begin_window[index])+round_offset;
+    // total is used as safe-guard against loss due to discrete conversion
     ASSERT( pre_offset[index]+post_offset[index]+length[index] == total[index],
         "SamplingGrid::addOntoWindow() - pre, post, and length don't sum up to total for "
         +toString(index)+"th component.");
   }
+  // assert that calculated lengths match with given vector sizes
 #ifndef NDEBUG
   const size_t calculated_size = length[0]*length[1]*length[2];
@@ -362,5 +398,5 @@
 #endif
   size_t N[3];
-  size_t counter = 0;
+//  size_t counter = 0;
   sampledvalues_t::iterator griditer = sampled_grid.begin();
   std::advance(griditer, pre_offset[0]*total[1]*total[2]);
