|
@@ -0,0 +1,100 @@
|
|
|
+#include <glib.h>
|
|
|
+#include <hdf5.h>
|
|
|
+
|
|
|
+
|
|
|
+static const int WIDTH = 2048;
|
|
|
+static const int HEIGHT = 1024;
|
|
|
+static const int N_DARKS = 10;
|
|
|
+static const int N_FLATS = 10;
|
|
|
+static const int N_PROJS = 100;
|
|
|
+
|
|
|
+
|
|
|
+static void
|
|
|
+write_dataset (hid_t file, const char *name, const float *data, int n_items)
|
|
|
+{
|
|
|
+ GTimer *timer;
|
|
|
+ hid_t datatype;
|
|
|
+ hid_t dataspace;
|
|
|
+ hid_t dataset;
|
|
|
+ hsize_t dims[3];
|
|
|
+
|
|
|
+ timer = g_timer_new ();
|
|
|
+
|
|
|
+ dims[0] = WIDTH;
|
|
|
+ dims[1] = HEIGHT;
|
|
|
+ dims[2] = n_items;
|
|
|
+
|
|
|
+ datatype = H5Tcopy (H5T_NATIVE_FLOAT);
|
|
|
+
|
|
|
+ g_timer_start (timer);
|
|
|
+ dataspace = H5Screate_simple (3, dims, NULL);
|
|
|
+ g_timer_stop (timer);
|
|
|
+ g_print (" H5Screate_simple: %3.5fs\n", g_timer_elapsed(timer, NULL));
|
|
|
+
|
|
|
+ g_timer_start (timer);
|
|
|
+ dataset = H5Dcreate (file, name, datatype, dataspace, H5P_DEFAULT);
|
|
|
+ g_timer_stop (timer);
|
|
|
+ g_print (" H5Dcreate: %3.5fs\n", g_timer_elapsed(timer, NULL));
|
|
|
+
|
|
|
+ g_timer_start (timer);
|
|
|
+ H5Dwrite (dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
|
|
|
+ g_timer_stop (timer);
|
|
|
+ g_print (" H5Dwrite: %3.5fs\n", g_timer_elapsed(timer, NULL));
|
|
|
+
|
|
|
+ H5Sclose (dataspace);
|
|
|
+ H5Dclose (dataset);
|
|
|
+ H5Tclose (datatype);
|
|
|
+ g_timer_destroy (timer);
|
|
|
+}
|
|
|
+
|
|
|
+static void
|
|
|
+create_individual_data_sets (hid_t file, const float *data)
|
|
|
+{
|
|
|
+ write_dataset (file, "projs", data, N_PROJS);
|
|
|
+ write_dataset (file, "darks", data, N_DARKS);
|
|
|
+ write_dataset (file, "flats", data, N_FLATS);
|
|
|
+}
|
|
|
+
|
|
|
+static void
|
|
|
+create_single_dataset (hid_t file, const float *data)
|
|
|
+{
|
|
|
+ write_dataset (file, "all", data, N_DARKS + N_FLATS + N_PROJS);
|
|
|
+}
|
|
|
+
|
|
|
+static void
|
|
|
+run (void (*func)(hid_t, const float *), const char *fname, const float *data)
|
|
|
+{
|
|
|
+ hid_t file;
|
|
|
+ GTimer *timer;
|
|
|
+
|
|
|
+ timer = g_timer_new ();
|
|
|
+
|
|
|
+ g_timer_start (timer);
|
|
|
+ file = H5Fcreate (fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
|
|
+
|
|
|
+ func (file, data);
|
|
|
+
|
|
|
+ H5Fflush (file, H5F_SCOPE_GLOBAL);
|
|
|
+ H5Fclose (file);
|
|
|
+
|
|
|
+ g_timer_stop (timer);
|
|
|
+ g_print (" Total: %3.5fs\n", g_timer_elapsed (timer, NULL));
|
|
|
+ g_timer_destroy (timer);
|
|
|
+}
|
|
|
+
|
|
|
+int
|
|
|
+main (int argc, char const* argv[])
|
|
|
+{
|
|
|
+ float *data;
|
|
|
+
|
|
|
+ data = g_malloc (sizeof(float) * WIDTH * HEIGHT * (N_DARKS + N_FLATS + N_PROJS));
|
|
|
+
|
|
|
+ g_print ("Single data set\n");
|
|
|
+ run (create_single_dataset, "bar.h5", data);
|
|
|
+
|
|
|
+ g_print ("\nIndividual data sets\n");
|
|
|
+ run (create_individual_data_sets, "foo.h5", data);
|
|
|
+
|
|
|
+ g_free (data);
|
|
|
+ return 0;
|
|
|
+}
|