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

HE5GdField クラスに関して

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 951
951:        def create(file, gname, fldname, xdimsize, ydimsize, upleftpt, lowrightpt)
952:          if(file.is_a?(String))
953:            gdid = HE5Gd.create(file, gname, xdimsize, ydimsize, upleftpt, lowrightpt)
954:          elsif(!file.is_a?(HE5))
955:            raise TypeError,
956:                 "1st arg must be a HDF-EOS5 (file object) or a String (path)"
957:          end
958:          file.var(fldname)
959:        end

[Source]

     # File lib/hdfeos5.rb, line 961
961:        def open(file, gname, fldname)
962:          if(file.is_a?(String))
963:            gdid = HE5Gd.open(file, gname)
964:          elsif(!file.is_a?(HE5))
965:            raise TypeError,
966:                 "1st arg must be a HDF-EOS5 (file object) or a String (path)"
967:          end
968:          gdid.var(fldname)
969:        end

Public Instance methods

[Source]

      # File lib/hdfeos5.rb, line 1265
1265:     def [](*a)
1266:       if a.length == 0
1267:         return self.get
1268:       end
1269:       a = __rubber_expansion(a)
1270:       first = Array.new
1271:       last = Array.new
1272:       stride = Array.new
1273:       set_stride = false
1274:       a.each{|i|
1275:       if(i.is_a?(Fixnum))
1276:         first.push(i)
1277:         last.push(i)
1278:         stride.push(1)
1279:       elsif(i.is_a?(Range))
1280:         first.push(i.first)
1281:         last.push(i.exclude_end? ? i.last-1 : i.last)
1282:         stride.push(1)
1283:       elsif(i.is_a?(Hash))
1284:         r = (i.to_a[0])[0]
1285:         s = (i.to_a[0])[1]
1286:         if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) )
1287:             raise TypeError, "Hash argument must be {a_Range, step}"
1288:         end
1289:         first.push(r.first) 
1290:         last.push(r.exclude_end? ? r.last-1 : r.last)
1291:         stride.push(s)
1292:         set_stride = true
1293:       elsif(i.is_a?(TrueClass))
1294:         first.push(0)
1295:         last.push(-1)
1296:         stride.push(1)
1297:       elsif( i.is_a?(Array) || i.is_a?(NArray))
1298:         a_new = a.dup
1299:         at = a.index(i)
1300:         i = NArray.to_na(i) if i.is_a?(Array)
1301:         for n in 0..i.length-1
1302:           a_new[at] = i[n]..i[n]
1303:           na_tmp = self[*a_new]
1304:           if n==0 then
1305:             k = at
1306:             if at > 0
1307:               a[0..at-1].each{|x| if x.is_a?(Fixnum) then k -= 1 end}
1308:             end
1309:             shape_tmp = na_tmp.shape
1310:             shape_tmp[k] = i.length
1311:             na = na_tmp.class.new(na_tmp.typecode,*shape_tmp)
1312:             index_tmp = Array.new(shape_tmp.length,true)
1313:           end
1314:           index_tmp[k] = n..n
1315:           na[*index_tmp] = na_tmp
1316:         end
1317:         return na
1318:       else
1319:          raise TypeError, "argument must be Fixnum, Range, Hash, TrueClass, Array, or NArray"
1320:       end
1321:       }
1322: 
1323:       if(set_stride)
1324:         na = self.get({"start"=>first, "end"=>last, "stride"=>stride})
1325:       else
1326:         na = self.get({"start"=>first, "end"=>last})
1327:       end
1328:       shape = na.shape
1329:       (a.length-1).downto(0){ |i|
1330:          shape.delete_at(i) if a[i].is_a?(Fixnum)
1331:       }
1332:       na.reshape!( *shape )
1333:       na
1334:     end

[Source]

      # File lib/hdfeos5.rb, line 1336
1336:     def []=(*a)
1337:       val = a.pop
1338:       a = __rubber_expansion(a)
1339:       first = Array.new
1340:       last = Array.new
1341:       stride = Array.new
1342:       set_stride = false
1343:       a.each{|i|
1344:       if(i.is_a?(Fixnum))
1345:         first.push(i)
1346:         last.push(i)
1347:         stride.push(1)
1348:       elsif(i.is_a?(Range))
1349:         first.push(i.first)
1350:         last.push(i.exclude_end? ? i.last-1 : i.last)
1351:         stride.push(1)
1352:       elsif(i.is_a?(Hash))
1353:         r = (i.to_a[0])[0]
1354:         s = (i.to_a[0])[1]
1355:         if ( !( r.is_a?(Range) ) || ! ( s.is_a?(Integer) ) )
1356:             raise ArgumentError, "Hash argument must be {first..last, step}"
1357:         end
1358:         first.push(r.first) 
1359:         last.push(r.exclude_end? ? r.last-1 : r.last)
1360:         stride.push(s)
1361:         set_stride = true
1362:       elsif(i.is_a?(TrueClass))
1363:         first.push(0)
1364:         last.push(-1)
1365:         stride.push(1)
1366:       elsif(i.is_a?(Array) || i.is_a?(NArray))
1367:         a_new = a.dup
1368:         at = a.index(i)
1369:         i = NArray.to_na(i) if i.is_a?(Array)
1370:         val = NArray.to_na(val) if val.is_a?(Array)
1371:         rank_of_subset = a.dup.delete_if{|v| v.is_a?(Fixnum)}.length
1372:         if val.rank != rank_of_subset
1373:            raise "rank of the rhs (#{val.rank}) is not equal to the rank "+
1374:                  "of the subset specified by #{a.inspect} (#{rank_of_subset})"
1375:         end
1376:         k = at
1377:         a[0..at-1].each{|x| if x.is_a?(Fixnum) then k -= 1 end}
1378:         if i.length != val.shape[k]
1379:            raise "length of the #{k+1}-th dim of rhs is incorrect "+
1380:                  "(#{i.length} for #{val.shape[k]})"
1381:         end
1382:         index_tmp = Array.new(val.rank,true) if !val.is_a?(Numeric) #==>Array-like
1383:         for n in 0..i.length-1
1384:           a_new[at] = i[n]..i[n]
1385:           if !val.is_a?(Numeric) then
1386:             index_tmp[k] = n..n
1387:             self[*a_new] = val[*index_tmp]
1388:           else
1389:             self[*a_new] = val
1390:           end
1391:         end
1392:         return self
1393:       else
1394:         raise TypeError, "argument must be Fixnum, Range, Hash, TrueClass, Array, or NArray"
1395:       end
1396:       }
1397: 
1398:       if(set_stride)
1399:         self.put(val, {"start"=>first, "end"=>last, "stride"=>stride})
1400:       else
1401:         self.put(val, {"start"=>first, "end"=>last})
1402:       end
1403:     end

[Source]

      # File lib/hdfeos5.rb, line 1033
1033:     def att_names
1034:       nattrs, attrnames, strbufsize = inqlocattrs()
1035:       return attrnames.split(/,/)
1036:     end

[Source]

      # File lib/hdfeos5.rb, line 1057
1057:     def attr
1058:       @attr
1059:     end

[Source]

      # File lib/hdfeos5.rb, line 1001
1001:     def dim(dimid)
1002:       rank, dims, ntype, dimlist = fieldinfo()
1003:       return dimlist.split(",")[dimid]
1004:     end

[Source]

      # File lib/hdfeos5.rb, line 1011
1011:     def dim_names
1012:       rank, dims, ntype, dimlist = fieldinfo()
1013:       return dimlist.split(",").reverse
1014:     end

[Source]

      # File lib/hdfeos5.rb, line 1006
1006:     def dim_val(dimid)
1007:       rank, dims, ntype, dimlist = fieldinfo()
1008:       return dimlist.split(",")[dimid]
1009:     end

[Source]

      # File lib/hdfeos5.rb, line 1038
1038:     def each_att
1039:       attlist=Array.new
1040:       attnames=att_names()
1041:       attnum = natts()
1042:       attnames.each{|attname|
1043:         list=Array.new
1044:         attrval=att(attname)
1045:         list.push(attname, attrval)
1046:         attlist.push(list)
1047:       }
1048:       attlist
1049:     end
get(*args)

Alias for get_with_miss

[Source]

      # File lib/hdfeos5.rb, line 1025
1025:     def get_att(attname)
1026:       if att_names.include?(attname)
1027:         get_att_(attname)
1028:       else
1029:         nil
1030:       end
1031:     end

[Source]

      # File lib/hdfeos5.rb, line 1232
1232:     def get_with_miss(*args)
1233:       na = simple_get(*args)
1234:       mv = nil
1235:       MissValAtts.each do |nm|
1236:         mv = get_att(nm)
1237:         break if !mv.nil?
1238:       end
1239:       if mv.nil?
1240:         na
1241:       else
1242:         NArrayMiss.to_nam_no_dup( na, (na.ne(mv[0])) )
1243:       end
1244:     end

[Source]

      # File lib/hdfeos5.rb, line 1405
1405:     def inspect
1406:       'HE5GdField:'+grid.file.path+'?var='+name
1407:     end

[Source]

      # File lib/hdfeos5.rb, line 1016
1016:     def name=
1017:       raise "name= not supported"
1018:     end

[Source]

      # File lib/hdfeos5.rb, line 1020
1020:     def natts
1021:       nattrs, attrname, strbufsize = inqlocattrs()
1022:       return nattrs
1023:     end

[Source]

     # File lib/hdfeos5.rb, line 995
995:     def ndims
996:       rank, dims, ntype, dimlist = fieldinfo()
997:       return rank
998:     end

[Source]

     # File lib/hdfeos5.rb, line 972
972:     def ntype
973:       rank, dims, ntype, dimlist = fieldinfo()
974:       return ntype
975:     end
put(var,hash=nil)

Alias for simple_put

[Source]

      # File lib/hdfeos5.rb, line 1051
1051:     def put_att(name,value,atttype=nil)
1052:        count = Array.new
1053:        count[0] = value.size
1054:        writelocattr(name,atttype,count,value)
1055:     end
rank()

Alias for ndims

[Source]

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

Alias for shape

[Source]

     # File lib/hdfeos5.rb, line 985
985:     def shape_ul0
986:       sh = shape_current
987:       dim_names.each_with_index do |dnm,i|
988:         if dnm == "Unlim"
989:           sh[i] = 0
990:         end
991:       end
992:       sh
993:     end

[Source]

      # File lib/hdfeos5.rb, line 1147
1147:     def simple_get(hash=nil)
1148:       if hash == nil
1149:         if self.ntype == "char" || self.ntype=="byte"
1150:           get_vars_char([0,0,0,0,0,0,0,0], nil, nil)
1151:         elsif self.ntype=="sint"
1152:           get_vars_short([0,0,0,0,0,0,0,0], nil, nil)
1153:         elsif self.ntype=="int"
1154:           get_vars_int([0,0,0,0,0,0,0,0], nil, nil)
1155:         elsif self.ntype=="sfloat"
1156:           get_vars_float([0,0,0,0,0,0,0,0], nil, nil)
1157:         elsif self.ntype=="float"
1158:           get_vars_double([0,0,0,0,0,0,0,0], nil, nil)
1159:         else
1160:           raise ArgumentError, "variable type isn't supported in HDF-EOS5"
1161:         end
1162:       elsif hash.key?("index")==true ||  hash.key?("start")==true
1163:         h_sta = hash["start"]
1164:         endq = hash.key?("end")
1165:         strq = hash.key?("stride")
1166:         if endq == false && strq == false
1167:           if self.ntype == "char" || self.ntype=="byte"
1168:             get_vars_char(h_sta, nil, nil)
1169:           elsif self.ntype=="sint"
1170:             get_vars_short(h_sta, nil, nil)
1171:           elsif self.ntype=="int"
1172:             get_vars_int(h_sta, nil, nil)
1173:           elsif self.ntype=="sfloat"
1174:             get_vars_float(h_sta, nil, nil)
1175:           elsif self.ntype=="float"
1176:             get_vars_double(h_sta, nil, nil)
1177:           else
1178:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
1179:           end
1180:         elsif endq == true && strq == false
1181:           h_end = hash["end"]
1182:           if self.ntype == "char" || self.ntype=="byte"
1183:             get_vars_char(h_sta, nil, h_end)
1184:           elsif self.ntype=="sint"
1185:             get_vars_short(h_sta, nil, h_end)
1186:           elsif self.ntype=="int"
1187:             get_vars_int(h_sta, nil, h_end)
1188:           elsif self.ntype=="sfloat"
1189:             get_vars_float(h_sta, nil, h_end)
1190:           elsif self.ntype=="float"
1191:             get_vars_double(h_sta, nil, h_end)
1192:           else
1193:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
1194:           end
1195:         elsif endq == false && strq == true
1196:           h_str = hash["stride"]
1197:           if self.ntype == "char" || self.ntype=="byte"
1198:             get_vars_char(h_sta, h_str, nil)
1199:           elsif self.ntype=="sint"
1200:             get_vars_short(h_sta, h_str, nil)
1201:           elsif self.ntype=="int"
1202:             get_vars_int(h_sta, h_str, nil)
1203:           elsif self.ntype=="sfloat"
1204:             get_vars_float(h_sta, h_str, nil)
1205:           elsif self.ntype=="float"
1206:             get_vars_double(h_sta, h_str, nil)
1207:           else
1208:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
1209:           end
1210:         else endq == true && strq == true
1211:           h_end = hash["end"]
1212:           h_str = hash["stride"]
1213:           if self.ntype == "char" || self.ntype=="byte"
1214:             get_vars_char(h_sta, h_str, h_end)
1215:           elsif self.ntype=="sint"
1216:             get_vars_short(h_sta, h_str, h_end)
1217:           elsif self.ntype=="int"
1218:             get_vars_int(h_sta, h_str, h_end)
1219:           elsif self.ntype=="sfloat"
1220:             get_vars_float(h_sta, h_str, h_end)
1221:           elsif self.ntype=="float"
1222:             get_vars_double(h_sta, h_str, h_end)
1223:           else
1224:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
1225:           end
1226:         end
1227:       else
1228:         raise ArgumentError,"{'start'}=>{ARRAY} or {'index'}=>{ARRAY} is needed"
1229:       end
1230:     end

[Source]

      # File lib/hdfeos5.rb, line 1061
1061:     def simple_put(var,hash=nil)
1062:       if hash == nil
1063:         if self.ntype == "char" || self.ntype=="byte"
1064:           put_vars_char([0,0,0,0,0,0,0,0], nil, nil, var)
1065:         elsif self.ntype=="sint"
1066:           put_vars_short([0,0,0,0,0,0,0,0], nil, nil, var)
1067:         elsif self.ntype=="int"
1068:           put_vars_int([0,0,0,0,0,0,0,0], nil, nil, var)
1069:         elsif self.ntype=="sfloat"
1070:           put_vars_float([0,0,0,0,0,0,0,0], nil, nil, var)
1071:         elsif self.ntype=="float"
1072:           put_vars_double([0,0,0,0,0,0,0,0], nil, nil, var)
1073:         else
1074:           raise ArgumentError, "variable type isn't supported in HDF-EOS5"
1075:         end
1076:       elsif hash.key?("index")==true ||  hash.key?("start")==true
1077:         h_sta = hash["start"]
1078:         endq = hash.key?("end")
1079:         strq = hash.key?("stride")
1080:         if endq == false && strq == false
1081:           if self.ntype == "char" || self.ntype=="byte"
1082:             put_vars_char(h_sta, nil, nil, var)
1083:           elsif self.ntype=="sint"
1084:             put_vars_short(h_sta, nil, nil, var)
1085:           elsif self.ntype=="int"
1086:             put_vars_int(h_sta, nil, nil, var)
1087:           elsif self.ntype=="sfloat"
1088:             put_vars_float(h_sta, nil, nil, var)
1089:           elsif self.ntype=="float"
1090:             put_vars_double(h_sta, nil, nil, var)
1091:           else
1092:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
1093:           end
1094:         elsif endq == true && strq == false
1095:           h_end = hash["end"]
1096:           if self.ntype == "char" || self.ntype=="byte"
1097:             put_vars_char(h_sta, nil, h_end, var)
1098:           elsif self.ntype=="sint"
1099:             put_vars_short(h_sta, nil, h_end, var)
1100:           elsif self.ntype=="int"
1101:             put_vars_int(h_sta, nil, h_end, var)
1102:           elsif self.ntype=="sfloat"
1103:             put_vars_float(h_sta, nil, h_end, var)
1104:           elsif self.ntype=="float"
1105:             put_vars_double(h_sta, nil, h_end, var)
1106:           else
1107:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
1108:           end
1109:         elsif endq == false && strq == true
1110:           h_str = hash["stride"]
1111:           if self.ntype == "char" || self.ntype=="byte"
1112:             put_vars_char(h_sta, h_str, nil, var)
1113:           elsif self.ntype=="sint"
1114:             put_vars_short(h_sta, h_str, nil, var)
1115:           elsif self.ntype=="int"
1116:             put_vars_int(h_sta, h_str, nil, var)
1117:           elsif self.ntype=="sfloat"
1118:             put_vars_float(h_sta, h_str, nil, var)
1119:           elsif self.ntype=="float"
1120:             put_vars_double(h_sta, h_str, nil, var)
1121:           else
1122:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
1123:           end
1124:         else endq == true && strq == true
1125:           h_end = hash["end"]
1126:           h_str = hash["stride"]
1127:           if self.ntype == "char" || self.ntype=="byte"
1128:             put_vars_char(h_sta, h_str, h_end, var)
1129:           elsif self.ntype=="sint"
1130:             put_vars_short(h_sta, h_str, h_end, var)
1131:           elsif self.ntype=="int"
1132:             put_vars_int(h_sta, h_str, h_end, var)
1133:           elsif self.ntype=="sfloat"
1134:             put_vars_float(h_sta, h_str, h_end, var)
1135:           elsif self.ntype=="float"
1136:             put_vars_double(h_sta, h_str, h_end, var)
1137:           else
1138:             raise ArgumentError, "variable type isn't supported in HDF-EOS5"
1139:           end
1140:         end
1141:       else
1142:         raise ArgumentError,"{'start'}=>{ARRAY} or {'index'}=>{ARRAY} is needed"
1143:       end
1144:     end
typecode()

Alias for ntype

Private Instance methods

[Source]

      # File lib/hdfeos5.rb, line 1247
1247:     def __rubber_expansion( args )
1248:       if (id = args.index(false))  # substitution into id
1249:         # false is incuded
1250:         alen = args.length
1251:         if args.rindex(false) != id
1252:           raise ArguemntError,"only one rubber dimension is permitted"
1253:         elsif alen > rank+1
1254:           raise ArgumentError, "too many args"
1255:         end
1256:         ar = ( id!=0 ? args[0..id-1] : [] )
1257:         args = ar + [true]*(rank-alen+1) + args[id+1..-1]
1258:       elsif args.length == 0   # to support empty [], []=
1259:         args = [true]*rank
1260:       end
1261:       args
1262:     end

[Validate]