01: package it.geosolutions.imageio.plugins.jhdf.tovs;
02:
03: import it.geosolutions.imageio.plugins.jhdf.JHDFTest;
04: import it.geosolutions.imageio.plugins.slices2D.SliceImageReader;
05: import it.geosolutions.resources.TestData;
06:
07: import java.io.File;
08: import java.io.IOException;
09:
10: import javax.imageio.ImageReader;
11: import javax.imageio.metadata.IIOMetadata;
12: import javax.media.jai.JAI;
13: import javax.media.jai.ParameterBlockJAI;
14: import javax.media.jai.RenderedOp;
15:
16: import junit.framework.Test;
17: import junit.framework.TestSuite;
18:
19: import org.w3c.dom.NamedNodeMap;
20: import org.w3c.dom.Node;
21:
22: public class TOVSReadTest extends JHDFTest {
23: public TOVSReadTest(String name) {
24: super (name);
25: }
26:
27: /**
28: *
29: * @throws IOException
30: */
31:
32: public void testJaiTOVSRead() throws IOException {
33: for (int i = 0; i < 45; i++) {
34: //this Test File is available at
35: //ftp://ftp.geo-solutions.it/incoming/TOVS_5DAYS_PM_B790625.E790629_TN.zip
36: //as anonymous ftp access.
37:
38: //TODO: build an utility to auto-download and unzip this file in
39: //the setUp method.
40:
41: final File file = TestData.file(this ,
42: "TOVS_5DAYS_PM_B790625.E790629_TN.HDF");
43: final ImageReader reader = new TOVSImageReader(
44: new TOVSImageReaderSpi());
45: reader.setInput(file);
46:
47: final IIOMetadata metadata = reader.getImageMetadata(i);
48: Node imageNode = metadata
49: .getAsTree(TOVSImageMetadata.nativeMetadataFormatName);
50: imageNode = imageNode.getFirstChild();
51: NamedNodeMap nodeMap = imageNode.getAttributes();
52: final String productName = nodeMap.getNamedItem("Name")
53: .getNodeValue();
54: final int[] indexes = ((SliceImageReader) reader)
55: .getSlice2DIndexCoordinates(i);
56:
57: final ParameterBlockJAI pbjImageRead = new ParameterBlockJAI(
58: "ImageRead");
59: pbjImageRead.setParameter("reader", reader);
60: pbjImageRead
61: .setParameter("imageChoice", Integer.valueOf(i));
62:
63: final RenderedOp image = JAI.create("ImageRead",
64: pbjImageRead);
65: final StringBuffer sb = new StringBuffer(
66: "coverage index = ").append(
67: Integer.toString(indexes[0])).append(
68: " coverage Name = ").append(productName);
69: if (indexes.length > 1)
70: sb.append(" 3rd Dim index = ").append(
71: Integer.toString(indexes[1]));
72: visualize(image, sb.toString(), true);
73: reader.dispose();
74: }
75: }
76:
77: public static Test suite() {
78: TestSuite suite = new TestSuite();
79:
80: suite.addTest(new TOVSReadTest("testJaiTOVSRead"));
81:
82: return suite;
83: }
84:
85: public static void main(java.lang.String[] args) {
86: junit.textui.TestRunner.run(suite());
87: }
88: }
|