Class: NumRu::GPhys::Grib::GribBDS
- Inherits:
-
Object
- Object
- NumRu::GPhys::Grib::GribBDS
- Includes:
- NumRu::GPhys::GribUtils
- Defined in:
- lib/numru/gphys/grib.rb
Overview
end definition of class GribBMS
Instance Method Summary collapse
- #bit_maps? ⇒ Boolean
- #complex? ⇒ Boolean
- #constant? ⇒ Boolean
- #efactor ⇒ Object
- #float? ⇒ Boolean
- #get ⇒ Object
- #grid? ⇒ Boolean
- #integer? ⇒ Boolean
- #length ⇒ Object
- #matrix? ⇒ Boolean
- #offset ⇒ Object
- #set_bit_map(l) ⇒ Object
- #set_complex(l) ⇒ Object
- #set_constant(l) ⇒ Object
- #set_float(l) ⇒ Object
- #set_grid(l) ⇒ Object
- #set_integer(l) ⇒ Object
- #set_matrix(l) ⇒ Object
- #set_simple(l) ⇒ Object
- #set_single(l) ⇒ Object
- #set_spectrum(l) ⇒ Object
- #set_value(val) ⇒ Object
- #simple? ⇒ Boolean
- #single? ⇒ Boolean
- #spectrum? ⇒ Boolean
- #value(shape, index = nil) ⇒ Object
Instance Method Details
#bit_maps? ⇒ Boolean
1169 1170 1171 |
# File 'lib/numru/gphys/grib.rb', line 1169 def bit_maps? return flag7 && flag7==1 end |
#complex? ⇒ Boolean
1120 1121 1122 |
# File 'lib/numru/gphys/grib.rb', line 1120 def complex? return flag2==1 end |
#constant? ⇒ Boolean
1180 1181 1182 |
# File 'lib/numru/gphys/grib.rb', line 1180 def constant? return flag8 && flag8==0 end |
#efactor ⇒ Object
1197 1198 1199 1200 1201 1202 |
# File 'lib/numru/gphys/grib.rb', line 1197 def efactor return @efactor if @efactor @sgm.file.seek(@pos+1, ::IO::SEEK_SET) @efactor = 2.0**str2int2( @sgm.file.read(2) ) return @efactor end |
#float? ⇒ Boolean
1129 1130 1131 |
# File 'lib/numru/gphys/grib.rb', line 1129 def float? return flag3==0 end |
#get ⇒ Object
1336 1337 1338 |
# File 'lib/numru/gphys/grib.rb', line 1336 def get uint2str(length,3) << @bds end |
#grid? ⇒ Boolean
1093 1094 1095 |
# File 'lib/numru/gphys/grib.rb', line 1093 def grid? return flag1==0 end |
#integer? ⇒ Boolean
1138 1139 1140 |
# File 'lib/numru/gphys/grib.rb', line 1138 def integer? return flag3==1 end |
#length ⇒ Object
1086 1087 1088 1089 1090 1091 1092 |
# File 'lib/numru/gphys/grib.rb', line 1086 def length if @pos return @length else return @bds.length+3 end end |
#matrix? ⇒ Boolean
1158 1159 1160 |
# File 'lib/numru/gphys/grib.rb', line 1158 def matrix? return flag6 && flag6==1 end |
#offset ⇒ Object
1191 1192 1193 1194 1195 1196 |
# File 'lib/numru/gphys/grib.rb', line 1191 def offset return @offset if @offset @sgm.file.seek(@pos+3, ::IO::SEEK_SET) @offset = float_value(@sgm.file.read(4)) return @offset end |
#set_bit_map(l) ⇒ Object
1172 1173 1174 1175 1176 1177 1178 1179 |
# File 'lib/numru/gphys/grib.rb', line 1172 def set_bit_map(l) @oct14 = oct14&0xbf @oct14 += 64 if l @oct4 = (oct4&0xef)+16 @bds[0,1] = uint2str(@oct4,1) @bds[10,1] = uint2str(@oct14,1) return l end |
#set_complex(l) ⇒ Object
1123 1124 1125 1126 1127 1128 |
# File 'lib/numru/gphys/grib.rb', line 1123 def set_complex(l) @oct4 = oct4&0xbf @oct4 += 64 if l @bds[0,1] = uint2str(@oct4,1) return l end |
#set_constant(l) ⇒ Object
1183 1184 1185 1186 1187 1188 1189 1190 |
# File 'lib/numru/gphys/grib.rb', line 1183 def set_constant(l) @oct14 = oct14&0xdf @oct14 += 32 unless l @oct4 = (oct4&0xef)+16 @bds[0,1] = uint2str(@oct4,1) @bds[10,1] = uint2str(@oct14,1) return l end |
#set_float(l) ⇒ Object
1132 1133 1134 1135 1136 1137 |
# File 'lib/numru/gphys/grib.rb', line 1132 def set_float(l) @oct4 = oct4&0xdf @oct4 += 32 unless l @bds[0,1] = uint2str(@oct4,1) return l end |
#set_grid(l) ⇒ Object
1096 1097 1098 1099 1100 1101 |
# File 'lib/numru/gphys/grib.rb', line 1096 def set_grid(l) @oct4 = oct4&0x7f @oct4 += 128 unless l @bds[0,1] = uint2str(@oct4,1) return l end |
#set_integer(l) ⇒ Object
1141 1142 1143 1144 1145 1146 |
# File 'lib/numru/gphys/grib.rb', line 1141 def set_integer(l) @oct4 = oct4&0xdf @oct4 += 32 if l @bds[0,1] = uint2str(@oct4,1) return l end |
#set_matrix(l) ⇒ Object
1161 1162 1163 1164 1165 1166 1167 1168 |
# File 'lib/numru/gphys/grib.rb', line 1161 def set_matrix(l) @oct14 = oct14&0x7f @oct14 += 128 if l @oct4 = (oct4&0xef)+16 @bds[0,1] = uint2str(@oct4,1) @bds[10,1] = uint2str(@oct14,1) return l end |
#set_simple(l) ⇒ Object
1114 1115 1116 1117 1118 1119 |
# File 'lib/numru/gphys/grib.rb', line 1114 def set_simple(l) @oct4 = oct4&0xbf @oct4 += 64 unless l @bds[0,1] = uint2str(@oct4,1) return l end |
#set_single(l) ⇒ Object
1150 1151 1152 1153 1154 1155 1156 1157 |
# File 'lib/numru/gphys/grib.rb', line 1150 def set_single(l) @oct14 = oct14&0x7f @oct14 += 128 unless l @oct4 = (oct4&0xef)+16 @bds[0,1] = uint2str(@oct4,1) @bds[10,1] = uint2str(@oct14,1) return l end |
#set_spectrum(l) ⇒ Object
1105 1106 1107 1108 1109 1110 |
# File 'lib/numru/gphys/grib.rb', line 1105 def set_spectrum(l) @oct4 = oct4&0x7f @oct4 += 128 if l @bds[0,1] = uint2str(@oct4,1) return l end |
#set_value(val) ⇒ Object
1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 |
# File 'lib/numru/gphys/grib.rb', line 1298 def set_value(val) val = val.reshape!(val.length) if NArrayMiss===val val = val.get_array![val.get_mask!.where] end dfact = @sgm.pds.dfact val = val*10**dfact ref = val.min val = val-ref max = val.max nbits = 16 e = (Math::log(max)/Math::log(2)).ceil-nbits val = val*2**(-e) if (nbits%8) == 0 nstep = 8 elsif (nbits%4) == 0 nstep = 4 elsif (nbits%2) == 0 nstep == 2 else nstep == 1 end str, bu = data2str(val.to_type(NArray::INT),nstep,nbits) @oct4 = (@oct4&15)+bu*16 @bds[0,1] = uint2str(@oct4,1) @bds[1,2] = int2str(e,2) s = (ref<0) ? -1 : 1 ref = ref.abs a = (Math::log(ref)/Math::log(16)).ceil+64 a<0 && raise("invalid range") a = 127 if a>127 b = ref*2**24*16**(64-a) a = a*s @bds[3,4] = int2str(a,1) << uint2str(b,3) @bds[7,1] = uint2str(nbits,1) @bds = @bds[0,8] << str @sgm.is.update_total_length end |
#simple? ⇒ Boolean
1111 1112 1113 |
# File 'lib/numru/gphys/grib.rb', line 1111 def simple? return flag2==0 end |
#single? ⇒ Boolean
1147 1148 1149 |
# File 'lib/numru/gphys/grib.rb', line 1147 def single? return flag6 && flag6==0 end |
#spectrum? ⇒ Boolean
1102 1103 1104 |
# File 'lib/numru/gphys/grib.rb', line 1102 def spectrum? return flag1==1 end |
#value(shape, index = nil) ⇒ Object
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 |
# File 'lib/numru/gphys/grib.rb', line 1203 def value(shape,index=nil) nbits_unuse = oct4&15 @sgm.file.seek(@pos+7, ::IO::SEEK_SET) nbits_pack = @sgm.file.read(1).to_uint1 if (nbits_pack%8) == 0 nstep = 8 elsif (nbits_pack%4) == 0 nstep = 4 elsif (nbits_pack%2) == 0 nstep = 2 else nstep = 1 end r = offset e = efactor map = @sgm.bms.map nmiss = map ? map.count_false : 0 if flag4==0 nlen = ((length-3-8)*8-nbits_unuse)/nbits_pack nlon,nlat = shape (nlon*nlat)==nlen+nmiss || raise("length is not collect") if index index = index.collect{|el| Fixnum===el ? el..el : el} il = index[0] i0 = il.first i1 = il.last i0 = i0 < 0 ? nlon+i0 : i0 i1 = i1 < 0 ? nlon+i1 : i1 index[0] = il.exclude_end? ? i0...i1 : i0..i1 il = index[1] i0 = il.first i1 = il.last i0 = i0 < 0 ? nlat+i0 : i0 i1 = i1 < 0 ? nlat+i1 : i1 index[1] = il.exclude_end? ? i0...i1 : i0..i1 #j = nil #i = nil if map var = NArrayMiss.sfloat(index[0].count, index[1].count) map.reshape!(nlon,nlat) mask = map[*index] nd = mask.count_true var[mask.where] = @sgm.mbio.read2D(@pos+8, nbits_pack, nd, 1, 0, nd-1, 1, 0, 0, 1, nil, nil, e, r).reshape!(nd) =begin index[1].each{|j| jj = j-index[1].first sb = j*nlon+index[0].first sb = sb-map[true,0..jj-1].count_false if jj>0 sb = sb*nbits_pack eb = sb+mask[true,j].count_true*nbits_pack if sb!=eb var[mask[true,j].where,jj] = get_value(@sgm.file,@pos+8,sb,eb,nbits_pack,nstep) end } =end else var = @sgm.mbio.read2D(@pos+8, nbits_pack, nlon, nlat, index[0].first, index[0].end, 1, index[1].first, index[1].end, 1, nil, nil, e, r) =begin sb = index[1].first*nlon*nbits_pack eb = (index[1].end+1)*nlon*nbits_pack var = get_value(@sgm.file,@pos+8,sb,eb,nbits_pack,nstep) var.reshape!(nlon, var.length/nlon) var = var[index[0],true] =end end else if map eb = nlen*nbits_pack var = NArrayMiss.sfloat(nlon,nlat) # var[map.where] = get_value(@sgm.file,@pos+8,0,eb,nbits_pack,nstep) nd = map.count_true var[map.where] = @sgm.mbio.read2D(@pos+8, nbits_pack, nd, 1, 0, nd-1, 1, 0, 0, 1, nil, nil, e, r).reshape!(nd) else =begin eb = nlen*nbits_pack var = get_value(@sgm.file,@pos+8,0,eb,nbits_pack,nstep) var.reshape!(nlon,nlat) =end var = @sgm.mbio.read2D(@pos+8, nbits_pack, nlon, nlat, 0, nlon-1, 1, 0, nlat-1, 1, nil, nil, e, r) end end # var = var*e+r return var else raise "not defined yet" n1 = @file.read(2).to_uint2 @sgm.file.seek(1, ::IO::SEEK_CUR) str = @sgm.file.read(6) n2 = str.to_uint2 p1 = str.to_uint2(2) p2 = str.to_uint2(4) # @bds[15..16] # width = str2uint( @bds[18..??] ) # bitmap = str2uint( @bds[??+1..n1-4] ) end end |