Package nom.tam.fits

Class AsciiTable

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private ByteParser bp
      The parser used to convert from buffer to data.
      private byte[] buffer
      The byte buffer used to read/write the ASCII table
      private ArrayDataInput currInput
      The actual stream used to input data
      private java.lang.Object[] data
      An array of arrays giving the data in the table in binary numbers
      private static int DOUBLE_MAX_LENGTH  
      private static int FLOAT_MAX_LENGTH  
      private static int INT_MAX_LENGTH  
      private boolean[] isNull
      Markers indicating fields that are null
      private int[] lengths
      The number of bytes in the field
      private static java.util.logging.Logger LOG  
      private static int LONG_MAX_LENGTH  
      private static int MAX_INTEGER_LENGTH  
      private int nFields
      The number of fields in the table
      private int nRows
      The number of rows in the table
      private java.lang.String[] nulls
      The null string for the field
      private int[] offsets
      The offset from the beginning of the row at which the field starts
      private int rowLen
      The number of bytes in a row
      private java.lang.Class<?>[] types
      The type of data in the field
    • Constructor Summary

      Constructors 
      Constructor Description
      AsciiTable()
      Create an empty ASCII table
      AsciiTable​(Header hdr)
      Create an ASCII table given a header
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) int addColInfo​(int col, Cursor<java.lang.String,​HeaderCard> iter)  
      int addColumn​(java.lang.Object newCol)
      Add a column to the table without any associated header information.
      int addColumn​(java.lang.Object newCol, int length)
      This version of addColumn allows the user to override the default length associated with each column type.
      int addRow​(java.lang.Object[] newRow)
      Add a row at the end of the table.
      void deleteColumns​(int start, int len)
      Delete columns from the table.
      void deleteRows​(int start, int len)
      Delete rows from a FITS table
      private void ensureData()
      be sure that the data is filled.
      private boolean extractElement​(int offset, int length, java.lang.Object[] array, int col, int row, java.lang.String nullFld)
      Move an element from the buffer into a data array.
      void fillHeader​(Header hdr)
      Fill in a header with information that points to this data.
      private void getBuffer​(int size, long offset)
      Read some data into the buffer.
      java.lang.Object getColumn​(int col)
      Get a column of data
      java.lang.Object getData()
      Get the ASCII table information.
      java.lang.Object getElement​(int row, int col)
      Get a single element as a one-d array.
      int getNCols()
      Get the number of columns in the table
      int getNRows()
      Get the number of rows in the table
      java.lang.Object[] getRow​(int row)
      Get a row.
      int getRowLen()
      Get the number of bytes in a row
      protected long getTrueSize()
      Return the size of the data section
      boolean isNull​(int row, int col)
      See if an element is null.
      private java.lang.Object parseSingleElement​(int row, int col)
      Read a single element from the table.
      private java.lang.Object[] parseSingleRow​(int row)
      Read a single row from the table.
      void read​(ArrayDataInput str)
      Read in an ASCII table.
      void setColumn​(int col, java.lang.Object newData)
      Replace a column with new data.
      void setElement​(int row, int col, java.lang.Object newData)
      Modify an element in the table
      void setNull​(int row, int col, boolean flag)
      Mark (or unmark) an element as null.
      (package private) void setNullString​(int col, java.lang.String newNull)
      Set the null string for a columns.
      void setRow​(int row, java.lang.Object[] newData)
      Modify a row in the table
      private java.lang.Object singleElement​(int row, int col)
      Extract a single element from a table.
      private java.lang.Object[] singleRow​(int row)
      Extract a single row from a table.
      void updateAfterDelete​(int oldNCol, Header hdr)
      This is called after we delete columns.
      void write​(ArrayDataOutput str)
      Write the data to an output stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        private static final java.util.logging.Logger LOG
      • nRows

        private int nRows
        The number of rows in the table
      • nFields

        private int nFields
        The number of fields in the table
      • rowLen

        private int rowLen
        The number of bytes in a row
      • nulls

        private java.lang.String[] nulls
        The null string for the field
      • types

        private java.lang.Class<?>[] types
        The type of data in the field
      • offsets

        private int[] offsets
        The offset from the beginning of the row at which the field starts
      • lengths

        private int[] lengths
        The number of bytes in the field
      • buffer

        private byte[] buffer
        The byte buffer used to read/write the ASCII table
      • isNull

        private boolean[] isNull
        Markers indicating fields that are null
      • data

        private java.lang.Object[] data
        An array of arrays giving the data in the table in binary numbers
      • bp

        private ByteParser bp
        The parser used to convert from buffer to data.
      • currInput

        private ArrayDataInput currInput
        The actual stream used to input data
    • Constructor Detail

      • AsciiTable

        public AsciiTable()
        Create an empty ASCII table
      • AsciiTable

        public AsciiTable​(Header hdr)
                   throws FitsException
        Create an ASCII table given a header
        Parameters:
        hdr - The header describing the table
        Throws:
        FitsException - if the operation failed
    • Method Detail

      • addColumn

        public int addColumn​(java.lang.Object newCol)
                      throws FitsException
        Description copied from interface: TableData
        Add a column to the table without any associated header information. Users should be cautious of calling this routine directly rather than the corresponding routine in AsciiTableHDU since this routine knows nothing of the FITS header modifications required.
        Parameters:
        newCol - the new column information. the newCol should be an Object[] where type of all of the constituents is identical. The length of data should match the other columns. Note: It is valid for data to be a 2 or higher dimensionality primitive array. In this case the column index is the first (in Java speak) index of the array. E.g., if called with int[30][20][10], the number of rows in the table should be 30 and this column will have elements which are 2-d integer arrays with TDIM = (10,20).
        Returns:
        the number of columns in the adapted table
        Throws:
        FitsException - if the operation failed
      • addColumn

        public int addColumn​(java.lang.Object newCol,
                             int length)
                      throws FitsException
        This version of addColumn allows the user to override the default length associated with each column type.
        Parameters:
        newCol - The new column data
        length - the requested length for the column
        Returns:
        the number of columns after this one is added.
        Throws:
        FitsException - if the operation failed
      • addRow

        public int addRow​(java.lang.Object[] newRow)
                   throws FitsException
        Description copied from interface: TableData
        Add a row at the end of the table. Given the way the table is structured this will normally not be very efficient.Users should be cautious of calling this routine directly rather than the corresponding routine in AsciiTableHDU since this routine knows nothing of the FITS header modifications required.
        Parameters:
        newRow - An array of elements to be added. Each element of o should be an array of primitives or a String.
        Returns:
        the number of rows in the adapted table
        Throws:
        FitsException - if the operation failed
      • deleteColumns

        public void deleteColumns​(int start,
                                  int len)
                           throws FitsException
        Delete columns from the table.
        Parameters:
        start - The first, 0-indexed, column to be deleted.
        len - The number of columns to be deleted.
        Throws:
        FitsException - if the operation failed
      • deleteRows

        public void deleteRows​(int start,
                               int len)
                        throws FitsException
        Delete rows from a FITS table
        Parameters:
        start - The first (0-indexed) row to be deleted.
        len - The number of rows to be deleted.
        Throws:
        FitsException - if the operation failed
      • ensureData

        private void ensureData()
                         throws FitsException
        be sure that the data is filled. because the getData already tests null the getData is called without check.
        Throws:
        FitsException - if the operation failed
      • extractElement

        private boolean extractElement​(int offset,
                                       int length,
                                       java.lang.Object[] array,
                                       int col,
                                       int row,
                                       java.lang.String nullFld)
                                throws FitsException
        Move an element from the buffer into a data array.
        Parameters:
        offset - The offset within buffer at which the element starts.
        length - The number of bytes in the buffer for the element.
        array - An array of objects, each of which is a simple array.
        col - Which element of array is to be modified?
        row - Which index into that element is to be modified?
        nullFld - What string signifies a null element?
        Throws:
        FitsException - if the operation failed
      • fillHeader

        public void fillHeader​(Header hdr)
        Fill in a header with information that points to this data.
        Specified by:
        fillHeader in class Data
        Parameters:
        hdr - The header to be updated with information appropriate to the current table data.
      • getBuffer

        private void getBuffer​(int size,
                               long offset)
                        throws java.io.IOException,
                               FitsException
        Read some data into the buffer.
        Throws:
        java.io.IOException
        FitsException
      • getColumn

        public java.lang.Object getColumn​(int col)
                                   throws FitsException
        Get a column of data
        Parameters:
        col - The 0-indexed column to be returned.
        Returns:
        The column object -- typically as a 1-d array.
        Throws:
        FitsException - if the operation failed
      • getData

        public java.lang.Object getData()
                                 throws FitsException
        Get the ASCII table information. This will actually do the read if it had previously been deferred
        Specified by:
        getData in class Data
        Returns:
        The table data as an Object[] array.
        Throws:
        FitsException - if the operation failed
      • getElement

        public java.lang.Object getElement​(int row,
                                           int col)
                                    throws FitsException
        Get a single element as a one-d array. We return String's as arrays for consistency though they could be returned as a scalar.
        Parameters:
        row - The 0-based row
        col - The 0-based column
        Returns:
        The requested cell data.
        Throws:
        FitsException - when unable to get the data.
      • getNCols

        public int getNCols()
        Get the number of columns in the table
        Returns:
        The number of columns
      • getNRows

        public int getNRows()
        Get the number of rows in the table
        Returns:
        The number of rows.
      • getRow

        public java.lang.Object[] getRow​(int row)
                                  throws FitsException
        Get a row. If the data has not yet been read just read this row.
        Parameters:
        row - The 0-indexed row to be returned.
        Returns:
        A row of data.
        Throws:
        FitsException - if the operation failed
      • getRowLen

        public int getRowLen()
        Get the number of bytes in a row
        Returns:
        The number of bytes for a single row in the table.
      • getTrueSize

        protected long getTrueSize()
        Return the size of the data section
        Specified by:
        getTrueSize in class Data
        Returns:
        The size in bytes of the data section, not includeing the padding.
      • isNull

        public boolean isNull​(int row,
                              int col)
        See if an element is null.
        Parameters:
        row - The 0-based row
        col - The 0-based column
        Returns:
        if the given element has been nulled.
      • parseSingleElement

        private java.lang.Object parseSingleElement​(int row,
                                                    int col)
                                             throws FitsException
        Read a single element from the table. This returns an array of dimension 1.
        Throws:
        FitsException - if the operation failed
      • parseSingleRow

        private java.lang.Object[] parseSingleRow​(int row)
                                           throws FitsException
        Read a single row from the table. This returns a set of arrays of dimension 1.
        Throws:
        FitsException - if the operation failed
      • read

        public void read​(ArrayDataInput str)
                  throws FitsException
        Read in an ASCII table. Reading is deferred if we are reading from a random access device
        Specified by:
        read in interface FitsElement
        Specified by:
        read in class Data
        Parameters:
        str - the stream to read from
        Throws:
        FitsException - if the operation failed
      • setColumn

        public void setColumn​(int col,
                              java.lang.Object newData)
                       throws FitsException
        Replace a column with new data.
        Parameters:
        col - The 0-based index to the column
        newData - The column data. This is typically a 1-d array.
        Throws:
        FitsException - if the operation failed
      • setElement

        public void setElement​(int row,
                               int col,
                               java.lang.Object newData)
                        throws FitsException
        Modify an element in the table
        Parameters:
        row - the 0-based row
        col - the 0-based column
        newData - The new value for the column. Typically a primitive[1] array.
        Throws:
        FitsException - if the operation failed
      • setNull

        public void setNull​(int row,
                            int col,
                            boolean flag)
        Mark (or unmark) an element as null. Note that if this FITS file is latter written out, a TNULL keyword needs to be defined in the corresponding header. This routine does not add an element for String columns.
        Parameters:
        row - The 0-based row.
        col - The 0-based column.
        flag - True if the element is to be set to null.
      • setNullString

        void setNullString​(int col,
                           java.lang.String newNull)
        Set the null string for a columns. This is not a public method since we want users to call the method in AsciiTableHDU and update the header also.
      • setRow

        public void setRow​(int row,
                           java.lang.Object[] newData)
                    throws FitsException
        Modify a row in the table
        Parameters:
        row - The 0-based index of the row
        newData - The new data. Each element of this array is typically a primitive[1] array.
        Throws:
        FitsException - if the operation failed
      • singleElement

        private java.lang.Object singleElement​(int row,
                                               int col)
        Extract a single element from a table. This returns an array of length 1.
      • singleRow

        private java.lang.Object[] singleRow​(int row)
        Extract a single row from a table. This returns an array of Objects each of which is an array of length 1.
      • updateAfterDelete

        public void updateAfterDelete​(int oldNCol,
                                      Header hdr)
                               throws FitsException
        This is called after we delete columns. The HDU doesn't know how to update the TBCOL entries.
        Parameters:
        oldNCol - The number of columns we had before deletion.
        hdr - The associated header. @throws FitsException if the operation failed
        Throws:
        FitsException
      • write

        public void write​(ArrayDataOutput str)
                   throws FitsException
        Write the data to an output stream.
        Specified by:
        write in interface FitsElement
        Specified by:
        write in class Data
        Parameters:
        str - The output stream to be written to
        Throws:
        FitsException - if any IO exception is found or some inconsistency the FITS file arises.