hdf5 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/ext/hdf5/hdf5.c +4 -4
- data/hdf5.gemspec +3 -3
- data/lib/hdf5.rb +55 -36
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b29f81b9aa64ee2dacbcfb1d0e572433ddfe6ea4
|
4
|
+
data.tar.gz: d1437ce28a4b03e0f7d6566f70645805901694cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a35e8318c4748305fbc5007c4c892653e9414f92f07d9db80be31747a8922a682c08f6bc6a68aeae6eb69169fc8413826c24963c884aeeb51920dc9ca8a2b587
|
7
|
+
data.tar.gz: 8129fed65a5829e1f902a9f9642910e1b8c31f643ec8178ced2515ee07acb0964346dd8d50ff295bef65120a38afdb82770bdbd30bb7dc027278ef7c2a41f9d2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/ext/hdf5/hdf5.c
CHANGED
@@ -37,11 +37,11 @@ static VALUE narray_data_address(VALUE class, VALUE narray_obj){
|
|
37
37
|
void Init_hdf5()
|
38
38
|
{
|
39
39
|
VALUE ch5_simple_reader;
|
40
|
-
VALUE ch5_simple_reader_dataset
|
40
|
+
/*VALUE ch5_simple_reader_dataset;*/
|
41
41
|
|
42
|
-
ch5_simple_reader = rb_const_get(rb_cObject, rb_intern("
|
43
|
-
ch5_simple_reader_dataset = rb_const_get(ch5_simple_reader, rb_intern("H5Dataset"));
|
44
|
-
|
42
|
+
ch5_simple_reader = rb_const_get(rb_cObject, rb_intern("Hdf5"));
|
43
|
+
/*ch5_simple_reader_dataset = rb_const_get(ch5_simple_reader, rb_intern("H5Dataset")); */
|
44
|
+
rb_define_singleton_method(ch5_simple_reader, "narray_data_address", narray_data_address, 1);
|
45
45
|
/*VALUE ctrinity;*/
|
46
46
|
/**/
|
47
47
|
/**//**//*cgraph_kit = Qnil;*/
|
data/hdf5.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: hdf5 0.
|
5
|
+
# stub: hdf5 0.2.0 ruby lib
|
6
6
|
# stub: ext/hdf5/extconf.rb
|
7
7
|
|
8
8
|
Gem::Specification.new do |s|
|
9
9
|
s.name = "hdf5"
|
10
|
-
s.version = "0.
|
10
|
+
s.version = "0.2.0"
|
11
11
|
|
12
12
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
13
13
|
s.require_paths = ["lib"]
|
14
14
|
s.authors = ["Edmund Highcock"]
|
15
|
-
s.date = "2014-07-
|
15
|
+
s.date = "2014-07-23"
|
16
16
|
s.description = "A ruby wrapper to the HDF5 data library. Currently read only."
|
17
17
|
s.email = "edmundhighcock@users.sourceforge.net"
|
18
18
|
s.extensions = ["ext/hdf5/extconf.rb"]
|
data/lib/hdf5.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
require 'ffi'
|
2
|
-
|
2
|
+
class NArray
|
3
|
+
def ffi_mem_pointer
|
4
|
+
FFI::Pointer.new(Hdf5.narray_data_address(self))
|
5
|
+
end
|
6
|
+
end
|
7
|
+
module Hdf5
|
3
8
|
module H5Types
|
4
9
|
extend FFI::Library
|
5
10
|
class << self
|
@@ -65,12 +70,12 @@ module H5SimpleReader
|
|
65
70
|
def close
|
66
71
|
basic_close(@id)
|
67
72
|
end
|
68
|
-
# Return a group object with the given name
|
73
|
+
# Return a group object with the given name
|
69
74
|
# (relative to the root of the file)
|
70
75
|
def group(name)
|
71
76
|
return H5Group.open(@id, name)
|
72
77
|
end
|
73
|
-
# Return a dataset object with the given name
|
78
|
+
# Return a dataset object with the given name
|
74
79
|
# (relative to the root of the file)
|
75
80
|
def dataset(name)
|
76
81
|
return H5Dataset.open(@id, name)
|
@@ -78,7 +83,7 @@ module H5SimpleReader
|
|
78
83
|
end
|
79
84
|
# Object wrapping an HDF5 Dataset, which contains
|
80
85
|
# a set of data, and information about the type of
|
81
|
-
# the data elements and the size and shape of the
|
86
|
+
# the data elements and the size and shape of the
|
82
87
|
# data array.
|
83
88
|
class H5Dataset
|
84
89
|
extend FFI::Library
|
@@ -94,7 +99,7 @@ module H5SimpleReader
|
|
94
99
|
return new(basic_open(location_id, name, 0))
|
95
100
|
end
|
96
101
|
# Create a new object. id is the id of the HDF5 dataset this wraps.
|
97
|
-
# Use H5Dataset.open to open a dataset
|
102
|
+
# Use H5Dataset.open to open a dataset
|
98
103
|
def initialize(id)
|
99
104
|
@id = id
|
100
105
|
end
|
@@ -106,46 +111,37 @@ module H5SimpleReader
|
|
106
111
|
def dataspace
|
107
112
|
H5Dataspace.new(basic_get_space(@id))
|
108
113
|
end
|
114
|
+
# Gives the narray type corresponding to the datatype of the dataset
|
115
|
+
# Raises an error for unsupported datatypes.
|
116
|
+
# datatypes (basically only works for ints, floats and complexes, where a datatype
|
117
|
+
# composed of two floats is assumed to be a complex).
|
109
118
|
def narray_type
|
110
119
|
#cls = H5Types.h5t_class_t
|
111
120
|
#p 'datatype', datatype.h5_class
|
112
|
-
case datatype.h5_class
|
121
|
+
case h5c = datatype.h5_class
|
122
|
+
when :h5t_integer
|
123
|
+
:integer
|
113
124
|
when :h5t_float
|
114
125
|
:float
|
115
126
|
when :h5t_compound
|
116
127
|
if datatype.is_complex?
|
117
128
|
:complex
|
118
129
|
else
|
119
|
-
:
|
130
|
+
raise "Unsupported datatype for narray: #{h5c}"
|
120
131
|
end
|
121
|
-
else
|
122
|
-
raise "
|
132
|
+
else
|
133
|
+
raise "Unsupported datatype for narray: #{h5c}"
|
123
134
|
end
|
124
135
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
#EOF
|
133
|
-
#end
|
134
|
-
def get_narray_pointer(narray)
|
135
|
-
p 'p address', narray_data_address(narray)
|
136
|
-
#void * narray_pointer(VALUE
|
137
|
-
narray_data_address(narray)
|
138
|
-
end
|
136
|
+
# Create an NArray of the appropriate size and read the entire
|
137
|
+
# content of the dataset into it. Will not work for complicated
|
138
|
+
# datatypes (basically only works for ints, floats and complexes, where a datatype
|
139
|
+
# composed of two floats is assumed to be a complex). There is
|
140
|
+
# scope in the future for writing custom closures for reading in more
|
141
|
+
# complex datatypes.
|
139
142
|
def narray_all
|
140
|
-
p ['ddims', dataspace.dims]
|
141
143
|
narr = NArray.send(narray_type, *dataspace.dims)
|
142
|
-
|
143
|
-
ptr = FFI::Pointer.new(get_narray_pointer(narr))
|
144
|
-
|
145
|
-
#basic_read(@id, self.class.h5t_native_float_g, 0, 0, 0, ptr)
|
146
|
-
basic_read(@id, datatype.id, 0, 0, 0, ptr)
|
147
|
-
#p ptr.get_array_of_float64(0, 6)
|
148
|
-
p narr.shape
|
144
|
+
basic_read(@id, datatype.id, 0, 0, 0, narr.ffi_mem_pointer)
|
149
145
|
narr
|
150
146
|
end
|
151
147
|
#def array
|
@@ -158,6 +154,22 @@ module H5SimpleReader
|
|
158
154
|
ffi_lib 'hdf5'
|
159
155
|
attach_function :basic_get_simple_extent_ndims, :H5Sget_simple_extent_ndims, [H5Types.hid_t], :int
|
160
156
|
attach_function :basic_get_simple_extent_dims, :H5Sget_simple_extent_dims, [H5Types.hid_t, :pointer, :pointer], :int
|
157
|
+
attach_function :basic_create_simple, :H5Screate_simple, [:int, :pointer, :pointer], H5Types.hid_t
|
158
|
+
# Create a new HDF5 dataspace with the given current and maximum
|
159
|
+
# dimensions. If maximum_dims is omitted it is set to current_dims.
|
160
|
+
# Returns an H5Dataspace object wrapping the dataspace
|
161
|
+
def self.create_simple(current_dims, maximum_dims=nil)
|
162
|
+
maximum_dims ||= current_dims
|
163
|
+
raise ArgumentError.new("current_dims and maximum_dims must be the same size") unless current_dims.size == maximum_dims.size
|
164
|
+
n = current_dims.size
|
165
|
+
basic_dims = FFI::MemoryPointer.new(H5Types.hsize_t, n)
|
166
|
+
basic_maxdims = FFI::MemoryPointer.new(H5Types.hsize_t, n)
|
167
|
+
basic_dims.write_array_of_int64(current_dims)
|
168
|
+
basic_maxdims.write_array_of_int64(maximum_dims)
|
169
|
+
new(basic_create_simple(n, basic_dims, basic_maxdims))
|
170
|
+
end
|
171
|
+
# Create a new H5Dataspace object. id must be the id
|
172
|
+
# of a pre-existing HDF5 dataspace.
|
161
173
|
def initialize(id)
|
162
174
|
@id = id
|
163
175
|
end
|
@@ -165,16 +177,23 @@ module H5SimpleReader
|
|
165
177
|
def ndims
|
166
178
|
basic_get_simple_extent_ndims(@id)
|
167
179
|
end
|
168
|
-
def
|
180
|
+
def basic_dims_maxdims
|
169
181
|
basic_dims = FFI::MemoryPointer.new(H5Types.hsize_t, ndims)
|
170
|
-
basic_maxdims = FFI::MemoryPointer.new(H5Types.hsize_t,
|
182
|
+
basic_maxdims = FFI::MemoryPointer.new(H5Types.hsize_t, ndims)
|
171
183
|
basic_get_simple_extent_dims(@id, basic_dims, basic_maxdims)
|
172
|
-
basic_dims
|
184
|
+
return [basic_dims, basic_maxdims]
|
185
|
+
end
|
186
|
+
private :basic_dims_maxdims
|
187
|
+
def dims
|
188
|
+
basic_dims_maxdims[0].get_array_of_int64(0, ndims)
|
189
|
+
end
|
190
|
+
def maxdims
|
191
|
+
basic_dims_maxdims[1].get_array_of_int64(0, ndims)
|
173
192
|
end
|
174
193
|
end
|
175
194
|
# Object for wrapping an HD5 datatype, which contains
|
176
195
|
# information about the type and makeup of an individual element
|
177
|
-
# of the dataset, which may be a float or integer, or may be
|
196
|
+
# of the dataset, which may be a float or integer, or may be
|
178
197
|
# a vast compound type
|
179
198
|
class H5Datatype
|
180
199
|
extend FFI::Library
|
@@ -209,7 +228,7 @@ module H5SimpleReader
|
|
209
228
|
# Open the group. location_id is the id of the parent
|
210
229
|
# file or group
|
211
230
|
def self.open(location_id, name)
|
212
|
-
return new(
|
231
|
+
return new(Hdf5.basic_group_open(location_id, name, 0))
|
213
232
|
end
|
214
233
|
def initialize(id)
|
215
234
|
@id = id
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hdf5
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edmund Highcock
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|