Class: Hdf5::H5File

Inherits:
Object
  • Object
show all
Extended by:
FFI::Library
Defined in:
lib/hdf5.rb

Overview

Object for wrapping an HDF file. Basic usage:

file = Hdf5::H5File.new('filename.hdf5')
dataset = file.dataset('/path/to/dataset')
narray = dataset.narray_all
file.close

Defined Under Namespace

Classes: InvalidFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ H5File

Open the file with the given filename. Currently read only

Raises:

  • (Errno::ENOENT)


116
117
118
119
120
121
122
# File 'lib/hdf5.rb', line 116

def initialize(filename)
  raise Errno::ENOENT.new("File #{filename} does not exist") unless FileTest.exist?(filename)
  raise InvalidFile.new("File #{filename} is not a valid hdf5 file") unless basic_is_hdf5(filename) > 0
  @filename = filename
  @id = basic_open(filename, 0x0000, 0)
  raise InvalidFile.new("An unknown problem occured opening #{filename}") if @id < 0
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



114
115
116
# File 'lib/hdf5.rb', line 114

def id
  @id
end

Instance Method Details

#closeObject

Close the file



128
129
130
# File 'lib/hdf5.rb', line 128

def close
  basic_close(@id)
end

#dataset(name) ⇒ Object

Return a dataset object with the given name (relative to the root of the file)



138
139
140
# File 'lib/hdf5.rb', line 138

def dataset(name)
  return H5Dataset.open(@id, name)
end

#group(name) ⇒ Object

Return a group object with the given name (relative to the root of the file)



133
134
135
# File 'lib/hdf5.rb', line 133

def group(name)
  return H5Group.open(@id, name)
end

#is_hdf5?Boolean

Is the file a valid hdf5 file

Returns:

  • (Boolean)


124
125
126
# File 'lib/hdf5.rb', line 124

def is_hdf5?
  basic_is_hdf5(@filename) > 0
end