Package nom.tam.fits
Class HeaderCard
java.lang.Object
nom.tam.fits.HeaderCard
- All Implemented Interfaces:
CursorValue<String>
This class describes methods to access and manipulate the individual cards
for a FITS Header.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
The comment part of the card (set to null if there's no comment)private static final String
static final int
private static final String
private static final int
private static final String
private static final Pattern
regexp for IEEE floatsprivate boolean
A flag indicating whether or not this is a string valueprivate String
The keyword part of the card (set to null if there's no keyword)private static final Logger
private static final BigDecimal
private static final Pattern
regexp for numbers.private static final double
private static final int
max number of characters an integer can have.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.private static final int
max number of characters a long can have.static final int
Maximum length of a FITS long string value field.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 int
Maximum length of a FITS value field.private static final int
private static final int
private boolean
Does this card represent a nullable field.private static final int
private static final int
private String
The value part of the card (set to null if there's no value) -
Constructor Summary
ConstructorsModifierConstructorDescriptionHeaderCard
(String key, boolean value, String comment) Create a HeaderCard from its component partsHeaderCard
(String key, double value, int precision, String comment) Create a HeaderCard from its component partsHeaderCard
(String key, double value, String comment) Create a HeaderCard from its component partsHeaderCard
(String key, float value, int precision, String comment) Create a HeaderCard from its component partsHeaderCard
(String key, float value, String comment) Create a HeaderCard from its component partsHeaderCard
(String key, int value, String comment) Create a HeaderCard from its component partsHeaderCard
(String key, long value, String comment) Create a HeaderCard from its component partsHeaderCard
(String key, String comment, boolean nullable) Create a comment style card.HeaderCard
(String key, String value, String comment) Create a HeaderCard from its component partsHeaderCard
(String key, String value, String comment, boolean nullable) Create a HeaderCard from its component partsprivate
HeaderCard
(String key, String value, String comment, boolean nullable, boolean isString) Create a HeaderCard from its component partsHeaderCard
(String key, BigDecimal value, String comment) Create a HeaderCard from its component partsHeaderCard
(String key, BigInteger value, String comment) Create a HeaderCard from its component partsHeaderCard
(ArrayDataInput dis) -
Method Summary
Modifier and TypeMethodDescriptionint
cardSize()
copy()
static HeaderCard
private static String
dblString
(double decimalValue, int availableSpace) Create a string from a BigDecimal making sure that it's not longer than the available space.private static String
dblString
(double input, int precision, int availableSpace) private static String
dblString
(BigDecimal decimalValue, int availableSpace) Create a string from a BigDecimal making sure that it's not longer than the available space.private static String
dblString
(BigDecimal decimalValue, int precision, int availableSpace) Create a string from a BigDecimal making sure that it's not longer than the available space.private void
private static BigDecimal
floatToBigDecimal
(float floatValue) attention float to double cases are very lossy so a toString is needed to keep the precision.private Boolean
getBooleanValue
(Boolean defaultValue) private static Class<?>
getDecimalNumberType
(String value) detect the decimal type of the value, does it fit in a Double/BigInteger or must it be a BigDecimal to keep the needed precission.private static Class<?>
getIntegerNumberType
(String value) getKey()
getValue()
<T> T
private void
hierarchCard
(String card, HeaderCardCountingArrayDataInput dis) Process HIERARCH style cards...boolean
boolean
private void
longStringCard
(HeaderCardCountingArrayDataInput dis, FitsHeaderCardParser.ParsedValue parsedValue) private int
private static String
Read exactly one complete fits header line from the input.protected static HeaderCard
saveNewHeaderCard
(String key, String comment, boolean isString) This method is only used internally when it is sure that the creation of the card is granted not to throw an exceptionvoid
setComment
(String comment) set the comment of a card.(package private) void
Set the key.setValue
(boolean update) Set the value for this card.setValue
(double update) Set the value for this card.setValue
(double update, int precision) Set the value for this card.setValue
(float update) Set the value for this card.setValue
(float update, int precision) Set the value for this card.setValue
(int update) Set the value for this card.setValue
(long update) Set the value for this card.Set the value for this card.setValue
(BigDecimal update) Set the value for this card.private static int
private static ArrayDataInput
private boolean
stringValueToString
(int alignSmallString, int alignPosition, FitsLineAppender buf, boolean commentHandled) toString()
Return 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.protected String
toString
(FitsFactory.FitsSettings settings) Same astoString()
just with a prefetched settings objectClass<?>
private void
writeLongStringValue
(FitsLineAppender buf, String stringValueString)
-
Field Details
-
SPACE_NEEDED_FOR_EQUAL_AND_TWO_BLANKS
private static final int SPACE_NEEDED_FOR_EQUAL_AND_TWO_BLANKS- See Also:
-
MAX_DECIMAL_VALUE_TO_USE_PLAIN_STRING
private static final double MAX_DECIMAL_VALUE_TO_USE_PLAIN_STRING- See Also:
-
LOG
-
CONTINUE_CARD_PREFIX
-
FITS_HEADER_CARD_SIZE
public static final int FITS_HEADER_CARD_SIZE- See Also:
-
HIERARCH_WITH_BLANK
-
HIERARCH_WITH_BLANK_LENGTH
private static final int HIERARCH_WITH_BLANK_LENGTH -
HIERARCH_WITH_DOT
-
IEEE_REGEX
regexp for IEEE floats -
LONG_MAX_VALUE_AS_BIG_DECIMAL
-
LONG_REGEX
regexp for numbers. -
MAX_INTEGER_STRING_SIZE
private static final int MAX_INTEGER_STRING_SIZEmax number of characters an integer can have. -
MAX_KEYWORD_LENGTH
public static final int MAX_KEYWORD_LENGTHMaximum length of a FITS keyword field- 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:
-
MAX_LONG_STRING_SIZE
private static final int MAX_LONG_STRING_SIZEmax number of characters a long can have. -
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_STRING_VALUE_LENGTH
public static final int MAX_STRING_VALUE_LENGTHMaximum length of a FITS string value field.- See Also:
-
MAX_VALUE_LENGTH
public static final int MAX_VALUE_LENGTHMaximum length of a FITS value field.- See Also:
-
NORMAL_ALIGN_POSITION
private static final int NORMAL_ALIGN_POSITION- See Also:
-
NORMAL_SMALL_STRING_ALIGN_POSITION
private static final int NORMAL_SMALL_STRING_ALIGN_POSITION- See Also:
-
STRING_SPLIT_POSITION_FOR_EXTRA_COMMENT_SPACE
private static final int STRING_SPLIT_POSITION_FOR_EXTRA_COMMENT_SPACE- See Also:
-
comment
The comment part of the card (set to null if there's no comment) -
isString
private boolean isStringA flag indicating whether or not this is a string value -
key
The keyword part of the card (set to null if there's no keyword) -
nullable
private boolean nullableDoes this card represent a nullable field. ? -
value
The value part of the card (set to null if there's no value)
-
-
Constructor Details
-
HeaderCard
- Throws:
TruncatedFileException
IOException
-
HeaderCard
- Throws:
TruncatedFileException
IOException
-
HeaderCard
Create a HeaderCard from its component parts- Parameters:
key
- keyword (null for a comment)value
- value (null for a comment or keyword without an '=')comment
- comment- Throws:
HeaderCardException
- for any invalid keyword
-
HeaderCard
Create a HeaderCard from its component parts- Parameters:
key
- keyword (null for a comment)value
- value (null for a comment or keyword without an '=')comment
- comment- Throws:
HeaderCardException
- for any invalid keyword
-
HeaderCard
Create a HeaderCard from its component parts- Parameters:
key
- keyword (null for a comment)value
- value (null for a comment or keyword without an '=')comment
- comment- Throws:
HeaderCardException
- for any invalid keyword
-
HeaderCard
public HeaderCard(String key, double value, int precision, String comment) throws HeaderCardException Create a HeaderCard from its component parts- Parameters:
key
- keyword (null for a comment)value
- value (null for a comment or keyword without an '=')precision
- Number of decimal places (fixed format).comment
- comment- Throws:
HeaderCardException
- for any invalid keyword
-
HeaderCard
Create a HeaderCard from its component parts- Parameters:
key
- keyword (null for a comment)value
- value (null for a comment or keyword without an '=')comment
- comment- Throws:
HeaderCardException
- for any invalid keyword
-
HeaderCard
public HeaderCard(String key, float value, int precision, String comment) throws HeaderCardException Create a HeaderCard from its component parts- Parameters:
key
- keyword (null for a comment)value
- value (null for a comment or keyword without an '=')precision
- Number of decimal places (fixed format).comment
- comment- Throws:
HeaderCardException
- for any invalid keyword
-
HeaderCard
Create a HeaderCard from its component parts- Parameters:
key
- keyword (null for a comment)value
- value (null for a comment or keyword without an '=')comment
- comment- Throws:
HeaderCardException
- for any invalid keyword
-
HeaderCard
Create a HeaderCard from its component parts- Parameters:
key
- keyword (null for a comment)value
- value (null for a comment or keyword without an '=')comment
- comment- Throws:
HeaderCardException
- for any invalid keyword
-
HeaderCard
Create a HeaderCard from its component parts- Parameters:
key
- keyword (null for a comment)value
- value (null for a comment or keyword without an '=')comment
- comment- Throws:
HeaderCardException
- for any invalid keyword
-
HeaderCard
Create a comment style card. This constructor builds a card which has no value. This may be either 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.- Parameters:
key
- The key for the comment or nullable field.comment
- The commentnullable
- Is this a nullable field or a comment-style card?- Throws:
HeaderCardException
- for any invalid keyword or value
-
HeaderCard
Create a HeaderCard from its component parts- Parameters:
key
- keyword (null for a comment)value
- value (null for a comment or keyword without an '=')comment
- comment- Throws:
HeaderCardException
- for any invalid keyword or value
-
HeaderCard
public HeaderCard(String key, String value, String comment, boolean nullable) throws HeaderCardException Create a HeaderCard from its component parts- Parameters:
key
- Keyword (null for a COMMENT)value
- Valuecomment
- Commentnullable
- Is this a nullable value card?- Throws:
HeaderCardException
- for any invalid keyword or value
-
HeaderCard
private HeaderCard(String key, String value, String comment, boolean nullable, boolean isString) throws HeaderCardException Create a HeaderCard from its component parts- Parameters:
key
- Keyword (null for a COMMENT)value
- Valuecomment
- Commentnullable
- Is this a nullable value card?- Throws:
HeaderCardException
- for any invalid keyword or value
-
-
Method Details
-
create
- Parameters:
card
- the 80 character card image- Returns:
- a created HeaderCard from a FITS card string.
-
dblString
Create a string from a BigDecimal making sure that it's not longer than the available space.- Parameters:
decimalValue
- the decimal value to printavailableSpace
- the space available for the value- Returns:
- the string representing the value.
-
dblString
Create a string from a BigDecimal making sure that it's not longer than the available space.- Parameters:
decimalValue
- the decimal value to printprecision
- the precision to useavailableSpace
- the space available for the value- Returns:
- the string representing the value.
-
dblString
Create a string from a BigDecimal making sure that it's not longer than the available space.- Parameters:
decimalValue
- the decimal value to printavailableSpace
- the space available for the value- Returns:
- the string representing the value.
-
dblString
- Parameters:
input
- float value being convertedprecision
- the number of decimal places to show- Returns:
- Create a fixed decimal string from a double with the specified precision.
-
floatToBigDecimal
attention float to double cases are very lossy so a toString is needed to keep the precision. proof (double)500.055f = 500.05499267578125d- Parameters:
floatValue
- the float value- Returns:
- the BigDecimal as close to the value of the float as possible
-
getDecimalNumberType
detect the decimal type of the value, does it fit in a Double/BigInteger or must it be a BigDecimal to keep the needed precission.- Parameters:
value
- the String value to check.- Returns:
- the type to fit the value
-
getIntegerNumberType
-
readOneHeaderLine
private static String readOneHeaderLine(HeaderCardCountingArrayDataInput dis) throws IOException, TruncatedFileException Read exactly one complete fits header line from the input.- Parameters:
dis
- the data input stream to read the line- Returns:
- a string of exactly 80 characters
- Throws:
IOException
- if the input stream could not be readTruncatedFileException
- is there was not a complete line available in the input.
-
spaceAvailableForValue
-
stringToArrayInputStream
-
saveNewHeaderCard
This method is only used internally when it is sure that the creation of the card is granted not to throw an exception- Parameters:
key
- the key for the cardcomment
- the comment for the cardisString
- is this a string value card?- Returns:
- the new HeaderCard
-
cardSize
public int cardSize()- 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.
-
copy
- Throws:
HeaderCardException
-
getComment
- Returns:
- the comment from this card
-
getKey
- Specified by:
getKey
in interfaceCursorValue<String>
- Returns:
- the keyword from this card
-
getValue
- Returns:
- the value from this card
-
getValue
- Type Parameters:
T
- the type of the requested class- Parameters:
clazz
- the requested class of the valuedefaultValue
- the value if the card was not present.- Returns:
- the value from this card as a specific type
-
isKeyValuePair
public boolean isKeyValuePair()- Returns:
- Is this a key/value card?
-
isStringValue
public boolean isStringValue()- Returns:
- if this card contain does a string value?
-
setComment
set the comment of a card.- Parameters:
comment
- the comment to set.
-
setValue
Set the value for this card.- Parameters:
update
- the new value to set- Returns:
- the HeaderCard itself
-
setValue
Set the value for this card.- Parameters:
update
- the new value to set- Returns:
- the HeaderCard itself
-
setValue
Set the value for this card.- Parameters:
update
- the new value to set- Returns:
- the HeaderCard itself
-
setValue
Set the value for this card.- Parameters:
update
- the new value to setprecision
- the number of decimal places to show- Returns:
- the HeaderCard itself
-
setValue
Set the value for this card.- Parameters:
update
- the new value to set- Returns:
- the HeaderCard itself
-
setValue
Set the value for this card.- Parameters:
update
- the new value to setprecision
- the number of decimal places to show- Returns:
- the HeaderCard itself
-
setValue
Set the value for this card.- Parameters:
update
- the new value to set- Returns:
- the HeaderCard itself
-
setValue
Set the value for this card.- Parameters:
update
- the new value to set- Returns:
- the HeaderCard itself
-
setValue
Set the value for this card.- Parameters:
update
- the new value to set- Returns:
- the HeaderCard itself
-
toString
Return 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. -
toString
Same astoString()
just with a prefetched settings object- Parameters:
settings
- the settings to use for writing the header card- Returns:
- the string representing the card.
-
valueType
- Returns:
- the type of the value.
-
extractValueCommentFromString
private void extractValueCommentFromString(HeaderCardCountingArrayDataInput dis, String card) throws IOException, TruncatedFileException - Throws:
IOException
TruncatedFileException
-
getBooleanValue
-
hierarchCard
private void hierarchCard(String card, HeaderCardCountingArrayDataInput dis) throws IOException, TruncatedFileException Process HIERARCH style cards... HIERARCH LEV1 LEV2 ... = value / comment The keyword for the card will be "HIERARCH.LEV1.LEV2..." A '/' is assumed to start a comment.- Parameters:
dis
-- Throws:
IOException
TruncatedFileException
-
longStringCard
private void longStringCard(HeaderCardCountingArrayDataInput dis, FitsHeaderCardParser.ParsedValue parsedValue) throws IOException, TruncatedFileException - Throws:
IOException
TruncatedFileException
-
maxStringValueLength
private int maxStringValueLength() -
stringValueToString
private boolean stringValueToString(int alignSmallString, int alignPosition, FitsLineAppender buf, boolean commentHandled) -
writeLongStringValue
-
setKey
Set the key.
-