lib/numru/gphys/gphys.rb in gphys-1.5.0 vs lib/numru/gphys/gphys.rb in gphys-1.5.1

- old
+ new

@@ -522,11 +522,31 @@ * dim_or_dimname (String or Integer) RETURN VALUE * a GPhys (possibly self) +---mask!(mask) + Mask the data by the mask array (additionally by the "&" + operation, if self has data missing). + (Destructive version to replace the data array by the result. + -- replaced but not over-written.) + ARGUMENTS + * mask (byte type NArray or NArrayMiss) + + RETURN VALUE + * self + +---mask(mask) + Same as mask! but self is preserved. + + ARGUMENTS + * mask (byte type NArray or NArrayMiss) + + RETURN VALUE + * a GPhys + === Math functions (instance methods) ====sqrt, exp, log, log10, log2, sin, cos, tan, sinh, cosh, tanh, asin, acos, atan, asinh, acosh, atanh, csc, sec, cot, csch, sech, coth, acsc, asec, acot, acsch, asech, acoth === Binary operators @@ -1100,10 +1120,33 @@ end return to_return end + def mask!(mask) + mask = mask.to_na(0) if mask.is_a?(NArrayMiss) + v = self.val + if v.is_a?(NArrayMiss) + v.set_mask( v.get_mask & mask ) + else + v = NArrayMiss.to_nam(v,mask) + end + self.replace_val(v) + end + + def mask(mask) + mask = mask.to_na(0) if mask.is_a?(NArrayMiss) + v = self.val + if v.is_a?(NArrayMiss) + v.set_mask( v.get_mask & mask ) + else + v = NArrayMiss.to_nam(v,mask) + end + self.copy.replace_val(v) + end + + def marshal_dump [@data.copy, @grid.copy] end def marshal_load(ary) @@ -1470,23 +1513,28 @@ (shlc.length-idx).times{ shlc.pop } end rtable.reverse! if table != rtable - # < matching ambiguous => try to match by name > + # < matching ambiguous => match by name where ambiguous > - real_table = table.dup # just to start with. - # rtable will be merged in the following - - shs.each_index do |i| - #print axnms[i]," ",axnml[ table[i] ]," ",axnml[ rtable[i] ],"\n" - if axnms[i] == axnml[ rtable[i] ] - real_table[i] = rtable[i] - elsif axnms[i] != axnml[ table[i] ] - raise "Both matchings by orders and by names failed for the #{i}-th axis #{axnms[i]}." - end - end - + real_table = Array.new + for i in 0...shs.length + if table[i] == rtable[i] + real_table[i] = table[i] + else + for j in table[i]..rtable[i] + if axnms[i] == axnml[j] && shs[i] == shl[j] + real_table[i] = j + break + end + end + if real_table[i].nil? + raise("Matching failed: #{shl.inspect}(#{axnml.inspect})" + + " and #{shs.inspect}(#{axnms.inspect})") + end + end + end table = real_table end # < derive the argument for the reshape method >