diff --git a/bfps/cpp/field.cpp b/bfps/cpp/field.cpp
index ba7fa5e4e2f1649ee31e776561ba1dc5c0af4889..ecb3d838477232f337f53b1e95eeffb2cf0c998e 100644
--- a/bfps/cpp/field.cpp
+++ b/bfps/cpp/field.cpp
@@ -619,13 +619,17 @@ int field<rnumber, be, fc>::write_filtered(
         const std::string fname,
         const std::string field_name,
         const int iteration,
-        int nx)
+        int nx,
+        int ny,
+        int nz)
 {
     /* file dataset has same dimensions as field */
     TIMEZONE("field::write_filtered");
     // only works in Fourier representation
     assert(!this->real_space_representation);
-    assert(nx <= this->rlayout->sizes[2]);
+    assert(hsize_t(nx) <= this->rlayout->sizes[2]);
+    assert(hsize_t(ny) <= this->rlayout->sizes[1]);
+    assert(hsize_t(nz) <= this->rlayout->sizes[0]);
     hid_t file_id, dset_id, plist_id;
     dset_id = H5I_BADID;
     std::string dset_name = (
@@ -660,28 +664,11 @@ int field<rnumber, be, fc>::write_filtered(
         memshape [i] = count[i];
         memoffset[i] = 0;
     }
-    // set up smaller dimensions
-    unsigned int ii = 0;
-    count [ii] = this->clayout->subsizes[ii];
-    offset[ii] = this->clayout->starts[ii];
-    dims  [ii] = this->clayout->sizes[ii];
-    memshape [ii] = count[ii];
-    memoffset[ii] = 0;
-    ii = 1;
-    count [ii] = this->clayout->subsizes[ii];
-    offset[ii] = this->clayout->starts[ii];
-    dims  [ii] = this->clayout->sizes[ii];
-    memshape [ii] = count[ii];
-    memoffset[ii] = 0;
-    ii = 2;
-    count [ii] = nx/2+1;
-    offset[ii] = 0;
-    dims  [ii] = nx/2+1;
-    memshape [ii] = this->clayout->subsizes[ii];
-    memoffset[ii] = 0;
-
-    mspace = H5Screate_simple(ndim(fc), memshape, NULL);
-    H5Sselect_hyperslab(mspace, H5S_SELECT_SET, memoffset, NULL, count, NULL);
+    // these are dimensions of dataset, needed
+    // to create dataset
+    dims[0] = nz;
+    dims[1] = ny;
+    dims[2] = nx/2+1;
 
     /* open/create data set */
     if (!H5Lexists(file_id, field_name.c_str(), H5P_DEFAULT))
@@ -719,20 +706,46 @@ int field<rnumber, be, fc>::write_filtered(
                 H5P_DEFAULT,
                 H5P_DEFAULT);
     }
-    /* both dset_id and fspace now have sane values */
-
     /* check file space */
     int ndims_fspace = H5Sget_simple_extent_dims(fspace, fdims, NULL);
     assert(((unsigned int)(ndims_fspace)) == ndim(fc));
-
     for (unsigned int i=0; i<ndim(fc); i++)
     {
-        offset[i] = this->clayout->starts[i];
         assert(dims[i] == fdims[i]);
     }
-    H5Sselect_hyperslab(fspace, H5S_SELECT_SET, offset, NULL, count, NULL);
-    H5Dwrite(dset_id, this->cnumber_H5T, mspace, fspace, H5P_DEFAULT, this->data);
-    H5Sclose(mspace);
+    /* both dset_id and fspace now have sane values */
+
+    /// set up counts and offsets
+    /// x is easy, since only positive modes are present
+    count [2] = nx/2+1;
+    offset[2] = 0;
+    memshape [2] = this->clayout->subsizes[2];
+    memoffset[2] = 0;
+
+    /// now we need to visit the four corners of the data
+    for (int cy = 0; cy<2; cy++)
+    {
+        for (int cz = 0; cz < 2; cz++)
+        {
+            // for z, we need to take into account that there are
+            // both positive and negative modes
+            count [1] = nz/2;
+            offset[1] = cz*nz/2;
+            memshape [1] = this->clayout->sizes[1];
+            memoffset[1] = cz*(this->clayout->sizes[1] - nz/2);
+        }
+        count [0] = this->clayout->subsizes[0];
+        offset[0] = this->clayout->starts[0];
+        memshape [0] = this->clayout->subsizes[0];
+        memoffset[0] = 0;
+
+        //now write data
+        mspace = H5Screate_simple(ndim(fc), memshape, NULL);
+        H5Sselect_hyperslab(mspace, H5S_SELECT_SET, memoffset, NULL, count, NULL);
+        H5Sselect_hyperslab(fspace, H5S_SELECT_SET, offset, NULL, count, NULL);
+        H5Dwrite(dset_id, this->cnumber_H5T, mspace, fspace, H5P_DEFAULT, this->data);
+        H5Sclose(mspace);
+    }
 
 
     /* close file data space */
diff --git a/bfps/cpp/field.hpp b/bfps/cpp/field.hpp
index 861246a4b66f44b9813581feaddccb04f740be51..fe6f8975e63ad1acd766b26baa84aca20ef92cc2 100644
--- a/bfps/cpp/field.hpp
+++ b/bfps/cpp/field.hpp
@@ -107,7 +107,9 @@ class field
                 const std::string fname,
                 const std::string field_name,
                 const int iteration,
-                const int nx);
+                const int nx,
+                const int ny,
+                const int nz);
 
         int io_binary(
                 const std::string fname,