Package net.ivoa.fits.data

Examples of net.ivoa.fits.data.BinaryTable


      }
    }
  }

  public void testTable3() throws Exception {
    BinaryTable btab = new BinaryTable();

    btab.addColumn(floats);
    btab.addColumn(vf);
    btab.addColumn(strings);
    btab.addColumn(vbool);
    btab.addColumn(ints);

    Fits f = new Fits();
    f.addHDU(Fits.makeHDU(btab));

    BufferedDataOutputStream bdos = new BufferedDataOutputStream(
        new FileOutputStream("bt3.fits"));
    f.write(bdos);

    f = new Fits("bt3.fits");
    BinaryTableHDU bhdu = (BinaryTableHDU) f.getHDU(1);
    btab = (BinaryTable) bhdu.getData();

    float[] flatfloat = (float[]) btab.getFlattenedColumn(0);
    float[][] tvf = (float[][]) btab.getColumn(1);
    String[] xstr = (String[]) btab.getColumn(2);
    boolean[][] tvbool = (boolean[][]) btab.getColumn(3);

    for (int i = 0; i < 50; i += 3) {
      assertEquals(flatfloat[16 * i], flatfloat[16 * i + 1], 0);
      assertEquals(vf[i].length, tvf[i].length);
      for (int j = 0; j < vf[i].length; j++) {
        assertEquals(vf[i][j], tvf[i][j], 0);
      }
      assertEquals(strings[i], xstr[i]);
      assertEquals(vbool[i].length, tvbool[i].length);
      for (int j = 0; j < vbool[i].length; j++) {
        assertEquals(vbool[i][j], tvbool[i][j]);
      }
    }

    // add again some columns
    btab.addColumn(floats);
    btab.addColumn(vf);
    btab.addColumn(strings);
    btab.addColumn(vbool);
    btab.addColumn(ints);
       
    // add 50 rows..
    for (int i = 0; i < 50; i += 1) {
      Object[] row = btab.getRow(i);
      // test that we really have 10 cols
      assertEquals(10, row.length);
      float[] qx = (float[]) row[1];

      assertEquals(strings[i], (String) row[2]);
      // change string to new string
      row[2] = "new string:" + i;
      btab.addRow(row);
    }

    f = new Fits();
    f.addHDU(Fits.makeHDU(btab));
    BufferedFile bf = new BufferedFile("bt4.fits", "rw");
    f.write(bf);
    bf.flush();
    bf.close();

    f = new Fits("bt4.fits");

    btab = (BinaryTable) f.getHDU(1).getData();

    // Try getting data before we read in the table.

    xstr = (String[]) btab.getColumn(2);

        //char[] c = btab.getTypes();
        //System.out.println(c[3]);
        boolean[] batest = (boolean[]) btab.getElement(99, 3);
        System.out.println(batest.length);
       
        boolean[] ob = new boolean[]{true, false, true, false};
        System.out.println(ob[0] + " " + ob[1] + " " + ob[2] + " " + ob[3]);
        System.out.println(batest[0] + " " + batest[1] + " " + batest[2] + " " + batest[3]);
       
        btab.setElement(99, 3, ob);
       
    for (int i = 0; i < xstr.length; i++) {

      boolean[] ba = (boolean[]) btab.getElement(i, 3);
      float[] fx = (float[]) btab.getElement(i, 1);
      float[][] tst = (float[][]) btab.getElement(i, 0);
      String s = (String) btab.getElement(i, 2);

      int trow = i % 50;

            System.out.println(vbool[trow].length + " " + ba.length);
      assertEquals(vbool[trow].length, ba.length);
      for (int j = 0; j < ba.length; j += 1) {
        assertEquals(ba[j], vbool[trow][j]);
      }

      assertEquals(vf[trow].length, fx.length);
      for (int j = 0; j < fx.length; j += 1) {
        assertEquals(vf[trow][j], fx[j], 0);
      }
      if (i >= 50)
        assertEquals("new string:" + trow, s);
      else
        assertEquals(strings[i], s);

      // that's for second set of cols
      ba = (boolean[]) btab.getElement(i, 8);
      fx = (float[]) btab.getElement(i, 6);
      tst = (float[][]) btab.getElement(i, 5);
      s = (String) btab.getElement(i, 7);

      assertEquals(vbool[trow].length, ba.length);
      for (int j = 0; j < ba.length; j += 1) {
        assertEquals(ba[j], vbool[trow][j]);
      }

      assertEquals(vf[trow].length, fx.length);
      for (int j = 0; j < fx.length; j += 1) {
        assertEquals(vf[trow][j], fx[j], 0);
      }
      assertEquals(strings[trow], s);
    }
    // Fill the table.
    f.getHDU(1).getData();

    xstr = (String[]) btab.getColumn(2);

    for (int i = 0; i < xstr.length; i += 3) {
      int trow = i % 50;

      String s = (String) btab.getElement(i, 2);
      if (i > 50)
        assertEquals("new string:" + trow, s);
      else
        assertEquals(strings[i], s);
      assertEquals(s, xstr[i]);
View Full Code Here


   * @exception FitsException
   *                if there was a problem with the header.
   */

  public static Data manufactureData(Header header) throws FitsException {
    return new BinaryTable(header);
  }
View Full Code Here

  /** Encapsulate data in a BinaryTable data type */
  public static Data encapsulate(Object o) throws FitsException {

    if (o instanceof net.ivoa.util.ColumnTable) {
      return new BinaryTable((net.ivoa.util.ColumnTable) o);
    } else if (o instanceof Object[][]) {
      return new BinaryTable((Object[][]) o);
    } else if (o instanceof Object[]) {
      return new BinaryTable((Object[]) o);
    } else {
      throw new FitsException("Unable to encapsulate object of type:"
          + o.getClass().getName() + " as BinaryTable");
    }
  }
View Full Code Here

  /**
   * Print out some information about this HDU.
   */
  public String toString() {

    BinaryTable myData = (BinaryTable) this.myData;
    StringBuffer sb = new StringBuffer("  Binary Table\n");
    sb.append("      Header Information:\n");

    int nhcol = myHeader.getIntValue("TFIELDS", -1);
    int nrow = myHeader.getIntValue("NAXIS2", -1);
View Full Code Here

TOP

Related Classes of net.ivoa.fits.data.BinaryTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.