Class: GrADS::Gridded::Variable
- Inherits:
-
Object
- Object
- GrADS::Gridded::Variable
- Defined in:
- lib/grads/gridded.rb
Instance Attribute Summary collapse
-
#dim ⇒ Object
readonly
Returns the value of attribute dim.
-
#dset ⇒ Object
readonly
Returns the value of attribute dset.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #[](*argv) ⇒ Object
- #each_trange(trng = nil) ⇒ Object
-
#initialize(name, ctl) ⇒ Variable
constructor
A new instance of Variable.
- #to_ca ⇒ Object
- #tsize(trng = nil) ⇒ Object
Constructor Details
#initialize(name, ctl) ⇒ Variable
Returns a new instance of Variable.
45 46 47 48 49 50 51 52 53 |
# File 'lib/grads/gridded.rb', line 45 def initialize (name, ctl) @name = name @dim = ctl.vardims[name] @tsize = ctl.tsize @dset = ctl.dset @chunksize = ctl.chunksize @offset = ctl.varoffsets[name] @undef = ctl.undef end |
Instance Attribute Details
#dim ⇒ Object (readonly)
Returns the value of attribute dim.
55 56 57 |
# File 'lib/grads/gridded.rb', line 55 def dim @dim end |
#dset ⇒ Object (readonly)
Returns the value of attribute dset.
55 56 57 |
# File 'lib/grads/gridded.rb', line 55 def dset @dset end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
55 56 57 |
# File 'lib/grads/gridded.rb', line 55 def name @name end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
55 56 57 |
# File 'lib/grads/gridded.rb', line 55 def offset @offset end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
55 56 57 |
# File 'lib/grads/gridded.rb', line 55 def size @size end |
Instance Method Details
#[](*argv) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/grads/gridded.rb', line 84 def [] (*argv) trng = argv.shift buf = CArray.float(*@dim) out = nil open(@dset) { |io| if tsize(trng) == 1 each_trange(trng) { |t| io.seek(t * @chunksize + offset) buf.load_binary(io) out = buf[*argv] } else outlist = [] i = 0 bind_ok = false each_trange(trng) { |t| t * @chunksize + offset io.seek(t * @chunksize + offset) buf.load_binary(io) obj = buf[*argv].to_ca if obj.is_a?(CArray) outlist << obj else outlist << CA_FLOAT(obj) bind_ok = true end i += 1 } if bind_ok out = CArray.bind(:float, outlist, 0) else out = CArray.merge(:float, outlist, 0) end end } out[:eq, @undef] = UNDEF return out end |
#each_trange(trng = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/grads/gridded.rb', line 57 def each_trange (trng=nil) case trng when NilClass, FalseClass (0...@tsize).each do |t| yield(t) end when Range trng.each do |t| yield(t) end else t = trng yield(t) end end |
#to_ca ⇒ Object
123 124 125 |
# File 'lib/grads/gridded.rb', line 123 def to_ca return self[] end |
#tsize(trng = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/grads/gridded.rb', line 73 def tsize (trng=nil) case trng when NilClass, FalseClass return @tsize when Range return trng.to_a.size else return 1 end end |