Skip to content

Commit fc832f5

Browse files
committed
Update README.md
1 parent d27f050 commit fc832f5

1 file changed

Lines changed: 68 additions & 46 deletions

File tree

README.md

Lines changed: 68 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@
22

33
[![test](https://github.com/red-data-tools/ruby-hdf5/actions/workflows/test.yml/badge.svg)](https://github.com/red-data-tools/ruby-hdf5/actions/workflows/test.yml)
44

5-
experimental Ruby bindings for the HDF5 library
5+
Ruby bindings for the HDF5 library.
6+
7+
## Scope
8+
9+
This gem currently provides practical high-level wrappers for:
10+
11+
- opening and creating files
12+
- creating groups
13+
- creating, writing, and reading one-dimensional numeric datasets
14+
- reading attributes
15+
16+
Unsupported at this stage:
17+
18+
- string dataset read/write
19+
- attribute write
20+
- multidimensional array write
621

722
## Supported HDF5 Versions
823

@@ -12,57 +27,81 @@ experimental Ruby bindings for the HDF5 library
1227

1328
HDF5 versions older than 1.10 are not supported.
1429

15-
## Basic I/O
30+
## Install
31+
32+
Add to your Gemfile:
33+
34+
```ruby
35+
gem 'ruby-hdf5'
36+
```
37+
38+
Install:
39+
40+
```sh
41+
bundle install
42+
```
43+
44+
System library (`libhdf5`) is required.
1645

17-
Current high-level API supports these operations:
46+
## Runtime Notes
1847

19-
- open an existing HDF5 file
20-
- create a new HDF5 file
21-
- create groups
22-
- create, write, and read one-dimensional numeric datasets
48+
- The gem loads `libhdf5` through FFI.
49+
- If the shared library cannot be found automatically, set `HDF5_LIB_PATH`.
2350

24-
Not supported yet:
51+
Examples:
2552

26-
- string datasets
27-
- attribute writes
28-
- multidimensional array writes
53+
```sh
54+
# Point to a directory containing libhdf5.so
55+
export HDF5_LIB_PATH=/usr/lib
56+
57+
# Or point directly to the shared object
58+
export HDF5_LIB_PATH=/usr/lib/libhdf5.so
59+
```
60+
61+
## Quick Start
2962

3063
### Read an existing file
3164

3265
```ruby
3366
require 'hdf5'
3467

35-
file = HDF5::File.open('example.h5')
36-
group = file['foo']
37-
dataset = group['bar_int']
38-
39-
p dataset.shape
40-
p dataset.dtype
41-
p dataset.read
42-
43-
dataset.close
44-
group.close
45-
file.close
68+
HDF5::File.open('example.h5') do |file|
69+
group = file['foo']
70+
dataset = group['bar_int']
71+
p dataset.shape
72+
p dataset.dtype
73+
p dataset.read
74+
end
4675
```
4776

4877
### Create and write a file
4978

5079
```ruby
5180
require 'hdf5'
5281

53-
file = HDF5::File.create('numbers.h5')
54-
group = file.create_group('values')
55-
dataset = group.create_dataset('ints', [1, 2, 3, 4])
56-
57-
dataset.close
58-
group.close
59-
file.close
82+
HDF5::File.create('numbers.h5') do |file|
83+
file.create_group('values') do |group|
84+
group.create_dataset('ints', [1, 2, 3, 4])
85+
end
86+
end
6087

6188
reopened = HDF5::File.open('numbers.h5')
6289
p reopened['values']['ints'].read
6390
reopened.close
6491
```
6592

93+
## Error Handling
94+
95+
High-level API failures raise `HDF5::Error`.
96+
97+
```ruby
98+
begin
99+
HDF5::File.open('missing.h5')
100+
rescue HDF5::Error => e
101+
warn e.message
102+
end
103+
```
104+
66105
## Development
67106

68107
- [c2ffi](https://github.com/rpav/c2ffi)
@@ -83,23 +122,6 @@ c2ffi4rb hdf5.json > lib/hdf5/ffi.rb
83122

84123
The auto-generated bindings require some minor manual modifications.
85124

86-
### Development Strategy
87-
88-
#### All pull requests will be merged
89-
90-
- All pull requests received will be merged unless there is detrimental code.
91-
- If the pull request contains a bug, it still will be merged.
92-
- The author can add a comment that there is a bug here, or revert the commit if the bug is critical.
93-
- The author can add a commit to the pull request or send another pull request to fix the bug later.
94-
95-
#### Why are all pull requests merged?
96-
97-
- Development is a transition of code states.
98-
- We pay more attention to transient events, the probability that new commitments will continue to occur, than to the quality of the code at a given point in time.
99-
- Usually, High code quality is important to keep developers and users motivated.
100-
- However, HDF5 binding for Ruby has not been maintained for a long time.
101-
- This situation means that developer density is low and requires unusual strategies to maintain the project.
102-
103125
## Acknowledgement
104126

105127
[https://github.com/edmundhighcock/hdf5](https://github.com/edmundhighcock/hdf5)

0 commit comments

Comments
 (0)