}
f = new Fits("at1.fits");
AsciiTableHDU hdu = (AsciiTableHDU) f.getHDU(1);
AsciiTable data = (AsciiTable) hdu.getData();
for (int i = 0; i < 10; i += 1) {
Object[] row = data.getRow(i);
float[] f2 = (float[]) row[0];
String[] s2 = (String[]) row[4];
f1 = (float[]) data.getElement(i, 0);
s1 = (String[]) data.getElement(i, 4);
assertEquals(f1[0], f2[0], 0.0f);
assertEquals(s1[0], s2[0]);
}
f1 = (float[]) data.getColumn(0);
s1 = (String[]) data.getColumn(4);
for (int i = 0; i < 10; i += 1) {
assertEquals(realCol[i], f1[i], 0.0f);
assertEquals(s1[i].trim(), strCol[i]);
}
for (int i = 0; i < 10; i += 1) {
Object[] row = data.getRow(i);
f1 = (float[]) row[0];
s1 = (String[]) row[4];
float[] f2 = (float[]) data.getElement(i, 0);
String[] s2 = (String[]) data.getElement(i, 4);
assertEquals(f1[0], f2[0], 0.0f);
assertEquals(s1[0], s2[0]);
}
f1 = (float[]) data.getColumn(0);
float[] f2 = (float[]) f1.clone();
for (int i = 0; i < f2.length; i += 1) {
f2[i] = 2 * f2[i];
}
data.setColumn(0, f2);
f1 = new float[]{3.14159f};
data.setElement(3, 0, f1);
hdu.setNullString(0, "**INVALID**");
data.setNull(5, 0, true);
data.setNull(6, 0, true);
Object[] row = new Object[5];
row[0] = new float[]{6.28f};
row[1] = new int[]{22};
row[2] = new long[]{0};
row[3] = new double[]{-3};
row[4] = new String[]{"A string"};
data.setRow(4, row);
// Rewrite (for grins rewrite header second)
hdu.getHeader().rewrite();
BufferedFile bf = new BufferedFile("at1.fits", "rw");
f.write(bf);
bf.flush();
bf.close();
f = new Fits("at1.fits");
data = (AsciiTable) f.getHDU(1).getData();
for (int i = 0; i < 35; i += 1) {
row = data.getRow(i);
f1 = (float[]) row[0];
s1 = (String[]) row[4];
if (i == 4) {
assertEquals(6.28f, f1[0], 0.0f);
assertEquals("A string", s1[0].trim());
} else {
if (i == 3) {
assertEquals(3.14159f, f1[0], 0.0f);
} else if (i == 5 || i == 6) {
try {
assertEquals(0, f1[0], 0);
fail("Expected null, get non-null");
} catch (NullPointerException ex) {
}
} else {
assertEquals(2 * realCol[i], f1[0], 0.0f);
}
}
f1 = (float[]) data.getElement(i, 0);
s1 = (String[]) data.getElement(i, 4);
if (i == 4) {
assertEquals(6.28f, f1[0], 0);
assertEquals("A string", s1[0].trim());
} else {
if (i == 3) {
assertEquals(3.14159f, f1[0], 0);
} else if (i == 5 || i == 6) {
try {
assertEquals(0, f1[0], 0);
fail("Expected null, get non-null");
} catch (NullPointerException ex) {
}
} else {
assertEquals((2 * realCol[i]), f1[0], 0);
}
assertEquals(strCol[i], s1[0].trim());
}
}
f1 = (float[]) data.getColumn(0);
for (int i = 0; i < 35; i += 1) {
if (i == 3) {
assertEquals(3.14159f, f1[i], 0);
} else if (i == 4) {
assertEquals(6.28f, f1[i], 0);
} else if (i == 5 || i == 6) {
assertTrue(data.isNull(i, 0));
assertEquals(0, f1[i], 0);
} else {
assertFalse(data.isNull(i, 0));
assertEquals((2 * realCol[i]), f1[i], 0);
}
}
// clean up