NetcdfDataReader extends DataReader { public static Set<String> getVariables(String path) { try (NetcdfDataset ncd = NetcdfDatasets.openDataset(path)) { List<Variable> variables = ncd.getVariables(); Set<String> variableNames = new HashSet<>(); variables.forEach(variable -> { if (variable instanceof VariableDS) { VariableDS variableDS = (VariableDS) variable; List<CoordinateSystem> coordinateSystems = variableDS.getCoordinateSystems(); if (!coordinateSystems.isEmpty()) { variableNames.add(variable.getFullName()); } } }); return variableNames; } catch (Exception e) { logger.log(Level.SEVERE, e, e::getMessage); } return Collections.emptySet(); } NetcdfDataReader(DataReaderBuilder builder); @Override List<VortexData> getDtos(); @Override VortexData getDto(int idx); @Override int getDtoCount(); static Set<String> getVariables(String path);  }
@Test void GCIP_EOP_Stage_IV(){ String inFile = new File(getClass().getResource("/ST4.2005010100.01h").getFile()).toString(); Set<String> variables = DataReader.getVariables(inFile); assertTrue(variables.contains("Total_precipitation_surface_1_Hour_Accumulation")); assertEquals(2, variables.size()); }