Class NumRu::HE5ZaField
In: lib/hdfeos5.rb
Parent: Object
HE5Za HE5Gd HE5 HE5ZaField HE5GdField HE5Pt HE5SwField HE5Sw HE5PtField lib/hdfeos5.rb NumRu dot/m_0_0.png

HE5ZaField クラスに関して

Methods

[]   []=   __rubber_expansion   att_names   attr   create   dim   dim_names   dim_val   each_att   get   get_att   get_with_miss   inspect   name=   natts   ndims   ntype   open   put   put_att   rank   shape   shape_current   shape_ul0   simple_get   simple_put   typecode  

Constants

MissValAtts = ["MissingValue","_FillValue"]

Public Class methods

[Source]

      # File lib/hdfeos5.rb, line 2017
2017:        def create(file, zname,fldname)
2018:          if(file.is_a?(String))
2019:            zaid = HE5Za.create(file, zname)
2020:          elsif(!file.is_a?(HE5))
2021:            raise TypeError,
2022:                 "1st arg must be a HDF-EOS5 (file object) or a String (path)"
2023:          end
2024:          file.var(fldname)
2025:        end

[Source]

      # File lib/hdfeos5.rb, line 2027
2027:        def open(file, zname, fldname)
2028:          if(file.is_a?(String))
2029:            zaid = HE5Za.open(file, zname)
2030:          elsif(!file.is_a?(HE5))
2031:            raise TypeError,
2032:                 "1st arg must be a HDF-EOS5 (file object) or a String (path)"
2033:          end
2034:          zaid.var(fldname)
2035:        end

Public Instance methods

[Source]

      # File lib/hdfeos5.rb, line 2331
2331:     def [](*a)
2332:       if a.length == 0
2333:         return self.get
2334:       end
2335:       a = __rubber_expansion(a)
2336:       first = Array.new
2337:       last = Array.new
2338:       stride = Array.new
2339:       set_stride = false
2340:       a.each{|i|
2341:       if(i.is_a?(Fixnum))
2342:         first.push(i)
2343:         last.push(i)
2344:         stride.push(1)
2345:       elsif(i.is_a?(Range))
2346:         first.push(i.first)
2347:         last.push(i.exclude_end? ? i.last-1 : i.last)
2348:         stride.push(1)
2349:       elsif(i.is_a?(Hash))
2350:         r = (i.to_a[0])[0]
2351:         s = (i.to_a[0])[1]
2352:         if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) )
2353:             raise TypeError, "Hash argument must be {a_Range, step}"
2354:         end
2355:         first.push(r.first) 
2356:         last.push(r.exclude_end? ? r.last-1 : r.last)
2357:         stride.push(s)
2358:         set_stride = true
2359:       elsif(i.is_a?(TrueClass))
2360:         first.push(0)
2361:         last.push(-1)
2362:         stride.push(1)
2363:       elsif( i.is_a?(Array) || i.is_a?(NArray))
2364:         a_new = a.dup
2365:         at = a.index(i)
2366:         i = NArray.to_na(i) if i.is_a?(Array)
2367:         for n in 0..i.length-1
2368:           a_new[at] = i[n]..i[n]
2369:           na_tmp = self[*a_new]
2370:           if n==0 then
2371:             k = at
2372:             if at > 0
2373:               a[0..at-1].each{|x| if x.is_a?(Fixnum) then k -= 1 end}
2374:             end
2375:             shape_tmp = na_tmp.shape
2376:             shape_tmp[k] = i.length
2377:             na = na_tmp.class.new(na_tmp.typecode,*shape_tmp)
2378:             index_tmp = Array.new(shape_tmp.length,true)
2379:           end
2380:           index_tmp[k] = n..n
2381:           na[*index_tmp] = na_tmp
2382:         end
2383:         return na
2384:       else
2385:          raise TypeError, "argument must be Fixnum, Range, Hash, TrueClass, Array, or NArray"
2386:       end
2387:       }
2388: 
2389:       if(set_stride)
2390:         na = self.get({"start"=>first, "end"=>last, "stride"=>stride})
2391:       else
2392:         na = self.get({"start"=>first, "end"=>last})
2393:       end
2394:       shape = na.shape
2395:       (a.length-1).downto(0){ |i|
2396:          shape.delete_at(i) if a[i].is_a?(Fixnum)
2397:       }
2398:       na.reshape!( *shape )
2399:       na
2400:     end

[Source]

      # File lib/hdfeos5.rb, line 2402
2402:     def []=(*a)
2403:       val = a.pop
2404:       a = __rubber_expansion(a)
2405:       first = Array.new
2406:       last = Array.new
2407:       stride = Array.new
2408:       set_stride = false
2409:       a.each{|i|
2410:       if(i.is_a?(Fixnum))
2411:         first.push(i)
2412:         last.push(i)
2413:         stride.push(1)
2414:       elsif(i.is_a?(Range))
2415:         first.push(i.first)
2416:         last.push(i.exclude_end? ? i.last-1 : i.last)
2417:         stride.push(1)
2418:       elsif(i.is_a?(Hash))
2419:         r = (i.to_a[0])[0]
2420:         s = (i.to_a[0])[1]
2421:         if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) )
2422:             raise ArgumentError, "Hash argument must be {first..last, step}"
2423:         end
2424:         first.push(r.first) 
2425:         last.push(r.exclude_end? ? r.last-1 : r.last)
2426:         stride.push(s)
2427:         set_stride = true
2428:       elsif(i.is_a?(TrueClass))
2429:         first.push(0)
2430:         last.push(-1)
2431:         stride.push(1)
2432:       elsif(i.is_a?(Array) || i.is_a?(NArray))
2433:         a_new = a.dup
2434:         at = a.index(i)
2435:         i = NArray.to_na(i) if i.is_a?(Array)
2436:         val = NArray.to_na(val) if val.is_a?(Array)
2437:         rank_of_subset = a.dup.delete_if{|v| v.is_a?(Fixnum)}.length
2438:         if val.rank != rank_of_subset
2439:            raise "rank of the rhs (#{val.rank}) is not equal to the rank "+
2440:                  "of the subset specified by #{a.inspect} (#{rank_of_subset})"
2441:         end
2442:         k = at
2443:         a[0..at-1].each{|x| if x.is_a?(Fixnum) then k -= 1 end}
2444:         if i.length != val.shape[k]
2445:            raise "length of the #{k+1}-th dim of rhs is incorrect "+
2446:                  "(#{i.length} for #{val.shape[k]})"
2447:         end
2448:         index_tmp = Array.new(val.rank,true) if !val.is_a?(Numeric) #==>Array-like
2449:         for n in 0..i.length-1
2450:           a_new[at] = i[n]..i[n]
2451:           if !val.is_a?(Numeric) then
2452:             index_tmp[k] = n..n
2453:             self[*a_new] = val[*index_tmp]
2454:           else
2455:             self[*a_new] = val
2456:           end
2457:         end
2458:         return self
2459:       else
2460:         raise TypeError, "argument must be Fixnum, Range, Hash, TrueClass, Array, or NArray"
2461:       end
2462:       }
2463: 
2464:       if(set_stride)
2465:         self.put(val, {"start"=>first, "end"=>last, "stride"=>stride})
2466:       else
2467:         self.put(val, {"start"=>first, "end"=>last})
2468:       end
2469:     end

[Source]

      # File lib/hdfeos5.rb, line 2099
2099:     def att_names
2100:       nattrs, attrnames, strbufsize = inqlocattrs()
2101:       return attrnames.split(/,/)
2102:     end

[Source]

      # File lib/hdfeos5.rb, line 2123
2123:     def attr
2124:       @attr
2125:     end

[Source]

      # File lib/hdfeos5.rb, line 2067
2067:     def dim(dimid)
2068:       rank, dims, ntype, dimlist =fieldinfo()
2069:       return dimlist.split(",")[dimid]
2070:     end

[Source]

      # File lib/hdfeos5.rb, line 2077
2077:     def dim_names
2078:       rank, dims, ntype, dimlist =fieldinfo()
2079:       return dimlist.split(",").reverse
2080:     end

[Source]

      # File lib/hdfeos5.rb, line 2072
2072:     def dim_val(dimid)
2073:       rank, dims, ntype, dimlist =fieldinfo()
2074:       return dimlist.split(",")[dimid]
2075:     end

[Source]

      # File lib/hdfeos5.rb, line 2104
2104:     def each_att
2105:       attlist=Array.new
2106:       attnames=att_names()
2107:       attnum = natts()
2108:       attnames.each{|attname|
2109:         list=Array.new
2110:         attrval=att(attname)
2111:         list.push(attname, attrval)
2112:         attlist.push(list)
2113:       }
2114:       attlist
2115:     end
get(*args)

Alias for get_with_miss

[Source]

      # File lib/hdfeos5.rb, line 2091
2091:     def get_att(attname)
2092:       if att_names.include?(attname)
2093:         get_att_(attname)
2094:       else
2095:         nil
2096:       end
2097:     end

[Source]

      # File lib/hdfeos5.rb, line 2298
2298:     def get_with_miss(*args)
2299:       na = simple_get(*args)
2300:       mv = nil
2301:       MissValAtts.each do |nm|
2302:         mv = get_att(nm)
2303:         break if !mv.nil?
2304:       end
2305:       if mv.nil?
2306:         na
2307:       else
2308:         NArrayMiss.to_nam_no_dup( na, (na.ne(mv[0])) )
2309:       end
2310:     end

[Source]

      # File lib/hdfeos5.rb, line 2471
2471:     def inspect
2472:       'HE5ZaField:'+za.file.path+'?var='+name
2473:     end

[Source]

      # File lib/hdfeos5.rb, line 2082
2082:     def name=
2083:       raise "name= not supported"
2084:     end

[Source]

      # File lib/hdfeos5.rb, line 2086
2086:     def natts
2087:       nattrs, attrname, strbufsize = inqlocattrs()
2088:       return nattrs
2089:     end

[Source]

      # File lib/hdfeos5.rb, line 2061
2061:     def ndims
2062:       rank, dims, ntype, dimlist =fieldinfo()
2063:       return rank
2064:     end

[Source]

      # File lib/hdfeos5.rb, line 2038
2038:     def ntype
2039:       rank, dims, ntype, dimlist = fieldinfo()
2040:       return ntype
2041:     end
put(var,hash=nil)

Alias for simple_put

[Source]

      # File lib/hdfeos5.rb, line 2117
2117:     def put_att(name,value,atttype=nil)
2118:        count = Array.new
2119:        count[0] = value.size
2120:        writelocattr(name,atttype,count,value)
2121:     end
rank()

Alias for ndims

[Source]

      # File lib/hdfeos5.rb, line 2044
2044:     def shape
2045:       rank, dims, ntype, dimlist =fieldinfo
2046:       return dims[-1..0].to_a   # NArray --> reverced --> Array
2047:     end
shape_current()

Alias for shape

[Source]

      # File lib/hdfeos5.rb, line 2051
2051:     def shape_ul0
2052:       sh = shape_current
2053:       dim_names.each_with_index do |dnm,i|
2054:         if dnm == "Unlim"
2055:           sh[i] = 0
2056:         end
2057:       end
2058:       sh
2059:     end

[Source]

      # File lib/hdfeos5.rb, line 2213
2213:     def simple_get(hash=nil)
2214:       if hash == nil
2215:         if self.ntype == "char" || self.ntype=="byte"
2216:           get_vars_char([0,0,0,0,0,0,0,0], nil, nil)
2217:         elsif self.ntype=="sint"
2218:           get_vars_short([0,0,0,0,0,0,0,0], nil, nil)
2219:         elsif self.ntype=="int"
2220:           get_vars_int([0,0,0,0,0,0,0,0], nil, nil)
2221:         elsif self.ntype=="sfloat"
2222:           get_vars_float([0,0,0,0,0,0,0,0], nil, nil)
2223:         elsif self.ntype=="float"
2224:           get_vars_double([0,0,0,0,0,0,0,0], nil, nil)
2225:         else
2226:           raise ArgumentError, "variable type isn't supported in HDF-EOS5"
2227:         end
2228:       elsif hash.key?("index")==true ||  hash.key?("start")==true
2229:         h_sta = hash["start"]
2230:         endq = hash.key?("end")
2231:         strq = hash.key?("stride")
2232:         if endq == false && strq == false
2233:           if self.ntype == "char" || self.ntype=="byte"
2234:             get_vars_char(h_sta, nil, nil)
2235:           elsif self.ntype=="sint"
2236:             get_vars_short(h_sta, nil, nil)
2237:           elsif self.ntype=="int"
2238:             get_vars_int(h_sta, nil, nil)
2239:           elsif self.ntype=="sfloat"
2240:             get_vars_float(h_sta, nil, nil)
2241:           elsif self.ntype=="float"
2242:             get_vars_double(h_sta, nil, nil)
2243:           else
2244:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
2245:           end
2246:         elsif endq == true && strq == false
2247:           h_end = hash["end"]
2248:           if self.ntype == "char" || self.ntype=="byte"
2249:             get_vars_char(h_sta, nil, h_end)
2250:           elsif self.ntype=="sint"
2251:             get_vars_short(h_sta, nil, h_end)
2252:           elsif self.ntype=="int"
2253:             get_vars_int(h_sta, nil, h_end)
2254:           elsif self.ntype=="sfloat"
2255:             get_vars_float(h_sta, nil, h_end)
2256:           elsif self.ntype=="float"
2257:             get_vars_double(h_sta, nil, h_end)
2258:           else
2259:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
2260:           end
2261:         elsif endq == false && strq == true
2262:           h_str = hash["stride"]
2263:           if self.ntype == "char" || self.ntype=="byte"
2264:             get_vars_char(h_sta, h_str, nil)
2265:           elsif self.ntype=="sint"
2266:             get_vars_short(h_sta, h_str, nil)
2267:           elsif self.ntype=="int"
2268:             get_vars_int(h_sta, h_str, nil)
2269:           elsif self.ntype=="sfloat"
2270:             get_vars_float(h_sta, h_str, nil)
2271:           elsif self.ntype=="float"
2272:             get_vars_double(h_sta, h_str, nil)
2273:           else
2274:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
2275:           end
2276:         else endq == true && strq == true
2277:           h_end = hash["end"]
2278:           h_str = hash["stride"]
2279:           if self.ntype == "char" || self.ntype=="byte"
2280:             get_vars_char(h_sta, h_str, h_end)
2281:           elsif self.ntype=="sint"
2282:             get_vars_short(h_sta, h_str, h_end)
2283:           elsif self.ntype=="int"
2284:             get_vars_int(h_sta, h_str, h_end)
2285:           elsif self.ntype=="sfloat"
2286:             get_vars_float(h_sta, h_str, h_end)
2287:           elsif self.ntype=="float"
2288:             get_vars_double(h_sta, h_str, h_end)
2289:           else
2290:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
2291:           end
2292:         end
2293:       else
2294:         raise ArgumentError,"{'start'}=>{ARRAY} or {'index'}=>{ARRAY} is needed"
2295:       end
2296:     end

[Source]

      # File lib/hdfeos5.rb, line 2127
2127:     def simple_put(var,hash=nil)
2128:       if hash == nil
2129:         if self.ntype == "char" || self.ntype=="byte"
2130:           put_vars_char([0,0,0,0,0,0,0,0], nil, nil, var)
2131:         elsif self.ntype=="sint"
2132:           put_vars_short([0,0,0,0,0,0,0,0], nil, nil, var)
2133:         elsif self.ntype=="int"
2134:           put_vars_int([0,0,0,0,0,0,0,0], nil, nil, var)
2135:         elsif self.ntype=="sfloat"
2136:           put_vars_float([0,0,0,0,0,0,0,0], nil, nil, var)
2137:         elsif self.ntype=="float"
2138:           put_vars_double([0,0,0,0,0,0,0,0], nil, nil, var)
2139:         else
2140:           raise ArgumentError, "variable type isn't supported in HDF-EOS5"
2141:         end
2142:       elsif hash.key?("index")==true ||  hash.key?("start")==true
2143:         h_sta = hash["start"]
2144:         endq = hash.key?("end")
2145:         strq = hash.key?("stride")
2146:         if endq == false && strq == false
2147:           if self.ntype == "char" || self.ntype=="byte"
2148:             put_vars_char(h_sta, nil, nil, var)
2149:           elsif self.ntype=="sint"
2150:             put_vars_short(h_sta, nil, nil, var)
2151:           elsif self.ntype=="int"
2152:             put_vars_int(h_sta, nil, nil, var)
2153:           elsif self.ntype=="sfloat"
2154:             put_vars_float(h_sta, nil, nil, var)
2155:           elsif self.ntype=="float"
2156:             put_vars_double(h_sta, nil, nil, var)
2157:           else
2158:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
2159:           end
2160:         elsif endq == true && strq == false
2161:           h_end = hash["end"]
2162:           if self.ntype == "char" || self.ntype=="byte"
2163:             put_vars_char(h_sta, nil, h_end, var)
2164:           elsif self.ntype=="sint"
2165:             put_vars_short(h_sta, nil, h_end, var)
2166:           elsif self.ntype=="int"
2167:             put_vars_int(h_sta, nil, h_end, var)
2168:           elsif self.ntype=="sfloat"
2169:             put_vars_float(h_sta, nil, h_end, var)
2170:           elsif self.ntype=="float"
2171:             put_vars_double(h_sta, nil, h_end, var)
2172:           else
2173:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
2174:           end
2175:         elsif endq == false && strq == true
2176:           h_str = hash["stride"]
2177:           if self.ntype == "char" || self.ntype=="byte"
2178:             put_vars_char(h_sta, h_str, nil, var)
2179:           elsif self.ntype=="sint"
2180:             put_vars_short(h_sta, h_str, nil, var)
2181:           elsif self.ntype=="int"
2182:             put_vars_int(h_sta, h_str, nil, var)
2183:           elsif self.ntype=="sfloat"
2184:             put_vars_float(h_sta, h_str, nil, var)
2185:           elsif self.ntype=="float"
2186:             put_vars_double(h_sta, h_str, nil, var)
2187:           else
2188:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
2189:           end
2190:         else endq == true && strq == true
2191:           h_end = hash["end"]
2192:           h_str = hash["stride"]
2193:           if self.ntype == "char" || self.ntype=="byte"
2194:             put_vars_char(h_sta, h_str, h_end, var)
2195:           elsif self.ntype=="sint"
2196:             put_vars_short(h_sta, h_str, h_end, var)
2197:           elsif self.ntype=="int"
2198:             put_vars_int(h_sta, h_str, h_end, var)
2199:           elsif self.ntype=="sfloat"
2200:             put_vars_float(h_sta, h_str, h_end, var)
2201:           elsif self.ntype=="float"
2202:             put_vars_double(h_sta, h_str, h_end, var)
2203:           else
2204:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
2205:           end
2206:         end
2207:       else
2208:         raise ArgumentError,"{'start'}=>{ARRAY} or {'index'}=>{ARRAY} is needed"
2209:       end
2210:     end
typecode()

Alias for ntype

Private Instance methods

[Source]

      # File lib/hdfeos5.rb, line 2313
2313:     def __rubber_expansion( args )
2314:       if (id = args.index(false))  # substitution into id
2315:         # false is incuded
2316:         alen = args.length
2317:         if args.rindex(false) != id
2318:           raise ArguemntError,"only one rubber dimension is permitted"
2319:         elsif alen > rank+1
2320:           raise ArgumentError, "too many args"
2321:         end
2322:         ar = ( id!=0 ? args[0..id-1] : [] )
2323:         args = ar + [true]*(rank-alen+1) + args[id+1..-1]
2324:       elsif args.length == 0   # to support empty [], []=
2325:         args = [true]*rank
2326:       end
2327:       args
2328:     end

[Validate]