#include "hdf5.h"

#define DIM0 200
#define DIM1 100

int main(void)
{
   hid_t file, data_space, dataset32, properties;
   float ff[DIM0][DIM1];
   float inff[DIM0][DIM1];
   hsize_t dims[2], chunk_size[2];
   int     chkrank, i, j;
   herr_t  status;

   unsigned szip_options_mask = H5_SZIP_NN_OPTION_MASK;
   unsigned szip_pixels_per_block = 16;

   for (i=0; i<DIM0; i++)
      for (j=0; j<DIM1; j++)
        ff[i][j]=0;
 
   /* Describe the size of the array */
   dims[0] = DIM0;
   dims[1] = DIM1;
   data_space = H5Screate_simple (2, dims, NULL);

  /*
   * Create a new file using with read/write access,
   * default file creation properties, and default file
   * access properties.
   */
  file = H5Fcreate ("szip.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

  /*
   * Set the dataset creation plist to specify that
   * the raw data is to be partitioned into 100x100 element
   * chunks and that each chunk is to be compressed.
   */
  chunk_size[0] = chunk_size[1] = 100;
  properties = H5Pcreate (H5P_DATASET_CREATE);
  chkrank = H5Pset_chunk (properties, 2, chunk_size);

  /*
   * Set up Szip compression, with the parameters set as above.
   */
  status = H5Pset_szip (properties, szip_options_mask, szip_pixels_per_block);

  /*
   * Create a new dataset within the file.  The datatype
   * and data space describe the data on disk, which may
   * be different than the format used in the application's
   * memory.
   */

  dataset32 = H5Dcreate (file, "datasetF32", H5T_NATIVE_FLOAT,
                       data_space, properties);


  /*
   * Write the array to the file.  The datatype and data
   * space describe the format of the data in the `dd'
   * buffer.  The raw data is translated to the format
   * required on disk defined above.  We use default raw
   * data transfer properties.
   */

  status = H5Dwrite (dataset32, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
                     H5P_DEFAULT, ff);


  /*
   * Read the array.  This is similar to writing
   * data except the data flows in the opposite direction.
   * Note:  the decompression is automatic.
   */

  status = H5Dread (dataset32, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
                    H5P_DEFAULT, inff);


  status = H5Dclose (dataset32);
  status = H5Sclose (data_space);
  status = H5Pclose (properties);
  status = H5Fclose (file);
}
