org.jscience.io.fits
Class FitsCard

java.lang.Object
  extended by org.jscience.io.fits.FitsCard

public class FitsCard
extends java.lang.Object

Represents a single header record. It's called a "card" because when FITS was created, FORTRAN was the standard programming language for science and the designers had punchcards in mind. A card consists of 80 ASCII characters containing a key/value pair and a comment. The internal structure of a card is not parsed until needed. You may construct a new card by specifying its raw bytes or by specifying it's component fields. In the former case the bytes are taken without question, and in the latter case, the constructor forces correct FITS format.


Field Summary
static int CARDS_PER_BLOCK
          the number of cards in a FITS block = 2880/80
static int KEY_LENGTH
          the maximum number of bytes in a keyword = 8
static int LENGTH
          the number of bytes in a card = 80
static byte[] PADDING
          the value to use for padding out an incomplete block (80 ASCII spaces)
 
Constructor Summary
FitsCard(byte[] data)
          Create a new card initialized with the given data.
FitsCard(byte[] data, int offset)
          Create a new card from the bytes in an array, starting at the given offset into the array.
FitsCard(java.lang.String key)
          Create a card by specifying only its keyword.
FitsCard(java.lang.String key, boolean value, java.lang.String comment)
          construct a card by specifying it's keyword, value and comment.
FitsCard(java.lang.String key, java.lang.Boolean value, java.lang.String comment)
          construct a card by specifying it's keyword, value and comment.
FitsCard(java.lang.String key, double value, java.lang.String comment)
          construct a card by specifying it's keyword, value and comment.
FitsCard(java.lang.String key, float value, java.lang.String comment)
          construct a card by specifying it's keyword, value and comment.
FitsCard(java.lang.String key, int value, java.lang.String comment)
          construct a card by specifying it's keyword, value and comment.
FitsCard(java.lang.String key, long value, java.lang.String comment)
          construct a card by specifying it's keyword, value and comment.
FitsCard(java.lang.String key, java.lang.Number value, java.lang.String comment)
          construct a card by specifying it's keyword, value and comment.
FitsCard(java.lang.String key, java.lang.String comment)
          create a new card which has no value field.
FitsCard(java.lang.String key, java.lang.String value, java.lang.String comment)
          construct a card by specifying it's keyword, value and comment.
 
Method Summary
 java.lang.String comment()
          returns the commment field.
 byte[] data()
          returns the raw 80 bytes of data for this card.
 double doubleValue()
          returns a double value, if appropriate
static java.lang.String formatKeyword(java.lang.String template)
          returns a string which is guaranteed to be a legal FITS keyword.
 int intValue()
          returns an integer value, if appropriate.
 java.lang.String key()
          returns a string containing the keyword for this card
 java.lang.String stringValue()
          returns the value of the card as a string.
 java.lang.String toString()
          returns the raw bytes of the card converted to a string and with trailing white space removed.
 java.lang.Object value()
          returns an object representing the value field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LENGTH

public static final int LENGTH
the number of bytes in a card = 80

See Also:
Constant Field Values

KEY_LENGTH

public static final int KEY_LENGTH
the maximum number of bytes in a keyword = 8

See Also:
Constant Field Values

CARDS_PER_BLOCK

public static final int CARDS_PER_BLOCK
the number of cards in a FITS block = 2880/80

See Also:
Constant Field Values

PADDING

public static final byte[] PADDING
the value to use for padding out an incomplete block (80 ASCII spaces)

Constructor Detail

FitsCard

public FitsCard(byte[] data)
Create a new card initialized with the given data. The values are copied from the array, so the caller may reuse the array.

Parameters:
data - an array of at least 80 bytes

FitsCard

public FitsCard(byte[] data,
                int offset)
Create a new card from the bytes in an array, starting at the given offset into the array.

Parameters:
data - an array of bytes to use for the card data.
offset - the offset into the array at which to start reading data. an offset of "0" means read from the beginning of the array

FitsCard

public FitsCard(java.lang.String key)
Create a card by specifying only its keyword. The card will have no value and a blank comment field.

Parameters:
key - the keyword for this card.

FitsCard

public FitsCard(java.lang.String key,
                java.lang.String comment)
create a new card which has no value field. Use this constructor for things like HISTORY and COMMENT cards.

Parameters:
key - the keyword for the card
comment - the comment field for this card.

FitsCard

public FitsCard(java.lang.String key,
                java.lang.String value,
                java.lang.String comment)
construct a card by specifying it's keyword, value and comment. Use this constructor for string-valued cards. This method ensures the resulting card will have proper format, possibly truncating values.

Parameters:
key - the keyword for the card
value - the value of the keyword
comment - the comment field for this card.

FitsCard

public FitsCard(java.lang.String key,
                boolean value,
                java.lang.String comment)
construct a card by specifying it's keyword, value and comment. Use this constructor for boolean-valued cards. This method ensures the resulting card will have proper format, possibly truncating values.

Parameters:
key - the keyword for the card
value - the value of the keyword
comment - the comment field for this card.

FitsCard

public FitsCard(java.lang.String key,
                java.lang.Boolean value,
                java.lang.String comment)
construct a card by specifying it's keyword, value and comment. Use this constructor for boolean-valued cards. This method ensures the resulting card will have proper format, possibly truncating values.

Parameters:
key - the keyword for the card
value - the value of the keyword
comment - the comment field for this card.

FitsCard

public FitsCard(java.lang.String key,
                int value,
                java.lang.String comment)
construct a card by specifying it's keyword, value and comment. Use this constructor for numberical-valued cards. This method ensures the resulting card will have proper format, possibly truncating values.

Parameters:
key - the keyword for the card
value - the value of the keyword
comment - the comment field for this card.

FitsCard

public FitsCard(java.lang.String key,
                long value,
                java.lang.String comment)
construct a card by specifying it's keyword, value and comment. Use this constructor for numberical-valued cards. This method ensures the resulting card will have proper format, possibly truncating values.

Parameters:
key - the keyword for the card
value - the value of the keyword
comment - the comment field for this card.

FitsCard

public FitsCard(java.lang.String key,
                float value,
                java.lang.String comment)
construct a card by specifying it's keyword, value and comment. Use this constructor for numberical-valued cards. This method ensures the resulting card will have proper format, possibly truncating values.

Parameters:
key - the keyword for the card
value - the value of the keyword
comment - the comment field for this card.

FitsCard

public FitsCard(java.lang.String key,
                double value,
                java.lang.String comment)
construct a card by specifying it's keyword, value and comment. Use this constructor for numberical-valued cards. This method ensures the resulting card will have proper format, possibly truncating values.

Parameters:
key - the keyword for the card
value - the value of the keyword
comment - the comment field for this card.

FitsCard

public FitsCard(java.lang.String key,
                java.lang.Number value,
                java.lang.String comment)
construct a card by specifying it's keyword, value and comment. Use this constructor for numberical-valued cards. This method ensures the resulting card will have proper format, possibly truncating values.

Parameters:
key - the keyword for the card
value - the value of the keyword
comment - the comment field for this card.
Method Detail

data

public byte[] data()
returns the raw 80 bytes of data for this card. Note, this returns the actual internal array and not a copy, so it is usually a bad idea to modify the contents of the returned array.

Returns:
the 80 byte array representing this card.

key

public java.lang.String key()
returns a string containing the keyword for this card

Returns:
the keyword for this card.

value

public java.lang.Object value()
                       throws org.jscience.io.fits.FitsCardException
returns an object representing the value field. This object may be Boolean, String, Integer, Double, or null if the keyword has no value. Caling this method forces the card to parse its internal structure.

Returns:
the value field of the card or null if the card has no value.
Throws:
FitsCardException - if the raw data are not properly formatted

intValue

public int intValue()
             throws org.jscience.io.fits.FitsCardException
returns an integer value, if appropriate. If the card contains a floating point number it will be clipped to an integer.

Returns:
the card value clipped to an integer.
Throws:
FitsCardException - if the card does not have a numerical value

doubleValue

public double doubleValue()
                   throws org.jscience.io.fits.FitsCardException
returns a double value, if appropriate

Returns:
the value field of the card
Throws:
FitsCardException - if the card does not have a numerical value

stringValue

public java.lang.String stringValue()
                             throws org.jscience.io.fits.FitsCardException
returns the value of the card as a string. If the value is not actually a string, then the toString() method of the value will be returned. Note that this may be different from the literal value in the raw data - particularly for boolean values.

Returns:
DOCUMENT ME!
Throws:
FitsCardException - if the raw data are not properly formatted

comment

public java.lang.String comment()
                         throws org.jscience.io.fits.FitsCardException
returns the commment field. Calling this method forces the card to parse its internal structure.

Returns:
the comment field of the card.
Throws:
FitsCardException - if the raw data are not properly formatted.

toString

public java.lang.String toString()
returns the raw bytes of the card converted to a string and with trailing white space removed.

Overrides:
toString in class java.lang.Object
Returns:
DOCUMENT ME!

formatKeyword

public static java.lang.String formatKeyword(java.lang.String template)
returns a string which is guaranteed to be a legal FITS keyword. Lower case is converted to upper case, white space is trimmed, illegal characters are removed and the string length is truncated to 8 characters or less.

Parameters:
template - the intended keyword
Returns:
a properly formatted FITS keyword as close as possible to the template.