/** Read parameter table. */ private void readParameterTable() { if (path == null) { logger.error("GribPDSParamTable: unknown path for " + this); return; } try { InputStream is = GribResourceReader.getInputStream(path); if (is == null) { logger.error("GribPDSParamTable: error getInputStream on " + this); return; } BufferedReader br = new BufferedReader(new InputStreamReader(is)); // Read first line that has center, subcenter, and version of table String line = br.readLine(); if (debug) System.out.println(line); String[] tableDefArr = line.split(":"); /* LOOK - why not test values ? center = Integer.parseInt(tableDefArr[1].trim()); subcenter = Integer.parseInt(tableDefArr[2].trim()); number = Integer.parseInt(tableDefArr[3].trim()); if ((center != center_id) && (subcenter != subcenter_id) && (number != table_number)) { throw new java.io.IOException( "parameter table header values do not " + " match values in GRIB file. Possible error in lookup table."); } */ HashMap<String, GridParameter> tmpParameters = new HashMap<String, GridParameter>(); // thread safe - temp hash // rdg - added the 0 line length check to cover the case of blank lines at // the end of the parameter table file. while ((line = br.readLine()) != null) { if ((line.length() == 0) || line.startsWith("#")) { continue; } GridParameter parameter = new GridParameter(); tableDefArr = line.split(":"); parameter.setNumber(Integer.parseInt(tableDefArr[0].trim())); parameter.setName(tableDefArr[1].trim()); // check to see if unit defined, if not, parameter is undefined if (tableDefArr[2].indexOf('[') == -1) { // Undefined unit parameter.setDescription(tableDefArr[2].trim()); parameter.setUnit(tableDefArr[2].trim()); } else { String[] arr2 = tableDefArr[2].split("\\["); parameter.setDescription(makeValidDesc(arr2[0].trim())); // System.out.println( "Desc ="+ parameter.getDescription()); // Remove "]" parameter.setUnit(arr2[1].substring(0, arr2[1].lastIndexOf(']')).trim()); } tmpParameters.put(Integer.toString(parameter.getNumber()), parameter); if (debug) System.out.println( parameter.getNumber() + " " + parameter.getDescription() + " " + parameter.getUnit()); } this.parameters = tmpParameters; // thread safe } catch (IOException ioError) { logger.warn( "An error occurred in GribPDSParamTable while trying to open the parameter table " + filename + " : " + ioError); } }
public final GridParameter getParameter(Index.GribRecord gr) { GridParameter gd = ParameterTable.getParameter(gr.discipline, gr.category, gr.paramNumber); return new GridParameter(gd.getNumber(), gd.getName(), gd.getDescription(), gd.getUnit()); // return (Parameter) ParameterTable.getParameter(gr.discipline, gr.category, gr.paramNumber); }