Package nom.tam.fits
Class Header
java.lang.Object
nom.tam.fits.Header
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLine(HeaderCard fcard) Add a card image to the header.voidAdd or replace a key with the given boolean value and comment.voidAdd or replace a key with the given double value and comment.voidAdd or replace a key with the given double value and comment.voidAdd or replace a key with the given long value and comment.voidAdd or replace a key with the given string value and comment.voidaddValue(String key, BigDecimal val, String comment) Add or replace a key with the given bigdecimal value and comment.voidaddValue(String key, BigInteger val, String comment) Add or replace a key with the given BigInteger value and comment.voidaddValue(IFitsHeader key, boolean val) Add or replace a key with the given boolean value and comment.voidaddValue(IFitsHeader key, double val) Add or replace a key with the given double value and comment.voidaddValue(IFitsHeader key, int val) Add or replace a key with the given long value and comment.voidaddValue(IFitsHeader key, long val) Add or replace a key with the given long value and comment.voidaddValue(IFitsHeader key, String val) Add or replace a key with the given string value and comment.card(IFitsHeader key) get a builder for filling the header cards using the builder pattern.final booleancontainsKey(String key) Tests if the specified keyword is present in this table.final booleancontainsKey(IFitsHeader key) Tests if the specified keyword is present in this table.voidDelete the card associated with the given key.voiddeleteKey(IFitsHeader key) Delete the card associated with the given key.voidPrint the header to a given stream.Find the card associated with a given key.findCard(IFitsHeader key) Find the card associated with a given key.Find the card associated with a given key.getBigDecimalValue(String key) Get thedoublevalue associated with the given key.getBigDecimalValue(String key, BigDecimal dft) Get thedoublevalue associated with the given key.Get thedoublevalue associated with the given key.getBigIntegerValue(String key) Get thelongvalue associated with the given key.getBigIntegerValue(String key, BigInteger dft) Get thelongvalue associated with the given key.getBigIntegerValue(IFitsHeader key, BigInteger dft) Get thelongvalue associated with the given key.booleangetBooleanValue(String key) Get thebooleanvalue associated with the given key.booleangetBooleanValue(String key, boolean dft) Get thebooleanvalue associated with the given key.booleanGet thebooleanvalue associated with the given key.booleangetBooleanValue(IFitsHeader key, boolean dft) Get thebooleanvalue associated with the given key.getCard(int n) Deprecated.longReturn the size of the data including any needed padding.doublegetDoubleValue(String key) Get thedoublevalue associated with the given key.doublegetDoubleValue(String key, double dft) Get thedoublevalue associated with the given key.doubleGet thedoublevalue associated with the given key.doublegetDoubleValue(IFitsHeader key, double dft) Get thedoublevalue associated with the given key.longfloatgetFloatValue(String key) Get thefloatvalue associated with the given key.floatgetFloatValue(String key, float dft) floatgetFloatValue(IFitsHeader key) Get thefloatvalue associated with the given key.floatgetFloatValue(IFitsHeader key, float dft) intgetIntValue(String key) Get theintvalue associated with the given key.intgetIntValue(String key, int dft) intgetIntValue(IFitsHeader key) Get theintvalue associated with the given key.intgetIntValue(IFitsHeader key, int dft) getKey(int n) Deprecated.An iterator fromiterator(int)oriterator()should be used for sequential access to the header.longgetLongValue(String key) Get thelongvalue associated with the given key.longgetLongValue(String key, long dft) Get thelongvalue associated with the given key.longgetLongValue(IFitsHeader key) Get thelongvalue associated with the given key.longgetLongValue(IFitsHeader key, long dft) Get thelongvalue associated with the given key.intintlonglonggetSize()getStringValue(String key) Get theStringvalue associated with the given key.getStringValue(IFitsHeader header) booleanvoidinsertComment(String value) Add a COMMENT line.voidinsertCommentStyle(String header, String value) Add a line to the header using the COMMENT style, i.e., no '=' in column 9.voidinsertHistory(String value) Add a HISTORY line.iterator()iterator(int index) makeData()nextCard()voidpointToData(Data o) Deprecated.Use the appropriate Header constructor.voidread(ArrayDataInput dis) Read a stream for header data.static HeaderreadHeader(ArrayDataInput dis) Create a header by reading the information from the input stream.voidremoveCard(String key) Deprecated.booleanreset()Reset the file pointer to the beginning of the headervoidIndicate 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).voidrewrite()Rewrite the header.booleanvoidsetBitpix(int val) Set the BITPIX value for the header.voidsetHeaderSorter(Comparator<String> headerSorter) Overwite the default header card sorter.static voidsetLongStringsEnabled(boolean flag) Deprecated.voidsetNaxes(int val) Set the value of the NAXIS keywordvoidsetNaxis(int axis, int dim) Set the dimension for a given axis.voidsetSimple(boolean val) Set the SIMPLE keyword to the given value.voidsetXtension(String val) Set the XTENSION keyword to the given value.intsize()Deprecated.usegetNumberOfCards().voidupdateLine(String key, HeaderCard card) Update a line in the headervoidupdateLine(IFitsHeader key, HeaderCard card) Update a line in the headervoidupdateLines(Header newHdr) Overwrite the lines in the header.voidwrite(ArrayDataOutput dos) Write the current header (including any needed padding) to the output stream.
-
Constructor Details
-
Header
public Header()Create an empty header -
Header
Create a header and populate it from the input stream- Parameters:
is- The input stream where header information is expected.- Throws:
IOException- if the header could not be read.TruncatedFileException- if the stream ended prematurely
-
Header
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
Create a header and initialize it with a vector of strings.- Parameters:
newCards- Card images to be placed in the header.
-
-
Method Details
-
readHeader
Create a header by reading the information from the input stream.- Parameters:
dis- The input stream to read the data from.- Returns:
nullif there was a problem with the header; otherwise return the header read from the input stream.- Throws:
TruncatedFileException- if the stream ended prematurelyIOException- if the header could not be read.
-
setLongStringsEnabled
Deprecated.please useFitsFactory.setLongStringsEnabled(boolean)instead.- Parameters:
flag- the new value for long-string enabling.
-
addLine
Add a card image to the header.- Parameters:
fcard- The card to be added.
-
addValue
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
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
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
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
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
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
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
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(String key, double val, int precision, 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
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
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
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
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
Tests if the specified keyword is present in this table.- Parameters:
key- the keyword to be found.- Returns:
trueif the specified keyword is present in this table;falseotherwise.
-
containsKey
Tests if the specified keyword is present in this table.- Parameters:
key- the keyword to be found.- Returns:
trueif the specified keyword is present in this table;falseotherwise.
-
deleteKey
Delete the card associated with the given key. Nothing occurs if the key is not found.- Parameters:
key- The header key.
-
deleteKey
Delete the card associated with the given key. Nothing occurs if the key is not found.- Parameters:
key- The header key.
-
dumpHeader
Print the header to a given stream.- Parameters:
ps- the stream to which the card images are dumped.
-
findCard
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:
nullif the keyword could not be found; return the HeaderCard object otherwise.
-
findCard
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:
nullif the keyword could not be found; return the HeaderCard object otherwise.
-
findKey
Find the card associated with a given key.- Parameters:
key- The header key.- Returns:
nullif the keyword could not be found; return the card image otherwise.
-
getBigDecimalValue
Get thedoublevalue associated with the given key.- Parameters:
key- The header key.- Returns:
- The associated value or 0.0 if not found.
-
getBigDecimalValue
Get thedoublevalue associated with the given key.- Parameters:
key- The header key.- Returns:
- The associated value or 0.0 if not found.
-
getBigDecimalValue
Get thedoublevalue 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
Get thelongvalue 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
Get thelongvalue associated with the given key.- Parameters:
key- The header key.- Returns:
- The associated value or 0 if not found.
-
getBigIntegerValue
Get thelongvalue 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
Get thebooleanvalue 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
Get thebooleanvalue 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
Get thebooleanvalue 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
Get thebooleanvalue 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.An iterator fromiterator(int)oriterator()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
nullif 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
Get thedoublevalue associated with the given key.- Parameters:
key- The header key.- Returns:
- The associated value or 0.0 if not found.
-
getDoubleValue
Get thedoublevalue 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
Get thedoublevalue associated with the given key.- Parameters:
key- The header key.- Returns:
- The associated value or 0.0 if not found.
-
getDoubleValue
Get thedoublevalue 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
- 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:
getFileOffsetin interfaceFitsElement- Returns:
- Get the offset of this header
-
getFloatValue
Get thefloatvalue associated with the given key.- Parameters:
key- The header key.- Returns:
- The associated value or 0.0 if not found.
-
getFloatValue
- Parameters:
key- The header key.dft- The value to be returned if the key is not found.- Returns:
- the
floatvalue associated with the given key.
-
getFloatValue
Get thefloatvalue associated with the given key.- Parameters:
key- The header key.- Returns:
- The associated value or 0.0 if not found.
-
getFloatValue
- Parameters:
key- The header key.dft- The value to be returned if the key is not found.- Returns:
- the
floatvalue associated with the given key.
-
getIntValue
Get theintvalue associated with the given key.- Parameters:
key- The header key.- Returns:
- The associated value or 0 if not found.
-
getIntValue
- 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
Get theintvalue associated with the given key.- Parameters:
key- The header key.- Returns:
- The associated value or 0 if not found.
-
getIntValue
- 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.An iterator fromiterator(int)oriterator()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
nullif the n'th key does not exist.
-
getLongValue
Get thelongvalue associated with the given key.- Parameters:
key- The header key.- Returns:
- The associated value or 0 if not found.
-
getLongValue
Get thelongvalue 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
Get thelongvalue associated with the given key.- Parameters:
key- The header key.- Returns:
- The associated value or 0 if not found.
-
getLongValue
Get thelongvalue 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:
getSizein interfaceFitsElement- Returns:
- the size of the header in bytes
-
getStringValue
-
getStringValue
Get theStringvalue 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
Add a COMMENT line.- Parameters:
value- The comment.- Throws:
HeaderCardException- If the parameter is not a valid FITS comment.
-
insertCommentStyle
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
Add a HISTORY line.- Parameters:
value- The history record.- Throws:
HeaderCardException- If the parameter is not a valid FITS comment.
-
iterator
- Returns:
- an iterator over the header cards
-
iterator
- Parameters:
index- the card index to start the iterator- Returns:
- an iterator over the header cards starting at an index
-
makeData
- 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
- Returns:
- the next card in the Header using the current iterator
-
pointToData
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.
-
read
Read a stream for header data.- Specified by:
readin interfaceFitsElement- Parameters:
dis- The input stream to read the data from.- Throws:
TruncatedFileException- the the stream ended prematurelyIOException- if the operation failed
-
removeCard
Deprecated.Delete a key.- Parameters:
key- The header key.- Throws:
HeaderCardException- if the operation failed
-
reset
public boolean reset()Reset the file pointer to the beginning of the header- Specified by:
resetin interfaceFitsElement- 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
Rewrite the header.- Specified by:
rewritein interfaceFitsElement- Throws:
FitsException- if the rewrite was unsuccessful.IOException- if the rewrite was unsuccessful.
-
rewriteable
public boolean rewriteable()- Specified by:
rewriteablein interfaceFitsElement- Returns:
trueif 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
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
Set the XTENSION keyword to the given value.- Parameters:
val- The name of the extension.
-
size
Deprecated.usegetNumberOfCards(). The units of the size of the header may be unclear.- Returns:
- the number of cards in the header
-
updateLine
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
-
updateLine
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
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
Write the current header (including any needed padding) to the output stream.- Specified by:
writein interfaceFitsElement- Parameters:
dos- The output stream to which the data is to be written.- Throws:
FitsException- if the header could not be written.
-
iterator(int)oriterator()should be used for sequential access to the header.