1 package nom.tam.fits.test;
4 import static org.junit.Assert.assertEquals;
5 import junit.framework.JUnit4TestAdapter;
7 import nom.tam.image.*;
14 import java.io.FileInputStream;
15 import java.io.InputStream;
17 /** Test reading .Z and .gz compressed files.
19 public class CompressTest {
22 public void testgz() throws Exception {
24 File fil = new File(".");
25 System.out.println("File is:" + fil.getCanonicalPath());
26 Fits f = new Fits("http://heasarc.gsfc.nasa.gov/FTP/asca/data/rev2/43021000/images/ad43021000gis25670_lo.totsky.gz");
28 BasicHDU h = f.readHDU();
29 int[][] data = (int[][]) h.getKernel();
31 for (int i = 0; i < data.length; i += 1) {
32 for (int j = 0; j < data[i].length; j += 1) {
36 assertEquals("ZCompress", sum, 296915., 0);
40 public void testZ() throws Exception {
42 Fits f = new Fits("http://heasarc.gsfc.nasa.gov/FTP/rosat/data/pspc/processed_data/600000/rp600245n00/rp600245n00_im1.fits.Z");
44 BasicHDU h = f.readHDU();
45 short[][] data = (short[][]) h.getKernel();
47 for (int i = 0; i < data.length; i += 1) {
48 for (int j = 0; j < data[i].length; j += 1) {
52 assertEquals("ZCompress", sum, 91806., 0);
56 public void testStream() throws Exception {
60 assertEquals("Stream1", 300, streamRead(is, false, false));
63 assertEquals("Stream2", 300, streamRead(is, false, false));
66 assertEquals("Stream3", 300, streamRead(is, false, false));
69 assertEquals("Stream4", 300, streamRead(is, false, true));
72 assertEquals("Stream5", 300, streamRead(is, false, true));
75 assertEquals("Stream6", 300, streamRead(is, false, true));
78 assertEquals("Stream7", 300, streamRead(is, true, true));
81 assertEquals("Stream8", 300, streamRead(is, true, true));
84 assertEquals("Stream9", 300, streamRead(is, true, true));
88 public void testFile() throws Exception {
89 String is = "test.fits";
90 assertEquals("File1", 300, fileRead(is, false, false));
93 assertEquals("File2", 300, fileRead(is, false, false));
96 assertEquals("File3", 300, fileRead(is, false, false));
99 assertEquals("File4", 300, fileRead(is, false, true));
102 assertEquals("File7", 300, fileRead(is, true, true));
105 assertEquals("File8", 300, fileRead(is, true, true));
107 is = "test.fits.bz2";
108 assertEquals("File9", 300, fileRead(is, true, true));
112 public void testString() throws Exception {
113 String is = "test.fits";
114 assertEquals("String1", 300, stringRead(is, false, false));
117 assertEquals("String2", 300, stringRead(is, false, false));
120 assertEquals("String3", 300, stringRead(is, false, false));
123 assertEquals("String4", 300, stringRead(is, false, true));
126 assertEquals("String7", 300, stringRead(is, true, true));
129 assertEquals("String8", 300, stringRead(is, true, true));
131 is = "test.fits.bz2";
132 assertEquals("String8", 300, stringRead(is, true, true));
136 public void testURL() throws Exception {
137 String is = "test.fits";
138 assertEquals("String1", 300, urlRead(is, false, false));
141 assertEquals("String2", 300, urlRead(is, false, false));
144 assertEquals("String3", 300, urlRead(is, false, false));
147 assertEquals("String4", 300, urlRead(is, false, true));
150 assertEquals("String7", 300, urlRead(is, true, true));
153 assertEquals("String8", 300, urlRead(is, true, true));
155 is = "test.fits.bz2";
156 assertEquals("String8", 300, urlRead(is, true, true));
159 int urlRead(String filename, boolean comp, boolean useComp)
161 URL u = CompressTest.class.getResource(filename);
164 f = new Fits(u, comp);
168 short[][] data = (short[][]) f.readHDU().getKernel();
173 int streamRead(String filename, boolean comp, boolean useComp)
175 InputStream is = CompressTest.class.getResourceAsStream(filename);
178 f = new Fits(is, comp);
182 short[][] data = (short[][]) f.readHDU().getKernel();
188 int fileRead(String filename, boolean comp, boolean useComp)
190 File is = new File(CompressTest.class.getResource(filename).getPath());
193 f = new Fits(is, comp);
197 short[][] data = (short[][]) f.readHDU().getKernel();
202 int stringRead(String filename, boolean comp, boolean useComp)
204 String is = CompressTest.class.getResource(filename).getPath();
207 f = new Fits(is, comp);
211 short[][] data = (short[][]) f.readHDU().getKernel();
216 int total(short[][] data) {
218 for (int i = 0; i < data.length; i += 1) {
219 for (int j = 0; j < data[i].length; j += 1) {