[cig-commits] r6825 - in cs/cigma/trunk: include/cigma src

luis at geodynamics.org luis at geodynamics.org
Wed May 9 17:18:13 PDT 2007


Author: luis
Date: 2007-05-09 17:18:13 -0700 (Wed, 09 May 2007)
New Revision: 6825

Added:
   cs/cigma/trunk/include/cigma/points.h
   cs/cigma/trunk/src/points.c
Log:
Initial implementation of "point" field concept


Added: cs/cigma/trunk/include/cigma/points.h
===================================================================
--- cs/cigma/trunk/include/cigma/points.h	2007-05-10 00:17:10 UTC (rev 6824)
+++ cs/cigma/trunk/include/cigma/points.h	2007-05-10 00:18:13 UTC (rev 6825)
@@ -0,0 +1,32 @@
+#ifndef __CIGMA_POINTS_H__
+#define __CIGMA_POINTS_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <hdf5.h>
+
+
+typedef struct {
+    int nel;        // number of elements
+    int npts;       // number of points
+    int ndim;       // number of dimensions (or components)
+    hid_t dset;     // dataset view
+    double *x;      // [nel x npts x nsd] matrix -- point data
+} points_t;
+
+
+//int points_init(points_t *points, const char *filename, const char *path);
+int points_init_h5(points_t *points, hid_t loc_id, const char *name);
+int points_free(points_t *points);
+
+int points_read(points_t *points, int start, int end);
+int points_write(points_t *points, int start, int end);
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif

Added: cs/cigma/trunk/src/points.c
===================================================================
--- cs/cigma/trunk/src/points.c	2007-05-10 00:17:10 UTC (rev 6824)
+++ cs/cigma/trunk/src/points.c	2007-05-10 00:18:13 UTC (rev 6825)
@@ -0,0 +1,104 @@
+#include <stdlib.h>
+#include <hdf5.h>
+#include <cigma/array.h>
+#include <cigma/points.h>
+
+int points_init_h5(points_t *points, hid_t loc_id, const char *name)
+{
+    array_t a;
+    
+    points->nel = 0;
+    points->npts = 0;
+    points->ndim = 0;
+    points->x = NULL;
+
+    array_init(&a, H5T_NATIVE_DOUBLE, 3, NULL, NULL);
+    array_dims3(&a, &(points->nel), &(points->npts), &(points->ndim));
+
+    points->dset = array_open(&a, loc_id, name);
+    if (points->dset < 0)
+    {
+        array_free_dims(&a);
+        return -1;
+    }
+
+    array_free_dims(&a);
+    return 0;
+}
+
+
+int points_free(points_t *points)
+{
+    if (points->dset >= 0)
+        H5Dclose(points->dset);
+
+    if (points->x != NULL)
+        free(points->x);
+
+    points->nel  = 0;
+    points->npts = 0;
+    points->ndim = 0;
+
+    return 0;
+}
+
+
+
+int points_read(points_t *points, int start, int end)
+{
+    array_t a;
+    int shape[3];
+    int ierr;
+
+    shape[0] = points->nel;
+    shape[1] = points->npts;
+    shape[2] = points->ndim;
+
+    array_init(&a, H5T_NATIVE_DOUBLE, 3, shape, NULL);
+
+    ierr = array_slice_read(&a, points->dset, start, end);
+    if (ierr < 0)
+    {
+        array_free_dims(&a);
+        return -1;
+    }
+
+    if (a.data == NULL)
+    {
+        array_free_dims(&a);
+        return -2;
+    }
+
+    points->x = (double *) a.data;
+
+    array_free_dims(&a);
+    return 0;
+}
+
+int points_write(points_t *points, int start, int end)
+{
+    array_t a;
+    int shape[3];
+    int ierr;
+
+    shape[0] = points->nel;
+    shape[1] = points->npts;
+    shape[2] = points->ndim;
+
+    if (points->x == NULL)
+    {
+        return -1;
+    }
+
+    array_init(&a, H5T_NATIVE_DOUBLE, 3, shape, (void *)points->x);
+
+    ierr = array_slice_write(&a, points->dset, start, end);
+    if (ierr < 0)
+    {
+        array_free_dims(&a);
+        return -2;
+    }
+
+    array_free_dims(&a);
+    return 0;
+}



More information about the cig-commits mailing list