Package uk.ac.starlink.fits

# Class FitsHeader

java.lang.Object
uk.ac.starlink.fits.FitsHeader

public class FitsHeader extends Object
Represents the header part of a FITS HDU that has been read. It is composed of a number of ParsedCards.

The FITS 4.0 long-string syntax is supported.

Since:
  4 Mar 2022
Author:
  Mark Taylor

## Field Summary

Fields
Modifier and Type
Field
Description
`final String[]`
`BORING_KEYS`
Keywords which are never used as table parameters.

## Constructor Summary

Constructors
Constructor
Description
`FitsHeader(ParsedCard<?>[] cards)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`Boolean`
`getBooleanValue(String key)`
Returns the boolean value for a card with a given key, if one exists.
`ParsedCard<?>[]`
`getCards()`
Returns the header cards of which this header is composed.
`long`
`getDataBlockCount()`
Returns the number of FITS blocks occupied by the Data part of the HDU described by this header.
`long`
`getDataByteCount()`
Returns the number of bytes occupied by the Data part of the HDU described by this header, rounded up to an integer number of blocks.
`uk.ac.starlink.table.DescribedValue`
`getDescribedValue(String key)`
Returns the content of a card with a given key as a DescribedValue, if such a key exists.
`Double`
`getDoubleValue(String key)`
Returns the double value for a card with a given key, if one exists.
`long`
`getHeaderBlockCount()`
Returns the number of FITS blocks occupied by this header.
`long`
`getHeaderByteCount()`
Returns the number of bytes occupied by this header, rounded up to an integer number of blocks.
`Integer`
`getIntValue(String key)`
Returns the integer value for a card with a given key, if one exists.
`Long`
`getLongValue(String key)`
Returns the long value for a card with a given key, if one exists.
`Number`
`getNumberValue(String key)`
Returns a numeric value for a card with a given key, if one exists.
`int`
`getRequiredIntValue(String key)`
Returns an integer value for a card with a given key, or throws an exception if none exists.
`long`
`getRequiredLongValue(String key)`
Returns a long value for a card with a given key, or throws an exception if none exists.
`String`
`getRequiredStringValue(String key)`
Returns a long value for a card with a given key, or throws an exception if none exists.
`String`
`getStringValue(String key)`
Returns the string value for a card with a given key, if one exists.
`uk.ac.starlink.table.DescribedValue[]`
`getUnusedParams()`
Returns an array of DescribedValue objects suitable for use as items of per-table metadata derived from this FITS header.
`Object`
`getValue(String key)`
Returns the untyped value for a card with a given key, if one exists.
`void`
`useKey(String key)`
Marks a given keyword as used.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### BORING_KEYS

public final String[] BORING_KEYS
Keywords which are never used as table parameters.

## Constructor Details

### FitsHeader

public FitsHeader(ParsedCard<?>[] cards)
Constructor. All the header cards composing the header must be included so that the header knows its length in bytes.

Parameters:
  `cards` - header cards composing the header

## Method Details

### getCards

public ParsedCard<?>[] getCards()
Returns the header cards of which this header is composed.

Returns:
  ordered sequence of parsed header cards

### getValue

public Object getValue(String key)
Returns the untyped value for a card with a given key, if one exists.

Parameters:
  `key` - header keyword
Returns:
  value, or null

### getDescribedValue

public uk.ac.starlink.table.DescribedValue getDescribedValue(String key)
Returns the content of a card with a given key as a DescribedValue, if such a key exists. Any comment text is provided as the `ValueInfo.getDescription()`.

Parameters:
  `key` - header keyword
Returns:
  described value, or null

### getIntValue

public Integer getIntValue(String key)
Returns the integer value for a card with a given key, if one exists.

Parameters:
  `key` - header keyword
Returns:
  integer value, or null

### getLongValue

public Long getLongValue(String key)
Returns the long value for a card with a given key, if one exists.

Parameters:
  `key` - header keyword
Returns:
  long value, or null

### getDoubleValue

public Double getDoubleValue(String key)
Returns the double value for a card with a given key, if one exists.

Parameters:
  `key` - header keyword
Returns:
  double value, or null

### getNumberValue

public Number getNumberValue(String key)
Returns a numeric value for a card with a given key, if one exists. This may be a BigInteger or BigDecimal if no other Number class can represent the serialized value.

Parameters:
  `key` - header keyword
Returns:
  numeric value, or null

### getBooleanValue

public Boolean getBooleanValue(String key)
Returns the boolean value for a card with a given key, if one exists.

Parameters:
  `key` - header keyword
Returns:
  boolean value, or null

### getStringValue

public String getStringValue(String key)
Returns the string value for a card with a given key, if one exists.

Parameters:
  `key` - header keyword
Returns:
  string value, or null

### getRequiredIntValue

public int getRequiredIntValue(String key) throws HeaderValueException
Returns an integer value for a card with a given key, or throws an exception if none exists.

Parameters:
  `key` - header keyword
Returns:
  integer value
Throws:
  `HeaderValueException` - if no suitable card exists

### getRequiredLongValue

public long getRequiredLongValue(String key) throws HeaderValueException
Returns a long value for a card with a given key, or throws an exception if none exists.

Parameters:
  `key` - header keyword
Returns:
  long value
Throws:
  `HeaderValueException` - if no suitable card exists

### getRequiredStringValue

public String getRequiredStringValue(String key) throws HeaderValueException
Returns a long value for a card with a given key, or throws an exception if none exists.

Parameters:
  `key` - header keyword
Returns:
  long value
Throws:
  `HeaderValueException` - if no suitable card exists

### useKey

public void useKey(String key)
Marks a given keyword as used. This is invoked by all the `get*Value` methods.

Parameters:
  `key` - header keyword

### getHeaderBlockCount

public long getHeaderBlockCount()
Returns the number of FITS blocks occupied by this header.

Returns:
  number of 2880-byte blocks in header

### getDataBlockCount

public long getDataBlockCount() throws HeaderValueException
Returns the number of FITS blocks occupied by the Data part of the HDU described by this header.

Returns:
  number of 2880-byte blocks in data part of HDU
Throws:
  `HeaderValueException`

### getHeaderByteCount

public long getHeaderByteCount()
Returns the number of bytes occupied by this header, rounded up to an integer number of blocks.

Returns:
  `getHeaderBlockCount()` * 2880

### getDataByteCount

public long getDataByteCount() throws HeaderValueException
Returns the number of bytes occupied by the Data part of the HDU described by this header, rounded up to an integer number of blocks.

Returns:
  `getDataBlockCount()` * 2880
Throws:
  `HeaderValueException`

### getUnusedParams

public uk.ac.starlink.table.DescribedValue[] getUnusedParams()
Returns an array of DescribedValue objects suitable for use as items of per-table metadata derived from this FITS header. This contains entries for every card which has not already been queried within this object (for which `useKey(java.lang.String)` has not been explicitly or implicitly called. Certain standard structural FITS keywords (`BORING_KEYS`) are ignored as well.

The idea is that keywords which have already been read to determine table structure do not need to be recorded separately since their meaning is implicitly included in the table metadata already.

Returns:
  array of table parameters relating to this object