Esempio n. 1
0
  @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));
    }
  }
Esempio n. 2
0
  /** Update the display to show the FITS headers of the spectrum */
  public void updateDisplay() {
    Header header = null;
    if (specData != null) {
      header = specData.getHeaders();
    }

    //  Stop with null table if no spectrum or no headers.
    if (specData == null || header == null) {
      table.setModel(new DefaultTableModel());
      return;
    }

    String[] columnNames = {"Keyword", "Value", "Comment"};
    int numKeywords = header.getNumberOfCards();
    String[][] values = new String[numKeywords][3];
    Iterator it = header.iterator();
    int n = 0;
    while (it.hasNext()) {
      HeaderCard card = (HeaderCard) (it.next());
      String key = card.getKey();
      String value = card.getValue();
      String comment = card.getComment();
      //  A blank keyword is really a comment line.
      if ("".equals(key)) {
        value = comment;
        comment = "";
      }
      values[n][0] = key;
      values[n][1] = value;
      values[n++][2] = comment;
    }
    table.setModel(new DefaultTableModel(values, columnNames));

    //  Set default widths, matched to FITS format.
    TableColumn column = table.getColumnModel().getColumn(0);
    column.setPreferredWidth(100);
    column = table.getColumnModel().getColumn(1);
    column.setPreferredWidth(300);
    column = table.getColumnModel().getColumn(2);
    column.setPreferredWidth(450);
  }