@Test public void testFitsUndefinedHdu4() throws Exception { Fits fits1 = makeAsciiTable(); fits1.read(); byte[] undefinedData = new byte[1000]; for (int index = 0; index < undefinedData.length; index++) { undefinedData[index] = (byte) index; } Data data = UndefinedHDU.encapsulate(undefinedData); Header header = new Header(); header.pointToData(data); fits1.addHDU(FitsFactory.hduFactory(header, data)); BufferedDataOutputStream os = new BufferedDataOutputStream(new FileOutputStream("target/UndefindedHDU4.fits")); fits1.write(os); os.close(); Fits fits2 = new Fits("target/UndefindedHDU4.fits"); BasicHDU<?>[] hdus = fits2.read(); byte[] rereadUndefinedData = (byte[]) ((UndefinedData) hdus[hdus.length - 1].getData()).getData(); Assert.assertArrayEquals(undefinedData, rereadUndefinedData); ByteArrayOutputStream out = new ByteArrayOutputStream(); hdus[hdus.length - 1].info(new PrintStream(out)); String undefinedInfo = new String(out.toByteArray()); Assert.assertTrue(undefinedInfo.indexOf("Apparent size:1000") >= 0); }
/** * this test is only for manual usage with enough memory allocated. * * @throws Exception */ @Test @Ignore public void testVeryBigDataFiles() throws Exception { Fits f = new Fits(); ImageData data = new ImageData(new float[50000][50000]); Header manufactureHeader = ImageHDU.manufactureHeader(data); f.addHDU(FitsFactory.hduFactory(manufactureHeader, data)); BufferedFile bf = new BufferedFile("target/big.fits", "rw"); f.write(bf); System.out.println(Arrays.toString(ArrayFuncs.getDimensions(f.getHDU(0).getData().getData()))); f = new Fits("target/big.fits"); System.out.println(Arrays.toString(ArrayFuncs.getDimensions(f.getHDU(0).getData().getData()))); }
@Test public void testFitsUndefinedHdu3() throws Exception { Fits fits1 = makeAsciiTable(); fits1.read(); byte[] undefinedData = new byte[1000]; for (int index = 0; index < undefinedData.length; index++) { undefinedData[index] = (byte) index; } Data data = UndefinedHDU.encapsulate(undefinedData); Header header = new Header(data); Cursor<String, HeaderCard> iter = header.iterator(); String[] headers = new String[header.getNumberOfCards() - 1]; int index = 0; while (iter.hasNext()) { HeaderCard headerCard = iter.next(); // the EXTEND key will be deleted later on because the header is no // primary header so don't use it if (!headerCard.getKey().equals("EXTEND")) { headers[index++] = headerCard.toString(); } } Header newHeader = new Header(headers); for (index = 0; index < headers.length; index++) { Assert.assertEquals(header.getCard(index), newHeader.getCard(index)); } fits1.addHDU(FitsFactory.hduFactory(newHeader, data)); BufferedDataOutputStream os = new BufferedDataOutputStream(new FileOutputStream("target/UndefindedHDU3.fits")); fits1.write(os); os.close(); Fits fits2 = new Fits("target/UndefindedHDU3.fits"); BasicHDU[] hdus = fits2.read(); for (index = 0; index < headers.length; index++) { Assert.assertEquals(header.getCard(index), hdus[5].getHeader().getCard(index)); } }
@Test public void testFitsUndefinedHdu5() throws Exception { Header head = new Header(); head.setXtension("UNKNOWN"); head.setBitpix(BasicHDU.BITPIX_BYTE); head.setNaxes(1); head.addValue("NAXIS1", 1000, null); head.addValue("PCOUNT", 0, null); head.addValue("GCOUNT", 2, null); UndefinedHDU hdu = (UndefinedHDU) FitsFactory.hduFactory(head); byte[] data = (byte[]) hdu.getData().getData(); Assert.assertEquals(2000, data.length); Arrays.fill(data, (byte) 1); BufferedFile buf = new BufferedFile("target/testFitsUndefinedHdu5", "rw"); hdu.write(buf); buf.close(); Arrays.fill(data, (byte) 2); buf = new BufferedFile("target/testFitsUndefinedHdu5", "rw"); hdu.read(buf); data = (byte[]) hdu.getData().getData(); buf.close(); Assert.assertEquals((byte) 1, data[0]); }