Class: NumRu::GPhys::GribDim

Inherits:
Object
  • Object
show all
Defined in:
lib/numru/gphys/grib.rb

Overview

NumRu::GPhys::GribDim

Class Methods

—new( vat, name, length )

Methods

—var —length —name —typecode —get —[](indices) —put_att(key,val) —set_att(key,val) —att(key) —att_names —inspect

Instance Method Summary collapse

Constructor Details

#initialize(var, name) ⇒ GribDim

Returns a new instance of GribDim.



1594
1595
1596
1597
1598
# File 'lib/numru/gphys/grib.rb', line 1594

def initialize(var,name)
  @var = var
  @name = name
  @attr = Hash.new
end

Instance Method Details

#[](ind) ⇒ Object



1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
# File 'lib/numru/gphys/grib.rb', line 1630

def [](ind)
  v = val
  if Hash === ind    # {range=>step} --> array of indices
    ran, step = ind.to_a[0]
    dlen = v.length
    f = ran.first
    f += dlen if f<0
    e = ran.end
    e += dlen if e<0
    e -= 1 if ran.exclude_end?
    ind = Array.new
    (f..e).step(step){|n| ind.push(n)}
  end
  return v[ind]
end

#att(key) ⇒ Object



1657
1658
1659
# File 'lib/numru/gphys/grib.rb', line 1657

def att(key)
  @attr[key]
end

#att_namesObject



1660
1661
1662
# File 'lib/numru/gphys/grib.rb', line 1660

def att_names
  @attr.keys
end

#getObject



1609
1610
1611
# File 'lib/numru/gphys/grib.rb', line 1609

def get
  @ary
end

#inspectObject



1663
1664
1665
# File 'lib/numru/gphys/grib.rb', line 1663

def inspect
  "GribDim: #{name}"
end

#lengthObject Also known as: total



1602
1603
1604
# File 'lib/numru/gphys/grib.rb', line 1602

def length
  @length
end

#nameObject



1606
1607
1608
# File 'lib/numru/gphys/grib.rb', line 1606

def name
  @name
end

#put(ary) ⇒ Object



1645
1646
1647
1648
1649
1650
1651
1652
# File 'lib/numru/gphys/grib.rb', line 1645

def put(ary)
  if ary.typecode <= NArray::INT         # 2014-09-22 horinouchi
    ary = ary.to_type(NArray::DFLOAT)
  end 
  @ary = ary
  @length = val.length
  return @ary
end

#put_att(key, val) ⇒ Object Also known as: set_att



1653
1654
1655
# File 'lib/numru/gphys/grib.rb', line 1653

def put_att(key,val)
  @attr[key]=val
end

#typecodeObject



1612
1613
1614
1615
1616
1617
1618
# File 'lib/numru/gphys/grib.rb', line 1612

def typecode
  if NArray===@ary
    @ary.typecode
  elsif Array===@ary
    @ary[0]["value"].typecode
  end
end

#valObject



1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
# File 'lib/numru/gphys/grib.rb', line 1619

def val
  if Array===@ary
    if att("long_name")=="Hybrid level"
      return @ary[0]["value"]
    else
      return @ary[1]["value"]
    end
  else
    return @ary
  end
end

#varObject



1599
1600
1601
# File 'lib/numru/gphys/grib.rb', line 1599

def var
  @var
end