@Test public void testNcepBufrTable() throws IOException { String locationOld = "resource:/resources/bufrTables/local/ncep/ncep.bufrtab.ETACLS1"; String location = "../bufr/src/main/resources/resources/bufrTables/local/ncep/ncep.bufrtab.ETACLS1"; try (InputStream ios = BufrTables.openStream(location)) { BufrTables.Tables tables = new BufrTables.Tables(); NcepMnemonic.read(ios, tables); Formatter out = new Formatter(System.out); tables.b.show(out); tables.d.show(out); } }
public static boolean read(InputStream ios, BufrTables.Tables tables) throws IOException { if (ios == null) return false; if (tables.b == null) tables.b = new TableB("fake", "fake"); if (tables.d == null) tables.d = new TableD("fake", "fake"); HashMap<String, String> number = new HashMap<>(); HashMap<String, String> desc = new HashMap<>(); HashMap<String, String> mnseq = new HashMap<>(); try { BufferedReader dataIS = new BufferedReader(new InputStreamReader(ios, StandardCharsets.UTF_8)); Matcher m; while (true) { String line = dataIS.readLine(); if (line == null) throw new RuntimeException("Bad NCEP mnemonic BUFR table "); if (line.contains("MNEMONIC")) break; } while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.contains("----")) continue; if (line.startsWith("*")) continue; if (line.startsWith("| ")) continue; m = fields3.matcher(line); if (m.find()) { String mnu = m.group(1).trim(); String fxy = m.group(2).trim(); if (fxy.startsWith("3")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE D ENTRY - ", "").trim()); } else if (fxy.startsWith("0")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE B ENTRY - ", "").trim()); } else if (fxy.startsWith("A")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE A ENTRY - ", "").trim()); } } else if (debugTable) { System.out.println("bad mnemonic, number, and description: " + line); } } while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.contains("----")) continue; if (line.startsWith("| ")) continue; if (line.startsWith("*")) continue; m = fields2.matcher(line); if (m.find()) { String mnu = m.group(1).trim(); if (mnseq.containsKey(mnu)) { String value = mnseq.get(mnu); value = value + " " + m.group(2); mnseq.put(mnu, value); } else { mnseq.put(mnu, m.group(2)); } } else if (debugTable) { System.out.println("bad sequence mnemonic: " + line); } } for (Map.Entry<String, String> ent : mnseq.entrySet()) { String seq = ent.getValue(); seq = seq.replaceAll("\\<", "1-1-0 0-31-0 "); seq = seq.replaceAll("\\>", ""); seq = seq.replaceAll("\\{", "1-1-0 0-31-1 "); seq = seq.replaceAll("\\}", ""); seq = seq.replaceAll("\\(", "1-1-0 0-31-2 "); seq = seq.replaceAll("\\)", ""); StringTokenizer stoke = new StringTokenizer(seq, " "); List<Short> list = new ArrayList<>(); while (stoke.hasMoreTokens()) { String mn = stoke.nextToken(); if (mn.charAt(1) == '-') { list.add(Descriptor.getFxy(mn)); continue; } m = ints6.matcher(mn); if (m.find()) { String F = mn.substring(0, 1); String X = removeLeading0(mn.substring(1, 3)); String Y = removeLeading0(mn.substring(3)); list.add(Descriptor.getFxy(F + "-" + X + "-" + Y)); continue; } if (mn.startsWith("\"")) { int idx = mn.lastIndexOf('"'); String count = mn.substring(idx + 1); list.add(Descriptor.getFxy("1-1-" + count)); mn = mn.substring(1, idx); } if (mn.startsWith(".")) { String des = mn.substring(mn.length() - 4); mn = mn.replace(des, "...."); } String fxy = number.get(mn); String F = fxy.substring(0, 1); String X = removeLeading0(fxy.substring(1, 3)); String Y = removeLeading0(fxy.substring(3)); list.add(Descriptor.getFxy(F + "-" + X + "-" + Y)); } String fxy = number.get(ent.getKey()); String X = removeLeading0(fxy.substring(1, 3)); String Y = removeLeading0(fxy.substring(3)); if (XlocalCutoff > Integer.parseInt(X) && YlocalCutoff > Integer.parseInt(Y)) continue; short seqX = Short.parseShort(X.trim()); short seqY = Short.parseShort(Y.trim()); tables.d.addDescriptor(seqX, seqY, ent.getKey(), list); } List<Short> list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-2")); tables.d.addDescriptor((short) 60, (short) 1, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-1")); tables.d.addDescriptor((short) 60, (short) 2, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-1")); tables.d.addDescriptor((short) 60, (short) 3, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-0")); tables.d.addDescriptor((short) 60, (short) 4, "", list); while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.startsWith("| ")) continue; if (line.startsWith("*")) continue; m = fields5.matcher(line); if (m.find()) { if (m.group(1).equals("")) { } else if (number.containsKey(m.group(1).trim())) { String fxy = number.get(m.group(1).trim()); String X = fxy.substring(1, 3); String Y = fxy.substring(3); String mnu = m.group(1).trim(); String descr = desc.get(mnu); short x = Short.parseShort(X.trim()); short y = Short.parseShort(Y.trim()); if (XlocalCutoff > x && YlocalCutoff > y) continue; int scale = Integer.parseInt(m.group(2).trim()); int refVal = Integer.parseInt(m.group(3).trim()); int width = Integer.parseInt(m.group(4).trim()); String units = m.group(5).trim(); tables.b.addDescriptor(x, y, scale, refVal, width, mnu, units, descr); } else if (debugTable) { System.out.println("bad element descriptors: " + line); } } } } finally { ios.close(); } tables.b.addDescriptor((short) 63, (short) 0, 0, 0, 16, "Byte count", "Numeric", null); return true; }
NcepMnemonic { public static boolean read(InputStream ios, BufrTables.Tables tables) throws IOException { if (ios == null) return false; if (tables.b == null) tables.b = new TableB("fake", "fake"); if (tables.d == null) tables.d = new TableD("fake", "fake"); HashMap<String, String> number = new HashMap<>(); HashMap<String, String> desc = new HashMap<>(); HashMap<String, String> mnseq = new HashMap<>(); try { BufferedReader dataIS = new BufferedReader(new InputStreamReader(ios, StandardCharsets.UTF_8)); Matcher m; while (true) { String line = dataIS.readLine(); if (line == null) throw new RuntimeException("Bad NCEP mnemonic BUFR table "); if (line.contains("MNEMONIC")) break; } while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.contains("----")) continue; if (line.startsWith("*")) continue; if (line.startsWith("| ")) continue; m = fields3.matcher(line); if (m.find()) { String mnu = m.group(1).trim(); String fxy = m.group(2).trim(); if (fxy.startsWith("3")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE D ENTRY - ", "").trim()); } else if (fxy.startsWith("0")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE B ENTRY - ", "").trim()); } else if (fxy.startsWith("A")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE A ENTRY - ", "").trim()); } } else if (debugTable) { System.out.println("bad mnemonic, number, and description: " + line); } } while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.contains("----")) continue; if (line.startsWith("| ")) continue; if (line.startsWith("*")) continue; m = fields2.matcher(line); if (m.find()) { String mnu = m.group(1).trim(); if (mnseq.containsKey(mnu)) { String value = mnseq.get(mnu); value = value + " " + m.group(2); mnseq.put(mnu, value); } else { mnseq.put(mnu, m.group(2)); } } else if (debugTable) { System.out.println("bad sequence mnemonic: " + line); } } for (Map.Entry<String, String> ent : mnseq.entrySet()) { String seq = ent.getValue(); seq = seq.replaceAll("\\<", "1-1-0 0-31-0 "); seq = seq.replaceAll("\\>", ""); seq = seq.replaceAll("\\{", "1-1-0 0-31-1 "); seq = seq.replaceAll("\\}", ""); seq = seq.replaceAll("\\(", "1-1-0 0-31-2 "); seq = seq.replaceAll("\\)", ""); StringTokenizer stoke = new StringTokenizer(seq, " "); List<Short> list = new ArrayList<>(); while (stoke.hasMoreTokens()) { String mn = stoke.nextToken(); if (mn.charAt(1) == '-') { list.add(Descriptor.getFxy(mn)); continue; } m = ints6.matcher(mn); if (m.find()) { String F = mn.substring(0, 1); String X = removeLeading0(mn.substring(1, 3)); String Y = removeLeading0(mn.substring(3)); list.add(Descriptor.getFxy(F + "-" + X + "-" + Y)); continue; } if (mn.startsWith("\"")) { int idx = mn.lastIndexOf('"'); String count = mn.substring(idx + 1); list.add(Descriptor.getFxy("1-1-" + count)); mn = mn.substring(1, idx); } if (mn.startsWith(".")) { String des = mn.substring(mn.length() - 4); mn = mn.replace(des, "...."); } String fxy = number.get(mn); String F = fxy.substring(0, 1); String X = removeLeading0(fxy.substring(1, 3)); String Y = removeLeading0(fxy.substring(3)); list.add(Descriptor.getFxy(F + "-" + X + "-" + Y)); } String fxy = number.get(ent.getKey()); String X = removeLeading0(fxy.substring(1, 3)); String Y = removeLeading0(fxy.substring(3)); if (XlocalCutoff > Integer.parseInt(X) && YlocalCutoff > Integer.parseInt(Y)) continue; short seqX = Short.parseShort(X.trim()); short seqY = Short.parseShort(Y.trim()); tables.d.addDescriptor(seqX, seqY, ent.getKey(), list); } List<Short> list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-2")); tables.d.addDescriptor((short) 60, (short) 1, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-1")); tables.d.addDescriptor((short) 60, (short) 2, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-1")); tables.d.addDescriptor((short) 60, (short) 3, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-0")); tables.d.addDescriptor((short) 60, (short) 4, "", list); while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.startsWith("| ")) continue; if (line.startsWith("*")) continue; m = fields5.matcher(line); if (m.find()) { if (m.group(1).equals("")) { } else if (number.containsKey(m.group(1).trim())) { String fxy = number.get(m.group(1).trim()); String X = fxy.substring(1, 3); String Y = fxy.substring(3); String mnu = m.group(1).trim(); String descr = desc.get(mnu); short x = Short.parseShort(X.trim()); short y = Short.parseShort(Y.trim()); if (XlocalCutoff > x && YlocalCutoff > y) continue; int scale = Integer.parseInt(m.group(2).trim()); int refVal = Integer.parseInt(m.group(3).trim()); int width = Integer.parseInt(m.group(4).trim()); String units = m.group(5).trim(); tables.b.addDescriptor(x, y, scale, refVal, width, mnu, units, descr); } else if (debugTable) { System.out.println("bad element descriptors: " + line); } } } } finally { ios.close(); } tables.b.addDescriptor((short) 63, (short) 0, 0, 0, 16, "Byte count", "Numeric", null); return true; } }
NcepMnemonic { public static boolean read(InputStream ios, BufrTables.Tables tables) throws IOException { if (ios == null) return false; if (tables.b == null) tables.b = new TableB("fake", "fake"); if (tables.d == null) tables.d = new TableD("fake", "fake"); HashMap<String, String> number = new HashMap<>(); HashMap<String, String> desc = new HashMap<>(); HashMap<String, String> mnseq = new HashMap<>(); try { BufferedReader dataIS = new BufferedReader(new InputStreamReader(ios, StandardCharsets.UTF_8)); Matcher m; while (true) { String line = dataIS.readLine(); if (line == null) throw new RuntimeException("Bad NCEP mnemonic BUFR table "); if (line.contains("MNEMONIC")) break; } while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.contains("----")) continue; if (line.startsWith("*")) continue; if (line.startsWith("| ")) continue; m = fields3.matcher(line); if (m.find()) { String mnu = m.group(1).trim(); String fxy = m.group(2).trim(); if (fxy.startsWith("3")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE D ENTRY - ", "").trim()); } else if (fxy.startsWith("0")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE B ENTRY - ", "").trim()); } else if (fxy.startsWith("A")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE A ENTRY - ", "").trim()); } } else if (debugTable) { System.out.println("bad mnemonic, number, and description: " + line); } } while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.contains("----")) continue; if (line.startsWith("| ")) continue; if (line.startsWith("*")) continue; m = fields2.matcher(line); if (m.find()) { String mnu = m.group(1).trim(); if (mnseq.containsKey(mnu)) { String value = mnseq.get(mnu); value = value + " " + m.group(2); mnseq.put(mnu, value); } else { mnseq.put(mnu, m.group(2)); } } else if (debugTable) { System.out.println("bad sequence mnemonic: " + line); } } for (Map.Entry<String, String> ent : mnseq.entrySet()) { String seq = ent.getValue(); seq = seq.replaceAll("\\<", "1-1-0 0-31-0 "); seq = seq.replaceAll("\\>", ""); seq = seq.replaceAll("\\{", "1-1-0 0-31-1 "); seq = seq.replaceAll("\\}", ""); seq = seq.replaceAll("\\(", "1-1-0 0-31-2 "); seq = seq.replaceAll("\\)", ""); StringTokenizer stoke = new StringTokenizer(seq, " "); List<Short> list = new ArrayList<>(); while (stoke.hasMoreTokens()) { String mn = stoke.nextToken(); if (mn.charAt(1) == '-') { list.add(Descriptor.getFxy(mn)); continue; } m = ints6.matcher(mn); if (m.find()) { String F = mn.substring(0, 1); String X = removeLeading0(mn.substring(1, 3)); String Y = removeLeading0(mn.substring(3)); list.add(Descriptor.getFxy(F + "-" + X + "-" + Y)); continue; } if (mn.startsWith("\"")) { int idx = mn.lastIndexOf('"'); String count = mn.substring(idx + 1); list.add(Descriptor.getFxy("1-1-" + count)); mn = mn.substring(1, idx); } if (mn.startsWith(".")) { String des = mn.substring(mn.length() - 4); mn = mn.replace(des, "...."); } String fxy = number.get(mn); String F = fxy.substring(0, 1); String X = removeLeading0(fxy.substring(1, 3)); String Y = removeLeading0(fxy.substring(3)); list.add(Descriptor.getFxy(F + "-" + X + "-" + Y)); } String fxy = number.get(ent.getKey()); String X = removeLeading0(fxy.substring(1, 3)); String Y = removeLeading0(fxy.substring(3)); if (XlocalCutoff > Integer.parseInt(X) && YlocalCutoff > Integer.parseInt(Y)) continue; short seqX = Short.parseShort(X.trim()); short seqY = Short.parseShort(Y.trim()); tables.d.addDescriptor(seqX, seqY, ent.getKey(), list); } List<Short> list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-2")); tables.d.addDescriptor((short) 60, (short) 1, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-1")); tables.d.addDescriptor((short) 60, (short) 2, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-1")); tables.d.addDescriptor((short) 60, (short) 3, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-0")); tables.d.addDescriptor((short) 60, (short) 4, "", list); while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.startsWith("| ")) continue; if (line.startsWith("*")) continue; m = fields5.matcher(line); if (m.find()) { if (m.group(1).equals("")) { } else if (number.containsKey(m.group(1).trim())) { String fxy = number.get(m.group(1).trim()); String X = fxy.substring(1, 3); String Y = fxy.substring(3); String mnu = m.group(1).trim(); String descr = desc.get(mnu); short x = Short.parseShort(X.trim()); short y = Short.parseShort(Y.trim()); if (XlocalCutoff > x && YlocalCutoff > y) continue; int scale = Integer.parseInt(m.group(2).trim()); int refVal = Integer.parseInt(m.group(3).trim()); int width = Integer.parseInt(m.group(4).trim()); String units = m.group(5).trim(); tables.b.addDescriptor(x, y, scale, refVal, width, mnu, units, descr); } else if (debugTable) { System.out.println("bad element descriptors: " + line); } } } } finally { ios.close(); } tables.b.addDescriptor((short) 63, (short) 0, 0, 0, 16, "Byte count", "Numeric", null); return true; }  }
NcepMnemonic { public static boolean read(InputStream ios, BufrTables.Tables tables) throws IOException { if (ios == null) return false; if (tables.b == null) tables.b = new TableB("fake", "fake"); if (tables.d == null) tables.d = new TableD("fake", "fake"); HashMap<String, String> number = new HashMap<>(); HashMap<String, String> desc = new HashMap<>(); HashMap<String, String> mnseq = new HashMap<>(); try { BufferedReader dataIS = new BufferedReader(new InputStreamReader(ios, StandardCharsets.UTF_8)); Matcher m; while (true) { String line = dataIS.readLine(); if (line == null) throw new RuntimeException("Bad NCEP mnemonic BUFR table "); if (line.contains("MNEMONIC")) break; } while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.contains("----")) continue; if (line.startsWith("*")) continue; if (line.startsWith("| ")) continue; m = fields3.matcher(line); if (m.find()) { String mnu = m.group(1).trim(); String fxy = m.group(2).trim(); if (fxy.startsWith("3")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE D ENTRY - ", "").trim()); } else if (fxy.startsWith("0")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE B ENTRY - ", "").trim()); } else if (fxy.startsWith("A")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE A ENTRY - ", "").trim()); } } else if (debugTable) { System.out.println("bad mnemonic, number, and description: " + line); } } while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.contains("----")) continue; if (line.startsWith("| ")) continue; if (line.startsWith("*")) continue; m = fields2.matcher(line); if (m.find()) { String mnu = m.group(1).trim(); if (mnseq.containsKey(mnu)) { String value = mnseq.get(mnu); value = value + " " + m.group(2); mnseq.put(mnu, value); } else { mnseq.put(mnu, m.group(2)); } } else if (debugTable) { System.out.println("bad sequence mnemonic: " + line); } } for (Map.Entry<String, String> ent : mnseq.entrySet()) { String seq = ent.getValue(); seq = seq.replaceAll("\\<", "1-1-0 0-31-0 "); seq = seq.replaceAll("\\>", ""); seq = seq.replaceAll("\\{", "1-1-0 0-31-1 "); seq = seq.replaceAll("\\}", ""); seq = seq.replaceAll("\\(", "1-1-0 0-31-2 "); seq = seq.replaceAll("\\)", ""); StringTokenizer stoke = new StringTokenizer(seq, " "); List<Short> list = new ArrayList<>(); while (stoke.hasMoreTokens()) { String mn = stoke.nextToken(); if (mn.charAt(1) == '-') { list.add(Descriptor.getFxy(mn)); continue; } m = ints6.matcher(mn); if (m.find()) { String F = mn.substring(0, 1); String X = removeLeading0(mn.substring(1, 3)); String Y = removeLeading0(mn.substring(3)); list.add(Descriptor.getFxy(F + "-" + X + "-" + Y)); continue; } if (mn.startsWith("\"")) { int idx = mn.lastIndexOf('"'); String count = mn.substring(idx + 1); list.add(Descriptor.getFxy("1-1-" + count)); mn = mn.substring(1, idx); } if (mn.startsWith(".")) { String des = mn.substring(mn.length() - 4); mn = mn.replace(des, "...."); } String fxy = number.get(mn); String F = fxy.substring(0, 1); String X = removeLeading0(fxy.substring(1, 3)); String Y = removeLeading0(fxy.substring(3)); list.add(Descriptor.getFxy(F + "-" + X + "-" + Y)); } String fxy = number.get(ent.getKey()); String X = removeLeading0(fxy.substring(1, 3)); String Y = removeLeading0(fxy.substring(3)); if (XlocalCutoff > Integer.parseInt(X) && YlocalCutoff > Integer.parseInt(Y)) continue; short seqX = Short.parseShort(X.trim()); short seqY = Short.parseShort(Y.trim()); tables.d.addDescriptor(seqX, seqY, ent.getKey(), list); } List<Short> list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-2")); tables.d.addDescriptor((short) 60, (short) 1, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-1")); tables.d.addDescriptor((short) 60, (short) 2, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-1")); tables.d.addDescriptor((short) 60, (short) 3, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-0")); tables.d.addDescriptor((short) 60, (short) 4, "", list); while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.startsWith("| ")) continue; if (line.startsWith("*")) continue; m = fields5.matcher(line); if (m.find()) { if (m.group(1).equals("")) { } else if (number.containsKey(m.group(1).trim())) { String fxy = number.get(m.group(1).trim()); String X = fxy.substring(1, 3); String Y = fxy.substring(3); String mnu = m.group(1).trim(); String descr = desc.get(mnu); short x = Short.parseShort(X.trim()); short y = Short.parseShort(Y.trim()); if (XlocalCutoff > x && YlocalCutoff > y) continue; int scale = Integer.parseInt(m.group(2).trim()); int refVal = Integer.parseInt(m.group(3).trim()); int width = Integer.parseInt(m.group(4).trim()); String units = m.group(5).trim(); tables.b.addDescriptor(x, y, scale, refVal, width, mnu, units, descr); } else if (debugTable) { System.out.println("bad element descriptors: " + line); } } } } finally { ios.close(); } tables.b.addDescriptor((short) 63, (short) 0, 0, 0, 16, "Byte count", "Numeric", null); return true; }  static boolean read(InputStream ios, BufrTables.Tables tables); }
NcepMnemonic { public static boolean read(InputStream ios, BufrTables.Tables tables) throws IOException { if (ios == null) return false; if (tables.b == null) tables.b = new TableB("fake", "fake"); if (tables.d == null) tables.d = new TableD("fake", "fake"); HashMap<String, String> number = new HashMap<>(); HashMap<String, String> desc = new HashMap<>(); HashMap<String, String> mnseq = new HashMap<>(); try { BufferedReader dataIS = new BufferedReader(new InputStreamReader(ios, StandardCharsets.UTF_8)); Matcher m; while (true) { String line = dataIS.readLine(); if (line == null) throw new RuntimeException("Bad NCEP mnemonic BUFR table "); if (line.contains("MNEMONIC")) break; } while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.contains("----")) continue; if (line.startsWith("*")) continue; if (line.startsWith("| ")) continue; m = fields3.matcher(line); if (m.find()) { String mnu = m.group(1).trim(); String fxy = m.group(2).trim(); if (fxy.startsWith("3")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE D ENTRY - ", "").trim()); } else if (fxy.startsWith("0")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE B ENTRY - ", "").trim()); } else if (fxy.startsWith("A")) { number.put(mnu, fxy); desc.put(mnu, m.group(3).replace("TABLE A ENTRY - ", "").trim()); } } else if (debugTable) { System.out.println("bad mnemonic, number, and description: " + line); } } while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.contains("----")) continue; if (line.startsWith("| ")) continue; if (line.startsWith("*")) continue; m = fields2.matcher(line); if (m.find()) { String mnu = m.group(1).trim(); if (mnseq.containsKey(mnu)) { String value = mnseq.get(mnu); value = value + " " + m.group(2); mnseq.put(mnu, value); } else { mnseq.put(mnu, m.group(2)); } } else if (debugTable) { System.out.println("bad sequence mnemonic: " + line); } } for (Map.Entry<String, String> ent : mnseq.entrySet()) { String seq = ent.getValue(); seq = seq.replaceAll("\\<", "1-1-0 0-31-0 "); seq = seq.replaceAll("\\>", ""); seq = seq.replaceAll("\\{", "1-1-0 0-31-1 "); seq = seq.replaceAll("\\}", ""); seq = seq.replaceAll("\\(", "1-1-0 0-31-2 "); seq = seq.replaceAll("\\)", ""); StringTokenizer stoke = new StringTokenizer(seq, " "); List<Short> list = new ArrayList<>(); while (stoke.hasMoreTokens()) { String mn = stoke.nextToken(); if (mn.charAt(1) == '-') { list.add(Descriptor.getFxy(mn)); continue; } m = ints6.matcher(mn); if (m.find()) { String F = mn.substring(0, 1); String X = removeLeading0(mn.substring(1, 3)); String Y = removeLeading0(mn.substring(3)); list.add(Descriptor.getFxy(F + "-" + X + "-" + Y)); continue; } if (mn.startsWith("\"")) { int idx = mn.lastIndexOf('"'); String count = mn.substring(idx + 1); list.add(Descriptor.getFxy("1-1-" + count)); mn = mn.substring(1, idx); } if (mn.startsWith(".")) { String des = mn.substring(mn.length() - 4); mn = mn.replace(des, "...."); } String fxy = number.get(mn); String F = fxy.substring(0, 1); String X = removeLeading0(fxy.substring(1, 3)); String Y = removeLeading0(fxy.substring(3)); list.add(Descriptor.getFxy(F + "-" + X + "-" + Y)); } String fxy = number.get(ent.getKey()); String X = removeLeading0(fxy.substring(1, 3)); String Y = removeLeading0(fxy.substring(3)); if (XlocalCutoff > Integer.parseInt(X) && YlocalCutoff > Integer.parseInt(Y)) continue; short seqX = Short.parseShort(X.trim()); short seqY = Short.parseShort(Y.trim()); tables.d.addDescriptor(seqX, seqY, ent.getKey(), list); } List<Short> list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-2")); tables.d.addDescriptor((short) 60, (short) 1, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-1")); tables.d.addDescriptor((short) 60, (short) 2, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-1")); tables.d.addDescriptor((short) 60, (short) 3, "", list); list = new ArrayList<>(); list.add(Descriptor.getFxy("1-1-0")); list.add(Descriptor.getFxy("0-31-0")); tables.d.addDescriptor((short) 60, (short) 4, "", list); while (true) { String line = dataIS.readLine(); if (line == null) break; if (line.contains("MNEMONIC")) break; if (line.startsWith("| ")) continue; if (line.startsWith("*")) continue; m = fields5.matcher(line); if (m.find()) { if (m.group(1).equals("")) { } else if (number.containsKey(m.group(1).trim())) { String fxy = number.get(m.group(1).trim()); String X = fxy.substring(1, 3); String Y = fxy.substring(3); String mnu = m.group(1).trim(); String descr = desc.get(mnu); short x = Short.parseShort(X.trim()); short y = Short.parseShort(Y.trim()); if (XlocalCutoff > x && YlocalCutoff > y) continue; int scale = Integer.parseInt(m.group(2).trim()); int refVal = Integer.parseInt(m.group(3).trim()); int width = Integer.parseInt(m.group(4).trim()); String units = m.group(5).trim(); tables.b.addDescriptor(x, y, scale, refVal, width, mnu, units, descr); } else if (debugTable) { System.out.println("bad element descriptors: " + line); } } } } finally { ios.close(); } tables.b.addDescriptor((short) 63, (short) 0, 0, 0, 16, "Byte count", "Numeric", null); return true; }  static boolean read(InputStream ios, BufrTables.Tables tables);  }