hdf5 0.0.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f09793932ce1395ec008a08e49f534047178d78
4
- data.tar.gz: 9e35636d40e1c175deb2dbe796518adb5d0ae5ab
3
+ metadata.gz: 926cf4780d38820e5eb942368a56a6eafa12edad
4
+ data.tar.gz: a7e1e9fdc346d66ae0b3f874b965d05938cbd34f
5
5
  SHA512:
6
- metadata.gz: 696f95974054ff1736118b1e6a86fa3a0e2d2462ba59aa9c28ddd52cdc9c8ffb593e00ff27e26047f50a4a436c60ef80e8284069e78c96be90b7ed1815700d94
7
- data.tar.gz: 52ec1d11563b3b5ab9ee38e1904ad6b64bd9f602fa901899eee013fb980400dc3570cee0b070fc08fea42ffde709cef547a7c2d594b90a046a82925d0f738c0a
6
+ metadata.gz: b8ba5a730182ff1f456a69ace847b9ee3f9a9afe607f8cb3bd59d1f02a21ed1cb6e4bd28f0a81f607687594aeaab29621b67db0ea0d7d4a83c55d88fa43f0daa
7
+ data.tar.gz: a91d2bed998cdd3d2e3268ff3e82b8beac0b3ecea98e69e14257a5da73cd165f5a9c02d3307409245cd1fd718480e5d51816887dc346620bd03486d8f324c98a
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
  gem "ffi"
3
+ gem "narray"
3
4
 
4
5
  # Add dependencies to develop your gem here.
5
6
  # Include everything needed to run rake, tests, features, etc.
data/Rakefile CHANGED
@@ -21,6 +21,7 @@ Jeweler::Tasks.new do |gem|
21
21
  gem.description = %Q{A ruby wrapper to the HDF5 data library. Currently read only.}
22
22
  gem.email = "edmundhighcock@users.sourceforge.net"
23
23
  gem.authors = ["Edmund Highcock"]
24
+ gem.files.exclude 'test/**/*'
24
25
  # dependencies defined in Gemfile
25
26
  end
26
27
  Jeweler::RubygemsDotOrgTasks.new
@@ -40,6 +41,8 @@ end
40
41
 
41
42
  require "rake/extensiontask"
42
43
 
44
+ NAME = 'hdf5'
45
+
43
46
  Rake::ExtensionTask.new "hdf5" do |ext|
44
47
  ext.lib_dir = "lib/hdf5"
45
48
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
@@ -0,0 +1,20 @@
1
+ require 'mkmf'
2
+
3
+ #Need to link with C GSL libraries to use in C extensions
4
+ #gsl_inc = `gsl-config --cflags`
5
+
6
+ #$CFLAGS = " -Wall -I../include #{gsl_inc}"
7
+
8
+ #srcs = Dir.glob("*.c")
9
+
10
+ #p ['srcs', srcs]
11
+
12
+ #$objs = srcs.collect { |f| f.sub(".c", ".o") }
13
+ nagemspec=Gem::Specification.find_by_name('narray')
14
+ naconfig = nagemspec.full_gem_path
15
+ $CPPFLAGS = " -I#{File.join(naconfig, '')} "+$CPPFLAGS
16
+ p ['CPPFLAGS', $CPPFLAGS]
17
+
18
+ have_header("narray.h")
19
+
20
+ create_makefile("hdf5/hdf5")
data/ext/hdf5/hdf5.c ADDED
@@ -0,0 +1,77 @@
1
+ #include <math.h>
2
+ #include <string.h>
3
+ #include <ruby.h>
4
+ #include <narray.h>
5
+ /*#include "code_runner_ext.h"*/
6
+ /*#include <mpi.h>*/
7
+ #include <stdbool.h>
8
+
9
+ /* Taken from the ruby-mpi gem*/
10
+ /*struct _Comm {*/
11
+ /*MPI_Comm Comm;*/
12
+ /*bool free;*/
13
+ /*};*/
14
+
15
+ static VALUE narray_data_address(VALUE class, VALUE narray_obj){
16
+
17
+ struct NARRAY *narray;
18
+ int addrs;
19
+ VALUE address;
20
+
21
+ /*printf("RUNNING TRINITY!!!\n\n");*/
22
+ Data_Get_Struct(narray_obj, struct NARRAY, narray);
23
+ addrs = (int)narray->ptr;
24
+ address = INT2FIX(addrs);
25
+
26
+
27
+ /*printf("input file name was %s\n", input_file_name_c);*/
28
+ /**/
29
+ /*free(input_file_name_c);*/
30
+
31
+
32
+
33
+ return address;
34
+
35
+ }
36
+
37
+ void Init_hdf5()
38
+ {
39
+ VALUE ch5_simple_reader;
40
+ VALUE ch5_simple_reader_dataset;
41
+
42
+ ch5_simple_reader = rb_const_get(rb_cObject, rb_intern("H5SimpleReader"));
43
+ ch5_simple_reader_dataset = rb_const_get(ch5_simple_reader, rb_intern("H5Dataset"));
44
+ rb_define_method(ch5_simple_reader_dataset, "narray_data_address", narray_data_address, 1);
45
+ /*VALUE ctrinity;*/
46
+ /**/
47
+ /**//**//*cgraph_kit = Qnil;*/
48
+ /*ccode_runner_gs2 = Qnil;*/
49
+ /*ccode_runner_ext = Qnil;*/
50
+ /*printf("HERE!!!\n\n");*/
51
+ /**//*ccode_runner = RGET_CLASS_TOP("CodeRunner");*/
52
+ /*VALUE ctrinity = RGET_CLASS_TOP("CodeRunner");*/
53
+ /*ctrinity = RGET_CLASS(ccode_runner, "Trinity");*/
54
+ /*rb_define_class_under(ccode_runner, "Trinity",*/
55
+ /*RGET_CLASS(*/
56
+ /*RGET_CLASS(ccode_runner, "Run"), */
57
+ /*"FortranNamelist"*/
58
+ /*)*/
59
+ /*);*/
60
+
61
+ /*ccode_runner_gs2_gsl_tensor_complexes = rb_define_module_under(ccode_runner_gs2, "GSLComplexTensors");*/
62
+ /*rb_include_module(ccode_runner_gs2, ccode_runner_gs2_gsl_tensor_complexes);*/
63
+
64
+ /*ccode_runner_gs2_gsl_tensors = rb_define_module_under(ccode_runner_gs2, "GSLTensors"); */
65
+ /*rb_include_module(ccode_runner_gs2, ccode_runner_gs2_gsl_tensors);*/
66
+
67
+ /*cgsl = RGET_CLASS_TOP("GSL");*/
68
+ /*cgsl_vector = RGET_CLASS(cgsl, "Vector");*/
69
+ /*cgsl_vector_complex = RGET_CLASS(cgsl_vector, "Complex");*/
70
+
71
+ /*rb_define_method(ccode_runner_gs2_gsl_tensor_complexes, "field_gsl_tensor_complex_2", gs2crmod_tensor_complexes_field_gsl_tensor_complex_2, 1);*/
72
+ /*rb_define_method(ccode_runner_gs2_gsl_tensors, "field_real_space_gsl_tensor", gs2crmod_tensor_field_gsl_tensor, 1);*/
73
+ /*rb_define_method(ccode_runner_gs2_gsl_tensors, "field_correlation_gsl_tensor", gs2crmod_tensor_field_correlation_gsl_tensor, 1);*/
74
+
75
+ /*rb_define_method(ccode_runner_ext, "hello_world", code_runner_ext_hello_world, 0);*/
76
+ }
77
+
data/hdf5.gemspec ADDED
@@ -0,0 +1,76 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: hdf5 0.1.0 ruby lib
6
+ # stub: ext/hdf5/extconf.rb
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = "hdf5"
10
+ s.version = "0.1.0"
11
+
12
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
13
+ s.require_paths = ["lib"]
14
+ s.authors = ["Edmund Highcock"]
15
+ s.date = "2014-07-22"
16
+ s.description = "A ruby wrapper to the HDF5 data library. Currently read only."
17
+ s.email = "edmundhighcock@users.sourceforge.net"
18
+ s.extensions = ["ext/hdf5/extconf.rb"]
19
+ s.extra_rdoc_files = [
20
+ "LICENSE.txt",
21
+ "README.rdoc"
22
+ ]
23
+ s.files = [
24
+ ".document",
25
+ "Gemfile",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "ext/hdf5/extconf.rb",
31
+ "ext/hdf5/hdf5.c",
32
+ "hdf5.gemspec",
33
+ "lib/hdf5.rb"
34
+ ]
35
+ s.homepage = "http://github.com/edmundhighcock/hdf5"
36
+ s.licenses = ["GPLv3"]
37
+ s.rubygems_version = "2.2.2"
38
+ s.summary = "A ruby wrapper to the HDF5 data library. Currently read only."
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 4
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<ffi>, [">= 0"])
45
+ s.add_runtime_dependency(%q<narray>, [">= 0"])
46
+ s.add_development_dependency(%q<shoulda>, ["= 3.0.1"])
47
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
+ s.add_development_dependency(%q<bundler>, ["> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, [">= 2.0.1"])
50
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
51
+ s.add_development_dependency(%q<minitest>, ["~> 4"])
52
+ s.add_development_dependency(%q<rake-compiler>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<ffi>, [">= 0"])
55
+ s.add_dependency(%q<narray>, [">= 0"])
56
+ s.add_dependency(%q<shoulda>, ["= 3.0.1"])
57
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
58
+ s.add_dependency(%q<bundler>, ["> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, [">= 2.0.1"])
60
+ s.add_dependency(%q<simplecov>, [">= 0"])
61
+ s.add_dependency(%q<minitest>, ["~> 4"])
62
+ s.add_dependency(%q<rake-compiler>, [">= 0"])
63
+ end
64
+ else
65
+ s.add_dependency(%q<ffi>, [">= 0"])
66
+ s.add_dependency(%q<narray>, [">= 0"])
67
+ s.add_dependency(%q<shoulda>, ["= 3.0.1"])
68
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
69
+ s.add_dependency(%q<bundler>, ["> 1.0.0"])
70
+ s.add_dependency(%q<jeweler>, [">= 2.0.1"])
71
+ s.add_dependency(%q<simplecov>, [">= 0"])
72
+ s.add_dependency(%q<minitest>, ["~> 4"])
73
+ s.add_dependency(%q<rake-compiler>, [">= 0"])
74
+ end
75
+ end
76
+
data/lib/hdf5.rb CHANGED
@@ -0,0 +1,222 @@
1
+ require 'ffi'
2
+ module H5SimpleReader
3
+ module H5Types
4
+ extend FFI::Library
5
+ class << self
6
+ def herr_t
7
+ :int
8
+ end
9
+ def hid_t
10
+ :int
11
+ end
12
+ def hbool_t
13
+ :uint
14
+ end
15
+ def htri_t
16
+ :int
17
+ end
18
+ def hsize_t
19
+ :size_t
20
+ end
21
+ def h5t_class_t
22
+ enum [
23
+ :h5t_no_class , -1, #*error */
24
+ :h5t_integer , 0, #*integer types */
25
+ :h5t_float , 1, #*floating-point types */
26
+ :h5t_time , 2, #*date and time types */
27
+ :h5t_string , 3, #*character string types */
28
+ :h5t_bitfield , 4, #*bit field types */
29
+ :h5t_opaque , 5, #*opaque types */
30
+ :h5t_compound , 6, #*compound types */
31
+ :h5t_reference , 7, #*reference types */
32
+ :h5t_enum , 8, #*enumeration types */
33
+ :h5t_vlen , 9, #*variable-length types */
34
+ :h5t_array , 10, #*array types */
35
+
36
+ :h5t_nclasses #*this must be last */
37
+ ]
38
+ end
39
+ end
40
+ end
41
+
42
+ extend FFI::Library
43
+ ffi_lib 'hdf5'
44
+ attach_function :group_open, :H5Gopen2, [H5Types.hid_t, :string, H5Types.hid_t], H5Types.hid_t
45
+ attach_function :get_type, :H5Iget_type, [H5Types.hid_t], H5Types.hid_t
46
+ #
47
+ # Object for wrapping an HDF file
48
+ class H5File
49
+ extend FFI::Library
50
+ ffi_lib 'hdf5'
51
+ attach_function :basic_is_hdf5, :H5Fis_hdf5, [:string], H5Types.htri_t
52
+ attach_function :basic_open, :H5Fopen, [:string, :uint, H5Types.hid_t], H5Types.hid_t
53
+ attach_function :basic_close, :H5Fclose, [H5Types.hid_t], H5Types.herr_t
54
+ attr_reader :id
55
+ # Open the file with the given filename. Currently read only
56
+ def initialize(filename)
57
+ @filename = filename
58
+ @id = basic_open(filename, 0x0000, 0)
59
+ end
60
+ # Is the file a valid hdf5 file
61
+ def is_hdf5?
62
+ basic_is_hdf5(@filename) > 0
63
+ end
64
+ # Close the file
65
+ def close
66
+ basic_close(@id)
67
+ end
68
+ # Return a group object with the given name
69
+ # (relative to the root of the file)
70
+ def group(name)
71
+ return H5Group.open(@id, name)
72
+ end
73
+ # Return a dataset object with the given name
74
+ # (relative to the root of the file)
75
+ def dataset(name)
76
+ return H5Dataset.open(@id, name)
77
+ end
78
+ end
79
+ # Object wrapping an HDF5 Dataset, which contains
80
+ # a set of data, and information about the type of
81
+ # the data elements and the size and shape of the
82
+ # data array.
83
+ class H5Dataset
84
+ extend FFI::Library
85
+ ffi_lib 'hdf5'
86
+ attach_function :basic_open, :H5Dopen2, [H5Types.hid_t, :string, H5Types.hid_t], H5Types.hid_t
87
+ attach_function :basic_get_type, :H5Dget_type, [H5Types.hid_t], H5Types.hid_t
88
+ attach_function :basic_get_space, :H5Dget_space, [H5Types.hid_t], H5Types.hid_t
89
+ attach_function :basic_read, :H5Dread, [H5Types.hid_t, H5Types.hid_t, H5Types.hid_t, H5Types.hid_t, H5Types.hid_t, :pointer], H5Types.herr_t
90
+ attach_variable :h5t_native_float_g, :H5T_NATIVE_FLOAT_g, :int
91
+ # Open the dataset. location_id is the id of the parent
92
+ # file or group. Returns and H5Dataset object
93
+ def self.open(location_id, name)
94
+ return new(basic_open(location_id, name, 0))
95
+ end
96
+ # Create a new object. id is the id of the HDF5 dataset this wraps.
97
+ # Use H5Dataset.open to open a dataset
98
+ def initialize(id)
99
+ @id = id
100
+ end
101
+ # Return an H5Datatype object containing information about the type
102
+ # of an individual member of the dataset
103
+ def datatype
104
+ H5Datatype.new(basic_get_type(@id))
105
+ end
106
+ def dataspace
107
+ H5Dataspace.new(basic_get_space(@id))
108
+ end
109
+ def narray_type
110
+ #cls = H5Types.h5t_class_t
111
+ #p 'datatype', datatype.h5_class
112
+ case datatype.h5_class
113
+ when :h5t_float
114
+ :float
115
+ when :h5t_compound
116
+ if datatype.is_complex?
117
+ :complex
118
+ else
119
+ :compound
120
+ end
121
+ else
122
+ raise "unknown datatype"
123
+ end
124
+ end
125
+ #inline :C do |builder|
126
+ #builder.c <<EOF
127
+ #long asfdsf(){
128
+ #long b;
129
+ #b = 24;
130
+ #return b;}
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
139
+ def narray_all
140
+ p ['ddims', dataspace.dims]
141
+ narr = NArray.send(narray_type, *dataspace.dims)
142
+ #get_narray_pointer(narr)
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
149
+ narr
150
+ end
151
+ #def array
152
+ #end
153
+ end
154
+ # Object for wrapping an HD5 dataspace, which contains
155
+ # information about the dimensions and size of the dataset
156
+ class H5Dataspace
157
+ extend FFI::Library
158
+ ffi_lib 'hdf5'
159
+ attach_function :basic_get_simple_extent_ndims, :H5Sget_simple_extent_ndims, [H5Types.hid_t], :int
160
+ attach_function :basic_get_simple_extent_dims, :H5Sget_simple_extent_dims, [H5Types.hid_t, :pointer, :pointer], :int
161
+ def initialize(id)
162
+ @id = id
163
+ end
164
+ # Number of dimensions in the dataspace
165
+ def ndims
166
+ basic_get_simple_extent_ndims(@id)
167
+ end
168
+ def dims
169
+ basic_dims = FFI::MemoryPointer.new(H5Types.hsize_t, ndims)
170
+ basic_maxdims = FFI::MemoryPointer.new(H5Types.hsize_t, 1)
171
+ basic_get_simple_extent_dims(@id, basic_dims, basic_maxdims)
172
+ basic_dims.get_array_of_int64(0, ndims)
173
+ end
174
+ end
175
+ # Object for wrapping an HD5 datatype, which contains
176
+ # information about the type and makeup of an individual element
177
+ # of the dataset, which may be a float or integer, or may be
178
+ # a vast compound type
179
+ class H5Datatype
180
+ extend FFI::Library
181
+ ffi_lib 'hdf5'
182
+ attach_function :basic_get_class, :H5Tget_class, [H5Types.hid_t], H5Types.h5t_class_t
183
+ attach_function :basic_get_nmembers, :H5Tget_nmembers, [H5Types.hid_t], :int
184
+ attach_function :basic_get_member_type, :H5Tget_member_type, [H5Types.hid_t, :uint], H5Types.hid_t
185
+ attr_reader :id
186
+ def initialize(id)
187
+ @id = id
188
+ end
189
+ def h5_class
190
+ basic_get_class(@id)
191
+ end
192
+ # The number of members in a compound datatype
193
+ def nmembers
194
+ basic_get_nmembers(@id)
195
+ end
196
+ # We assume that a compound datatype with two floating point members
197
+ # is a complex number. This may want to be revisisted...
198
+ def is_complex?
199
+ nmembers == 2 and member_types.map{|t| t.h5_class} == [:h5t_float, :h5t_float]
200
+ end
201
+ # An array of datatypes of the members of a compound datatype
202
+ def member_types
203
+ nmembers.times.map{|i| self.class.new(basic_get_member_type(@id, i))}
204
+ end
205
+ end
206
+
207
+ # Object representing an HDF5 group
208
+ class H5Group
209
+ # Open the group. location_id is the id of the parent
210
+ # file or group
211
+ def self.open(location_id, name)
212
+ return new(H5SimpleReader.basic_group_open(location_id, name, 0))
213
+ end
214
+ def initialize(id)
215
+ @id = id
216
+ end
217
+ def open_group(name)
218
+ return H5Group.open(@id, name)
219
+ end
220
+ end
221
+ end
222
+ require 'hdf5/hdf5'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hdf5
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edmund Highcock
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: narray
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: shoulda
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -125,7 +139,8 @@ dependencies:
125
139
  description: A ruby wrapper to the HDF5 data library. Currently read only.
126
140
  email: edmundhighcock@users.sourceforge.net
127
141
  executables: []
128
- extensions: []
142
+ extensions:
143
+ - ext/hdf5/extconf.rb
129
144
  extra_rdoc_files:
130
145
  - LICENSE.txt
131
146
  - README.rdoc
@@ -136,9 +151,10 @@ files:
136
151
  - README.rdoc
137
152
  - Rakefile
138
153
  - VERSION
154
+ - ext/hdf5/extconf.rb
155
+ - ext/hdf5/hdf5.c
156
+ - hdf5.gemspec
139
157
  - lib/hdf5.rb
140
- - test/helper.rb
141
- - test/test_hdf5.rb
142
158
  homepage: http://github.com/edmundhighcock/hdf5
143
159
  licenses:
144
160
  - GPLv3
data/test/helper.rb DELETED
@@ -1,34 +0,0 @@
1
- require 'simplecov'
2
-
3
- module SimpleCov::Configuration
4
- def clean_filters
5
- @filters = []
6
- end
7
- end
8
-
9
- SimpleCov.configure do
10
- clean_filters
11
- load_adapter 'test_frameworks'
12
- end
13
-
14
- ENV["COVERAGE"] && SimpleCov.start do
15
- add_filter "/.rvm/"
16
- end
17
- require 'rubygems'
18
- require 'bundler'
19
- begin
20
- Bundler.setup(:default, :development)
21
- rescue Bundler::BundlerError => e
22
- $stderr.puts e.message
23
- $stderr.puts "Run `bundle install` to install missing gems"
24
- exit e.status_code
25
- end
26
- require 'test/unit'
27
- require 'shoulda'
28
-
29
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
- $LOAD_PATH.unshift(File.dirname(__FILE__))
31
- require 'hdf5'
32
-
33
- class Test::Unit::TestCase
34
- end
data/test/test_hdf5.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestHdf5 < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end