private Map<Integer, Grib2Parameter> readFim(String resourcePath, Formatter f) { Map<Integer, Grib2Parameter> result = new HashMap<>(100); ClassLoader cl = getClass().getClassLoader(); try (InputStream is = cl.getResourceAsStream(resourcePath)) { if (is == null) throw new IllegalStateException("Cant find " + resourcePath); if (f != null) f.format("%50s == %s, %s, %-20s, %-20s%n", "desc", "param", "ztype", "abbrev", "units"); List<TableParser.Record> recs = TableParser.readTable(is, "56,63i,68i,93,102,112", 50000); for (TableParser.Record record : recs) { String desc = ((String) record.get(0)).trim(); int param = (Integer) record.get(1); int ztype = (Integer) record.get(2); String abbrev = ((String) record.get(4)).trim(); String units = ((String) record.get(5)).trim(); if (f != null) f.format("%50s == %3d, %3d, %-20s, %-20s%n", desc, param, ztype, abbrev, units); Grib2Parameter gp = new Grib2Parameter(0, 0, param, abbrev, units, null, desc); result.put(makeParamId(0, 0, param), gp); } } catch (IOException ioe) { throw new RuntimeException(ioe); } return result; }
static Record make(String line, List fields) { try { Record r = new Record(); for (Object field : fields) { Field f = (Field) field; r.values.add(f.parse(line)); } return r; } catch (NumberFormatException e) { System.out.printf("Bad line=%s %n", line); return null; } }
public List<Record> readAllRecords(InputStream ios, int maxLines) throws IOException, NumberFormatException { List<Record> records = new ArrayList<>(); BufferedReader dataIS = new BufferedReader(new InputStreamReader(ios, CDM.utf8Charset)); int count = 0; while ((maxLines < 0) || (count < maxLines)) { String line = dataIS.readLine(); if (line == null) break; if (line.startsWith(comment)) continue; if (line.trim().length() == 0) continue; if (debug) System.out.printf("%s%n", line); Record r = Record.make(line, fields); if (r != null) records.add(r); count++; } return records; }
private Map<Integer, Grib2Parameter> initLocalTable(String resourcePath, Formatter f) { Map<Integer, Grib2Parameter> result = new HashMap<>(100); try (InputStream is = GribResourceReader.getInputStream(resourcePath)) { if (is == null) throw new IllegalStateException("Cant find " + resourcePath); if (f != null) f.format("%s, %-20s, %-20s, %-20s%n", "id", "name", "units", "gname"); TableParser parser = new TableParser("3i,7i,11i,15i,49,69,74,"); parser.setComment("!"); List<TableParser.Record> recs = parser.readAllRecords(is, 50000); for (TableParser.Record record : recs) { int disc = (Integer) record.get(0); int cat = (Integer) record.get(1); int id = (Integer) record.get(2); int template = (Integer) record.get(3); // LOOK - 19, 29, 39 ??? String name = ((String) record.get(4)).trim(); String units = ((String) record.get(5)).trim(); String gname = ((String) record.get(6)).trim(); String ids = disc+"-"+cat+"-"+id; if (f != null) f.format("%s == %-20s, %-20s, %-20s%n", ids, name, units, gname); Grib2Parameter gp = new Grib2Parameter(disc, cat, id, gname, units, null, name); result.put(Grib2Customizer.makeParamId(disc, cat, id), gp); } } catch (IOException ioe) { throw new RuntimeException(ioe); } return result; }
static private void initC1() { String location = BufrTables.RESOURCE_PATH + "wmo/wmoTableC1.txt"; InputStream ios = BufrTables.class.getResourceAsStream(location); tableC1 = new String[256]; try { String prev = null; List<TableParser.Record> recs = TableParser.readTable(ios, "8,13i,120", 500); for (TableParser.Record record : recs) { int no = (Integer) record.get(1); String name = (String) record.get(2); name = name.trim(); tableC1[no] = name.equals(")") ? prev : name; prev = name; } } catch (IOException ioe) { } finally { if (ios != null) try { ios.close(); } catch (IOException ioe) { } } }
static private TableB readEcmwfTableB(InputStream ios, TableB b) throws IOException { int count = 0; List<TableParser.Record> recs = TableParser.readTable(ios, "4i,7i,72,97,102i,114i,119i", 50000); for (TableParser.Record record : recs) { if (record.nfields() < 7) { continue; } int x = (Integer) record.get(0); int y = (Integer) record.get(1); String name = (String) record.get(2); String units = (String) record.get(3); int scale = (Integer) record.get(4); int ref = (Integer) record.get(5); int width = (Integer) record.get(6); b.addDescriptor((short) x, (short) y, scale, ref, width, name, units); /* System.out.println("Table B line =" + record); System.out.printf("%d %d, %d %d %d %s %s %n", x, y, scale, ref, width, name, units); if (count > 10) break; count++; */ } ios.close(); return b; }
static private void initTableA() { String location = BufrTables.RESOURCE_PATH + "wmo/TableA-11-2008.txt"; InputStream ios = BufrTables.class.getResourceAsStream(location); tableA = new String[256]; try { List<TableParser.Record> recs = TableParser.readTable(ios, "3i,60", 255); for (TableParser.Record record : recs) { int no = (Integer) record.get(0); String name = (String) record.get(1); name = name.trim(); tableA[no] = name; //System.out.printf("add %d %s%n", no, name); } } catch (IOException ioe) { } finally { if (ios != null) try { ios.close(); } catch (IOException ioe) { } } }
protected void initLocalTable() { ClassLoader cl = KmaLocalTables.class.getClassLoader(); try (InputStream is = cl.getResourceAsStream(tablePath)) { if (is == null) throw new IllegalStateException("Cant find "+tablePath); List<TableParser.Record> recs = TableParser.readTable(is, "41,112,124i,136i,148i,160", 1000); for (TableParser.Record record : recs) { String name = (String) record.get(0); int disc = (Integer) record.get(2); int cat = (Integer) record.get(3); int param = (Integer) record.get(4); String unit = (String) record.get(5); Grib2Parameter s = new Grib2Parameter(disc,cat,param,name,unit,null,null); local.put(makeParamId(disc, cat, param), s); } } catch (IOException ioe) { throw new RuntimeException(ioe); } } /*
static private TableB readEcmwfTableB(InputStream ios, TableB b) throws IOException { List<TableParser.Record> recs = TableParser.readTable(ios, "4i,7i,72,97,102i,114i,119i", 50000); for (TableParser.Record record : recs) { if (record.nfields() < 7) { continue; } int x = (Integer) record.get(0); int y = (Integer) record.get(1); String name = (String) record.get(2); String units = (String) record.get(3); int scale = (Integer) record.get(4); int ref = (Integer) record.get(5); int width = (Integer) record.get(6); b.addDescriptor((short) x, (short) y, scale, ref, width, name, units, null); /* System.out.println("Table B line =" + record); System.out.printf("%d %d, %d %d %d %s %s %n", x, y, scale, ref, width, name, units); if (count > 10) break; count++; */ } return b; }
@Test public void testReadNexradTable() throws IOException { Class c = TableParser.class; InputStream is = c.getResourceAsStream(testName3); List<TableParser.Record> recs = TableParser.readTable(is, "3,15,54,60d,67d,73d", 50000); TableParser.Record rec = recs.get(0); Assert.assertEquals("TLX", rec.get(0)); Assert.assertEquals(" 000001", rec.get(1)); Assert.assertEquals(" OKLAHOMA_CITY/Norman OK US", rec.get(2)); Assert.assertEquals(3532.0, (Double)rec.get(3), 0.1); Assert.assertEquals(-9727.0, (Double)rec.get(4), 0.1); Assert.assertEquals(370.0, (Double)rec.get(5), 0.1); rec = recs.get(20); Assert.assertEquals("TWX", rec.get(0)); Assert.assertEquals(" 000554", rec.get(1)); Assert.assertEquals(" TOPEKA/Alma KS US", rec.get(2)); Assert.assertEquals(3898.0, (Double)rec.get(3), 0.1); Assert.assertEquals(-9622.0, (Double)rec.get(4), 0.1); Assert.assertEquals(417.0, (Double)rec.get(5), 0.1); }
public List<Record> readAllRecords(InputStream ios, int maxLines) throws IOException, NumberFormatException { List<Record> records = new ArrayList<Record>(); BufferedReader dataIS = new BufferedReader(new InputStreamReader(ios)); int count = 0; while ((maxLines < 0) || (count < maxLines)) { String line = dataIS.readLine(); if (line == null) break; if (line.startsWith("#")) continue; if (line.trim().length() == 0) continue; //System.out.printf("%s%n", line); Record r = Record.make(line, fields); if (r != null) records.add(r); count++; } return records; }
private static void readStationTable() throws IOException { stationTableHash = new HashMap<String,Station>(); ClassLoader cl = Level2VolumeScan.class.getClassLoader(); InputStream is = cl.getResourceAsStream("resources/nj22/tables/nexrad.tbl"); List<TableParser.Record> recs = TableParser.readTable(is, "3,15,46, 54,60d,67d,73d", 50000); for (TableParser.Record record : recs) { Station s = new Station(); s.id = "K" + record.get(0); s.name = record.get(2) + " " + record.get(3); s.lat = (Double) record.get(4) * .01; s.lon = (Double) record.get(5) * .01; s.elev = (Double) record.get(6); stationTableHash.put(s.id, s); if (showStations) System.out.println(" station= " + s); } }
public List<Record> readAllRecords(InputStream ios, int maxLines) throws IOException, NumberFormatException { List<Record> records = new ArrayList<>(); BufferedReader dataIS = new BufferedReader(new InputStreamReader(ios, CDM.utf8Charset)); int count = 0; while ((maxLines < 0) || (count < maxLines)) { String line = dataIS.readLine(); if (line == null) break; if (line.startsWith(comment)) continue; if (line.trim().length() == 0) continue; if (debug) System.out.printf("%s%n", line); Record r = Record.make(line, fields); if (r != null) records.add(r); count++; } return records; }
private static void readStationTable() throws IOException { stationTableHash = new HashMap<String,Station>(); ClassLoader cl = Level2VolumeScan.class.getClassLoader(); InputStream is = cl.getResourceAsStream("resources/nj22/tables/nexrad.tbl"); List<TableParser.Record> recs = TableParser.readTable(is, "3,15,46, 54,60d,67d,73d", 50000); for (TableParser.Record record : recs) { Station s = new Station(); s.id = "K" + record.get(0); s.name = record.get(2) + " " + record.get(3); s.lat = (Double) record.get(4) * .01; s.lon = (Double) record.get(5) * .01; s.elev = (Double) record.get(6); stationTableHash.put(s.id, s); if (showStations) System.out.println(" station= " + s); } }
private static void readStationTable() throws IOException { stationTableHash = new HashMap<String,Station>(); ClassLoader cl = Level2VolumeScan.class.getClassLoader(); InputStream is = cl.getResourceAsStream("resources/nj22/tables/nexrad.tbl"); List<TableParser.Record> recs = TableParser.readTable(is, "3,15,46, 54,60d,67d,73d", 50000); for (TableParser.Record record : recs) { Station s = new Station(); s.id = "K" + record.get(0); s.name = record.get(2) + " " + record.get(3); s.lat = (Double) record.get(4) * .01; s.lon = (Double) record.get(5) * .01; s.elev = (Double) record.get(6); stationTableHash.put(s.id, s); if (showStations) System.out.println(" station= " + s); } }
static Record make(String line, List fields) { try { Record r = new Record(); for (Object field : fields) { Field f = (Field) field; r.values.add(f.parse(line)); } return r; } catch (NumberFormatException e) { System.out.printf("Bad line=%s %n", line); return null; } }
public Record readRecord(String line) throws IOException, NumberFormatException { if (line == null) return null; if (line.startsWith("#")) return null; if (line.trim().length() == 0) return null; //System.out.printf("%s%n", line); return Record.make(line, fields); }
static Record make(String line, List fields) { try { Record r = new Record(); for (Object field : fields) { Field f = (Field) field; r.values.add(f.parse(line)); } return r; } catch (NumberFormatException e) { System.out.printf("Bad line=%s %n", line); return null; } }