   realsphere reals;
   reals.sigma = 30;
 
-  for (int img = 0; img < fullsize[0]; img++)
+  for (int img = 0; img < fullsize[0]; img+=BS)
     {
+	int end = min(fullsize[0], img + BS);
+	int imgcount = end - img;
+	count[0] = imgcount;
       offset[0] = img;
       lambdaSpace.selectHyperslab(H5S_SELECT_SET, count, offset);
 //      expectedLambdaSpace.selectHyperslab(H5S_SELECT_SET, count, offset);


const int FX = 2048;
const int FY = 2048;

struct realsphere : public thrust::unary_function<int, cufftComplex>
{

  photonSpace.selectHyperslab(H5S_SELECT_SET, count, offset);
  H5::DataSpace memSpace(3, count);

  boost::multi_array<float, 3> lambdaVals(extents[BS][NY][NX]);
  boost::multi_array<float, 3> lambdaValsZero(extents[BS][NY][NX]);
  thrust::host_vector<float> expLambdaVals(NY * NX);
  thrust::host_vector<float> logLsVals(NY * NX);
  boost::multi_array<short, 3> photonVals(extents[BS][NY][NX]);
  thrust::device_vector<short> dPhotons(BS * NY * NX);
  thrust::device_vector<float> dLambdas(BS * NY * NX);
  thrust::device_vector<float> dExpLambdas(NY * NX);
  thrust::device_vector<float> dLogLs(NY * NX);
  thrust::device_vector<float> dIntensity(BS * 32 * 32);
  thrust::host_vector<float> hIntensity(BS * 32 * 32);
  thrust::device_vector<float> dIntensity2(BS * 32 * 32);
  thrust::host_vector<float> hIntensity2(BS * 32 * 32);

  thrust::device_vector<cufftComplex> d_complexSpace(FY * FX);
  thrust::device_vector<float> dPattern(FY * FX);
