public class Header extends Object implements FitsElement
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 and Description |
---|
Header()
Create an empty header
|
Header(ArrayDataInput is)
Create a header and populate it from the input stream
|
Header(Data o)
Create a header which points to the given data object.
|
Header(String[] newCards)
Create a header and initialize it with a vector of strings.
|
Modifier and Type | Method and Description |
---|---|
void |
addLine(HeaderCard fcard)
Add a card image to the header.
|
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,
String val)
Add or replace a key with the given string value and comment.
|
void |
addValue(String key,
BigDecimal val,
String comment)
Add or replace a key with the given bigdecimal value and comment.
|
void |
addValue(String key,
BigInteger val,
String comment)
Add or replace a key with the given BigInteger value and comment.
|
void |
addValue(String key,
boolean val,
String comment)
Add or replace a key with the given boolean value and comment.
|
void |
addValue(String key,
double val,
String comment)
Add or replace a key with the given double value and comment.
|
void |
addValue(String key,
long val,
String comment)
Add or replace a key with the given long value and comment.
|
void |
addValue(String key,
String val,
String comment)
Add or replace a key with the given string value and comment.
|
HeaderCardBuilder |
card(IFitsHeader key)
get a builder for filling the header cards using the builder pattern.
|
boolean |
containsKey(IFitsHeader key)
Tests if the specified keyword is present in this table.
|
boolean |
containsKey(String key)
Tests if the specified keyword is present in this table.
|
void |
deleteKey(IFitsHeader key)
Delete the card associated with the given key.
|
void |
deleteKey(String key)
Delete the card associated with the given key.
|
void |
dumpHeader(PrintStream ps)
Print the header to a given stream.
|
HeaderCard |
findCard(IFitsHeader key)
Find the card associated with a given key.
|
HeaderCard |
findCard(String key)
Find the card associated with a given key.
|
String |
findKey(String key)
Find the card associated with a given key.
|
BigDecimal |
getBigDecimalValue(IFitsHeader key)
Get the
double value associated with the given key. |
BigDecimal |
getBigDecimalValue(String key)
Get the
double value associated with the given key. |
BigDecimal |
getBigDecimalValue(String key,
BigDecimal dft)
Get the
double value associated with the given key. |
BigInteger |
getBigIntegerValue(IFitsHeader key,
BigInteger dft)
Get the
long value associated with the given key. |
BigInteger |
getBigIntegerValue(String key)
Get the
long value associated with the given key. |
BigInteger |
getBigIntegerValue(String key,
BigInteger dft)
Get the
long 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. |
boolean |
getBooleanValue(String key)
Get the
boolean value associated with the given key. |
boolean |
getBooleanValue(String key,
boolean dft)
Get the
boolean value associated with the given key. |
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(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. |
double |
getDoubleValue(String key)
Get the
double value associated with the given key. |
double |
getDoubleValue(String key,
double dft)
Get the
double value associated with the given key. |
List<HeaderCard> |
getDuplicates() |
long |
getFileOffset() |
float |
getFloatValue(IFitsHeader key)
Get the
float value associated with the given key. |
float |
getFloatValue(IFitsHeader key,
float dft) |
float |
getFloatValue(String key)
Get the
float value associated with the given key. |
float |
getFloatValue(String key,
float dft) |
int |
getIntValue(IFitsHeader key)
Get the
int value associated with the given key. |
int |
getIntValue(IFitsHeader key,
int dft) |
int |
getIntValue(String key)
Get the
int value associated with the given key. |
int |
getIntValue(String key,
int dft) |
String |
getKey(int n)
Deprecated.
An iterator from
iterator(int) or
iterator() should be used for sequential access to
the header. |
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. |
long |
getLongValue(String key)
Get the
long value associated with the given key. |
long |
getLongValue(String key,
long dft)
Get the
long value associated with the given key. |
int |
getNumberOfCards() |
int |
getNumberOfPhysicalCards() |
long |
getOriginalSize() |
long |
getSize() |
String |
getStringValue(IFitsHeader header) |
String |
getStringValue(String key)
Get the
String value associated with the given key. |
boolean |
hadDuplicates() |
void |
insertComment(String value)
Add a COMMENT line.
|
void |
insertCommentStyle(String header,
String value)
Add a line to the header using the COMMENT style, i.e., no '=' in column
9.
|
void |
insertHistory(String value)
Add a HISTORY line.
|
Cursor<String,HeaderCard> |
iterator() |
Cursor<String,HeaderCard> |
iterator(int index) |
Data |
makeData() |
HeaderCard |
nextCard() |
void |
pointToData(Data o)
Deprecated.
Use the appropriate Header constructor.
|
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(String key)
Deprecated.
|
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.
|
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(String val)
Set the XTENSION keyword to the given value.
|
int |
size()
Deprecated.
use
getNumberOfCards() . The units of the size of the
header may be unclear. |
void |
updateLine(IFitsHeader key,
HeaderCard card)
Update a line in the header
|
void |
updateLine(String 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.
|
public Header()
public Header(ArrayDataInput is) throws TruncatedFileException, IOException
is
- The input stream where header information is expected.IOException
- if the header could not be read.TruncatedFileException
- if the stream ended prematurelypublic Header(Data o) throws FitsException
o
- The data object to be described.FitsException
- if the data was not valid for this header.public Header(String[] newCards)
newCards
- Card images to be placed in the header.public static Header readHeader(ArrayDataInput dis) throws TruncatedFileException, IOException
dis
- The input stream to read the data from.null
if there was a problem with the header;
otherwise return the header read from the input stream.TruncatedFileException
- if the stream ended prematurelyIOException
- if the header could not be read.@Deprecated public static void setLongStringsEnabled(boolean flag)
FitsFactory.setLongStringsEnabled(boolean)
instead.flag
- the new value for long-string enabling.public void addLine(HeaderCard fcard)
fcard
- The card to be added.public void addValue(IFitsHeader key, boolean val) throws HeaderCardException
key
- The header key.val
- The boolean value.HeaderCardException
- If the parameters cannot build a valid FITS card.public void addValue(IFitsHeader key, double val) throws HeaderCardException
key
- The header key.val
- The double value.HeaderCardException
- If the parameters cannot build a valid FITS card.public void addValue(IFitsHeader key, int val) throws HeaderCardException
key
- The header key.val
- The long value.HeaderCardException
- If the parameters cannot build a valid FITS card.public void addValue(IFitsHeader key, long val) throws HeaderCardException
key
- The header key.val
- The long value.HeaderCardException
- If the parameters cannot build a valid FITS card.public void addValue(IFitsHeader key, String val) throws HeaderCardException
key
- The header key.val
- The string value.HeaderCardException
- If the parameters cannot build a valid FITS card.public void addValue(String key, BigDecimal val, String comment) throws HeaderCardException
key
- The header key.val
- The bigDecimal value.comment
- A comment to append to the card.HeaderCardException
- If the parameters cannot build a valid FITS card.public void addValue(String key, BigInteger val, String comment) throws HeaderCardException
key
- The header key.val
- The BigInteger value.comment
- A comment to append to the card.HeaderCardException
- If the parameters cannot build a valid FITS card.public void addValue(String key, boolean val, String comment) throws HeaderCardException
key
- The header key.val
- The boolean value.comment
- A comment to append to the card.HeaderCardException
- If the parameters cannot build a valid FITS card.public void addValue(String key, double val, String comment) throws HeaderCardException
key
- The header key.val
- The double value.comment
- A comment to append to the card.HeaderCardException
- If the parameters cannot build a valid FITS card.public void addValue(String key, long val, String comment) throws HeaderCardException
key
- The header key.val
- The long value.comment
- A comment to append to the card.HeaderCardException
- If the parameters cannot build a valid FITS card.public void addValue(String key, String val, String comment) throws HeaderCardException
key
- The header key.val
- The string value.comment
- A comment to append to the card.HeaderCardException
- If the parameters cannot build a valid FITS card.public HeaderCardBuilder card(IFitsHeader key)
key
- the key for the first card.public final boolean containsKey(IFitsHeader key)
key
- the keyword to be found.true
if the specified keyword is present in this
table; false
otherwise.public final boolean containsKey(String key)
key
- the keyword to be found.true
if the specified keyword is present in this
table; false
otherwise.public void deleteKey(IFitsHeader key)
key
- The header key.public void deleteKey(String key)
key
- The header key.public void dumpHeader(PrintStream ps)
ps
- the stream to which the card images are dumped.public HeaderCard findCard(IFitsHeader key)
key
- The header key.null
if the keyword could not be found; return the
HeaderCard object otherwise.public HeaderCard findCard(String key)
key
- The header key.null
if the keyword could not be found; return the
HeaderCard object otherwise.public String findKey(String key)
key
- The header key.null
if the keyword could not be found; return the
card image otherwise.public BigDecimal getBigDecimalValue(IFitsHeader key)
double
value associated with the given key.key
- The header key.public BigDecimal getBigDecimalValue(String key)
double
value associated with the given key.key
- The header key.public BigDecimal getBigDecimalValue(String key, BigDecimal dft)
double
value associated with the given key.key
- The header key.dft
- The default value to return if the key cannot be found.public BigInteger getBigIntegerValue(IFitsHeader key, BigInteger dft)
long
value associated with the given key.key
- The header key.dft
- The default value to be returned if the key cannot be found.public BigInteger getBigIntegerValue(String key)
long
value associated with the given key.key
- The header key.public BigInteger getBigIntegerValue(String key, BigInteger dft)
long
value associated with the given key.key
- The header key.dft
- The default value to be returned if the key cannot be found.public boolean getBooleanValue(IFitsHeader key)
boolean
value associated with the given key.key
- The header key.public boolean getBooleanValue(IFitsHeader key, boolean dft)
boolean
value associated with the given key.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.public boolean getBooleanValue(String key)
boolean
value associated with the given key.key
- The header key.public boolean getBooleanValue(String key, boolean dft)
boolean
value associated with the given key.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.@Deprecated public String getCard(int n)
iterator(int)
or
iterator()
should be used for sequential access to
the header.n
- the card index to getnull
if the n'th card does
not exist.public long getDataSize()
public double getDoubleValue(IFitsHeader key)
double
value associated with the given key.key
- The header key.public double getDoubleValue(IFitsHeader key, double dft)
double
value associated with the given key.key
- The header key.dft
- The default value to return if the key cannot be found.public double getDoubleValue(String key)
double
value associated with the given key.key
- The header key.public double getDoubleValue(String key, double dft)
double
value associated with the given key.key
- The header key.dft
- The default value to return if the key cannot be found.public List<HeaderCard> getDuplicates()
public long getFileOffset()
getFileOffset
in interface FitsElement
public float getFloatValue(IFitsHeader key)
float
value associated with the given key.key
- The header key.public float getFloatValue(IFitsHeader key, float dft)
key
- The header key.dft
- The value to be returned if the key is not found.float
value associated with the given key.public float getFloatValue(String key)
float
value associated with the given key.key
- The header key.public float getFloatValue(String key, float dft)
key
- The header key.dft
- The value to be returned if the key is not found.float
value associated with the given key.public int getIntValue(IFitsHeader key)
int
value associated with the given key.key
- The header key.public int getIntValue(IFitsHeader key, int dft)
key
- The header key.dft
- The value to be returned if the key is not found.public int getIntValue(String key)
int
value associated with the given key.key
- The header key.public int getIntValue(String key, int dft)
key
- The header key.dft
- The value to be returned if the key is not found.@Deprecated public String getKey(int n)
iterator(int)
or
iterator()
should be used for sequential access to
the header.n
- the index of the keynull
if the n'th key does not
exist.public long getLongValue(IFitsHeader key)
long
value associated with the given key.key
- The header key.public long getLongValue(IFitsHeader key, long dft)
long
value associated with the given key.key
- The header key.dft
- The default value to be returned if the key cannot be found.public long getLongValue(String key)
long
value associated with the given key.key
- The header key.public long getLongValue(String key, long dft)
long
value associated with the given key.key
- The header key.dft
- The default value to be returned if the key cannot be found.public int getNumberOfCards()
public int getNumberOfPhysicalCards()
public long getOriginalSize()
public long getSize()
getSize
in interface FitsElement
public String getStringValue(IFitsHeader header)
public String getStringValue(String key)
String
value associated with the given key.key
- The header key.public boolean hadDuplicates()
public void insertComment(String value) throws HeaderCardException
value
- The comment.HeaderCardException
- If the parameter is not a valid FITS comment.public void insertCommentStyle(String header, String value)
header
- The comment style header.value
- A string to follow the header.public void insertHistory(String value) throws HeaderCardException
value
- The history record.HeaderCardException
- If the parameter is not a valid FITS comment.public Cursor<String,HeaderCard> iterator()
public Cursor<String,HeaderCard> iterator(int index)
index
- the card index to start the iteratorpublic Data makeData() throws FitsException
FitsException
- if the header did not contain enough information to detect
the type of the datapublic HeaderCard nextCard()
@Deprecated public void pointToData(Data o) throws FitsException
o
- The data object to be described.FitsException
- if the data was not valid for this header.public void read(ArrayDataInput dis) throws TruncatedFileException, IOException
read
in interface FitsElement
dis
- The input stream to read the data from.TruncatedFileException
- the the stream ended prematurelyIOException
- if the operation failed@Deprecated public void removeCard(String key) throws HeaderCardException
deleteKey(String)
key
- The header key.HeaderCardException
- if the operation failedpublic boolean reset()
reset
in interface FitsElement
public void resetOriginalSize()
public void rewrite() throws FitsException, IOException
rewrite
in interface FitsElement
FitsException
- if the rewrite was unsuccessful.IOException
- if the rewrite was unsuccessful.public boolean rewriteable()
rewriteable
in interface FitsElement
true
if this element can be rewritten?public void setBitpix(int val)
val
- The value set by the user.public void setNaxes(int val)
val
- The dimensionality of the data.public void setNaxis(int axis, int dim)
axis
- The axis being set.dim
- The dimensionpublic void setSimple(boolean val)
val
- The boolean value -- Should be true for FITS data.public void setXtension(String val)
val
- The name of the extension. "IMAGE" and "BINTABLE" are
supported.@Deprecated public int size()
getNumberOfCards()
. The units of the size of the
header may be unclear.public void updateLine(IFitsHeader key, HeaderCard card) throws HeaderCardException
key
- The key of the card to be replaced.card
- A new cardHeaderCardException
- if the operation failedpublic void updateLine(String key, HeaderCard card) throws HeaderCardException
key
- The key of the card to be replaced.card
- A new cardHeaderCardException
- if the operation failedpublic void updateLines(Header newHdr) throws HeaderCardException
newHdr
- the list of new header data lines to replace the current ones.HeaderCardException
- if the operation failedpublic void write(ArrayDataOutput dos) throws FitsException
write
in interface FitsElement
dos
- The output stream to which the data is to be written.FitsException
- if the header could not be written.Copyright © 1996–2016 nom-tam-fits. All rights reserved.