78
79
80
81
82
83
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/numru/gphys/gphys_grib_io.rb', line 78
def open(file, varname)
if file.is_a?(String)
file = VArrayGrib.grib.open(file)
elsif ! VArrayGrib.grib===file
raise ArgumentError, "1st arg must be a Grib or a file name"
end
var = file.var(varname)
var.nil? && raise("variable '#{varname}' not found in '#{file.path}'")
data = VArrayGrib.new(var)
rank = data.rank
bare_index = [ false ] * rank
axes = Array.new
var_names = file.var_names
for i in 0...rank
dim = var.dim(i)
val = dim.get
if Array===val && val.length!=1
bare_index[i] = true
end
axpos = VArrayGrib.new( dim )
cell_center = true
cell = false
axis = Axis.new(cell,bare_index[i])
if !cell
axis.set_pos( axpos )
else
if cell_center
if varray_cell_bounds
axis.set_cell(axpos, varray_cell_bounds).set_pos_to_center
else
p "cell bounds are guessed"
axis.set_cell_guess_bounds(axpos).set_pos_to_center
end
else if varray_cell_center
axis.set_cell(varray_cell_center, axpos).set_pos_to_bounds
else
p "cell center is guessed"
axis.set_cell_guess_center(axpos).set_pos_to_bounds
end
end
end
if Array===val && val.length!=1
val[1..-1].each{|hash|
va =
va = VArray.new(hash["value"],nil,hash["name"])
hash.each{|k,v|
next if k=="value"||k=="name"
va.put_att(k,v)
}
axis.set_aux(hash["name"],va)
}
end
axes[i] = axis
end
grid = Grid.new( *axes )
GPhys.new(grid,data)
end
|