}
FileUtils.copyFile(file, new File(TestData.file(this, null), "polyphemus.nc"));
file = TestData.file(this, "polyphemus.nc");
final NetCDFImageReaderSpi unidataImageReaderSpi = new NetCDFImageReaderSpi();
assertTrue(unidataImageReaderSpi.canDecodeInput(file));
NetCDFImageReader reader = null;
try {
reader = (NetCDFImageReader) unidataImageReaderSpi.createReaderInstance();
reader.setInput(file);
int numImages = reader.getNumImages(true);
assertEquals(1008, numImages);
for (int i = 0; i < numImages; i++) {
Slice2DIndex sliceIndex = reader.getSlice2DIndex(i);
assertNotNull(sliceIndex);
spitOutSliceInformation(i, sliceIndex);
}
// check dimensions
CoverageSourceDescriptor cd = reader.getCoverageDescriptor(new NameImpl("NO2"));
final List<AdditionalDomain> additionalDomains = cd.getAdditionalDomains();
assertNull(additionalDomains);
final List<DimensionDescriptor> dimensions = cd.getDimensionDescriptors();
assertNotNull(dimensions);
assertTrue(!dimensions.isEmpty());
assertEquals("wrong dimensions", 2, dimensions.size());
DimensionDescriptor dim = dimensions.get(0);
assertTrue(dim.getName().equals("TIME"));
assertTrue(dim.getStartAttribute().equals("time"));
dim = dimensions.get(1);
assertTrue(dim.getName().equals("ELEVATION"));
assertTrue(dim.getStartAttribute().equals("z"));
// check coverage names
final List<Name> names = reader.getCoveragesNames();
assertNotNull(names);
assertTrue(!names.isEmpty());
assertTrue(3 == names.size());
assertTrue(names.contains(new NameImpl("NO2")));
assertTrue(names.contains(new NameImpl("O3")));
assertTrue(names.contains(new NameImpl("V")));
// checking slice catalog
final CoverageSlicesCatalog cs = reader.getCatalog();
assertNotNull(cs);
// get typenames
final String[] typeNames = cs.getTypeNames();
for (String typeName : typeNames) {
final List<CoverageSlice> granules = cs.getGranules(new Query(typeName,
Filter.INCLUDE));
assertNotNull(granules);
assertFalse(granules.isEmpty());
for (CoverageSlice slice : granules) {
final SimpleFeature sf = slice.getOriginator();
if (TestData.isInteractiveTest()) {
LOGGER.info(DataUtilities.encodeFeature(sf));
}
// checks
for (Property p : sf.getProperties()) {
assertNotNull("Property " + p.getName() + " had a null value!",
p.getValue());
}
}
}
} finally {
// close reader
if (reader != null) {
try {
reader.dispose();
} catch (Throwable t) {
// Does nothing
}
}