DAPDownloader { static List<Dimension> filterDimensions(List<String> variables, NetcdfFile netcdfFile) { final List<Dimension> filteredDimensions = new ArrayList<Dimension>(); for (String variableName : variables) { final Variable variable = netcdfFile.findVariable(variableName); for (Dimension dimension : variable.getDimensions()) { if (!filteredDimensions.contains(dimension)) { filteredDimensions.add(dimension); } } } return filteredDimensions; } DAPDownloader(Map<String, Boolean> dapUris, List<String> fileURIs, DownloadContext downloadContext,
                         DownloadProgressBarPM pm); void saveProducts(File targetDir);  }
@Test public void testFilterDimensions() throws Exception { final URL resource = getClass().getResource("test.nc"); final NetcdfFile netcdfFile = NetcdfFileOpener.open(resource.toString()); List<String> variableNames = new ArrayList<String>(); variableNames.add("sst"); variableNames.add("wind"); List<Dimension> dimensions = DAPDownloader.filterDimensions(variableNames, netcdfFile); Collections.sort(dimensions); assertEquals(3, dimensions.size()); assertEquals("COADSX", dimensions.get(0).getShortName()); assertEquals("COADSY", dimensions.get(1).getShortName()); assertEquals("TIME", dimensions.get(2).getShortName()); variableNames.clear(); variableNames.add("wind"); dimensions = DAPDownloader.filterDimensions(variableNames, netcdfFile); Collections.sort(dimensions); assertEquals(2, dimensions.size()); assertEquals("COADSX", dimensions.get(0).getShortName()); assertEquals("COADSY", dimensions.get(1).getShortName()); variableNames.clear(); variableNames.add("sst"); dimensions = DAPDownloader.filterDimensions(variableNames, netcdfFile); Collections.sort(dimensions); assertEquals("COADSX", dimensions.get(0).getShortName()); assertEquals("COADSY", dimensions.get(1).getShortName()); assertEquals("TIME", dimensions.get(2).getShortName()); }