   unsigned int j = blockIdx.y * blockDim.y + threadIdx.y;
   unsigned int k = blockIdx.z * blockDim.z + threadIdx.z;
 
-  if (i >= (c_Size.x - 1) || j >= (c_Size.y - 1)  || k >= (c_Size.z - 1))
+  if (i >= c_Size.x || j >= c_Size.y  || k >= c_Size.z)
       return;
 
   long int id   = (k     * c_Size.y + j)    * c_Size.x + i;

  unsigned int j = blockIdx.y * blockDim.y + threadIdx.y;
  unsigned int k = blockIdx.z * blockDim.z + threadIdx.z;

  if (i >= (c_Size.x - 1) || j >= (c_Size.y - 1)  || k >= (c_Size.z - 1))
      return;

  long int id   = (k     * c_Size.y + j)    * c_Size.x + i;

  long int id_y = (k     * c_Size.y + j + 1)* c_Size.x + i;
  long int id_z = ((k+1) * c_Size.y + j)    * c_Size.x + i;

  if (i == (c_Size.x - 1)) grad_x[id] = 0;
  else grad_x[id] = in[id_x] - in[id];

  if (j == (c_Size.y - 1)) grad_y[id] = 0;
  else grad_y[id] = in[id_y] - in[id];

  if (k == (c_Size.z - 1)) grad_z[id] = 0;
  else grad_z[id] = in[id_z] - in[id];
}

__global__
