Package uk.ac.starlink.fits
Class AbstractFitsTableWriter
java.lang.Object
uk.ac.starlink.table.StreamStarTableWriter
uk.ac.starlink.fits.AbstractFitsTableWriter
- All Implemented Interfaces:
uk.ac.starlink.table.MultiStarTableWriter
,uk.ac.starlink.table.StarTableWriter
- Direct Known Subclasses:
ColFitsTableWriter
,FitsTableWriter
,HduFitsTableWriter
,HealpixFitsTableWriter
,VariableFitsTableWriter
public abstract class AbstractFitsTableWriter
extends uk.ac.starlink.table.StreamStarTableWriter
implements uk.ac.starlink.table.MultiStarTableWriter
Abstract table writer superclass designed for writing FITS tables.
A couple of Auxiliary metadata items of the ColumnInfo metadata from written tables are respected:
Tables.NULL_VALUE_INFO
: sets the value ofTNULLn
"magic" blank value for integer columnsTables.UBYTE_FLAG_INFO
: if set toBoolean.TRUE
and if the column has content classShort
orshort[]
, the data will be written as unsigned bytes (TFORMn='B'
) not 16-bit signed integers (TFORMn='I'
).BintableStarTable.LONGOFF_INFO
: if this is set to a string representation of an integer value, and the column has content class String or String[], then the data will be written as long integers (TFORMn='K'
) with the given offset (TZEROn=...
). This option supports round-tripping of offset long values (typically representing unsigned longs) which are converted to strings on read.
- Since:
- 27 Jun 2006
- Author:
- Mark Taylor
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract FitsTableSerializer
createSerializer
(uk.ac.starlink.table.StarTable table) Provides a suitable serializer for a given table.boolean
Returns a flag indicating how Byte-valued columns are written.boolean
Indicates whether zero-length string columns may be output.Returns the configuration details for writing FITS files.static String
Returns an ISO-8601 data string representing the time at which this method is called.Adds some standard metadata header cards to a FITS table header.Returns "application/fits".byte
Returns the byte value with which under-length string (character array) values will be padded.getWide()
Indicates the convention in use for representing over-wide tables.boolean
Indicates whether a datestamp is written to output FITS files.void
setAllowSignedByte
(boolean allowSignedByte) Configures how Byte-valued columns are written.void
setAllowZeroLengthString
(boolean allowZeroLengthString) Sets whether zero-length string columns may be written.void
setFormatName
(String formatName) Sets the declared format name.void
setPadCharacter
(byte padChar) Sets the byte value with which under-length string (character array) values should be padded.void
Sets the convention for representing over-wide (>999 column) tables.void
setWriteDate
(boolean writeDate) Configures whether a datestamp is written to output FITS files.void
Writes the primary HDU.void
writeStarTable
(uk.ac.starlink.table.StarTable table, OutputStream out) Writes a single table.void
writeStarTables
(uk.ac.starlink.table.TableSequence tableSeq, OutputStream out) Writes tables.void
writeStarTables
(uk.ac.starlink.table.TableSequence tableSeq, String location, uk.ac.starlink.table.StarTableOutput sto) void
writeTableHDU
(uk.ac.starlink.table.StarTable table, FitsTableSerializer fitser, OutputStream out) Writes a data HDU.Methods inherited from class uk.ac.starlink.table.StreamStarTableWriter
writeStarTable, writeStarTable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface uk.ac.starlink.table.StarTableWriter
looksLikeFile, writeStarTable
-
Constructor Details
-
AbstractFitsTableWriter
Constructor.- Parameters:
formatName
- format name
-
-
Method Details
-
getFormatName
- Specified by:
getFormatName
in interfaceuk.ac.starlink.table.StarTableWriter
-
setFormatName
Sets the declared format name.- Parameters:
formatName
- format name
-
getMimeType
Returns "application/fits".- Specified by:
getMimeType
in interfaceuk.ac.starlink.table.StarTableWriter
- Returns:
- MIME type
-
writeStarTable
public void writeStarTable(uk.ac.starlink.table.StarTable table, OutputStream out) throws IOException Writes a single table. InvokeswriteStarTables(uk.ac.starlink.table.TableSequence, java.io.OutputStream)
.- Specified by:
writeStarTable
in interfaceuk.ac.starlink.table.StarTableWriter
- Throws:
IOException
-
writeStarTables
public void writeStarTables(uk.ac.starlink.table.TableSequence tableSeq, OutputStream out) throws IOException Writes tables. CallswritePrimaryHDU(java.io.OutputStream)
to write the primary HDU. Subclasses which want to put something related to the input tables into the primary HDU will need to override this method (writeStarTables).- Specified by:
writeStarTables
in interfaceuk.ac.starlink.table.MultiStarTableWriter
- Throws:
IOException
-
writeStarTables
public void writeStarTables(uk.ac.starlink.table.TableSequence tableSeq, String location, uk.ac.starlink.table.StarTableOutput sto) throws IOException - Specified by:
writeStarTables
in interfaceuk.ac.starlink.table.MultiStarTableWriter
- Throws:
IOException
-
writePrimaryHDU
Writes the primary HDU. This cannot contain a table since BINTABLE HDUs can only be extensions. The AbstractFitsTableWriter implementation writes a minimal, data-less HDU.- Parameters:
out
- destination stream- Throws:
IOException
-
writeTableHDU
public void writeTableHDU(uk.ac.starlink.table.StarTable table, FitsTableSerializer fitser, OutputStream out) throws IOException Writes a data HDU.- Parameters:
table
- the table to be written into the HDUfitser
- fits serializer initalised fromtable
out
- destination stream- Throws:
IOException
-
getConfig
Returns the configuration details for writing FITS files. Its content can be controlled using single-config-item mutator methods (which may also be labelled asConfigMethod
s) on this class. This covers things that are generally orthogonal to the type of serialization, so may be set for any kind of FITS output, which is why it makes sense to manage them in theAbstractFitsTableWriter
abstract superclass.- Returns:
- object representing the FITS serialization options currently configured for this writer
-
createSerializer
protected abstract FitsTableSerializer createSerializer(uk.ac.starlink.table.StarTable table) throws IOException Provides a suitable serializer for a given table. Note this should throw an IOException if it can be determined that the submitted table cannot be written by this writer, for instance if it has too many columns.- Parameters:
table
- table to serialize- Returns:
- FITS serializer
- Throws:
IOException
- if the table can't be written
-
getMetadataCards
Adds some standard metadata header cards to a FITS table header. This includes date stamp, STIL version, etc.- Returns:
- list of cards giving write-specific metadata
-
setWriteDate
@ConfigMethod(property="date", doc="<p>If true, the DATE-HDU header is filled in with the current date; otherwise it is not included.</p>") public void setWriteDate(boolean writeDate) Configures whether a datestamp is written to output FITS files.- Parameters:
writeDate
- true to include DATE-HDU, false to omit it
-
getWriteDate
public boolean getWriteDate()Indicates whether a datestamp is written to output FITS files.- Returns:
- true to include DATE-HDU, false to omit it
-
setAllowSignedByte
public void setAllowSignedByte(boolean allowSignedByte) Configures how Byte-valued columns are written. This is a bit fiddly, since java bytes are signed, but FITS 8-bit integers are unsigned. If true, they are written as FITS unsigned 8-bit integers with an offset, as discussed in the FITS standard (TFORMn='B'
,TZERO=-128
). If false, they are written as FITS signed 16-bit integers.- Parameters:
allowSignedByte
- true to write offset bytes, false to write shorts
-
getAllowSignedByte
public boolean getAllowSignedByte()Returns a flag indicating how Byte-valued columns are written.- Returns:
- true to write offset bytes, false to write shorts
-
setAllowZeroLengthString
public void setAllowZeroLengthString(boolean allowZeroLengthString) Sets whether zero-length string columns may be written. Such columns (TFORMn='0A'
) are explicitly permitted by the FITS standard, but they can cause crashes because of divide-by-zero errors when encountered by some versions of CFITSIO (v3.50 and earlier), so FITS writing code may wish to avoid them. If this is set false, then A repeat values will always be >=1.- Parameters:
allowZeroLengthString
- false to prevent zero-length string columns
-
getAllowZeroLengthString
public boolean getAllowZeroLengthString()Indicates whether zero-length string columns may be output.- Returns:
- false if zero-length string columns are avoided
-
setWide
Sets the convention for representing over-wide (>999 column) tables.- Parameters:
wide
- wide-table representation policy, null to avoid wide tables
-
getWide
Indicates the convention in use for representing over-wide tables.- Returns:
- wide-table representation policy, null for no wide tables
-
setPadCharacter
public void setPadCharacter(byte padChar) Sets the byte value with which under-length string (character array) values should be padded. This should normally be one of 0x00 (ASCII NUL) or 0x20 (space). The function of an ASCII NUL is to terminate the string early, as described in Section 7.3.3.1 of the FITS 4.0 standard; space characters pad it to its declared length with whitespace. Other values in the range 0x21-0x7E are permitted but probably not sensible.- Parameters:
padChar
- character data padding byte
-
getPadCharacter
public byte getPadCharacter()Returns the byte value with which under-length string (character array) values will be padded. This will normally be one of 0x00 (ASCII NUL) or 0x20 (space).- Returns:
- character data padding byte
-
getCurrentDate
Returns an ISO-8601 data string representing the time at which this method is called.- Returns:
- date string
-