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



439
440
441
# File 'lib/nmatrix/io/mat5_reader.rb', line 439

def bytes
  @bytes
end

#data_typeObject

Returns the value of attribute data_type

Returns:

  • (Object)

    the current value of data_type



439
440
441
# File 'lib/nmatrix/io/mat5_reader.rb', line 439

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



439
440
441
# File 'lib/nmatrix/io/mat5_reader.rb', line 439

def raw_data_type
  @raw_data_type
end

#smallObject

Returns the value of attribute small

Returns:

  • (Object)

    the current value of small



439
440
441
# File 'lib/nmatrix/io/mat5_reader.rb', line 439

def small
  @small
end

Instance Method Details

#inspectObject



479
480
481
# File 'lib/nmatrix/io/mat5_reader.rb', line 479

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



458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/nmatrix/io/mat5_reader.rb', line 458

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



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

def size
  small? ? 4 : 8
end

#small?Boolean

Returns:

  • (Boolean)


450
451
452
# File 'lib/nmatrix/io/mat5_reader.rb', line 450

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

#write_packed(packedio, options) ⇒ Object

TODO: TEST WRITE.



446
447
448
# File 'lib/nmatrix/io/mat5_reader.rb', line 446

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