// Read a FITS file
f = new Fits("image2.fits");
BasicHDU[] hdus = f.read();
ImageHDU h = (ImageHDU) hdus[1];
// Put this HDU at the beginning of the FITS file
f.insertHDU(h, 0);
// Make it an extension again!
f.insertHDU(hdus[0], 0);
// Check out image tiling from files.
ImageTiler t = h.getTiler();
short[] stile = (short[]) t.getTile(new int[]{10, 10}, new int[]{2, 2});
assertEquals(4, stile.length);
assertEquals(20, stile[0]);
assertEquals(21, stile[1]);
assertEquals(21, stile[2]);
assertEquals(22, stile[3]);
stile = (short[]) t.getTile(new int[]{20, 20}, new int[]{2, 2});
assertEquals(40, stile[0]);
assertEquals(41, stile[1]);
assertEquals(41, stile[2]);
assertEquals(42, stile[3]);
short[] xtile = new short[4];
t.getTile(xtile, new int[]{20, 20}, new int[]{2, 2});
assertEquals(40, xtile[0]);
assertEquals(41, xtile[1]);
assertEquals(41, xtile[2]);
assertEquals(42, xtile[3]);
// Check a 3-d image.
h = (ImageHDU) hdus[6];
t = h.getTiler();
int[] itile = (int[]) t.getTile(new int[]{3, 3, 3}, new int[]{2, 2, 2});
assertEquals(8, itile.length);
assertEquals(9, itile[0]);
assertEquals(10, itile[1]);
assertEquals(10, itile[2]);
assertEquals(11, itile[3]);
assertEquals(10, itile[4]);
assertEquals(11, itile[5]);
assertEquals(11, itile[6]);
assertEquals(12, itile[7]);
// How about a 1-d image.
h = (ImageHDU) hdus[7];
t = h.getTiler();
double[] dtile = (double[]) t.getTile(new int[]{410}, new int[]{3});
assertEquals(3, dtile.length);
assertEquals(20.0d, dtile[0], 0d);
assertEquals(21.0d, dtile[1], 0d);
assertEquals(22.0d, dtile[2], 0d);
// Check from memory tiling!
t = ((ImageHDU) hdus[1]).getTiler();
stile = (short[]) t.getTile(new int[]{20, 20}, new int[]{2, 2});
assertEquals(40, stile[0]);
assertEquals(41, stile[1]);
assertEquals(41, stile[2]);
assertEquals(42, stile[3]);
stile = (short[]) t.getTile(new int[]{25, 25}, new int[]{2, 2});
assertEquals(50, stile[0]);
assertEquals(51, stile[1]);
assertEquals(51, stile[2]);
assertEquals(52, stile[3]);
h = (ImageHDU) hdus[6];
t = h.getTiler();
itile = (int[]) t.getTile(new int[]{3, 3, 3}, new int[]{2, 2, 2});
assertEquals(8, itile.length);
assertEquals(9, itile[0]);
assertEquals(10, itile[1]);
assertEquals(10, itile[2]);
assertEquals(11, itile[3]);
assertEquals(10, itile[4]);
assertEquals(11, itile[5]);
assertEquals(11, itile[6]);
assertEquals(12, itile[7]);
h = (ImageHDU) hdus[7];
t = h.getTiler();
dtile = (double[]) t.getTile(new int[]{410}, new int[]{3});
assertEquals(3, dtile.length);
assertEquals(20.0d, dtile[0], 0d);
assertEquals(21d, dtile[1], 0d);
assertEquals(22d, dtile[2], 0d);