[h5py] 20/455: h5f additions
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:13 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.
commit e6dfc05d3f5f3316ad11bf1d8eb3c1ae4900211d
Author: andrewcollette <andrew.collette at gmail.com>
Date: Thu May 15 23:54:51 2008 +0000
h5f additions
---
README.txt | 26 ++++-----
h5py/defs_c.pxd | 6 +++
h5py/h5f.pxd | 29 ++++++++++-
h5py/h5f.pyx | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 206 insertions(+), 14 deletions(-)
diff --git a/README.txt b/README.txt
index 04b2063..7e02851 100644
--- a/README.txt
+++ b/README.txt
@@ -1,11 +1,22 @@
README for the "h5py" Python/HDF5 interface
===========================================
Copyright (c) 2008 Andrew Collette
-http://h5py.alfven.org
-mail: "h5py" at the domain "alfven dot org"
+* http://h5py.alfven.org
+* mail: "h5py" at the domain "alfven dot org"
Version 0.1.1
+Introduction
+============
+
+The h5py package provides both a high- and low-level interface to the
+`NCSA HDF5 library`__ from Python. The low-level interface is
+intended to be a complete wrapping of the HDF5 1.6 API, while the high-
+level component supports Python-style object-oriented access to HDF5 files,
+datasets and groups.
+
+__ http://hdf.ncsa.uiuc.edu
+
DISCLAIMER
==========
@@ -23,15 +34,6 @@ Contents
* `High-level interface`_
* `Low-level interface`_
-Introduction
-============
-
-The h5py package provides both a high- and low-level interface to the NCSA
-HDF5 library (hdf.ncsa.uiuc.edu) from Python. The low-level interface is
-intended to be a complete wrapping of the HDF5 1.6 API, while the high-
-level component supports Python-style object-oriented access to HDF5 files,
-datasets and groups.
-
Documentation
-------------
Extensive documentation is available through docstrings, as well as in
@@ -62,7 +64,7 @@ Features
H5E Errors Python exceptions
===== ============== =================
- See the section "Low-level interface" below for a better overview.
+ See the section `Low-level interface`_ below for a better overview.
- Calls that fail will raise exceptions; no more checking return values.
Wrapper functions have been carefully designed to provide a Pythonic
diff --git a/h5py/defs_c.pxd b/h5py/defs_c.pxd
index 5d0b2ba..69a7793 100644
--- a/h5py/defs_c.pxd
+++ b/h5py/defs_c.pxd
@@ -31,3 +31,9 @@ cdef extern from "string.h":
cdef extern from "time.h":
ctypedef int time_t
+
+cdef extern from "unistd.h":
+ ctypedef long ssize_t
+
+
+
diff --git a/h5py/h5f.pxd b/h5py/h5f.pxd
index f11b118..f405a5f 100644
--- a/h5py/h5f.pxd
+++ b/h5py/h5f.pxd
@@ -14,7 +14,7 @@
# license is available at licenses/pytables.txt, in the distribution root
# directory.
-from defs_c cimport size_t, time_t
+from defs_c cimport size_t, time_t, ssize_t
from h5 cimport hid_t, hbool_t, herr_t, htri_t, hsize_t, hssize_t, hvl_t
cdef extern from "hdf5.h":
@@ -35,6 +35,14 @@ cdef extern from "hdf5.h":
H5F_CLOSE_STRONG = 2,
H5F_CLOSE_DEFAULT = 3
+ int H5F_OBJ_FILE
+ int H5F_OBJ_DATASET
+ int H5F_OBJ_GROUP
+ int H5F_OBJ_DATATYPE
+ int H5F_OBJ_ATTR
+ int H5F_OBJ_ALL
+ int H5F_OBJ_LOCAL
+
# --- File operations -------------------------------------------------------
hid_t H5Fcreate(char *filename, unsigned int flags,
hid_t create_plist, hid_t access_plist)
@@ -43,4 +51,23 @@ cdef extern from "hdf5.h":
htri_t H5Fis_hdf5(char *name)
herr_t H5Fflush(hid_t object_id, H5F_scope_t scope)
+ hid_t H5Freopen(hid_t file_id)
+ herr_t H5Fmount(hid_t loc_id, char *name, hid_t child_id, hid_t plist_id)
+ herr_t H5Funmount(hid_t loc_id, char *name)
+ herr_t H5Fget_filesize(hid_t file_id, hsize_t *size)
+ hid_t H5Fget_create_plist(hid_t file_id )
+ hid_t H5Fget_access_plist(hid_t file_id)
+ hssize_t H5Fget_freespace(hid_t file_id)
+ ssize_t H5Fget_name(hid_t obj_id, char *name, size_t size)
+ int H5Fget_obj_count(hid_t file_id, unsigned int types)
+ int H5Fget_obj_ids(hid_t file_id, unsigned int types, int max_objs, hid_t *obj_id_list)
+
+
+
+
+
+
+
+
+
diff --git a/h5py/h5f.pyx b/h5py/h5f.pyx
index aee1835..1050c7d 100644
--- a/h5py/h5f.pyx
+++ b/h5py/h5f.pyx
@@ -17,7 +17,8 @@
"""
# Pyrex compile-time imports
-from h5 cimport herr_t, hid_t, htri_t
+from defs_c cimport malloc, free
+from h5 cimport herr_t, hid_t, htri_t, hssize_t
from h5p cimport H5P_DEFAULT
# Runtime imports
@@ -48,6 +49,18 @@ CLOSE_MAPPER = {H5F_CLOSE_WEAK: 'WEAK', H5F_CLOSE_SEMI: 'SEMI',
H5F_CLOSE_STRONG: 'STRONG', H5F_CLOSE_DEFAULT: 'DEFAULT'}
CLOSE_MAPPER = DDict(CLOSE_MAPPER)
+OBJ_FILE = H5F_OBJ_FILE
+OBJ_DATASET = H5F_OBJ_DATASET
+OBJ_GROUP = H5F_OBJ_GROUP
+OBJ_DATATYPE = H5F_OBJ_DATATYPE
+OBJ_ATTR = H5F_OBJ_ATTR
+OBJ_ALL = H5F_OBJ_ALL
+OBJ_LOCAL = H5F_OBJ_LOCAL
+OBJ_MAPPER = {H5F_OBJ_FILE: 'FILE', H5F_OBJ_DATASET: 'DATASET',
+ H5F_OBJ_GROUP: 'GROUP', H5F_OBJ_DATATYPE: 'DATATYPE',
+ H5F_OBJ_ATTR: 'ATTRIBUTE', H5F_OBJ_ALL: 'ALL', H5F_OBJ_LOCAL: 'LOCAL'}
+OBJ_MAPPER = DDict(OBJ_MAPPER)
+
# === File operations =========================================================
def open(char* name, unsigned int flags=H5F_ACC_RDWR, hid_t access_id=H5P_DEFAULT):
@@ -114,8 +127,152 @@ def is_hdf5(char* name):
raise FileError("Can't determine status of file '%s'" % name)
return bool(retval)
+def reopen(hid_t file_id):
+ """ (INT file_id) => INT new_file_id
+
+ Retrieve another identifier for a file (which must still be open).
+ """
+ cdef hid_t retval
+ retval = H5Freopen(file_id)
+ if retval < 0:
+ raise FileError("Faile to re-open file %d" % file_id)
+ return retval
+
+def mount(hid_t loc_id, char* name, hid_t file_id, hid_t plist_id=H5P_DEFAULT):
+ """ (INT loc_id, STRING name, INT file_id, INT, plist_id=H5P_DEFAULT)
+
+ Mount an open file as "name" under group loc_id. If present, plist_id
+ is a mount property list.
+ """
+ cdef herr_t retval
+ retval = H5Fmount(loc_id, name, file_id, plist_id)
+ if retval < 0:
+ raise FileError('Failed to mount file %s as "%s" under group %d' % (file_id, name, loc_id))
+
+def unmount(hid_t loc_id, char* name):
+ """ (INT loc_id, STRING name)
+
+ Unmount a file, mounted as "name" under group loc_id
+ """
+ cdef herr_t retval
+ retval = H5Funmount(loc_id, name)
+ if retval < 0:
+ raise FileError('Failed to unmount "%s" under group %d' % (name, loc_id))
+
+# === File inspection =========================================================
+
+def get_filesize(hid_t file_id):
+ """ (INT file_id) => LONG size_in_bytes
+
+ Determine the total size of the HDF5 file, including the user block.
+ """
+ cdef herr_t retval
+ cdef hsize_t size
+ retval = H5Fget_filesize(file_id, &size)
+ if retval < 0:
+ raise FileError("Can't determine size of file %d" % file_id)
+ return size
+
+def get_create_plist(hid_t file_id):
+ """ (INT file_id) => INT plist_id
+
+ Retrieve a copy of the property list used to create this file.
+ """
+ cdef hid_t retval
+ retval = H5Fget_create_plist(file_id)
+ if retval < 0:
+ raise FileError("Can't retrieve creation property list for file %d" % file_id)
+ return retval
+
+def get_access_plist(hid_t file_id):
+ """ (INT file_id) => INT plist_id
+
+ Retrieve a copy of the property list which manages access to this file.
+ """
+ cdef hid_t retval
+ retval = H5Fget_access_plist(file_id)
+ if retval < 0:
+ raise FileError("Can't retrieve access property list for file %d" % file_id)
+ return retval
+
+def get_freespace(hid_t file_id):
+ """ (INT file_id) => LONG free space
+
+ Determine the amount of free space in this file. Note that this only
+ tracks free space until the file is closed.
+ """
+ cdef hssize_t retval
+ retval = H5Fget_freespace(file_id)
+ if retval < 0:
+ raise FileError("Can't determine free space in file %d" % file_id)
+ return retval
+
+def get_name(hid_t obj_id):
+ """ (INT obj_id) => STRING file_name
+
+ Determine the name of the file in which the specified object resides.
+ """
+ cdef ssize_t retval
+ cdef char* name
+ name = NULL
+
+ retval = H5Fget_name(obj_id, NULL, 0)
+ if retval < 0:
+ raise FileError("Can't determine file name associated with object %d" % obj_id)
+
+ name = <char*>malloc(retval+1)
+ retval = H5Fget_name(obj_id, name, retval+1)
+ if retval < 0:
+ free(name)
+ raise FileError("Can't determine file name associated with object %d" % obj_id)
+
+ pname = name
+ free(name)
+ return pname
+def get_obj_count(hid_t file_id, int types):
+ """ (INT file_id, INT types) => INT n_objs
+
+ Get the number of open objects in the file. The value of "types" may
+ be one of h5f.OBJ_*, or any bitwise combination (e.g.
+ OBJ_FILE | OBJ_ATTR). The special value OBJ_ALL matches all object
+ types, and OBJ_LOCAL will only match objects opened through this
+ specific identifier.
+ """
+ cdef int retval
+ retval = H5Fget_obj_count(file_id, types)
+ if retval < 0:
+ raise FileError("Can't determine number of open identifiers of types %d in file %d" % (types, file_id))
+ return retval
+def get_obj_ids(hid_t file_id, int types):
+ """ (INT file_id, INT types) => LIST open_ids
+
+ Get a list of identifiers for open objects in the file. The value of
+ "types" may be one of h5f.OBJ_*, or any bitwise combination (e.g.
+ OBJ_FILE | OBJ_ATTR). The special value OBJ_ALL matches all object
+ types, and OBJ_LOCAL will only match objects opened through this
+ specific identifier.
+
+ """
+ cdef int retval
+ cdef hid_t *obj_list
+ cdef int i
+ obj_list = NULL
+ py_obj_list = []
+
+ try:
+ retval = H5Fget_obj_ids(file_id, types, -1, obj_list)
+ if retval < 0:
+ raise FileError("Failed to enumerate open objects of types %d in file %d" % (types, file_id))
+
+ for i from 0<=i<retval:
+ py_obj_list[i] = obj_list[i]
+ finally:
+ if obj_list != NULL:
+ free(obj_list)
+
+ return py_obj_list
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/h5py.git
More information about the debian-science-commits
mailing list