[cig-commits] r3838 - mc/3D/CitcomCU/branches/v1.1/sandbox/hdf5

luis at geodynamics.org luis at geodynamics.org
Wed Jun 21 12:14:00 PDT 2006


Author: luis
Date: 2006-06-21 12:14:00 -0700 (Wed, 21 Jun 2006)
New Revision: 3838

Added:
   mc/3D/CitcomCU/branches/v1.1/sandbox/hdf5/3d-array.c
   mc/3D/CitcomCU/branches/v1.1/sandbox/hdf5/3d-array.py
Modified:
   mc/3D/CitcomCU/branches/v1.1/sandbox/hdf5/Makefile
Log:
Added test programs to create a 3D array both in C and in python.


Added: mc/3D/CitcomCU/branches/v1.1/sandbox/hdf5/3d-array.c
===================================================================
--- mc/3D/CitcomCU/branches/v1.1/sandbox/hdf5/3d-array.c	2006-06-21 18:45:25 UTC (rev 3837)
+++ mc/3D/CitcomCU/branches/v1.1/sandbox/hdf5/3d-array.c	2006-06-21 19:14:00 UTC (rev 3838)
@@ -0,0 +1,69 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <hdf5.h>
+#include "pytables.h"
+
+int main(int argc, char *argv[])
+{
+    hid_t file;
+    hid_t root;
+    hid_t box_dset;
+
+    int rank;
+    hsize_t dims[3];
+
+    int i,j,k;
+    int n, nno;
+    float *data;
+
+    herr_t status;
+
+    /* open file */
+    file = H5Fcreate("3d-array1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+    /* open root group */
+    root = H5Gopen(file, "/");
+
+    /* root attributes */
+    set_attribute_string(root, "TITLE", "pytables Numeric array!");
+    set_attribute_string(root, "CLASS", "GROUP");
+    set_attribute_string(root, "VERSION", "1.0");
+    set_attribute_string(root, "FILTERS", FILTERS_P);
+    set_attribute_string(root, "PYTABLES_FORMAT_VERSION", "1.5");
+
+    /* array of shape (5,6,2) */
+    rank = 3;
+    dims[0] = 5;
+    dims[1] = 6;
+    dims[2] = 7;
+    nno = dims[0]*dims[1]*dims[2];
+
+    /* data */
+    n = 0;
+    data = (float *)malloc(nno*sizeof(float));
+    for(j = 0; j < dims[1]; j++)
+    {
+        for(i = 0; i < dims[0]; i++)
+        {
+            for(k = 0; k < dims[2]; k++)
+            {
+                data[i*dims[2]*dims[1] + j*dims[2] + k] = (float)n;
+                n++;
+            }
+        }
+    }
+
+    /* write data */
+    box_dset = make_array(root, "box", rank, dims, H5T_NATIVE_FLOAT, data);
+
+    /* free memory */
+    free(data);
+
+    /* close root group */
+    status = H5Gclose(root);
+
+    /* close file */
+    status = H5Fclose(file);
+
+    return EXIT_SUCCESS;
+}

Added: mc/3D/CitcomCU/branches/v1.1/sandbox/hdf5/3d-array.py
===================================================================
--- mc/3D/CitcomCU/branches/v1.1/sandbox/hdf5/3d-array.py	2006-06-21 18:45:25 UTC (rev 3837)
+++ mc/3D/CitcomCU/branches/v1.1/sandbox/hdf5/3d-array.py	2006-06-21 19:14:00 UTC (rev 3838)
@@ -0,0 +1,21 @@
+import Numeric
+import tables
+
+def traversal(nx,ny,nz):
+    n = 0
+    for y in xrange(ny):
+        for x in xrange(nx):
+            for z in xrange(nz):
+                yield n, x, y, z
+                n += 1
+
+file = tables.openFile('3d-array2.h5', mode='w', 
+                       title='pytables Numeric array!')
+
+box = Numeric.zeros((5,6,2), typecode=Numeric.Float)
+
+for n,x,y,z in traversal(5,6,2):
+    box[x,y,z] = n
+
+file.createArray(file.root, 'box', box, title='Box array!')
+file.close()

Modified: mc/3D/CitcomCU/branches/v1.1/sandbox/hdf5/Makefile
===================================================================
--- mc/3D/CitcomCU/branches/v1.1/sandbox/hdf5/Makefile	2006-06-21 18:45:25 UTC (rev 3837)
+++ mc/3D/CitcomCU/branches/v1.1/sandbox/hdf5/Makefile	2006-06-21 19:14:00 UTC (rev 3838)
@@ -6,3 +6,6 @@
 
 2d-array: 2d-array.c pytables.o
 	gcc $^ -o $@ -lhdf5
+
+3d-array: 3d-array.c pytables.o
+	gcc $^ -o $@ -lhdf5



More information about the Cig-commits mailing list