Class: NumRu::VArrayHE5SwField

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

Constant Summary

Constants inherited from VArray

NumRu::VArray::Binary_operators, NumRu::VArray::Binary_operatorsL, NumRu::VArray::Binary_operatorsL_comp, NumRu::VArray::Binary_operatorsL_other, NumRu::VArray::Binary_operators_Uconv, NumRu::VArray::Binary_operators_Unone, NumRu::VArray::Binary_operators_Uop, NumRu::VArray::Math_funcs, NumRu::VArray::Math_funcs_nondim, NumRu::VArray::Math_funcs_radian, NumRu::VArray::NArray_type1_methods, NumRu::VArray::NArray_type2_methods, NumRu::VArray::NArray_type2_methods1, NumRu::VArray::NArray_type2_methods2, NumRu::VArray::NArray_type2_methods3, NumRu::VArray::NArray_type3_methods, NumRu::VArray::Unary_operators

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VArray

#+@, #[], #[]=, #att_names, #attr_copy, #axis_cyclic?, #axis_cyclic_extendible?, #axis_draw_positive, #axis_modulo, #bin_mean, #bin_sum, #coerce, #convert_units, #copy, #del_att, #get_att, #long_name, #long_name=, #mapped?, #marshal_dump, #marshal_load, #name, #name=, #rename, #rename!, #replace_val, #reshape, #reshape!, #set_att, #sqrt, #to_g1D, #transpose, #units, #units=

Constructor Details

#initialize(aHE5SwField) ⇒ VArrayHE5SwField

< initialization redefined > ##



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 11

def initialize(aHE5SwField)
  @name = aHE5SwField.name
  @mapping = nil
  @varray = nil
  if ! aHE5SwField.is_a?(HE5SwField)
 	raise ArgumentError,"Not a HE5SwField" 
  end
  @ary = aHE5SwField
  @attr = Attribute.new
  aHE5SwField.att_names.each{|name|
       @attr[name.downcase] = aHE5SwField.get_att(name).to_s 
       @attr["long_name"] = aHE5SwField.get_att(name).to_s if  name == "Title"  # For SMILES /MLS 
  }
end

Class Method Details

.new2(swath, name, ntype, dimensions, vary = nil) ⇒ Object Also known as: def_var



32
33
34
35
36
37
38
39
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 32

def new2(swath, name, ntype, dimensions, vary=nil)
  dimensions = dimensions.join(',') 
  va = new( swath.def_var(name, ntype, dimensions) )
  if vary
    vary.att_names.each{|name| va.set_att(name, vary.get_att(name))}
	end
  va
end

.new3(swath, name, ntype, dimensions, vary = nil) ⇒ Object Also known as: def_geo



42
43
44
45
46
47
48
49
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 42

def new3(swath, name, ntype, dimensions, vary=nil)
  dimensions = dimensions.join(',')
  va = new( swath.def_geo(name, ntype, dimensions) )
  if vary
	  vary.att_names.each{|name| va.set_att(name, vary.get_att(name))}
	end
  va
end

.write(file, vary, rename = nil, dimnames = nil) ⇒ Object

< additional class methods > ##

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 55

def write(file, vary, rename=nil, dimnames=nil)
	raise ArgumentError, "1st arg: not a HE5Sw" if !file.is_a?(HE5Sw)
	raise ArgumentError, "2nd arg: not a VArray" if !vary.is_a?(VArray)
	rank=vary.rank
	if dimnames == nil
	  if vary.is_a?(VArrayHE5SwField)
	    dimnames = vary.dim_names
	  else
	    dimnames=Array.new
	    for i in 0...rank
 dimnames[i]='x'+i.to_s
	    end
	  end
  elsif( rank != dimnames.length)
    raise ArgumentError, 
    "# of dim names does not agree with the rank of the VArray"
  end
	fdimnms = file.dim_names
	begin
	  shape = vary.shape
	rescue StandardError, NameError
	  shape = vary.shape_ul0
	end
	dims = Array.new
	for i in 0...rank
	  nm = dimnames[i]
	  if fdimnms.include?(nm)
	    dims[i] = nm
	  else
	    dims[i] = file.defdim(nm.name,shape[i])
	  end
	end
	nm = ( rename || vary.name )
	val = vary.val
	newvary = new2(file, nm, vary.typecode, dims, vary)
	newvary.val = val
  return newvary
end

Instance Method Details

#dim_namesObject



144
145
146
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 144

def dim_names
  @ary.dim_names
end

#fileObject



148
149
150
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 148

def file
  @ary.swath
end

#inspectObject



26
27
28
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 26

def inspect
  "<'#{@name}' in '#{@ary.swath.file.path}' #{@ary.ntype}#{shape_current.inspect}>"
end

#ntypeObject



119
120
121
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 119

def ntype
  @ary.ntype
end

#rankObject



138
139
140
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 138

def rank
  @ary.rank
end

#shapeObject



114
115
116
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 114

def shape
  raise "The shape method is not available. Use shape_ul0 or shape_current instead."
end

#shape_currentObject



127
128
129
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 127

def shape_current
  @ary.shape_current
end

#shape_ul0Object



123
124
125
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 123

def shape_ul0
  @ary.shape_ul0
end

#totalObject Also known as: length



131
132
133
134
135
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 131

def total
  len = 1
  @ary.shape_current.each{|i| len *= i}
  len
end

#valObject

< redefined instance methods > ##



97
98
99
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 97

def val
  return @ary.get
end

#val=(narray) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/numru/gphys/varrayhdfeos5.rb', line 101

def val=(narray)
  if narray.is_a?(Numeric)
    @ary.put( narray )
  else
    narray = __check_ary_class(narray)
    slicer = (0...rank).collect{|i|
      (shape_ul0[i] != 0) ? true : 0...narray.shape[i]
    }
    @ary[*slicer] = narray
    narray
  end
end