Class: NMatrix::IO::Matlab::Mat5Reader::Tag

Inherits:
Struct
  • Object
show all
Includes:
Packable
Defined in:
lib/nmatrix/io/mat5_reader.rb

Overview

:nodoc:

Constant Summary collapse

DATA_TYPE_OPTS =
BYTES_OPTS = {:bytes => 4, :signed => false}
LENGTH =

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bytesObject

Returns the value of attribute bytes

Returns:

  • (Object)

    the current value of bytes



455
456
457
# File 'lib/nmatrix/io/mat5_reader.rb', line 455

def bytes
  @bytes
end

#data_typeObject

Returns the value of attribute data_type

Returns:

  • (Object)

    the current value of data_type



455
456
457
# File 'lib/nmatrix/io/mat5_reader.rb', line 455

def data_type
  @data_type
end

#raw_data_typeObject

Returns the value of attribute raw_data_type

Returns:

  • (Object)

    the current value of raw_data_type



455
456
457
# File 'lib/nmatrix/io/mat5_reader.rb', line 455

def raw_data_type
  @raw_data_type
end

#smallObject

Returns the value of attribute small

Returns:

  • (Object)

    the current value of small



455
456
457
# File 'lib/nmatrix/io/mat5_reader.rb', line 455

def small
  @small
end

Instance Method Details

#inspectObject



496
497
498
# File 'lib/nmatrix/io/mat5_reader.rb', line 496

def inspect
  "#<#{self.class.to_s} data_type=#{data_type}[#{raw_data_type}][#{raw_data_type.to_s(2)}] bytes=#{bytes} size=#{size}#{small? ? ' small' : ''}>"
end

#read_packed(packedio, options) ⇒ Object



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
# File 'lib/nmatrix/io/mat5_reader.rb', line 474

def read_packed packedio, options
  self.raw_data_type = packedio.read([Integer, \
   DATA_TYPE_OPTS.merge(options)])

  # Borrowed from a SciPy patch
  upper = self.raw_data_type >> 16
  lower = self.raw_data_type & 0xFFFF

  if upper > 0
    # Small data element format
    raise IOError, 'Small data element format indicated, but length is more than 4 bytes!' if upper > 4

    self.bytes     = upper
    self.raw_data_type = lower

  else
    self.bytes = packedio.read([Integer, BYTES_OPTS.merge(options)])
  end

  self.data_type = MatReader::MDTYPES[self.raw_data_type]
end

#sizeObject



470
471
472
# File 'lib/nmatrix/io/mat5_reader.rb', line 470

def size
  small? ? 4 : 8
end

#small?Boolean

Returns:

  • (Boolean)


466
467
468
# File 'lib/nmatrix/io/mat5_reader.rb', line 466

def small?
  self.bytes > 0 and self.bytes <= 4
end

#write_packed(packedio, options) ⇒ Object

TODO: TEST WRITE.



462
463
464
# File 'lib/nmatrix/io/mat5_reader.rb', line 462

def write_packed packedio, options
  packedio << [data_type, DATA_TYPE_OPTS] << [bytes, BYTES_OPTS]
end