src/Python:
- file and step attributes added - all attribute i/o function have exactly 3 arguments now - string attributes are handled the same way as attributes of other type
This commit is contained in:
+24
-13
@@ -1,6 +1,9 @@
|
||||
%module H5hut
|
||||
%{
|
||||
#define SWIG_FILE_WITH_INIT
|
||||
#if defined(PARALLEL_IO)
|
||||
#include <mpi.h>
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
#include "h5core/h5_types.h"
|
||||
//#include "H5.h"
|
||||
@@ -28,6 +31,19 @@
|
||||
import_array();
|
||||
%}
|
||||
|
||||
#if defined (PARALLEL_IO)
|
||||
%include mpi4py/mpi4py.i
|
||||
%mpi4py_typemap(Comm, MPI_Comm);
|
||||
%typemap(in) MPI_Comm* {
|
||||
MPI_Comm *ptr = (MPI_Comm *)0;
|
||||
int res = SWIG_AsPtr_MPI_Comm($input, &ptr);
|
||||
if (!SWIG_IsOK(res) || !ptr) {
|
||||
SWIG_exception_fail(SWIG_ArgError((ptr ? res : SWIG_TypeError)), "in method '" "$symname" "', argument " "$argnum"" of type '" "MPI_Comm""'");
|
||||
}
|
||||
$1 = ptr;
|
||||
if (SWIG_IsNewObj(res)) free((char*)ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
%ignore h5_report_errorhandler;
|
||||
%ignore h5_abort_errorhandler;
|
||||
@@ -37,22 +53,17 @@ import_array();
|
||||
%ignore H5AbortErrorhandler;
|
||||
|
||||
%include "h5core/h5_types.h"
|
||||
//%include "H5.h"
|
||||
//%include "H5_attribs.h"
|
||||
|
||||
%include "H5_attachments.h"
|
||||
%include "H5_file.h"
|
||||
%include "H5_model.h"
|
||||
%include "H5hut.h"
|
||||
%include "H5_file_attribs.h"
|
||||
%include "H5_step_attribs.h"
|
||||
%include "H5_log.h"
|
||||
|
||||
%include "H5Block_attribs.h"
|
||||
//%include "H5Block.h"
|
||||
%include "H5Block_io.h"
|
||||
%include "H5Block_model.h"
|
||||
//%include "H5Part.h"
|
||||
|
||||
%include "H5Part_io.h"
|
||||
%include "H5Part_model.h"
|
||||
//%include "H5Fed_adjacency.h"
|
||||
//%include "H5Fed.h"
|
||||
//%include "H5Fed_model.h"
|
||||
//%include "H5Fed_retrieve.h"
|
||||
//%include "H5Fed_store.h"
|
||||
//%include "H5Fed_tags.h"
|
||||
|
||||
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
%module H5hut_mpi
|
||||
%{
|
||||
#define SWIG_FILE_WITH_INIT
|
||||
#define PARALLEL_IO 1
|
||||
#include <mpi.h>
|
||||
#include <stdint.h>
|
||||
#include "h5core/h5_types.h"
|
||||
//#include "H5.h"
|
||||
#include "H5hut.h"
|
||||
%}
|
||||
|
||||
%import <stdint.i>
|
||||
|
||||
%include numpy.i
|
||||
|
||||
%apply unsigned long int { h5_prop_t };
|
||||
%apply unsigned long int { h5_file_t };
|
||||
|
||||
|
||||
%apply (unsigned long long* IN_ARRAY1) { h5_size_t* };
|
||||
%apply (unsigned int* IN_ARRAY1) { h5_uint32_t* }; //uint32_t
|
||||
%apply (unsigned long long* IN_ARRAY1) { h5_uint64_t* }; //uint64_t
|
||||
%apply (int* IN_ARRAY1) { h5_int32_t* }; //int32_t
|
||||
%apply (long long* IN_ARRAY1) { h5_int64_t* }; //int64_t
|
||||
%apply (float* IN_ARRAY1) { h5_float32_t* };
|
||||
%apply (double* IN_ARRAY1) { h5_float64_t* };
|
||||
|
||||
|
||||
%init %{
|
||||
import_array();
|
||||
%}
|
||||
|
||||
%include mpi4py/mpi4py.i
|
||||
%mpi4py_typemap(Comm, MPI_Comm);
|
||||
%typemap(in) MPI_Comm* {
|
||||
MPI_Comm *ptr = (MPI_Comm *)0;
|
||||
int res = SWIG_AsPtr_MPI_Comm($input, &ptr);
|
||||
if (!SWIG_IsOK(res) || !ptr) {
|
||||
SWIG_exception_fail(SWIG_ArgError((ptr ? res : SWIG_TypeError)), "in method '" "$symname" "', argument " "$argnum"" of type '" "MPI_Comm""'");
|
||||
}
|
||||
$1 = ptr;
|
||||
if (SWIG_IsNewObj(res)) free((char*)ptr);
|
||||
}
|
||||
|
||||
%ignore h5_report_errorhandler;
|
||||
%ignore h5_abort_errorhandler;
|
||||
%ignore h5priv_vprintf;
|
||||
%ignore h5_verror;
|
||||
%ignore H5ReportErrorhandler;
|
||||
%ignore H5AbortErrorhandler;
|
||||
|
||||
%include "h5core/h5_types.h"
|
||||
//%include "H5.h"
|
||||
//%include "H5_attribs.h"
|
||||
%include "H5_model.h"
|
||||
%include "H5hut.h"
|
||||
%include "H5Block_attribs.h"
|
||||
//%include "H5Block.h"
|
||||
%include "H5Block_io.h"
|
||||
%include "H5Block_model.h"
|
||||
//%include "H5Part.h"
|
||||
%include "H5Part_io.h"
|
||||
%include "H5Part_model.h"
|
||||
//%include "H5Fed_adjacency.h"
|
||||
//%include "H5Fed.h"
|
||||
//%include "H5Fed_model.h"
|
||||
//%include "H5Fed_retrieve.h"
|
||||
//%include "H5Fed_store.h"
|
||||
//%include "H5Fed_tags.h"
|
||||
|
||||
|
||||
+7
-14
@@ -1,4 +1,3 @@
|
||||
|
||||
if ENABLE_PYTHON
|
||||
|
||||
BUILT_SOURCES = H5hut_wrap.c
|
||||
@@ -10,34 +9,28 @@ pkgpyexec_LTLIBRARIES = _H5hut.la
|
||||
_H5hut_la_SOURCES = H5hut_wrap.c $(SWIG_SOURCES)
|
||||
_H5hut_la_LDFLAGS = -module
|
||||
_H5hut_la_LIBADD = $(top_builddir)/src/h5core/libH5hut.la
|
||||
_H5hut_la_CPPFLAGS = $(SWIG_PYTHON_CPPFLAGS)
|
||||
_H5hut_la_CPPFLAGS += -I$(top_srcdir)/src/include
|
||||
_H5hut_la_CPPFLAGS += -I$(PYTHON_PREFIX)/include/python$(PYTHON_VERSION)/
|
||||
_H5hut_la_CPPFLAGS += -I$(NUMPY_INCLUDE)
|
||||
|
||||
if ENABLE_PARALLEL
|
||||
|
||||
#SWIG_SOURCES += $(MPI4PY_INCLUDE)/mpi4py/mpi4py.i
|
||||
|
||||
_H5hut_la_CPPFLAGS = -DPARALLEL_IO $(SWIG_PYTHON_CPPFLAGS) -I$(top_srcdir)/src/include -I$(PYTHON_PREFIX)/include/python$(PYTHON_VERSION)/ -I$(MPI4PY_INCLUDE) -I$(NUMPY_INCLUDE)
|
||||
_H5hut_la_CPPFLAGS += -DPARALLEL_IO -I$(MPI4PY_INCLUDE)
|
||||
|
||||
H5hut_wrap.c : $(SWIG_SOURCES)
|
||||
$(SWIG) $(SWIG_PYTHON_OPT) -python -DPARALLEL_IO -I$(top_srcdir)/src/include -I$(MPI4PY_INCLUDE) -o $@ $<
|
||||
$(SWIG) $(SWIG_PYTHON_OPT) -python -I$(top_srcdir)/src/include -DPARALLEL_IO -I$(MPI4PY_INCLUDE) -o $@ $<
|
||||
|
||||
else
|
||||
|
||||
|
||||
_H5hut_la_CPPFLAGS = $(SWIG_PYTHON_CPPFLAGS) -I$(top_srcdir)/src/include -I$(PYTHON_PREFIX)/include/python$(PYTHON_VERSION)/ -I$(NUMPY_INCLUDE)
|
||||
|
||||
H5hut_wrap.c : $(SWIG_SOURCES)
|
||||
$(SWIG) $(SWIG_PYTHON_OPT) -python -I$(top_srcdir)/src/include -o $@ $<
|
||||
|
||||
|
||||
endif
|
||||
|
||||
#all-local:
|
||||
# $(INSTALL) -d $(DESTDIR)/site-packages/h5hut
|
||||
# $(INSTALL) -m644 H5hut.py $(DESTDIR)/site-packages/h5hut/
|
||||
# $(INSTALL) -m644 .libs/_H5hut.so $(DESTDIR)/site-packages/h5hut/
|
||||
endif
|
||||
|
||||
clean: clean-am
|
||||
|
||||
clean-local:
|
||||
$(RM) -f *~ H5hut_wrap.c H5hut.py H5hut.pyc H5hut_mpi.pyc
|
||||
$(RM) -f *~ H5hut_wrap.c H5hut.py *.pyc
|
||||
|
||||
+46
-17
@@ -2,28 +2,52 @@
|
||||
|
||||
import numpy
|
||||
|
||||
try:
|
||||
import H5hut_mpi as H5hut_rewrite
|
||||
from H5hut_mpi import *
|
||||
except:
|
||||
import H5hut as H5hut_rewrite
|
||||
from H5hut import *
|
||||
import H5hut as H5hut_rewrite
|
||||
from H5hut import *
|
||||
|
||||
|
||||
__h5hut_table__ = {}
|
||||
|
||||
# for now assume last parameter is the data field..
|
||||
#
|
||||
# Rewrite functions for reading and writing datasets and attributes for
|
||||
# the types
|
||||
# - Int32
|
||||
# - Int64
|
||||
# - Float32
|
||||
# - Float64
|
||||
#
|
||||
# These functions have either three or four arguments:
|
||||
# - functions to read or write a dataset have three arguments
|
||||
# - functions to read an attribute have three arguments
|
||||
# - functions to write an attribute have four attributes (except the functions
|
||||
# to write a string attribute, which are not handled here)
|
||||
#
|
||||
# The third arguments is an array in all cases.
|
||||
#
|
||||
funcx = """
|
||||
def {0}(*args, **kwargs):
|
||||
import numpy
|
||||
if type(args[-1]) is numpy.ndarray:
|
||||
#print "writing type", args[-1].dtype
|
||||
__h5hut_table__['{0}'][args[-1].dtype](*args, **kwargs)
|
||||
elif ((type(args[-1]) is list or type(args[-1]) is tuple) and len(args[-1]) > 0):
|
||||
#print "writing type", type(args[-1][0]).dtype
|
||||
__h5hut_table__['{0}'][numpy.dtype(type(args[-1][0]))](*args, **kwargs)
|
||||
import numpy
|
||||
if not len(args) == 3:
|
||||
print 'wrong number of arguments'
|
||||
return -2
|
||||
|
||||
if type (args[2]) is numpy.ndarray:
|
||||
dtype = args[2].dtype
|
||||
size = args[2].size
|
||||
elif isinstance (args[2], (numpy.str)):
|
||||
dtype = numpy.str
|
||||
size = len (args[2])
|
||||
elif isinstance (args[2], (list, tuple)):
|
||||
dtype = numpy.dtype (type(args[2][0]))
|
||||
size = len (args[2])
|
||||
else:
|
||||
print 'last argument is not a numpy data array'
|
||||
print 'third argument must be an array'
|
||||
return -2
|
||||
|
||||
if 'Attrib' in '{0}' and 'Write' in '{0}' and not dtype == type(''):
|
||||
return __h5hut_table__['{0}'][dtype] (args[0], args[1], args[2], size, **kwargs)
|
||||
else:
|
||||
return __h5hut_table__['{0}'][dtype](*args, **kwargs)
|
||||
"""
|
||||
|
||||
def __update_types__():
|
||||
@@ -33,12 +57,17 @@ def __update_types__():
|
||||
|
||||
__h5hut_api__ = dir(H5hut_rewrite)
|
||||
|
||||
__h5hut_types__ = [ "Int32", "Int64", "Float32", "Float64" ]
|
||||
__h5hut_types__ = [ "Int32", "Int64", "Float32", "Float64", "String" ]
|
||||
__numpy_types__ = [ numpy.dtype(numpy.int32),
|
||||
numpy.dtype(numpy.int64),
|
||||
numpy.dtype(numpy.float32),
|
||||
numpy.dtype(numpy.float64) ]
|
||||
numpy.dtype(numpy.float64),
|
||||
numpy.str]
|
||||
|
||||
#
|
||||
# loop over all H5hut C-functions and above types.
|
||||
# Replace function if type is in name.
|
||||
#
|
||||
for __i__ in __h5hut_api__:
|
||||
for __j__ in __h5hut_types__:
|
||||
if __j__ in __i__:
|
||||
|
||||
Reference in New Issue
Block a user