Package nom.tam.fits

Class Header

  • All Implemented Interfaces:
    FitsElement

    public class Header
    extends java.lang.Object
    implements FitsElement
    This class describes methods to access and manipulate the header for a FITS HDU. This class does not include code specific to particular types of HDU. As of version 1.1 this class supports the long keyword convention which allows long string keyword values to be split among multiple keywords
        KEY        = 'ABC&'   /A comment
        CONTINUE      'DEF&'  / Another comment
        CONTINUE      'GHIJKL '
     
    The methods getStringValue(key), addValue(key,value,comment) and deleteCard(key) will get, create/update and delete long string values if the longStringsEnabled flag is set. This flag is set automatically when a FITS header with a LONGSTRN card is found. The value is not checked. It may also be set/unset using the static method setLongStringsEnabled(boolean). [So if a user wishes to ensure that it is not set, it should be unset after any header is read] When long strings are found in the FITS header users should be careful not to interpose new header cards within a long value sequence. When writing long strings, the comment is included in the last card. If a user is writing long strings, a the keyword LONGSTRN = 'OGIP 1.0' should be added to the FITS header, but this is not done automatically for the user.
    • Constructor Summary

      Constructors 
      Constructor Description
      Header()
      Create an empty header
      Header​(java.lang.String[] newCards)
      Create a header and initialize it with a vector of strings.
      Header​(Data o)
      Create a header which points to the given data object.
      Header​(ArrayDataInput is)
      Create a header and populate it from the input stream
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      private void addDuplicate​(HeaderCard dup)  
      private void addHeaderCard​(java.lang.String key, HeaderCard card)  
      void addLine​(HeaderCard fcard)
      Add a card image to the header.
      void addValue​(java.lang.String key, boolean val, java.lang.String comment)
      Add or replace a key with the given boolean value and comment.
      void addValue​(java.lang.String key, double val, int precision, java.lang.String comment)
      Add or replace a key with the given double value and comment.
      void addValue​(java.lang.String key, double val, java.lang.String comment)
      Add or replace a key with the given double value and comment.
      void addValue​(java.lang.String key, long val, java.lang.String comment)
      Add or replace a key with the given long value and comment.
      void addValue​(java.lang.String key, java.lang.String val, java.lang.String comment)
      Add or replace a key with the given string value and comment.
      void addValue​(java.lang.String key, java.math.BigDecimal val, java.lang.String comment)
      Add or replace a key with the given bigdecimal value and comment.
      void addValue​(java.lang.String key, java.math.BigInteger val, java.lang.String comment)
      Add or replace a key with the given BigInteger value and comment.
      void addValue​(IFitsHeader key, boolean val)
      Add or replace a key with the given boolean value and comment.
      void addValue​(IFitsHeader key, double val)
      Add or replace a key with the given double value and comment.
      void addValue​(IFitsHeader key, int val)
      Add or replace a key with the given long value and comment.
      void addValue​(IFitsHeader key, long val)
      Add or replace a key with the given long value and comment.
      void addValue​(IFitsHeader key, java.lang.String val)
      Add or replace a key with the given string value and comment.
      (package private) void afterExtend()
      Move after the EXTEND keyword in images.
      HeaderCardBuilder card​(IFitsHeader key)
      get a builder for filling the header cards using the builder pattern.
      private void cardCheck​(java.lang.String key)
      Check if the given key is the next one available in the header.
      private void cardCheck​(IFitsHeader key)
      Check if the given key is the next one available in the header.
      (package private) void checkBeginning()
      Ensure that the header begins with a valid set of keywords.
      (package private) void checkEnd()
      Ensure that the header has exactly one END keyword in the appropriate location.
      private void checkFirstCard​(java.lang.String key)  
      boolean containsKey​(java.lang.String key)
      Tests if the specified keyword is present in this table.
      boolean containsKey​(IFitsHeader key)
      Tests if the specified keyword is present in this table.
      void deleteKey​(java.lang.String key)
      Delete the card associated with the given key.
      void deleteKey​(IFitsHeader key)
      Delete the card associated with the given key.
      private void doCardChecks​(boolean isTable, boolean isExtension)  
      void dumpHeader​(java.io.PrintStream ps)
      Print the header to a given stream.
      HeaderCard findCard​(java.lang.String key)
      Find the card associated with a given key.
      HeaderCard findCard​(IFitsHeader key)
      Find the card associated with a given key.
      java.lang.String findKey​(java.lang.String key)
      Find the card associated with a given key.
      java.math.BigDecimal getBigDecimalValue​(java.lang.String key)
      Get the double value associated with the given key.
      java.math.BigDecimal getBigDecimalValue​(java.lang.String key, java.math.BigDecimal dft)
      Get the double value associated with the given key.
      java.math.BigDecimal getBigDecimalValue​(IFitsHeader key)
      Get the double value associated with the given key.
      java.math.BigInteger getBigIntegerValue​(java.lang.String key)
      Get the long value associated with the given key.
      java.math.BigInteger getBigIntegerValue​(java.lang.String key, java.math.BigInteger dft)
      Get the long value associated with the given key.
      java.math.BigInteger getBigIntegerValue​(IFitsHeader key, java.math.BigInteger dft)
      Get the long value associated with the given key.
      boolean getBooleanValue​(java.lang.String key)
      Get the boolean value associated with the given key.
      boolean getBooleanValue​(java.lang.String key, boolean dft)
      Get the boolean value associated with the given key.
      boolean getBooleanValue​(IFitsHeader key)
      Get the boolean value associated with the given key.
      boolean getBooleanValue​(IFitsHeader key, boolean dft)
      Get the boolean value associated with the given key.
      java.lang.String getCard​(int n)
      Deprecated.
      An iterator from iterator(int) or iterator() should be used for sequential access to the header.
      long getDataSize()
      Return the size of the data including any needed padding.
      double getDoubleValue​(java.lang.String key)
      Get the double value associated with the given key.
      double getDoubleValue​(java.lang.String key, double dft)
      Get the double value associated with the given key.
      double getDoubleValue​(IFitsHeader key)
      Get the double value associated with the given key.
      double getDoubleValue​(IFitsHeader key, double dft)
      Get the double value associated with the given key.
      java.util.List<HeaderCard> getDuplicates()  
      long getFileOffset()  
      float getFloatValue​(java.lang.String key)
      Get the float value associated with the given key.
      float getFloatValue​(java.lang.String key, float dft)  
      float getFloatValue​(IFitsHeader key)
      Get the float value associated with the given key.
      float getFloatValue​(IFitsHeader key, float dft)  
      int getIntValue​(java.lang.String key)
      Get the int value associated with the given key.
      int getIntValue​(java.lang.String key, int dft)  
      int getIntValue​(IFitsHeader key)
      Get the int value associated with the given key.
      int getIntValue​(IFitsHeader key, int dft)  
      java.lang.String getKey​(int n)
      Deprecated.
      An iterator from iterator(int) or iterator() should be used for sequential access to the header.
      long getLongValue​(java.lang.String key)
      Get the long value associated with the given key.
      long getLongValue​(java.lang.String key, long dft)
      Get the long value associated with the given key.
      long getLongValue​(IFitsHeader key)
      Get the long value associated with the given key.
      long getLongValue​(IFitsHeader key, long dft)
      Get the long value associated with the given key.
      int getNumberOfCards()  
      int getNumberOfPhysicalCards()  
      long getOriginalSize()  
      long getSize()  
      java.lang.String getStringValue​(java.lang.String key)
      Get the String value associated with the given key.
      java.lang.String getStringValue​(IFitsHeader header)  
      boolean hadDuplicates()  
      (package private) int headerSize()
      Return the size of the header data including padding.
      void insertComment​(java.lang.String value)
      Add a COMMENT line.
      void insertCommentStyle​(java.lang.String header, java.lang.String value)
      Add a line to the header using the COMMENT style, i.e., no '=' in column 9.
      void insertHistory​(java.lang.String value)
      Add a HISTORY line.
      (package private) boolean isValidHeader()
      Is this a valid header.
      Cursor<java.lang.String,​HeaderCard> iterator()  
      Cursor<java.lang.String,​HeaderCard> iterator​(int index)  
      Data makeData()  
      HeaderCard nextCard()  
      (package private) void nullImage()
      Create a header for a null image.
      void pointToData​(Data o)
      Deprecated.
      Use the appropriate Header constructor.
      (package private) Cursor<java.lang.String,​HeaderCard> positionAfterIndex​(IFitsHeader prefix, int col)
      Find the end of a set of keywords describing a column or axis (or anything else terminated by an index.
      void read​(ArrayDataInput dis)
      Read a stream for header data.
      static Header readHeader​(ArrayDataInput dis)
      Create a header by reading the information from the input stream.
      void removeCard​(java.lang.String key)
      Deprecated.
      (package private) boolean replaceKey​(java.lang.String oldKey, java.lang.String newKey)
      Replace the key with a new key.
      (package private) boolean replaceKey​(IFitsHeader oldKey, IFitsHeader newKey)
      Replace the key with a new key.
      boolean reset()
      Reset the file pointer to the beginning of the header
      void resetOriginalSize()
      Indicate that we can use the current internal size of the Header as the 'original' size (e.g., perhaps we've rewritten the header to disk).
      void rewrite()
      Rewrite the header.
      boolean rewriteable()  
      void setBitpix​(int val)
      Set the BITPIX value for the header.
      void setHeaderSorter​(java.util.Comparator<java.lang.String> headerSorter)
      Overwite the default header card sorter.
      static void setLongStringsEnabled​(boolean flag)
      Deprecated.
      void setNaxes​(int val)
      Set the value of the NAXIS keyword
      void setNaxis​(int axis, int dim)
      Set the dimension for a given axis.
      void setSimple​(boolean val)
      Set the SIMPLE keyword to the given value.
      void setXtension​(java.lang.String val)
      Set the XTENSION keyword to the given value.
      int size()
      Deprecated.
      (package private) long trueDataSize()
      Calculate the unpadded size of the data segment from the header information.
      void updateLine​(java.lang.String key, HeaderCard card)
      Update a line in the header
      void updateLine​(IFitsHeader key, HeaderCard card)
      Update a line in the header
      void updateLines​(Header newHdr)
      Overwrite the lines in the header.
      void write​(ArrayDataOutput dos)
      Write the current header (including any needed padding) to the output stream.
      • Methods inherited from class java.lang.Object

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

      • MIN_NUMBER_OF_CARDS_FOR_VALID_HEADER

        private static final int MIN_NUMBER_OF_CARDS_FOR_VALID_HEADER
        See Also:
        Constant Field Values
      • LOG

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

        private final HashedList<HeaderCard> cards
        The actual header data stored as a HashedList of HeaderCard's.
      • iter

        private Cursor<java.lang.String,​HeaderCard> iter
        This iterator allows one to run through the list.
      • fileOffset

        private long fileOffset
        Offset of this Header in the FITS file
      • duplicates

        private java.util.List<HeaderCard> duplicates
      • input

        private ArrayDataInput input
        Input descriptor last time header was read
      • originalCardCount

        private int originalCardCount
        Number of cards in header before duplicates were removed. A user may want to know how large the actual FITS header was on input. Since the keyword hash removes duplicate keys the internal size may be smaller. Added by Booth Hartley (IPAC/Caltech).
      • headerSorter

        private java.util.Comparator<java.lang.String> headerSorter
        the sorter used to sort the header cards defore writing the header.
    • Constructor Detail

      • Header

        public Header()
        Create an empty header
      • Header

        public Header​(ArrayDataInput is)
               throws TruncatedFileException,
                      java.io.IOException
        Create a header and populate it from the input stream
        Parameters:
        is - The input stream where header information is expected.
        Throws:
        java.io.IOException - if the header could not be read.
        TruncatedFileException - if the stream ended prematurely
      • Header

        public Header​(Data o)
               throws FitsException
        Create a header which points to the given data object.
        Parameters:
        o - The data object to be described.
        Throws:
        FitsException - if the data was not valid for this header.
      • Header

        public Header​(java.lang.String[] newCards)
        Create a header and initialize it with a vector of strings.
        Parameters:
        newCards - Card images to be placed in the header.
    • Method Detail

      • readHeader

        public static Header readHeader​(ArrayDataInput dis)
                                 throws TruncatedFileException,
                                        java.io.IOException
        Create a header by reading the information from the input stream.
        Parameters:
        dis - The input stream to read the data from.
        Returns:
        null if there was a problem with the header; otherwise return the header read from the input stream.
        Throws:
        TruncatedFileException - if the stream ended prematurely
        java.io.IOException - if the header could not be read.
      • setLongStringsEnabled

        @Deprecated
        public static void setLongStringsEnabled​(boolean flag)
        Deprecated.
        Parameters:
        flag - the new value for long-string enabling.
      • addLine

        public void addLine​(HeaderCard fcard)
        Add a card image to the header.
        Parameters:
        fcard - The card to be added.
      • addValue

        public void addValue​(IFitsHeader key,
                             boolean val)
                      throws HeaderCardException
        Add or replace a key with the given boolean value and comment.
        Parameters:
        key - The header key.
        val - The boolean value.
        Throws:
        HeaderCardException - If the parameters cannot build a valid FITS card.
      • addValue

        public void addValue​(IFitsHeader key,
                             double val)
                      throws HeaderCardException
        Add or replace a key with the given double value and comment. Note that float values will be promoted to doubles.
        Parameters:
        key - The header key.
        val - The double value.
        Throws:
        HeaderCardException - If the parameters cannot build a valid FITS card.
      • addValue

        public void addValue​(IFitsHeader key,
                             int val)
                      throws HeaderCardException
        Add or replace a key with the given long value and comment. Note that int's will be promoted to long's.
        Parameters:
        key - The header key.
        val - The long value.
        Throws:
        HeaderCardException - If the parameters cannot build a valid FITS card.
      • addValue

        public void addValue​(IFitsHeader key,
                             long val)
                      throws HeaderCardException
        Add or replace a key with the given long value and comment. Note that int's will be promoted to long's.
        Parameters:
        key - The header key.
        val - The long value.
        Throws:
        HeaderCardException - If the parameters cannot build a valid FITS card.
      • addValue

        public void addValue​(IFitsHeader key,
                             java.lang.String val)
                      throws HeaderCardException
        Add or replace a key with the given string value and comment.
        Parameters:
        key - The header key.
        val - The string value.
        Throws:
        HeaderCardException - If the parameters cannot build a valid FITS card.
      • addValue

        public void addValue​(java.lang.String key,
                             java.math.BigDecimal val,
                             java.lang.String comment)
                      throws HeaderCardException
        Add or replace a key with the given bigdecimal value and comment. Note that float values will be promoted to doubles.
        Parameters:
        key - The header key.
        val - The bigDecimal value.
        comment - A comment to append to the card.
        Throws:
        HeaderCardException - If the parameters cannot build a valid FITS card.
      • addValue

        public void addValue​(java.lang.String key,
                             java.math.BigInteger val,
                             java.lang.String comment)
                      throws HeaderCardException
        Add or replace a key with the given BigInteger value and comment. Note that float values will be promoted to doubles.
        Parameters:
        key - The header key.
        val - The BigInteger value.
        comment - A comment to append to the card.
        Throws:
        HeaderCardException - If the parameters cannot build a valid FITS card.
      • addValue

        public void addValue​(java.lang.String key,
                             boolean val,
                             java.lang.String comment)
                      throws HeaderCardException
        Add or replace a key with the given boolean value and comment.
        Parameters:
        key - The header key.
        val - The boolean value.
        comment - A comment to append to the card.
        Throws:
        HeaderCardException - If the parameters cannot build a valid FITS card.
      • addValue

        public void addValue​(java.lang.String key,
                             double val,
                             int precision,
                             java.lang.String comment)
                      throws HeaderCardException
        Add or replace a key with the given double value and comment. Note that float values will be promoted to doubles.
        Parameters:
        key - The header key.
        val - The double value.
        precision - The fixed number of decimal places to show.
        comment - A comment to append to the card.
        Throws:
        HeaderCardException - If the parameters cannot build a valid FITS card.
      • addValue

        public void addValue​(java.lang.String key,
                             double val,
                             java.lang.String comment)
                      throws HeaderCardException
        Add or replace a key with the given double value and comment. Note that float values will be promoted to doubles.
        Parameters:
        key - The header key.
        val - The double value.
        comment - A comment to append to the card.
        Throws:
        HeaderCardException - If the parameters cannot build a valid FITS card.
      • addValue

        public void addValue​(java.lang.String key,
                             long val,
                             java.lang.String comment)
                      throws HeaderCardException
        Add or replace a key with the given long value and comment. Note that int's will be promoted to long's.
        Parameters:
        key - The header key.
        val - The long value.
        comment - A comment to append to the card.
        Throws:
        HeaderCardException - If the parameters cannot build a valid FITS card.
      • addValue

        public void addValue​(java.lang.String key,
                             java.lang.String val,
                             java.lang.String comment)
                      throws HeaderCardException
        Add or replace a key with the given string value and comment.
        Parameters:
        key - The header key.
        val - The string value.
        comment - A comment to append to the card.
        Throws:
        HeaderCardException - If the parameters cannot build a valid FITS card.
      • card

        public HeaderCardBuilder card​(IFitsHeader key)
        get a builder for filling the header cards using the builder pattern.
        Parameters:
        key - the key for the first card.
        Returns:
        the builder for header cards.
      • containsKey

        public final boolean containsKey​(IFitsHeader key)
        Tests if the specified keyword is present in this table.
        Parameters:
        key - the keyword to be found.
        Returns:
        true if the specified keyword is present in this table; false otherwise.
      • containsKey

        public final boolean containsKey​(java.lang.String key)
        Tests if the specified keyword is present in this table.
        Parameters:
        key - the keyword to be found.
        Returns:
        true if the specified keyword is present in this table; false otherwise.
      • deleteKey

        public void deleteKey​(IFitsHeader key)
        Delete the card associated with the given key. Nothing occurs if the key is not found.
        Parameters:
        key - The header key.
      • deleteKey

        public void deleteKey​(java.lang.String key)
        Delete the card associated with the given key. Nothing occurs if the key is not found.
        Parameters:
        key - The header key.
      • dumpHeader

        public void dumpHeader​(java.io.PrintStream ps)
        Print the header to a given stream.
        Parameters:
        ps - the stream to which the card images are dumped.
      • findCard

        public HeaderCard findCard​(IFitsHeader key)
        Find the card associated with a given key. If found this sets the mark to the card, otherwise it unsets the mark.
        Parameters:
        key - The header key.
        Returns:
        null if the keyword could not be found; return the HeaderCard object otherwise.
      • findCard

        public HeaderCard findCard​(java.lang.String key)
        Find the card associated with a given key. If found this sets the mark to the card, otherwise it unsets the mark.
        Parameters:
        key - The header key.
        Returns:
        null if the keyword could not be found; return the HeaderCard object otherwise.
      • findKey

        public java.lang.String findKey​(java.lang.String key)
        Find the card associated with a given key.
        Parameters:
        key - The header key.
        Returns:
        null if the keyword could not be found; return the card image otherwise.
      • getBigDecimalValue

        public java.math.BigDecimal getBigDecimalValue​(IFitsHeader key)
        Get the double value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The associated value or 0.0 if not found.
      • getBigDecimalValue

        public java.math.BigDecimal getBigDecimalValue​(java.lang.String key)
        Get the double value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The associated value or 0.0 if not found.
      • getBigDecimalValue

        public java.math.BigDecimal getBigDecimalValue​(java.lang.String key,
                                                       java.math.BigDecimal dft)
        Get the double value associated with the given key.
        Parameters:
        key - The header key.
        dft - The default value to return if the key cannot be found.
        Returns:
        the associated value.
      • getBigIntegerValue

        public java.math.BigInteger getBigIntegerValue​(IFitsHeader key,
                                                       java.math.BigInteger dft)
        Get the long value associated with the given key.
        Parameters:
        key - The header key.
        dft - The default value to be returned if the key cannot be found.
        Returns:
        the associated value.
      • getBigIntegerValue

        public java.math.BigInteger getBigIntegerValue​(java.lang.String key)
        Get the long value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The associated value or 0 if not found.
      • getBigIntegerValue

        public java.math.BigInteger getBigIntegerValue​(java.lang.String key,
                                                       java.math.BigInteger dft)
        Get the long value associated with the given key.
        Parameters:
        key - The header key.
        dft - The default value to be returned if the key cannot be found.
        Returns:
        the associated value.
      • getBooleanValue

        public boolean getBooleanValue​(IFitsHeader key)
        Get the boolean value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The value found, or false if not found or if the keyword is not a logical keyword.
      • getBooleanValue

        public boolean getBooleanValue​(IFitsHeader key,
                                       boolean dft)
        Get the boolean value associated with the given key.
        Parameters:
        key - The header key.
        dft - The value to be returned if the key cannot be found or if the parameter does not seem to be a boolean.
        Returns:
        the associated value.
      • getBooleanValue

        public boolean getBooleanValue​(java.lang.String key)
        Get the boolean value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The value found, or false if not found or if the keyword is not a logical keyword.
      • getBooleanValue

        public boolean getBooleanValue​(java.lang.String key,
                                       boolean dft)
        Get the boolean value associated with the given key.
        Parameters:
        key - The header key.
        dft - The value to be returned if the key cannot be found or if the parameter does not seem to be a boolean.
        Returns:
        the associated value.
      • getCard

        @Deprecated
        public java.lang.String getCard​(int n)
        Deprecated.
        An iterator from iterator(int) or iterator() should be used for sequential access to the header.
        Get the n'th card image in the header
        Parameters:
        n - the card index to get
        Returns:
        the card image; return null if the n'th card does not exist.
      • getDataSize

        public long getDataSize()
        Return the size of the data including any needed padding.
        Returns:
        the data segment size including any needed padding.
      • getDoubleValue

        public double getDoubleValue​(IFitsHeader key)
        Get the double value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The associated value or 0.0 if not found.
      • getDoubleValue

        public double getDoubleValue​(IFitsHeader key,
                                     double dft)
        Get the double value associated with the given key.
        Parameters:
        key - The header key.
        dft - The default value to return if the key cannot be found.
        Returns:
        the associated value.
      • getDoubleValue

        public double getDoubleValue​(java.lang.String key)
        Get the double value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The associated value or 0.0 if not found.
      • getDoubleValue

        public double getDoubleValue​(java.lang.String key,
                                     double dft)
        Get the double value associated with the given key.
        Parameters:
        key - The header key.
        dft - The default value to return if the key cannot be found.
        Returns:
        the associated value.
      • getDuplicates

        public java.util.List<HeaderCard> getDuplicates()
        Returns:
        the list of duplicate cards. Note that when the header is read in, only the last entry for a given keyword is retained in the active header. This method returns earlier cards that have been discarded in the order in which they were encountered in the header. It is possible for there to be many cards with the same keyword in this list.
      • getFileOffset

        public long getFileOffset()
        Specified by:
        getFileOffset in interface FitsElement
        Returns:
        Get the offset of this header
      • getFloatValue

        public float getFloatValue​(IFitsHeader key)
        Get the float value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The associated value or 0.0 if not found.
      • getFloatValue

        public float getFloatValue​(IFitsHeader key,
                                   float dft)
        Parameters:
        key - The header key.
        dft - The value to be returned if the key is not found.
        Returns:
        the float value associated with the given key.
      • getFloatValue

        public float getFloatValue​(java.lang.String key)
        Get the float value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The associated value or 0.0 if not found.
      • getFloatValue

        public float getFloatValue​(java.lang.String key,
                                   float dft)
        Parameters:
        key - The header key.
        dft - The value to be returned if the key is not found.
        Returns:
        the float value associated with the given key.
      • getIntValue

        public int getIntValue​(IFitsHeader key)
        Get the int value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The associated value or 0 if not found.
      • getIntValue

        public int getIntValue​(IFitsHeader key,
                               int dft)
        Parameters:
        key - The header key.
        dft - The value to be returned if the key is not found.
        Returns:
        the value associated with the key as an int.
      • getIntValue

        public int getIntValue​(java.lang.String key)
        Get the int value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The associated value or 0 if not found.
      • getIntValue

        public int getIntValue​(java.lang.String key,
                               int dft)
        Parameters:
        key - The header key.
        dft - The value to be returned if the key is not found.
        Returns:
        the value associated with the key as an int.
      • getKey

        @Deprecated
        public java.lang.String getKey​(int n)
        Deprecated.
        An iterator from iterator(int) or iterator() should be used for sequential access to the header.
        Get the n'th key in the header.
        Parameters:
        n - the index of the key
        Returns:
        the card image; return null if the n'th key does not exist.
      • getLongValue

        public long getLongValue​(IFitsHeader key)
        Get the long value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The associated value or 0 if not found.
      • getLongValue

        public long getLongValue​(IFitsHeader key,
                                 long dft)
        Get the long value associated with the given key.
        Parameters:
        key - The header key.
        dft - The default value to be returned if the key cannot be found.
        Returns:
        the associated value.
      • getLongValue

        public long getLongValue​(java.lang.String key)
        Get the long value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The associated value or 0 if not found.
      • getLongValue

        public long getLongValue​(java.lang.String key,
                                 long dft)
        Get the long value associated with the given key.
        Parameters:
        key - The header key.
        dft - The default value to be returned if the key cannot be found.
        Returns:
        the associated value.
      • getNumberOfCards

        public int getNumberOfCards()
        Returns:
        the number of cards in the header
      • getNumberOfPhysicalCards

        public int getNumberOfPhysicalCards()
        Returns:
        the number of physical cards in the header.
      • getOriginalSize

        public long getOriginalSize()
        Returns:
        the size of the original header in bytes.
      • getSize

        public long getSize()
        Specified by:
        getSize in interface FitsElement
        Returns:
        the size of the header in bytes
      • getStringValue

        public java.lang.String getStringValue​(IFitsHeader header)
      • getStringValue

        public java.lang.String getStringValue​(java.lang.String key)
        Get the String value associated with the given key.
        Parameters:
        key - The header key.
        Returns:
        The associated value or null if not found or if the value is not a string.
      • hadDuplicates

        public boolean hadDuplicates()
        Returns:
        Were duplicate header keys found when this record was read in?
      • insertComment

        public void insertComment​(java.lang.String value)
                           throws HeaderCardException
        Add a COMMENT line.
        Parameters:
        value - The comment.
        Throws:
        HeaderCardException - If the parameter is not a valid FITS comment.
      • insertCommentStyle

        public void insertCommentStyle​(java.lang.String header,
                                       java.lang.String value)
        Add a line to the header using the COMMENT style, i.e., no '=' in column 9.
        Parameters:
        header - The comment style header.
        value - A string to follow the header.
      • insertHistory

        public void insertHistory​(java.lang.String value)
                           throws HeaderCardException
        Add a HISTORY line.
        Parameters:
        value - The history record.
        Throws:
        HeaderCardException - If the parameter is not a valid FITS comment.
      • iterator

        public Cursor<java.lang.String,​HeaderCard> iterator()
        Returns:
        an iterator over the header cards
      • iterator

        public Cursor<java.lang.String,​HeaderCard> iterator​(int index)
        Parameters:
        index - the card index to start the iterator
        Returns:
        an iterator over the header cards starting at an index
      • makeData

        public Data makeData()
                      throws FitsException
        Returns:
        Create the data element corresponding to the current header
        Throws:
        FitsException - if the header did not contain enough information to detect the type of the data
      • nextCard

        public HeaderCard nextCard()
        Returns:
        the next card in the Header using the current iterator
      • pointToData

        @Deprecated
        public void pointToData​(Data o)
                         throws FitsException
        Deprecated.
        Use the appropriate Header constructor.
        Create a header which points to the given data object.
        Parameters:
        o - The data object to be described.
        Throws:
        FitsException - if the data was not valid for this header.
      • reset

        public boolean reset()
        Reset the file pointer to the beginning of the header
        Specified by:
        reset in interface FitsElement
        Returns:
        True if the reset succeeded.
      • resetOriginalSize

        public void resetOriginalSize()
        Indicate that we can use the current internal size of the Header as the 'original' size (e.g., perhaps we've rewritten the header to disk). Note that affects the results of rewriteable(), so users should not call this method unless the underlying data has actually been updated.
      • rewrite

        public void rewrite()
                     throws FitsException,
                            java.io.IOException
        Rewrite the header.
        Specified by:
        rewrite in interface FitsElement
        Throws:
        FitsException - if the rewrite was unsuccessful.
        java.io.IOException - if the rewrite was unsuccessful.
      • rewriteable

        public boolean rewriteable()
        Specified by:
        rewriteable in interface FitsElement
        Returns:
        true if this element can be rewritten?
      • setBitpix

        public void setBitpix​(int val)
        Set the BITPIX value for the header. The following values are permitted by FITS conventions:
        • 8 -- signed byte data. Also used for tables.
        • 16 -- signed short data.
        • 32 -- signed int data.
        • 64 -- signed long data.
        • -32 -- IEEE 32 bit floating point numbers.
        • -64 -- IEEE 64 bit floating point numbers.
        Parameters:
        val - The value set by the user.
      • setHeaderSorter

        public void setHeaderSorter​(java.util.Comparator<java.lang.String> headerSorter)
        Overwite the default header card sorter.
        Parameters:
        headerSorter - the sorter tu use or null to disable sorting
      • setNaxes

        public void setNaxes​(int val)
        Set the value of the NAXIS keyword
        Parameters:
        val - The dimensionality of the data.
      • setNaxis

        public void setNaxis​(int axis,
                             int dim)
        Set the dimension for a given axis.
        Parameters:
        axis - The axis being set.
        dim - The dimension
      • setSimple

        public void setSimple​(boolean val)
        Set the SIMPLE keyword to the given value.
        Parameters:
        val - The boolean value -- Should be true for FITS data.
      • setXtension

        public void setXtension​(java.lang.String val)
        Set the XTENSION keyword to the given value.
        Parameters:
        val - The name of the extension.
      • size

        @Deprecated
        public int size()
        Deprecated.
        use getNumberOfCards(). The units of the size of the header may be unclear.
        Returns:
        the number of cards in the header
      • updateLine

        public void updateLine​(java.lang.String key,
                               HeaderCard card)
                        throws HeaderCardException
        Update a line in the header
        Parameters:
        key - The key of the card to be replaced.
        card - A new card
        Throws:
        HeaderCardException - if the operation failed
      • updateLines

        public void updateLines​(Header newHdr)
                         throws HeaderCardException
        Overwrite the lines in the header. Add the new PHDU header to the current one. If keywords appear twice, the new value and comment overwrite the current contents. By Richard J Mathar.
        Parameters:
        newHdr - the list of new header data lines to replace the current ones.
        Throws:
        HeaderCardException - if the operation failed
      • write

        public void write​(ArrayDataOutput dos)
                   throws FitsException
        Write the current header (including any needed padding) to the output stream.
        Specified by:
        write in interface FitsElement
        Parameters:
        dos - The output stream to which the data is to be written.
        Throws:
        FitsException - if the header could not be written.
      • addDuplicate

        private void addDuplicate​(HeaderCard dup)
      • addHeaderCard

        private void addHeaderCard​(java.lang.String key,
                                   HeaderCard card)
      • cardCheck

        private void cardCheck​(java.lang.String key)
                        throws FitsException
        Check if the given key is the next one available in the header.
        Throws:
        FitsException
      • checkFirstCard

        private void checkFirstCard​(java.lang.String key)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • afterExtend

        void afterExtend()
        Move after the EXTEND keyword in images. Used in bug fix noted by V. Forchi
      • checkBeginning

        void checkBeginning()
                     throws FitsException
        Ensure that the header begins with a valid set of keywords. Note that we do not check the values of these keywords.
        Throws:
        FitsException
      • checkEnd

        void checkEnd()
        Ensure that the header has exactly one END keyword in the appropriate location.
      • headerSize

        int headerSize()
        Return the size of the header data including padding.
        Returns:
        the header size including any needed padding.
      • isValidHeader

        boolean isValidHeader()
        Is this a valid header.
        Returns:
        true for a valid header, false otherwise.
      • nullImage

        void nullImage()
        Create a header for a null image.
      • positionAfterIndex

        Cursor<java.lang.String,​HeaderCard> positionAfterIndex​(IFitsHeader prefix,
                                                                     int col)
        Find the end of a set of keywords describing a column or axis (or anything else terminated by an index. This routine leaves the header ready to add keywords after any existing keywords with the index specified. The user should specify a prefix to a keyword that is guaranteed to be present.
      • replaceKey

        boolean replaceKey​(IFitsHeader oldKey,
                           IFitsHeader newKey)
                    throws HeaderCardException
        Replace the key with a new key. Typically this is used when deleting or inserting columns so that TFORMx -> TFORMx-1
        Parameters:
        oldKey - The old header keyword.
        newKey - the new header keyword.
        Returns:
        true if the card was replaced.
        Throws:
        HeaderCardException - If newKey is not a valid FITS keyword.
      • replaceKey

        boolean replaceKey​(java.lang.String oldKey,
                           java.lang.String newKey)
                    throws HeaderCardException
        Replace the key with a new key. Typically this is used when deleting or inserting columns so that TFORMx -> TFORMx-1
        Parameters:
        oldKey - The old header keyword.
        newKey - the new header keyword.
        Returns:
        true if the card was replaced.
        Throws:
        HeaderCardException - If newKey is not a valid FITS keyword.
      • trueDataSize

        long trueDataSize()
        Calculate the unpadded size of the data segment from the header information.
        Returns:
        the unpadded data segment size.