[cig-commits] r7515 - in cs/cigma/branches/cigma-0.9/sandbox: . hdf5 sqlite

luis at geodynamics.org luis at geodynamics.org
Tue Jun 26 10:12:03 PDT 2007


Author: luis
Date: 2007-06-26 10:12:02 -0700 (Tue, 26 Jun 2007)
New Revision: 7515

Added:
   cs/cigma/branches/cigma-0.9/sandbox/hdf5/
   cs/cigma/branches/cigma-0.9/sandbox/hdf5/Makefile
   cs/cigma/branches/cigma-0.9/sandbox/hdf5/README
   cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_crtatt.c
   cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_crtdat.c
   cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_iterate.c
   cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_mount.c
   cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_rdwt.c
Modified:
   cs/cigma/branches/cigma-0.9/sandbox/sqlite/Makefile
Log:
darcs patches:
  * Added a few relevant examples for using the HDF5 C API
  * Updated makefile for sqlite example in sandbox
  - Removed linker flags from CFLAGS since they're unnecessary for the static build



Added: cs/cigma/branches/cigma-0.9/sandbox/hdf5/Makefile
===================================================================
--- cs/cigma/branches/cigma-0.9/sandbox/hdf5/Makefile	2007-06-26 17:10:18 UTC (rev 7514)
+++ cs/cigma/branches/cigma-0.9/sandbox/hdf5/Makefile	2007-06-26 17:12:02 UTC (rev 7515)
@@ -0,0 +1,27 @@
+HDF5_HOME = /usr
+
+CC = gcc
+CFLAGS = -Wall -g -UNDEBUG
+INCLUDES = -I$(HDF5_HOME)/include
+LIBS = -lhdf5
+
+
+TARGETS = \
+	h5_mount \
+	h5_iterate \
+	h5_crtdat \
+	h5_crtatt \
+	h5_rdwt
+
+all: $(TARGETS)
+
+.c:
+	$(CC) $(CFLAGS) $(INCLUDES) $< $(LIBS) -o $@
+
+clean:
+	rm -f $(TARGETS)
+
+clean-all: clean
+	rm -f *.h5
+
+.PHONY: clean clean-all

Added: cs/cigma/branches/cigma-0.9/sandbox/hdf5/README
===================================================================
--- cs/cigma/branches/cigma-0.9/sandbox/hdf5/README	2007-06-26 17:10:18 UTC (rev 7514)
+++ cs/cigma/branches/cigma-0.9/sandbox/hdf5/README	2007-06-26 17:12:02 UTC (rev 7515)
@@ -0,0 +1 @@
+Some relevant examples from http://hdf.ncsa.uiuc.edu/HDF5/Tutor/

Added: cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_crtatt.c
===================================================================
--- cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_crtatt.c	2007-06-26 17:10:18 UTC (rev 7514)
+++ cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_crtatt.c	2007-06-26 17:12:02 UTC (rev 7515)
@@ -0,0 +1,46 @@
+/*
+ *   Creating a dataset attribute.
+ */
+
+#include "hdf5.h"
+#define FILE "dset.h5"
+
+int main() {
+
+   hid_t       file_id, dataset_id, attribute_id, dataspace_id;  /* identifiers */
+   hsize_t     dims;
+   int         attr_data[2];
+   herr_t      status;
+
+   /* Initialize the attribute data. */
+   attr_data[0] = 100;
+   attr_data[1] = 200;
+
+   /* Open an existing file. */
+   file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
+
+   /* Open an existing dataset. */
+   dataset_id = H5Dopen(file_id, "/dset");
+
+   /* Create the data space for the attribute. */
+   dims = 2;
+   dataspace_id = H5Screate_simple(1, &dims, NULL);
+
+   /* Create a dataset attribute. */
+   attribute_id = H5Acreate(dataset_id, "Units", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT);
+
+   /* Write the attribute data. */
+   status = H5Awrite(attribute_id, H5T_NATIVE_INT, attr_data);
+
+   /* Close the attribute. */
+   status = H5Aclose(attribute_id);
+
+   /* Close the dataspace. */
+   status = H5Sclose(dataspace_id);
+
+   /* Close to the dataset. */
+   status = H5Dclose(dataset_id);
+
+   /* Close the file. */
+   status = H5Fclose(file_id);
+}

Added: cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_crtdat.c
===================================================================
--- cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_crtdat.c	2007-06-26 17:10:18 UTC (rev 7514)
+++ cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_crtdat.c	2007-06-26 17:12:02 UTC (rev 7515)
@@ -0,0 +1,34 @@
+/*
+ *   Creating and closing a dataset.
+ */
+
+#include "hdf5.h"
+#define FILE "dset.h5"
+
+int main() {
+
+   hid_t       file_id, dataset_id, dataspace_id;  /* identifiers */
+   hsize_t     dims[2];
+   herr_t      status;
+
+   /* Create a new file using default properties. */
+   file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+   /* Create the data space for the dataset. */
+   dims[0] = 4; 
+   dims[1] = 6; 
+   dataspace_id = H5Screate_simple(2, dims, NULL);
+
+   /* Create the dataset. */
+   dataset_id = H5Dcreate(file_id, "/dset", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT);
+
+   /* End access to the dataset and release resources used by it. */
+   status = H5Dclose(dataset_id);
+
+   /* Terminate access to the data space. */ 
+   status = H5Sclose(dataspace_id);
+
+   /* Close the file. */
+   status = H5Fclose(file_id);
+}
+

Added: cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_iterate.c
===================================================================
--- cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_iterate.c	2007-06-26 17:10:18 UTC (rev 7514)
+++ cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_iterate.c	2007-06-26 17:12:02 UTC (rev 7515)
@@ -0,0 +1,105 @@
+#include "hdf5.h"
+
+#define FILENAME "iterate.h5"
+#define FALSE 0
+
+/* 1-D dataset with fixed dimensions */
+#define SPACE1_NAME "Space1"
+#define SPACE1_RANK 1
+#define SPACE1_DIM1 4
+
+/* operator function */
+herr_t file_info(hid_t loc_id, const char *name, void *opdata);
+
+
+int main(void)
+{
+    hid_t file;     /* HDF5 File ID */
+    hid_t dataset;  /* Dataset ID */
+    hid_t group;    /* Group ID */
+    hid_t sid;      /* Dataspace ID */
+    hid_t tid;      /* Datatype ID */
+    hsize_t dims[] = {SPACE1_DIM1};
+    herr_t ret;     /* Generic return value */
+
+    /* Compound datatype */
+    typedef struct s1_t {
+        unsigned int a;
+        unsigned int b;
+        float c;
+    } s1_t;
+
+    /* Create file */
+    file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+    /* Create dataspace for datasets */
+    sid = H5Screate_simple(SPACE1_RANK, dims, NULL);
+
+    /* Create a group */
+    group = H5Gcreate(file, "Group1", -1);
+
+    /* Close a group */
+    ret = H5Gclose(group);
+
+    /* Create a dataset */
+    dataset = H5Dcreate(file, "Dataset1", H5T_STD_U32LE, sid, H5P_DEFAULT);
+
+    /* Close dataset */
+    ret = H5Dclose(dataset);
+
+    /* Create a datatype */
+    tid = H5Tcreate(H5T_COMPOUND, sizeof(s1_t));
+
+    /* Insert fields */
+    ret = H5Tinsert(tid, "a", HOFFSET(s1_t,a), H5T_NATIVE_INT);
+    ret = H5Tinsert(tid, "b", HOFFSET(s1_t,b), H5T_NATIVE_INT);
+    ret = H5Tinsert(tid, "c", HOFFSET(s1_t,c), H5T_NATIVE_FLOAT);
+
+    /* Save datatype for later */
+    ret = H5Tcommit(file, "Datatype1", tid);
+
+    /* Close datatype */
+    ret = H5Tclose(tid);
+
+
+    /* Iterate through the file to see members of the root group */
+    printf(" Objects in the root group are:\n\n");
+    H5Giterate(file, "/", NULL, file_info, NULL);
+
+    /* Close file */
+    ret = H5Fclose(file);
+
+    return 0;
+}
+
+
+/*
+ * Operator function.
+ */
+herr_t file_info(hid_t loc_id, const char *name, void *opdata)
+{
+    H5G_stat_t statbuf;
+
+    /*
+     * Get type of the object and display its name and type.
+     * The name of the object is passed to this function by
+     * the Library. Some magic :-)
+     */
+    H5Gget_objinfo(loc_id, name, FALSE, &statbuf);
+    switch (statbuf.type)
+    {
+    case H5G_GROUP:
+        printf(" Object with name %s is a group\n", name);
+        break;
+    case H5G_DATASET:
+        printf(" Object with name %s is a dataset\n", name);
+        break;
+    case H5G_TYPE:
+        printf(" Object with name %s is a named datatype\n", name);
+        break;
+    default:
+        printf(" Unable to identify an object");
+    }
+
+    return 0;
+}

Added: cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_mount.c
===================================================================
--- cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_mount.c	2007-06-26 17:10:18 UTC (rev 7514)
+++ cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_mount.c	2007-06-26 17:12:02 UTC (rev 7515)
@@ -0,0 +1,123 @@
+
+/* This program shows the concept of "mounting files".
+ * Program creates one file with group G in it, and another
+ * file with dataset D. Then second file is mounted in the first one
+ * under the "mounting point" G. Dataset D is accessed in the first file
+ * under name /G/D and data is printed out.
+ *
+ * http://hdf.ncsa.uiuc.edu/HDF5/Tutor/examples/C/h5_mount.c
+ */
+
+#include "hdf5.h"
+
+#define FILE1 "mount1.h5"
+#define FILE2 "mount2.h5"
+
+#define RANK 2
+#define NX 4
+#define NY 5
+
+int main(void)
+{
+    hid_t fid1, fid2, gid;  /* Files and group identifiers */
+    hid_t did, tid, sid;    /* Dataset and datatype identifiers */
+
+    herr_t status;
+    hsize_t dims[] = {NX,NY};   /* Dataset dimensions */
+
+    int i,j;
+    int bm[NX][NY], bm_out[NX][NY];     /* Data buffers */
+
+    /*
+     * Initialization of buffer matrix "bm"
+     */
+    for (i = 0; i < NX; i++)
+    {
+        for (j = 0; j < NY; j++)
+        {
+            bm[i][j] = i + j;
+        }
+    }
+
+    /* 
+     * Create first file and a group in it.
+     */
+    fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+    gid = H5Gcreate(fid1, "/G", 0);
+
+    /*
+     * Close group and file
+     */
+    H5Gclose(gid);
+    H5Fclose(fid1);
+
+    /*
+     * Create second file and dataset "D" in it."
+     */
+    fid2 = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+    dims[0] = NX;
+    dims[1] = NY;
+    sid = H5Screate_simple(RANK, dims, NULL);
+    did = H5Dcreate(fid2, "D", H5T_NATIVE_INT, sid, H5P_DEFAULT);
+
+    /*
+     * Write data to the dataset.
+     */
+    status = H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, bm);
+
+    /*
+     * Close all identifiers.
+     */
+    H5Sclose(sid);
+    H5Dclose(did);
+    H5Fclose(fid2);
+
+    /* 
+     * Reopen both files
+     */
+    fid1 = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT);
+    fid2 = H5Fopen(FILE2, H5F_ACC_RDONLY, H5P_DEFAULT);
+
+    /*
+     * Mount second file under G in the first file.
+     */
+    H5Fmount(fid1, "/G", fid2, H5P_DEFAULT);
+
+    /*
+     * Access dataset D in the first file under /G/D name
+     */
+    did = H5Dopen(fid1, "/G/D");
+    tid = H5Dget_type(did);
+    status = H5Dread(did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, bm_out);
+
+    /*
+     * Print out the data.
+     */
+    for (i = 0; i < NX; i++)
+    {
+        for (j = 0; j < NY; j++)
+        {
+            printf("  %d", bm_out[i][j]);
+        }
+        printf("\n");
+    }
+
+    /*
+     * Close all identifiers
+     */
+    H5Tclose(tid);
+    H5Dclose(did);
+
+    /*
+     * Unmounting second file
+     */
+    H5Funmount(fid1, "/G");
+
+    /*
+     * Close both files
+     */
+    H5Fclose(fid1);
+    H5Fclose(fid2);
+
+    return 0;
+}

Added: cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_rdwt.c
===================================================================
--- cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_rdwt.c	2007-06-26 17:10:18 UTC (rev 7514)
+++ cs/cigma/branches/cigma-0.9/sandbox/hdf5/h5_rdwt.c	2007-06-26 17:12:02 UTC (rev 7515)
@@ -0,0 +1,37 @@
+/* 
+ *   Writing and reading an existing dataset.
+ */
+
+#include "hdf5.h"
+#define FILE "dset.h5"
+
+int main() {
+
+   hid_t       file_id, dataset_id;  /* identifiers */
+   herr_t      status;
+   int         i, j, dset_data[4][6];
+
+   /* Initialize the dataset. */
+   for (i = 0; i < 4; i++)
+      for (j = 0; j < 6; j++)
+         dset_data[i][j] = i * 6 + j + 1;
+
+   /* Open an existing file. */
+   file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
+
+   /* Open an existing dataset. */
+   dataset_id = H5Dopen(file_id, "/dset");
+
+   /* Write the dataset. */
+   status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, 
+                     dset_data);
+
+   status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, 
+                    dset_data);
+
+   /* Close the dataset. */
+   status = H5Dclose(dataset_id);
+
+   /* Close the file. */
+   status = H5Fclose(file_id);
+}

Modified: cs/cigma/branches/cigma-0.9/sandbox/sqlite/Makefile
===================================================================
--- cs/cigma/branches/cigma-0.9/sandbox/sqlite/Makefile	2007-06-26 17:10:18 UTC (rev 7514)
+++ cs/cigma/branches/cigma-0.9/sandbox/sqlite/Makefile	2007-06-26 17:12:02 UTC (rev 7515)
@@ -21,7 +21,7 @@
 STATICLIBS += /usr/lib/libpthread.a
 STATICLIBS += /usr/lib/libdl.a
 
-CFLAGS = -Wall $(INCLUDES) $(LIBRARIES) $(LDFLAGS) $(LIBS)
+CFLAGS = -Wall $(INCLUDES) $(LIBRARIES)
 
 
 #############################################################################
@@ -29,7 +29,7 @@
 all: $(TARGETS)
 
 ex: ex.c
-	$(CC) $(CFLAGS) $^ -o $@
+	$(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) $^ -o $@
 
 ex-static: ex.c
 	$(CC) -static $(CFLAGS) $^ $(STATICLIBS) -o $@



More information about the cig-commits mailing list