Class HeaderCard
- All Implemented Interfaces:
Cloneable
,CursorValue<String>
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Value type checking policies for when setting values for standardized keywords. -
Field Summary
Modifier and TypeFieldDescriptionstatic final HeaderCard.ValueCheck
Default value type checking policy for cards with standardizedIFitsHeader
keywords.static final String
The default keyword to use instead of null or any number of blanks.static final int
The number of characters per header card (line).static final int
Maximum length of a comment-style card comment field.static final int
Maximum HIERARCH keyword length (80 chars must fit [<keyword>=T] at minimum...static final int
Maximum length of a FITS keyword fieldstatic final int
The start and end quotes of the string and the ampasant to continue the string.static final int
Maximum length of a FITS long string value field. the & for the continuation needs one char.static final int
if a commend needs the be specified 2 extra chars are needed to start the commentstatic final int
Maximum length of a FITS string value field.static final char
The last ASCII character that may be used in header recordsstatic final int
Maximum length of a FITS value field.static final char
The first ASCII character that may be used in header recordsstatic final int
The length of two single quotes that must surround string values. -
Constructor Summary
ConstructorDescriptionHeaderCard
(String key, Boolean value) Creates a new card with a boolean value (and no comment).HeaderCard
(String key, Boolean value, String comment) Creates a new card with a boolean value, and a comment.HeaderCard
(String key, Number value) Creates a new card with a number value.HeaderCard
(String key, Number value, int decimals, String comment) Creates a new card with a number value, using scientific notation, with up to the specified decimal places showing between the decimal place and the exponent.HeaderCard
(String key, Number value, String comment) Creates a new card with a number value and a comment.HeaderCard
(String key, String value) Creates a new card with a string value (and no comment).HeaderCard
(String key, String comment, boolean withNullValue) Deprecated.HeaderCard
(String key, String value, String comment) Creates a new card with a string value, and a commentHeaderCard
(String key, String value, String comment, boolean nullable) Deprecated.UseHeaderCard(String, String, String)
, orcreateCommentStyleCard(String, String)
instead.HeaderCard
(String key, ComplexValue value) Creates a new card with a complex value.HeaderCard
(String key, ComplexValue value, int decimals, String comment) Creates a new card with a complex number value, using scientific (exponential) notation, with up to the specified number of decimal places showing between the decimal point and the exponent.HeaderCard
(String key, ComplexValue value, String comment) Creates a new card with a complex value and a comment.Deprecated.(for internal use) Its visibility may be reduced or may be removed entirely in the future.HeaderCard
(ArrayDataInput dis) Creates a new header card, but reading from the specified data input stream. -
Method Summary
Modifier and TypeMethodDescriptionint
cardSize()
Returns the number of 80-character header lines needed to store the data from this card.void
Updates the keyword for this card.copy()
Returns an independent copy of this card.static HeaderCard
Creates a new FITS header card from a FITS stream representation of it, which is how the key/value and comment are represented inside the FITS file, normally as an 80-character wide entry.static HeaderCard
create
(IFitsHeader key, Boolean value) Creates a new card with a standard or conventional keyword and a boolean value, with the default comment associated with the keyword.static HeaderCard
create
(IFitsHeader key, Number value) Creates a new card with a standard or conventional keyword and a number value, with the default comment associated with the keyword.static HeaderCard
create
(IFitsHeader key, String value) Creates a new card with a standard or conventional keyword and an integer value, with the default comment associated with the keyword.static HeaderCard
create
(IFitsHeader key, ComplexValue value) Creates a new card with a standard or conventional keyword and a number value, with the default comment associated with the keyword.static HeaderCard
createCommentCard
(String text) Creates a new keyed comment card for th FITS header.static HeaderCard
createCommentStyleCard
(String key, String comment) Creates a comment-style card with no associated value field.static HeaderCard
createHexValueCard
(String key, long value) Deprecated.Not supported by the FITS standard, so do not use.static HeaderCard
createHexValueCard
(String key, long value, String comment) Deprecated.Not supported by the FITS standard, so do not use.static HeaderCard
createHistoryCard
(String text) Creates a new history record for the FITS header.static HeaderCard
Creates a new unkeyed comment card for th FITS header.final String
Returns the comment component of this card, which may be null.final long
Deprecated.Not supported by the FITS standard, so do not use.final String
getKey()
Returns the keyword component of this card, which may be empty but nevernull
, but it may be an empty string.final String
getValue()
Returns the serialized value component of this card, which may be null.<T> T
Returns the value cast to the specified type, if possible, or the specified default value if the value isnull
or if the value is incompatible with the requested type.static HeaderCard.ValueCheck
Returns the current policy for checking if set values are of the allowed type for cards with standardizedIFitsHeader
keywords.final boolean
Checks if this card cas a hierarch style long keyword.boolean
isBlank()
Checks if the card is blank, that is if it contains only empty spaces.final boolean
Checks if this card is a comment-style card with no associated value field.boolean
Checks if this card has a decimal (floating-point) type value (which may benull
).boolean
Checks if this card has an integer type value (which may benull
).boolean
Checks if this card has both a valid keyword and a (non-null) value.boolean
Checks if this card has a string value (which may benull
).static boolean
isValidChar
(char c) Checks if a character is valid for inclusion in a FITS header record.static String
Replaces illegal characters in the string ith '?'static HeaderCard
saveNewHeaderCard
(String key, String comment, boolean hasValue) Deprecated.This was to be used internally only, without public visibility.void
setComment
(String comment) Sets a new comment component for this card.setHexValue
(long update) Deprecated.Not supported by the FITS standard, so do not use.Sets a new boolean value for this cardvalueTypefinal HeaderCard
Sets a new number value for this card.Sets a new number value for this card, using scientific (exponential) notation, with up to the specified decimal places showing between the decimal point and the exponent.Sets a new string value for this card.final HeaderCard
setValue
(ComplexValue update) Sets a new complex number value for this card.setValue
(ComplexValue update, int decimals) Sets a new complex number value for this card, using scientific (exponential) notation, with up to the specified number of decimal places showing between the decimal point and the exponent.static void
Sets the policy to used for checking if set values conform to the expected types for cards that use standardized FITS keywords via theIFitsHeader
interface.final int
Returns the space available for value and/or comment in a single record the keyword.toString()
Returns the modulo 80 character card image, the toString tries to preserve as much as possible of the comment value by reducing the alignment of the Strings if the comment is longer and if longString is enabled the string can be split into one more card to have more space for the comment.static void
validateChars
(String text) Checks the specified string for characters that are not allowed in FITS headers, and throws an exception if any are found.static void
validateKey
(String key) Checks if the specified string may be used as a FITS header keyword according to the FITS standard and currently settings for supporting extensions to the standard, such as HIERARCH-style keywords.Class<?>
Returns the class of the associated value, or null if it's a comment-style card.
-
Field Details
-
FITS_HEADER_CARD_SIZE
public static final int FITS_HEADER_CARD_SIZEThe number of characters per header card (line).- See Also:
-
MAX_KEYWORD_LENGTH
public static final int MAX_KEYWORD_LENGTHMaximum length of a FITS keyword field- See Also:
-
STRING_QUOTES_LENGTH
public static final int STRING_QUOTES_LENGTHThe length of two single quotes that must surround string values.- See Also:
-
MAX_VALUE_LENGTH
public static final int MAX_VALUE_LENGTHMaximum length of a FITS value field.- See Also:
-
MAX_COMMENT_CARD_COMMENT_LENGTH
public static final int MAX_COMMENT_CARD_COMMENT_LENGTHMaximum length of a comment-style card comment field.- See Also:
-
MAX_STRING_VALUE_LENGTH
public static final int MAX_STRING_VALUE_LENGTHMaximum length of a FITS string value field.- See Also:
-
MAX_LONG_STRING_VALUE_LENGTH
public static final int MAX_LONG_STRING_VALUE_LENGTHMaximum length of a FITS long string value field. the & for the continuation needs one char.- See Also:
-
MAX_LONG_STRING_VALUE_WITH_COMMENT_LENGTH
public static final int MAX_LONG_STRING_VALUE_WITH_COMMENT_LENGTHif a commend needs the be specified 2 extra chars are needed to start the comment- See Also:
-
MAX_HIERARCH_KEYWORD_LENGTH
public static final int MAX_HIERARCH_KEYWORD_LENGTHMaximum HIERARCH keyword length (80 chars must fit [<keyword>=T] at minimum...- See Also:
-
MAX_LONG_STRING_CONTINUE_OVERHEAD
public static final int MAX_LONG_STRING_CONTINUE_OVERHEADThe start and end quotes of the string and the ampasant to continue the string.- See Also:
-
MIN_VALID_CHAR
public static final char MIN_VALID_CHARThe first ASCII character that may be used in header records- See Also:
-
MAX_VALID_CHAR
public static final char MAX_VALID_CHARThe last ASCII character that may be used in header records- See Also:
-
EMPTY_KEY
The default keyword to use instead of null or any number of blanks.- See Also:
-
DEFAULT_VALUE_CHECK_POLICY
Default value type checking policy for cards with standardizedIFitsHeader
keywords.- Since:
- 1.19
-
-
Constructor Details
-
HeaderCard
public HeaderCard(ArrayDataInput dis) throws UnclosedQuoteException, TruncatedFileException, IOException Creates a new header card, but reading from the specified data input stream. The card is expected to be describes by one or more 80-character wide header 'lines'. If long string support is not enabled, then a new card is created from the next 80-characters. When long string support is enabled, cunsecutive lines starting with [CONTINUE
] after the first line will be aggregated into a single new card.- Parameters:
dis
- the data input stream- Throws:
UnclosedQuoteException
- if the line contained an unclosed single quote.TruncatedFileException
- if we reached the end of file unexpectedly before fully parsing an 80-character line.IOException
- if there was some IO issue.- See Also:
-
HeaderCard
@Deprecated public HeaderCard(HeaderCardCountingArrayDataInput dis) throws UnclosedQuoteException, TruncatedFileException, IOException Deprecated.(for internal use) Its visibility may be reduced or may be removed entirely in the future. Card counting should be internal toHeaderCard
.Creates a new header card, but reading from the specified data input. The card is expected to be describes by one or more 80-character wide header 'lines'. If long string support is not enabled, then a new card is created from the next 80-characters. When long string support is enabled, cunsecutive lines starting with [CONTINUE
] after the first line will be aggregated into a single new card.- Parameters:
dis
- the data input- Throws:
UnclosedQuoteException
- if the line contained an unclosed single quote.TruncatedFileException
- if we reached the end of file unexpectedly before fully parsing an 80-character line.IOException
- if there was some IO issue.- See Also:
-
HeaderCard
Creates a new card with a number value. The card will be created either in the integer, fixed-decimal, or format, with the native precision. If the native precision cannot be fitted in the available card space, the value will be represented with reduced precision with at leastFlexFormat.DOUBLE_DECIMALS
. Trailing zeroes will be omitted.- Parameters:
key
- keywordvalue
- value (can benull
, in which case the card type defaults toInteger.class
)- Throws:
HeaderCardException
- for any invalid keyword or value.- Since:
- 1.16
- See Also:
-
HeaderCard
Creates a new card with a number value and a comment. The card will be created either in the integer, fixed-decimal, or format. If the native precision cannot be fitted in the available card space, the value will be represented with reduced precision with at leastFlexFormat.DOUBLE_DECIMALS
. Trailing zeroes will be omitted.- Parameters:
key
- keywordvalue
- value (can benull
, in which case the card type defaults toInteger.class
)comment
- optional comment, ornull
- Throws:
HeaderCardException
- for any invalid keyword or value- See Also:
-
HeaderCard
public HeaderCard(String key, Number value, int decimals, String comment) throws HeaderCardException Creates a new card with a number value, using scientific notation, with up to the specified decimal places showing between the decimal place and the exponent. For example, ifdecimals
is set to 2, thenMath.PI
gets formatted as3.14E0
(or3.14D0
ifFitsFactory.setUseExponentD(boolean)
is enabled).- Parameters:
key
- keywordvalue
- value (can benull
, in which case the card type defaults toInteger.class
)decimals
- the number of decimal places to show in the scientific notation.comment
- optional comment, ornull
- Throws:
HeaderCardException
- for any invalid keyword or value- See Also:
-
HeaderCard
Creates a new card with a boolean value (and no comment).- Parameters:
key
- keywordvalue
- value (can benull
)- Throws:
HeaderCardException
- for any invalid keyword- See Also:
-
HeaderCard
Creates a new card with a boolean value, and a comment.- Parameters:
key
- keywordvalue
- value (can benull
)comment
- optional comment, ornull
- Throws:
HeaderCardException
- for any invalid keyword or value- See Also:
-
HeaderCard
Creates a new card with a complex value. The real and imaginary parts will be shown either in the fixed decimal format or in the exponential notation, whichever preserves more digits, or else whichever is the more compact notation. Trailing zeroes will be omitted.- Parameters:
key
- keywordvalue
- value (can benull
)- Throws:
HeaderCardException
- for any invalid keyword or value.- See Also:
-
HeaderCard
Creates a new card with a complex value and a comment. The real and imaginary parts will be shown either in the fixed decimal format or in the exponential notation, whichever preserves more digits, or else whichever is the more compact notation. Trailing zeroes will be omitted.- Parameters:
key
- keywordvalue
- value (can benull
)comment
- optional comment, ornull
- Throws:
HeaderCardException
- for any invalid keyword or value.- See Also:
-
HeaderCard
public HeaderCard(String key, ComplexValue value, int decimals, String comment) throws HeaderCardException Creates a new card with a complex number value, using scientific (exponential) notation, with up to the specified number of decimal places showing between the decimal point and the exponent. Trailing zeroes will be omitted. For example, ifdecimals
is set to 2, then (π, 12) gets formatted as(3.14E0,1.2E1)
.- Parameters:
key
- keywordvalue
- value (can benull
)decimals
- the number of decimal places to show.comment
- optional comment, ornull
- Throws:
HeaderCardException
- for any invalid keyword or value.- See Also:
-
HeaderCard
@Deprecated public HeaderCard(String key, String comment, boolean withNullValue) throws HeaderCardException Deprecated.UseHeaderCard(String, String, String)
, orcreateCommentStyleCard(String, String)
instead.This constructor is now DEPRECATED. You should use
HeaderCard(String, String, String)
to create cards withnull
strings, or elsecreateCommentStyleCard(String, String)
to create any comment-style card, orcreateCommentCard(String)
orcreateHistoryCard(String)
to create COMMENT or HISTORY cards.Creates a card with a string value or comment.
- Parameters:
key
- The key for the comment or nullable field.comment
- The commentwithNullValue
- Iftrue
the new card will be a value stle card with a null string value. Otherwise it's a comment-style card.- Throws:
HeaderCardException
- for any invalid keyword or value- See Also:
-
HeaderCard
@Deprecated public HeaderCard(String key, String value, String comment, boolean nullable) throws HeaderCardException Deprecated.UseHeaderCard(String, String, String)
, orcreateCommentStyleCard(String, String)
instead.This constructor is now DEPRECATED. It has always been a poor construct. You should use
Creates a comment style card. This may be a comment style card in which case the nullable field should be false, or a value field which has a null value, in which case the nullable field should be true.HeaderCard(String, String, String)
to create cards withnull
strings, or elsecreateCommentStyleCard(String, String)
to create any comment-style card, orcreateCommentCard(String)
orcreateHistoryCard(String)
to create COMMENT or HISTORY cards.- Parameters:
key
- The key for the comment or nullable field.value
- The value (can benull
)comment
- The commentnullable
- Iftrue
a null value is a valid value. Otherwise, anull
value turns this into a comment-style card.- Throws:
HeaderCardException
- for any invalid keyword or value- See Also:
-
HeaderCard
Creates a new card with a string value (and no comment).- Parameters:
key
- keywordvalue
- value- Throws:
HeaderCardException
- for any invalid keyword or value- See Also:
-
HeaderCard
Creates a new card with a string value, and a comment- Parameters:
key
- keywordvalue
- valuecomment
- optional comment, ornull
- Throws:
HeaderCardException
- for any invalid keyword or value- See Also:
-
-
Method Details
-
cardSize
public int cardSize()Returns the number of 80-character header lines needed to store the data from this card.- Returns:
- the size of the card in blocks of 80 bytes. So normally every card will return 1. only long stings can return more than one, provided support for long string is enabled.
-
copy
Returns an independent copy of this card. Both this card and the returned value will have identical content, but modifying one is guaranteed to not affect the other.- Returns:
- a copy of this carf.
-
getKey
Returns the keyword component of this card, which may be empty but nevernull
, but it may be an empty string.- Specified by:
getKey
in interfaceCursorValue<String>
- Returns:
- the keyword from this card, guaranteed to be not
null
). - See Also:
-
getValue
Returns the serialized value component of this card, which may be null.- Returns:
- the value from this card
- See Also:
-
getComment
Returns the comment component of this card, which may be null.- Returns:
- the comment from this card
- See Also:
-
getHexValue
Deprecated.Not supported by the FITS standard, so do not use. It was included due to a misreading of the standard itself.- Returns:
- the value from this card
- Throws:
NumberFormatException
- if the card's value is null or cannot be parsed as a hexadecimal value.- See Also:
-
getValue
Returns the value cast to the specified type, if possible, or the specified default value if the value is
null
or if the value is incompatible with the requested type.For number types and values, if the requested type has lesser range or precision than the number stored in the FITS header, the value is automatically downcast (i.e. possible rounded and/or truncated) -- the same as if an explicit cast were used in Java. As long as the header value is a proper decimal value, it will be returned as any requested number type.
- Type Parameters:
T
- the generic type of the requested class- Parameters:
asType
- the requested class of the valuedefaultValue
- the value to use if the card has a null value, or a value that cannot be cast to the specified type.- Returns:
- the value from this card as a specific type, or the specified default value
- Throws:
IllegalArgumentException
- if the specified Java type of not one that is supported for use in FITS headers.
-
isKeyValuePair
public boolean isKeyValuePair()Checks if this card has both a valid keyword and a (non-null) value.- Returns:
- Is this a key/value card?
- See Also:
-
isStringValue
public boolean isStringValue()Checks if this card has a string value (which may benull
).- Returns:
true
if this card has a string value, otherwisefalse
.- See Also:
-
isDecimalType
public boolean isDecimalType()Checks if this card has a decimal (floating-point) type value (which may benull
).- Returns:
true
if this card has a decimal (not integer) type number value, otherwisefalse
.- Since:
- 1.16
- See Also:
-
isIntegerType
public boolean isIntegerType()Checks if this card has an integer type value (which may benull
).- Returns:
true
if this card has an integer type value, otherwisefalse
.- Since:
- 1.16
- See Also:
-
isCommentStyleCard
public final boolean isCommentStyleCard()Checks if this card is a comment-style card with no associated value field.- Returns:
true
if this card is a comment-style card, otherwisefalse
.- Since:
- 1.16
- See Also:
-
hasHierarchKey
public final boolean hasHierarchKey()Checks if this card cas a hierarch style long keyword.- Returns:
true
if the card has a non-standard HIERARCH style long keyword, with dot-separated components. Otherwisefalse
.- Since:
- 1.16
-
setComment
Sets a new comment component for this card. The specified comment string will be sanitized to ensure it onlly contains characters suitable for FITS headers. Invalid characters will be replaced with '?'.- Parameters:
comment
- the new comment text.
-
setValue
Sets a new number value for this card. The new value will be shown in the integer, fixed-decimal, or format, whichever preserves more digits, or else whichever is the more compact notation. Trailing zeroes will be omitted.- Parameters:
update
- the new value to set (can benull
, in which case the card type defaults toInteger.class
)- Returns:
- the card itself
- Throws:
NumberFormatException
- if the input value is NaN or Infinity.LongValueException
- if the decimal value cannot be represented in the alotted space- See Also:
-
setValue
public HeaderCard setValue(Number update, int decimals) throws NumberFormatException, LongValueException Sets a new number value for this card, using scientific (exponential) notation, with up to the specified decimal places showing between the decimal point and the exponent. For example, ifdecimals
is set to 2, then π gets formatted as3.14E0
.- Parameters:
update
- the new value to set (can benull
, in which case the card type defaults toInteger.class
)decimals
- the number of decimal places to show in the scientific notation.- Returns:
- the card itself
- Throws:
NumberFormatException
- if the input value is NaN or Infinity.LongValueException
- if the decimal value cannot be represented in the alotted space- See Also:
-
setValue
Sets a new boolean value for this cardvalueType- Parameters:
update
- the new value to se (can benull
).- Returns:
- the card itself
- Throws:
LongValueException
- if the card has no room even for the single-character 'T' or 'F'. This can never happen with cards created programmatically as they will not allow setting HIERARCH-style keywords long enough to ever trigger this condition. But, it is possible to read cards from a non-standard header, which breaches this limit, by ommitting some required spaces (esp. after the '='), and have a null value. When that happens, we can be left without room for even a single character.ValueTypeException
- if the card's standard keyword does not support boolean values.
-
setValue
public final HeaderCard setValue(ComplexValue update) throws NumberFormatException, LongValueException Sets a new complex number value for this card. The real and imaginary part will be shown in the integer, fixed-decimal, or format, whichever preserves more digits, or else whichever is the more compact notation. Trailing zeroes will be omitted.- Parameters:
update
- the new value to set (can benull
)- Returns:
- the card itself
- Throws:
NumberFormatException
- if the input value is NaN or Infinity.LongValueException
- if the decimal value cannot be represented in the alotted space- Since:
- 1.16
- See Also:
-
setValue
Sets a new complex number value for this card, using scientific (exponential) notation, with up to the specified number of decimal places showing between the decimal point and the exponent. Trailing zeroes will be omitted. For example, ifdecimals
is set to 2, then (π, 12) gets formatted as(3.14E0,1.2E1)
.- Parameters:
update
- the new value to set (can benull
)decimals
- the number of decimal places to show in the scientific notation.- Returns:
- the HeaderCard itself
- Throws:
NumberFormatException
- if the input value is NaN or Infinity.LongValueException
- if the decimal value cannot be represented in the alotted space- Since:
- 1.16
- See Also:
-
setHexValue
Deprecated.Not supported by the FITS standard, so do not use. It was included due to a misreading of the standard itself.- Parameters:
update
- the new value to set- Returns:
- the HeaderCard itself
- Throws:
LongValueException
- if the value is too long to fit in the available space.- Since:
- 1.16
-
setValue
public HeaderCard setValue(String update) throws ValueTypeException, IllegalStateException, IllegalArgumentException, LongStringsNotEnabledException Sets a new string value for this card.- Parameters:
update
- the new value to set- Returns:
- the HeaderCard itself
- Throws:
ValueTypeException
- if the card's keyword does not support string values.IllegalStateException
- if the card has a HIERARCH keyword that is too long to fit any string value.IllegalArgumentException
- if the new value contains characters that cannot be added to the the FITS header.LongStringsNotEnabledException
- if the card contains a long string but support for long strings is currently disabled.- See Also:
-
toString
public String toString() throws LongValueException, LongStringsNotEnabledException, HierarchNotEnabledExceptionReturns the modulo 80 character card image, the toString tries to preserve as much as possible of the comment value by reducing the alignment of the Strings if the comment is longer and if longString is enabled the string can be split into one more card to have more space for the comment.- Overrides:
toString
in classObject
- Returns:
- the FITS card as one or more 80-character string blocks.
- Throws:
LongValueException
- if the card has a long string value that is too long to contain in the space available after the keyword.LongStringsNotEnabledException
- if the card contains a long string but support for long strings is currently disabled.HierarchNotEnabledException
- if the card contains a HIERARCH-style long keyword but support for these is currently disabled.- See Also:
-
valueType
Returns the class of the associated value, or null if it's a comment-style card.- Returns:
- the type of the value.
- See Also:
-
spaceForValue
public final int spaceForValue()Returns the space available for value and/or comment in a single record the keyword.- Returns:
- the number of characters available in a single 80-character header record for a standard (non long string) value and/or comment.
- Since:
- 1.16
-
changeKey
public void changeKey(String newKey) throws HierarchNotEnabledException, LongValueException, LongStringsNotEnabledException, IllegalArgumentException Updates the keyword for this card.- Parameters:
newKey
- the new FITS header keyword to use for this card.- Throws:
HierarchNotEnabledException
- if the new key is a HIERARCH-style long key but support for these is not currently enabled.IllegalArgumentException
- if the keyword contains invalid charactersLongValueException
- if the new keyword does not leave sufficient room for the current non-string value.LongStringsNotEnabledException
- if the new keyword does not leave sufficient rooom for the current string value without enabling long string support.- See Also:
-
isBlank
public boolean isBlank()Checks if the card is blank, that is if it contains only empty spaces.- Returns:
true
if the card contains nothing but blank spaces.
-
getValueCheckingPolicy
Returns the current policy for checking if set values are of the allowed type for cards with standardizedIFitsHeader
keywords.- Returns:
- the current value type checking policy
- Since:
- 1.19
- See Also:
-
setValueCheckingPolicy
Sets the policy to used for checking if set values conform to the expected types for cards that use standardized FITS keywords via theIFitsHeader
interface.- Parameters:
policy
- the new polict to use for checking value types.- Since:
- 1.19
- See Also:
-
create
Creates a new FITS header card from a FITS stream representation of it, which is how the key/value and comment are represented inside the FITS file, normally as an 80-character wide entry. The parsing of header 'lines' conforms to all FITS standards, and some optional conventions, such as HIERARCH keywords (if
FitsFactory.setUseHierarch(boolean)
is enabled), COMMENT and HISTORY entries, and OGIP 1.0 long CONTINUE lines (ifFitsFactory.setLongStringsEnabled(boolean)
is enabled).However, the parsing here is permissive beyond the standards and conventions, and will do its best to support a wide range of FITS files, which may deviate from the standard in subtle (or no so subtle) ways.
Here is a brief summary of the rules that guide the parsing of keywords, values, and comment 'fields' from the single header line:
A. Keywords
- The standard FITS keyword is the first 8 characters of the line, or up to an equal [=] character, whichever comes first, with trailing spaces removed, and always converted to upper-case.
- If
FitsFactory.setUseHierarch(boolean)
is enabled, structured longer keywords can be composed after aHIERARCH
base key, followed by space (and/or dot ].]) separated parts, up to an equal sign [=]. The library will represent the same components (includingHIERARCH
) but separated by single dots [.]. For example, the header line starting with [HIERARCH SMA OBS TARGET =
], will be referred as [HIERARCH.SMA.OBS.TARGET
] withing this library. The keyword parts can be composed of any ASCII characters except dot [.], white spaces, or equal [=]. - By default, all parts of the key are converted to upper-case. Case sensitive HIERARCH keywords can be
retained after enabling
IHierarchKeyFormatter.setCaseSensitive(boolean)
.
B. Values
Values are the part of the header line, that is between the keyword and an optional ending comment. Legal header values follow the following parse patterns:
- Begin with an equal sign [=], or else come after a CONTINUE keyword.
- Next can be a quoted value such as
'hello'
, placed inside two single quotes. Or an unquoted value, such as123
. - Quoted values must begin with a single quote ['] and and with the next single quote. If there is no end-quote
in the line, it is not considered a string value but rather a comment, unless
FitsFactory.setAllowHeaderRepairs(boolean)
is enabled, in which case the entire remaining line after the opening quote is assumed to be a malformed value. - Unquoted values end at the fist [/] character, or else go until the line end.
- Quoted values have trailing spaces removed, s.t. [
' value '
] becomes [value
]. - Unquoted values are trimmed, with both leading and trailing spaces removed, e.g. [
123
] becomes [123
].
C. Comments
The following rules guide the parsing of the values component:
- If a value is present (see above), the comment is what comes after it. That is, for quoted values, everything that follows the closing quote. For unquoted values, it's what comes after the first [/], with the [/] itself removed.
- If a value is not present, then everything following the keyword is considered the comment.
- Comments are trimmed, with both leading and trailing spaces removed.
- Parameters:
line
- the card image (typically 80 characters if in a FITS file).- Returns:
- a newly created HeaderCard from a FITS card string.
- Throws:
IllegalArgumentException
- if the card was malformed, truncated, or if there was an IO error.- See Also:
-
create
Creates a new card with a standard or conventional keyword and a boolean value, with the default comment associated with the keyword. UnlikeHeaderCard(String, Boolean)
, this call does not throw an exception, since the keyword and comment should be valid by design.- Parameters:
key
- The standard or conventional keyword with its associated default comment.value
- the boolean value associated to the keyword- Returns:
- A new header card with the speficied standard-style key and comment and the
specified value, or
null
if the standard key itself is malformed or illegal. - Throws:
IllegalArgumentException
- if the standard key was ill-defined.- Since:
- 1.16
-
create
Creates a new card with a standard or conventional keyword and a number value, with the default comment associated with the keyword. Unlike
HeaderCard(String, Number)
, this call does not throw a hardHeaderCardException
exception, since the keyword and comment should be valid by design. (A runtimeIllegalArgumentException
may still be thrown in the event that the supplied conventional keywords itself is ill-defined -- but this should not happen unless something was poorly coded in this library, on in an extension of it).If the value is not compatible with the convention of the keyword, a warning message is logged but no exception is thrown (at this point).
- Parameters:
key
- The standard or conventional keyword with its associated default comment.value
- the integer value associated to the keyword.- Returns:
- A new header card with the speficied standard-style key and comment and the specified value.
- Throws:
IllegalArgumentException
- if the standard key itself was ill-defined.- Since:
- 1.16
-
create
public static HeaderCard create(IFitsHeader key, ComplexValue value) throws IllegalArgumentException Creates a new card with a standard or conventional keyword and a number value, with the default comment associated with the keyword. UnlikeHeaderCard(String, Number)
, this call does not throw an exception, since the keyword and comment should be valid by design.- Parameters:
key
- The standard or conventional keyword with its associated default comment.value
- the integer value associated to the keyword.- Returns:
- A new header card with the speficied standard-style key and comment and the specified value.
- Throws:
IllegalArgumentException
- if the standard key was ill-defined.- Since:
- 1.16
-
create
Creates a new card with a standard or conventional keyword and an integer value, with the default comment associated with the keyword. UnlikeHeaderCard(String, Number)
, this call does not throw a hard exception, since the keyword and comment sohould be valid by design. The string value however will be checked, and an appropriate runtime exception is thrown if it cannot be included in a FITS header.- Parameters:
key
- The standard or conventional keyword with its associated default comment.value
- the string associated to the keyword.- Returns:
- A new header card with the speficied standard-style key and comment and the specified value.
- Throws:
IllegalArgumentException
- if the string value contains characters that are not allowed in FITS headers, that is characters outside of the 0x20 thru 0x7E range, or if the standard key was ill-defined.
-
createCommentStyleCard
public static HeaderCard createCommentStyleCard(String key, String comment) throws HeaderCardException, LongValueException Creates a comment-style card with no associated value field.- Parameters:
key
- The keyword, ornull
blank/empty string for an unkeyed comment.comment
- The comment text.- Returns:
- a new comment-style header card with the specified key and comment text.
- Throws:
HeaderCardException
- if the key or value were invalid.LongValueException
- if the comment text is longer than the space available in comment-style cards (71 characters max)- See Also:
-
createUnkeyedCommentCard
public static HeaderCard createUnkeyedCommentCard(String text) throws HeaderCardException, LongValueException Creates a new unkeyed comment card for th FITS header. These are comment-style cards with no associated value field, and with a blank keyword. They are commonly used to add explanatory notes in the FITS header. Keyed comments are another alternative...- Parameters:
text
- a concise descriptive entry (max 71 characters).- Returns:
- a new COMMENT card with the specified key and comment text.
- Throws:
HeaderCardException
- if the text contains invalid charaters.LongValueException
- if the comment text is longer than the space available in comment-style cards (71 characters max)- See Also:
-
createCommentCard
public static HeaderCard createCommentCard(String text) throws HeaderCardException, LongValueException Creates a new keyed comment card for th FITS header. These are comment-style cards with no associated value field, and with COMMENT as the keyword. They are commonly used to add explanatory notes in the FITS header. Unkeyed comments are another alternative...- Parameters:
text
- a concise descriptive entry (max 71 characters).- Returns:
- a new COMMENT card with the specified key and comment text.
- Throws:
HeaderCardException
- if the text contains invalid charaters.LongValueException
- if the comment text is longer than the space available in comment-style cards (71 characters max)- See Also:
-
createHistoryCard
public static HeaderCard createHistoryCard(String text) throws HeaderCardException, LongValueException Creates a new history record for the FITS header. These are comment-style cards with no associated value field, and with HISTORY as the keyword. They are commonly used to document the sequence operations that were performed on the data before it arrived to the state represented by the FITS file. The text field for history entries is limited to 70 characters max per card. However there is no limit to how many such entries are in a FITS header.- Parameters:
text
- a concise descriptive entry (max 71 characters).- Returns:
- a new HISTORY card with the specified key and comment text.
- Throws:
HeaderCardException
- if the text contains invalid charaters.LongValueException
- if the comment text is longer than the space available in comment-style cards (71 characters max)- See Also:
-
createHexValueCard
@Deprecated public static HeaderCard createHexValueCard(String key, long value) throws HeaderCardException Deprecated.Not supported by the FITS standard, so do not use. It was included due to a misreading of the standard itself.- Parameters:
key
- the keywordvalue
- the integer value- Returns:
- A new header card, with the specified integer in hexadecomal representation.
- Throws:
HeaderCardException
- if the card is invalid (for example the keyword is not valid).- See Also:
-
createHexValueCard
@Deprecated public static HeaderCard createHexValueCard(String key, long value, String comment) throws HeaderCardException Deprecated.Not supported by the FITS standard, so do not use. It was included due to a misreading of the standard itself.- Parameters:
key
- the keywordvalue
- the integer valuecomment
- optional comment, ornull
.- Returns:
- A new header card, with the specified integer in hexadecomal representation.
- Throws:
HeaderCardException
- if the card is invalid (for example the keyword is not valid).- See Also:
-
saveNewHeaderCard
@Deprecated public static HeaderCard saveNewHeaderCard(String key, String comment, boolean hasValue) throws HeaderCardException Deprecated.This was to be used internally only, without public visibility. It will become unexposed to users in a future release...This method was designed for use internally. It is 'safe' (not save!) in the sense that the runtime exception it may throw does not need to be caught.- Parameters:
key
- keywordcomment
- optional comment, ornull
hasValue
- does this card have a (null
) value field? Iftrue
a null value of typeString.class
is assumed (for backward compatibility).- Returns:
- the new HeaderCard
- Throws:
HeaderCardException
- if the card could not be created for some reason (noted as the cause).
-
sanitize
Replaces illegal characters in the string ith '?' to be suitable for FITS header records. According to the FITS standard, headers may only contain ASCII characters in the range 0x20 and 0x7E (inclusive).- Parameters:
str
- the input string.- Returns:
- the sanitized string for use in a FITS header, with illegal characters replaced by '?'.
- See Also:
-
isValidChar
public static boolean isValidChar(char c) Checks if a character is valid for inclusion in a FITS header record. The FITS standard specifies that only ASCII characters between 0x20 thru 0x7E may be used in FITS headers.- Parameters:
c
- the character to check- Returns:
true
if the character is allowed in the FITS header, otherwisefalse
.- See Also:
-
validateChars
Checks the specified string for characters that are not allowed in FITS headers, and throws an exception if any are found. According to the FITS standard, headers may only contain ASCII characters in the range 0x20 and 0x7E (inclusive).- Parameters:
text
- the input string- Throws:
IllegalArgumentException
- if the unput string contains any characters that cannot be in a FITS header, that is characters outside of the 0x20 to 0x7E range.- Since:
- 1.16
- See Also:
-
validateKey
Checks if the specified string may be used as a FITS header keyword according to the FITS standard and currently settings for supporting extensions to the standard, such as HIERARCH-style keywords.- Parameters:
key
- the proposed keyword string- Throws:
IllegalArgumentException
- if the string cannot be used as a FITS keyword with the current settings. The exception will contain an informative message describing the issue.- Since:
- 1.16
- See Also:
-
HeaderCard(String, String, String)
, orcreateCommentStyleCard(String, String)
instead.