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 {
59 is = new FileInputStream("test.fits");
60 assertEquals("Stream1", 300, streamRead(is, false, false));
62 is = new FileInputStream("test.fits.Z");
63 assertEquals("Stream2", 300, streamRead(is, false, false));
65 is = new FileInputStream("test.fits.gz");
66 assertEquals("Stream3", 300, streamRead(is, false, false));
68 is = new FileInputStream("test.fits");
69 assertEquals("Stream4", 300, streamRead(is, false, true));
71 is = new FileInputStream("test.fits.Z");
72 assertEquals("Stream5", 300, streamRead(is, false, true));
74 is = new FileInputStream("test.fits.gz");
75 assertEquals("Stream6", 300, streamRead(is, false, true));
78 is = new FileInputStream("test.fits.Z");
79 assertEquals("Stream7", 300, streamRead(is, true, true));
81 is = new FileInputStream("test.fits.gz");
82 assertEquals("Stream8", 300, streamRead(is, true, true));
84 is = new FileInputStream("test.fits.bz2");
85 assertEquals("Stream9", 300, streamRead(is, true, true));
89 public void testFile() throws Exception {
90 File is = new File("test.fits");
91 assertEquals("File1", 300, fileRead(is, false, false));
93 is = new File("test.fits.Z");
94 assertEquals("File2", 300, fileRead(is, false, false));
96 is = new File("test.fits.gz");
97 assertEquals("File3", 300, fileRead(is, false, false));
99 is = new File("test.fits");
100 assertEquals("File4", 300, fileRead(is, false, true));
102 is = new File("test.fits.Z");
103 assertEquals("File7", 300, fileRead(is, true, true));
105 is = new File("test.fits.gz");
106 assertEquals("File8", 300, fileRead(is, true, true));
108 is = new File("test.fits.bz2");
109 assertEquals("File9", 300, fileRead(is, true, true));
113 public void testString() throws Exception {
114 String is = "test.fits";
115 assertEquals("String1", 300, stringRead(is, false, false));
118 assertEquals("String2", 300, stringRead(is, false, false));
121 assertEquals("String3", 300, stringRead(is, false, false));
124 assertEquals("String4", 300, stringRead(is, false, true));
127 assertEquals("String7", 300, stringRead(is, true, true));
130 assertEquals("String8", 300, stringRead(is, true, true));
132 is = "test.fits.bz2";
133 assertEquals("String8", 300, stringRead(is, true, true));
138 public void testURL() throws Exception {
139 String is = "test.fits";
140 assertEquals("String1", 300, urlRead(is, false, false));
143 assertEquals("String2", 300, urlRead(is, false, false));
146 assertEquals("String3", 300, urlRead(is, false, false));
149 assertEquals("String4", 300, urlRead(is, false, true));
152 assertEquals("String7", 300, urlRead(is, true, true));
155 assertEquals("String8", 300, urlRead(is, true, true));
157 is = "test.fits.bz2";
158 assertEquals("String8", 300, urlRead(is, true, true));
161 int urlRead(String is, boolean comp, boolean useComp)
163 File fil = new File(is);
165 String path = fil.getCanonicalPath();
166 URL u = new URL("file://" + path);
170 f = new Fits(u, comp);
174 short[][] data = (short[][]) f.readHDU().getKernel();
179 int streamRead(InputStream is, boolean comp, boolean useComp)
183 f = new Fits(is, comp);
187 short[][] data = (short[][]) f.readHDU().getKernel();
193 int fileRead(File is, boolean comp, boolean useComp)
197 f = new Fits(is, comp);
201 short[][] data = (short[][]) f.readHDU().getKernel();
206 int stringRead(String is, boolean comp, boolean useComp)
210 f = new Fits(is, comp);
214 short[][] data = (short[][]) f.readHDU().getKernel();
219 int total(short[][] data) {
221 for (int i = 0; i < data.length; i += 1) {
222 for (int j = 0; j < data[i].length; j += 1) {