@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 testFitsUndefinedHdu() throws Exception { Fits fits1 = makeAsciiTable(); fits1.read(); byte[] undefinedData = new byte[1000]; for (int index = 0; index < undefinedData.length; index++) { undefinedData[index] = (byte) index; } fits1.addHDU(Fits.makeHDU(new UndefinedData(undefinedData))); BufferedDataOutputStream os = new BufferedDataOutputStream(new FileOutputStream("target/UndefindedHDU.fits")); fits1.write(os); os.close(); Fits fits2 = new Fits("target/UndefindedHDU.fits"); BasicHDU<?>[] hdus = fits2.read(); byte[] rereadUndefinedData = (byte[]) ((UndefinedData) hdus[hdus.length - 1].getData()).getData(); Assert.assertArrayEquals(undefinedData, rereadUndefinedData); }
@Test public void testFitsUndefinedHdu2() 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 = UndefinedHDU.manufactureHeader(data); fits1.addHDU(FitsFactory.HDUFactory(header, data)); BufferedDataOutputStream os = new BufferedDataOutputStream(new FileOutputStream("target/UndefindedHDU2.fits")); fits1.write(os); os.close(); Fits fits2 = new Fits("target/UndefindedHDU2.fits"); BasicHDU<?>[] hdus = fits2.read(); byte[] rereadUndefinedData = (byte[]) ((UndefinedData) hdus[hdus.length - 1].getData()).getData(); Assert.assertArrayEquals(undefinedData, rereadUndefinedData); }
private void writeFile(Fits f, String name) throws Exception { BufferedFile bf = new BufferedFile(name, "rw"); f.write(bf); bf.flush(); bf.close(); }