static Map<String, Counter> headerCount = new HashMap<String, Counter>();
static int total_msgs, bad_msgs, bad_wmo, bad_tables, bad_operation, total_different, good_msgs, total_obs;
static long file_size = 0;
static void scanMessageTypes(String filename) throws IOException {
RandomAccessFile raf = new RandomAccessFile(filename, "r");
//out.format("\n-----\nOpen %s size = %d Kb \n", raf.getLocation(), raf.length() / 1000);
file_size += raf.length();
MessageScanner scan = new MessageScanner(raf);
int count = 0;
while (scan.hasNext()) {
Message m = scan.next();
if (m == null) {
bad_msgs++;
continue;
}
// incomplete tables
try {
if (!m.isTablesComplete()) {
int[] nbad = badMap.get(m);
if (nbad == null) {
nbad = new int[1];
badMap.put(m, nbad);
}
nbad[0]++;
bad_tables++;
//continue; dont exclude
}
} catch (UnsupportedOperationException e) {
m.dumpHeader(out);
bad_operation++;
continue;
}
// track desc to headers
String ttaaii = extractWMO(m.getHeader());
if (ttaaii == null) {
bad_wmo++;
continue;
}
// map dds -> wmoheader
Map<String, Counter> keys = typeMap.get(m);
if (null == keys) {
//out.format(" new Descriptor Type msg %d ttaaii=%s hashCode=%d cat=%s\n",
// count, ttaaii, m.hashCode(), m.getCategory());
//new BufrDump2().dump(out, m);
keys = new HashMap<String, Counter>();
keys.put(ttaaii, new Counter(ttaaii));
typeMap.put(m, keys);
}
Counter c = keys.get(ttaaii);
if (c == null) {
//out.format(" msg %d has different ttaaii = %s hashcode=%d cat=%s\n",
// count, ttaaii, m.hashCode(), m.getCategory());
c = new Counter(ttaaii);
keys.put(ttaaii, c);
}
c.count++;
c.countObs += m.getNumberDatasets();
// map wmoheader to dds
List<Message> mtypes = headerMap.get(ttaaii);
if (mtypes == null) {
mtypes = new ArrayList<Message>();
headerMap.put(ttaaii, mtypes);
mtypes.add(m);
} else if (!mtypes.contains(m)) {
//out.format(" Different desc for header %s hashCode=%d prev hashcode=%d\n", ttaaii, desc.hashCode(), hdesc.hashCode());
mtypes.add(m);
total_different++;
}
// track header count
Counter hc = headerCount.get(ttaaii);
if (hc == null) {
hc = new Counter(ttaaii);
headerCount.put(ttaaii, hc);
}
hc.count++;
count++;
}
raf.close();
out.format(filename+" total_msgs= %d good=%d total_obs = %d\n", scan.getTotalMessages(), count, scan.getTotalObs());
total_msgs += scan.getTotalMessages();
good_msgs += count;
total_obs += scan.getTotalObs();
}