5
5
#include "H5Zlzo.h" /* Import FILTER_LZO */
6
6
#include "H5Zucl.h" /* Import FILTER_UCL */
9
/*-------------------------------------------------------------------------
12
* These are a replica of those in H5LT.c, but get_attribute_string_sys
13
* needs them, so it is better to copy them here.
16
*-------------------------------------------------------------------------
19
herr_t _open_id( hid_t loc_id,
23
herr_t _close_id( hid_t obj_id,
7
#include "H5Zbzip2.h" /* Import FILTER_BZIP2 */
10
/* ---------------------------------------------------------------- */
15
/* This routine is meant to detect whether a dynamic library can be
16
loaded on Windows. This is only way to detect its presence without
19
int getLibrary(char *libname) {
22
/* Load the dynamic library */
23
hinstLib = LoadLibrary(TEXT(libname));
25
if (hinstLib != NULL) {
26
/* Free the dynamic library */
27
FreeLibrary(hinstLib);
35
#else /* Unix platforms */
38
/* Routine to detect the existance of shared libraries in UNIX. This
39
has to be checked in MacOSX. However, this is not used right now in
40
utilsExtension.pyx because UNIX does not complain when trying to
41
load an extension library that depends on a shared library that it
42
is not in the system (python raises just the ImportError). */
43
int getLibrary(char *libname) {
46
/* Load the dynamic library */
47
hinstLib = dlopen(libname, RTLD_LAZY);
49
if (hinstLib != NULL) {
50
/* Free the dynamic library */
62
herr_t set_cache_size(hid_t file_id, size_t cache_size) {
67
#if H5_VERS_MAJOR == 1 && H5_VERS_MINOR >= 7
68
H5AC_cache_config_t config;
70
config.version = H5AC__CURR_CACHE_CONFIG_VERSION;
71
code = H5Fget_mdc_config(file_id, &config);
72
config.set_initial_size = TRUE;
73
config.initial_size = cache_size;
74
/* config.incr_mode = H5C_incr__off; */
75
/* config.decr_mode = H5C_decr__off; */
76
/* printf("Setting cache size to: %d\n", cache_size); */
77
code = H5Fset_mdc_config(file_id, &config);
78
/* printf("Return code for H5Fset_mdc_config: %d\n", code); */
80
#endif /* if H5_VERSION < "1.7" */
26
86
PyObject *_getTablesVersion() {
27
87
return PyString_FromString(PYTABLES_VERSION);
30
/* PyObject *getZLIBVersionInfo(void) { */
34
/* #ifdef ZLIB_VERNUM /\* Only available for zlib >= 1.2 *\/ */
35
/* binver = ZLIB_VERNUM; /\* This is not exactly the user's lib */
36
/* version but that of the binary */
37
/* packager version! However, this */
38
/* should be not too important *\/ */
40
/* binver = 1; /\* For version of zlib < 1.2 *\/ */
42
/* t = PyTuple_New(2); */
43
/* PyTuple_SetItem(t, 0, PyInt_FromLong(binver)); */
44
/* PyTuple_SetItem(t, 1, PyString_FromString(zlibVersion())); */
48
90
PyObject *getHDF5VersionInfo(void) {
50
92
unsigned majnum, minnum, relnum;
152
200
if ((nf = H5Pget_nfilters(dcpl))>0) {
153
201
for (i=0; i<nf; i++) {
203
#if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 7
156
205
filt_id = H5Pget_filter(dcpl, i, &filt_flags, &cd_nelmts,
157
206
cd_values, sizeof(f_name), f_name);
159
/* filt_id = H5Pget_filter(dcpl, i, &filt_flags, &cd_nelmts, */
160
/* cd_values, sizeof(f_name), f_name, NULL); */
161
/* printf("f_name--> %s\n", f_name); */
162
/* This code has been added because a
163
bug in the H5Pget_filter call that
164
returns a null string when DEFLATE filter is active */
165
/* The problem seems to have been solved in 1.6.2 though */
167
case H5Z_FILTER_DEFLATE:
168
strcpy(f_name, "deflate");
170
case H5Z_FILTER_SHUFFLE:
171
strcpy(f_name, "shuffle");
173
case H5Z_FILTER_FLETCHER32:
174
strcpy(f_name, "fletcher32");
176
case H5Z_FILTER_SZIP:
177
strcpy(f_name, "szip");
180
strcpy(f_name, "lzo");
183
strcpy(f_name, "ucl");
209
filt_id = H5Pget_filter(dcpl, i, &filt_flags, &cd_nelmts,
210
cd_values, sizeof(f_name), f_name, NULL);
211
#endif /* if H5_VERSION < "1.7" */
187
213
filter_values = PyTuple_New(cd_nelmts);
188
214
for (j=0;j<(long)cd_nelmts;j++) {
189
215
PyTuple_SetItem(filter_values, j, PyInt_FromLong(cd_values[j]));
450
/* Extract a slice index from a PyLong, and store in *pi. Silently
451
reduce values larger than LONGLONG_MAX to LONGLONG_MAX, and
452
silently boost values less than -LONGLONG_MAX to 0. Return 0 on
455
/* Note: This has been copied and modified from the original in
456
Python/ceval.c so as to allow working with long long values.
460
hsize_t _PyEval_SliceIndex_modif(PyObject *v, hsize_t *pi)
462
PY_LONG_LONG LONGLONG_MAX;
464
/* I think it should be a more efficient way to know LONGLONG_MAX,
465
but this should work on every platform, be 32 or 64 bits.
469
/* LONGLONG_MAX = (PY_LONG_LONG) (pow(2, 63) - 1); */ /* Works on Unix */
470
LONGLONG_MAX = (PY_LONG_LONG) (pow(2, 62) - 1); /* Safer on Windows */
474
if (PyInt_Check(v)) {
475
x = PyLong_AsLongLong(v);
477
else if (PyLong_Check(v)) {
478
x = PyLong_AsLongLong(v);
480
PyErr_SetString(PyExc_TypeError,
481
"PyTables slice indices must be integers");
484
/* Truncate -- very long indices are truncated anyway */
485
if (x > LONGLONG_MAX)
487
else if (x < -LONGLONG_MAX)
424
494
/* This has been copied from the Python 2.3 sources in order to get a
425
funtion similar to the method slice.indices(length) introduced in
426
python 2.3, but for 2.2 */
428
/* F. Alted 2004-01-19 */
430
int GetIndicesEx(PyObject *s, int length,
431
int *start, int *stop, int *step, int *slicelength)
433
/* this is harder to get right than you might think */
435
int defstart, defstop;
436
PySliceObject *r = (PySliceObject *) s;
438
if (r->step == Py_None) {
442
if (!_PyEval_SliceIndex(r->step, step)) return -1;
444
PyErr_SetString(PyExc_ValueError,
445
"slice step cannot be zero");
450
defstart = *step < 0 ? length-1 : 0;
451
defstop = *step < 0 ? -1 : length;
453
if (r->start == Py_None) {
457
if (!_PyEval_SliceIndex(r->start, start)) return -1;
458
if (*start < 0) *start += length;
459
if (*start < 0) *start = (*step < 0) ? -1 : 0;
460
if (*start >= length)
461
*start = (*step < 0) ? length - 1 : length;
464
if (r->stop == Py_None) {
468
if (!_PyEval_SliceIndex(r->stop, stop)) return -1;
469
if (*stop < 0) *stop += length;
470
if (*stop < 0) *stop = -1;
471
if (*stop > length) *stop = length;
474
if ((*step < 0 && *stop >= *start)
475
|| (*step > 0 && *start >= *stop)) {
478
else if (*step < 0) {
479
*slicelength = (*stop-*start+1)/(*step)+1;
482
*slicelength = (*stop-*start-1)/(*step)+1;
488
/*-------------------------------------------------------------------------
489
* Function: get_attribute_string_sys
491
* Purpose: Reads a attribute specific of PyTables in a fast way
493
* Return: Success: 0, Failure: -1
495
* Programmer: Francesc Alted, falted@pytables.org
497
* Date: September 19, 2003
503
*-------------------------------------------------------------------------
507
PyObject *get_attribute_string_sys( hid_t loc_id,
508
const char *obj_name,
509
const char *attr_name)
517
PyObject *attr_value;
521
/* Get the type of object */
522
if (H5Gget_objinfo(loc_id, obj_name, 1, &statbuf)<0)
525
/* Open the object */
526
if ((obj_id = _open_id( loc_id, obj_name, statbuf.type )) < 0)
529
/* Check if attribute exists */
530
/* This is commented out to make the attribute reading faster */
531
/* if (H5LT_find_attribute(obj_id, attr_name) <= 0) */
532
if ( ( attr_id = H5Aopen_name( obj_id, attr_name ) ) < 0 )
533
/* If the attribute does not exists, return None */
534
/* and do not even warn the user */
537
if ( (attr_type = H5Aget_type( attr_id )) < 0 )
541
attr_size = H5Tget_size( attr_type );
543
/* printf("name: %s. size: %d\n", attr_name, attr_size); */
544
/* Allocate memory for the input buffer */
545
data = (char *)malloc(attr_size);
547
if ( H5Aread( attr_id, attr_type, data ) < 0 )
550
attr_value = PyString_FromString(data);
553
if ( H5Tclose( attr_type ) < 0 )
556
if ( H5Aclose( attr_id ) < 0 )
559
/* Close the object */
560
if ( _close_id( obj_id, statbuf.type ) < 0 )
567
H5Aclose( attr_type );
572
/*-------------------------------------------------------------------------
575
* Purpose: Private function used by get_attribute_string_sys
577
* Return: Success: 0, Failure: -1
579
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
581
* Date: September 19, 2002
585
*-------------------------------------------------------------------------
590
herr_t _open_id( hid_t loc_id,
591
const char *obj_name,
592
int obj_type /*basic object type*/ )
601
/* Open the dataset. */
602
if ( (obj_id = H5Dopen( loc_id, obj_name )) < 0 )
608
/* Open the group. */
609
if ( (obj_id = H5Gopen( loc_id, obj_name )) < 0 )
622
/*-------------------------------------------------------------------------
623
* Function: _close_id
625
* Purpose: Private function used by get_attribute_string_sys
627
* Return: Success: 0, Failure: -1
629
* Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
631
* Date: September 19, 2002
635
*-------------------------------------------------------------------------
640
herr_t _close_id( hid_t obj_id,
641
int obj_type /*basic object type*/ )
647
/* Close the dataset. */
648
if ( H5Dclose( obj_id ) < 0 )
653
/* Close the group. */
654
if ( H5Gclose( obj_id ) < 0 )
495
function similar to the method slice.indices(length) but that works
496
with 64-bit ints and not only with ints.
499
/* F. Altet 2005-05-08 */
501
hsize_t getIndicesExt(PyObject *s, hsize_t length,
502
hsize_t *start, hsize_t *stop, hsize_t *step,
503
hsize_t *slicelength)
505
/* this is harder to get right than you might think */
507
hsize_t defstart, defstop;
508
PySliceObject *r = (PySliceObject *) s;
510
if (r->step == Py_None) {
514
if (!_PyEval_SliceIndex_modif(r->step, step)) return -1;
515
if ((PY_LONG_LONG)*step == 0) {
516
PyErr_SetString(PyExc_ValueError,
517
"slice step cannot be zero");
522
defstart = (PY_LONG_LONG)*step < 0 ? length-1 : 0;
523
defstop = (PY_LONG_LONG)*step < 0 ? -1 : length;
525
if (r->start == Py_None) {
529
if (!_PyEval_SliceIndex_modif(r->start, start)) return -1;
530
if ((PY_LONG_LONG)*start < 0L) *start += length;
531
if ((PY_LONG_LONG)*start < 0) *start = ((PY_LONG_LONG)*step < 0) ? -1 : 0;
532
if ((PY_LONG_LONG)*start >= length)
533
*start = ((PY_LONG_LONG)*step < 0) ? length - 1 : length;
536
if (r->stop == Py_None) {
540
if (!_PyEval_SliceIndex_modif(r->stop, stop)) return -1;
541
if ((PY_LONG_LONG)*stop < 0) *stop += length;
542
if ((PY_LONG_LONG)*stop < 0) *stop = -1;
543
if ((PY_LONG_LONG)*stop > length) *stop = length;
546
if (((PY_LONG_LONG)*step < 0 && (PY_LONG_LONG)*stop >= (PY_LONG_LONG)*start)
547
|| ((PY_LONG_LONG)*step > 0 && (PY_LONG_LONG)*start >= (PY_LONG_LONG)*stop)) {
550
else if ((PY_LONG_LONG)*step < 0) {
551
*slicelength = (*stop-*start+1)/(*step)+1;
554
*slicelength = (*stop-*start-1)/(*step)+1;
701
/* Test whether the datatype is of class complex
595
/* Test whether the datatype is of class complex
702
596
return 1 if it corresponds to our complex class, otherwise 0 */
703
/* It simply checks if its a H5T_COMPOUND type,
704
but we could be more strict by checking names and classes
597
/* This may be ultimately confused with nested types with 2 components
598
called 'r' and 'i' and being floats, but in that case, the user
599
most probably wanted to keep a complex type, so getting a complex
600
instead of a nested type should not be a big issue (I hope!) :-/
601
F. Altet 2005-05-23 */
706
602
int is_complex(hid_t type_id) {
707
hid_t class_id, base_type_id, base_class_id;
603
hid_t class_id, base_type_id;
604
hid_t class1, class2;
605
char *colname1, *colname2;
709
609
class_id = H5Tget_class(type_id);
710
610
if (class_id == H5T_COMPOUND) {
611
nfields = H5Tget_nmembers(type_id);
613
colname1 = H5Tget_member_name(type_id, 0);
614
colname2 = H5Tget_member_name(type_id, 1);
615
if ((strcmp(colname1, "r") == 0) && (strcmp(colname2, "i") == 0)) {
616
class1 = H5Tget_member_class(type_id, 0);
617
class2 = H5Tget_member_class(type_id, 1);
618
if (class1 == H5T_FLOAT && class2 == H5T_FLOAT)
713
625
/* Is an Array of Complex? */
714
626
else if (class_id == H5T_ARRAY) {
715
627
/* Get the array base component */
716
628
base_type_id = H5Tget_super(type_id);
717
/* Get the class of base component. */
718
base_class_id = H5Tget_class(base_type_id);
719
if (base_class_id == H5T_COMPOUND)
629
/* Call is_complex again */
630
result = is_complex(base_type_id);
631
H5Tclose(base_type_id);