public static ThreddsMetadata.Variables extractVariables( InvDatasetImpl threddsDataset, GridDataset gridDataset) { thredds.catalog.DataFormatType fileFormat = threddsDataset.getDataFormatType(); if ((fileFormat != null) && (fileFormat.equals(DataFormatType.GRIB1) || fileFormat.equals(DataFormatType.GRIB2))) { boolean isGrib1 = fileFormat.equals(DataFormatType.GRIB1); ThreddsMetadata.Variables vars = new ThreddsMetadata.Variables(fileFormat.toString()); for (GridDatatype grid : gridDataset.getGrids()) { ThreddsMetadata.Variable v = new ThreddsMetadata.Variable(); v.setName(grid.getName()); v.setDescription(grid.getDescription()); v.setUnits(grid.getUnitsString()); // ucar.nc2.Attribute att = grid.findAttributeIgnoreCase("GRIB_param_number"); // String paramNumber = (att != null) ? att.getNumericValue().toString() : null; if (isGrib1) { v.setVocabularyName(grid.findAttValueIgnoreCase("GRIB_param_name", "ERROR")); v.setVocabularyId(grid.findAttributeIgnoreCase("GRIB_param_id")); } else { String paramDisc = grid.findAttValueIgnoreCase("GRIB_param_discipline", ""); String paramCategory = grid.findAttValueIgnoreCase("GRIB_param_category", ""); String paramName = grid.findAttValueIgnoreCase("GRIB_param_name", ""); v.setVocabularyName(paramDisc + " / " + paramCategory + " / " + paramName); v.setVocabularyId(grid.findAttributeIgnoreCase("GRIB_param_id")); } vars.addVariable(v); } vars.sort(); return vars; } else { // GRID but not GRIB ThreddsMetadata.Variables vars = new ThreddsMetadata.Variables("CF-1.0"); for (GridDatatype grid : gridDataset.getGrids()) { ThreddsMetadata.Variable v = new ThreddsMetadata.Variable(); vars.addVariable(v); v.setName(grid.getName()); v.setDescription(grid.getDescription()); v.setUnits(grid.getUnitsString()); ucar.nc2.Attribute att = grid.findAttributeIgnoreCase("standard_name"); v.setVocabularyName((att != null) ? att.getStringValue() : "N/A"); } vars.sort(); return vars; } }