org.eso.fits
Class FitsFile

java.lang.Object
  extended by org.eso.fits.FitsFile

public class FitsFile
extends java.lang.Object

FitsFile class represents a FITS file consisting of a set of Header/Data Units. The header information is stored in FitsHeader objects while data are not saved in objects but accessed through file. Thus, files may be corrupted if the disk file is modified independently by other modules.


Constructor Summary
FitsFile()
          Default constructor for FitsFile class
FitsFile(java.io.DataInput file)
          Constructor for FitsFile class given a FITS stream.
FitsFile(java.io.DataInput file, boolean sflag)
          Constructor for FitsFile class given a FITS stream and a flag indicating if the data matrices should be stored internally.
FitsFile(java.io.File file)
          Constructor specifying a name of a disk file.
FitsFile(java.lang.String filename)
          Constructor from name of disk file.
 
Method Summary
 void addHDUnit(FitsHDUnit hdu)
          Add new HDUnit to FITS file.
 void closeFile()
          Remove all references to associated DataInput files.
protected  void finalize()
          Finalize method which close disk file
 java.io.File getFile()
          Gets file identifier for FITS file
 FitsHDUnit getHDUnit(int no)
          Get HDUnit in FitsFile by its position.
 java.lang.String getName()
          Gets Canonical path of FITS file
 int getNoHDUnits()
          Gets numnber of HDUnits in FITS file
 void insertHDUnitAt(FitsHDUnit hdu, int index)
          Insert new HDUnit to FITS file at specified location.
static boolean isFitsFile(java.io.File file)
          Static method to test if a disk file possibly is in FITS format.
static boolean isFitsFile(java.lang.String filename)
          Static method to test if a disk file possibly is in FITS format.
 void removeHDUnitAt(int index)
          Remove HDUnit with given location from FITS file.
 void saveFile()
          Save changes made to a FITS file on disk.
 void writeFile(java.io.DataOutput filename)
          Write FITS file to a DataOutput stream.
 void writeFile(java.io.File file)
          Write FITS file on a new diskfile.
 void writeFile(java.lang.String filename)
          Write FITS file on a new diskfile.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FitsFile

public FitsFile()
Default constructor for FitsFile class


FitsFile

public FitsFile(java.io.DataInput file)
         throws FitsException
Constructor for FitsFile class given a FITS stream.

Parameters:
file - DataInput stream positioned at its start
Throws:
FitsException

FitsFile

public FitsFile(java.io.DataInput file,
                boolean sflag)
         throws FitsException
Constructor for FitsFile class given a FITS stream and a flag indicating if the data matrices should be stored internally. The store flag must be true to allow access to the data matrices whereas header data will always be available.

Parameters:
file - DataInput stream positioned at its start
sflag - Flag indicating if data matrices should be stored internally in the class.
Throws:
FitsException

FitsFile

public FitsFile(java.io.File file)
         throws java.io.IOException,
                FitsException
Constructor specifying a name of a disk file. Note: the file will be opened in read-only mode for security reasons. This means that the data matrix cannot be modified although headers can as they are stored in memory. If data should be modified, one must create a DataInput object for the file explicitly (with read/write permissions) and use the appropriate constructor.

Parameters:
file - name of disk file in FITS format
Throws:
IOException,FitsException
java.io.IOException
FitsException

FitsFile

public FitsFile(java.lang.String filename)
         throws java.io.IOException,
                FitsException
Constructor from name of disk file. Note: the file will be opened in read-only mode for security reasons. This means that the data matrix cannot be modified although headers can as they are stored in memory. If data should be modified, one must create a DataInput object for the file explicitly (with read/write permissions) and use the appropriate constructor.

Parameters:
filename - name of disk file in FITS format
Throws:
IOException,FitsException
java.io.IOException
FitsException
Method Detail

finalize

protected void finalize()
                 throws java.io.IOException
Finalize method which close disk file

Overrides:
finalize in class java.lang.Object
Throws:
java.io.IOException

isFitsFile

public static boolean isFitsFile(java.io.File file)
Static method to test if a disk file possibly is in FITS format. The test is trivial in the sense that the file may not be a correct FITS file even if 'true' is returned. On the other hand, it is certainly not a FITS file if 'false' is returned.

Parameters:
file - disk file

isFitsFile

public static boolean isFitsFile(java.lang.String filename)
Static method to test if a disk file possibly is in FITS format. The test is trivial in the sense that the file may not be a correct FITS file even if 'true' is returned. On the other hand, it is certainly not a FITS file if 'false' is returned.

Parameters:
filename - name of disk file

addHDUnit

public void addHDUnit(FitsHDUnit hdu)
Add new HDUnit to FITS file.

Parameters:
hdu - FitsHDUnit to be added

insertHDUnitAt

public void insertHDUnitAt(FitsHDUnit hdu,
                           int index)
Insert new HDUnit to FITS file at specified location.

Parameters:
hdu - FitsHDUnit to be inserted
index - location at which hte HDU should be inserted

removeHDUnitAt

public void removeHDUnitAt(int index)
Remove HDUnit with given location from FITS file.

Parameters:
index - location of the HDU to be removed

getHDUnit

public final FitsHDUnit getHDUnit(int no)
Get HDUnit in FitsFile by its position. If the position is less that 0, the first HDU is returned while the last is given for positions beyond the actual number.

Parameters:
no - number of HDUnit to retrieve (starting with 0)

saveFile

public void saveFile()
              throws java.io.IOException,
                     FitsException
Save changes made to a FITS file on disk. The FitsFile must have been created from a read/write RandomAccess disk file. Further, headers and data must fit into the original file. Not check is done to verify the correctness of the FITS headers.

Throws:
IOException, - FitsException
java.io.IOException
FitsException

writeFile

public void writeFile(java.io.DataOutput filename)
               throws java.io.IOException,
                      FitsException
Write FITS file to a DataOutput stream. Not check is done to verify the correctness of the FITS headers.

Parameters:
filename - name of new file to be written
Throws:
IOException, - FitsException
java.io.IOException
FitsException

writeFile

public void writeFile(java.io.File file)
               throws java.io.IOException,
                      FitsException
Write FITS file on a new diskfile. Not check is done to verify the correctness of the FITS headers.

Parameters:
file - new file to be written
Throws:
IOException, - FitsException
java.io.IOException
FitsException

writeFile

public void writeFile(java.lang.String filename)
               throws java.io.IOException,
                      FitsException
Write FITS file on a new diskfile. Not check is done to verify the correctness of the FITS headers.

Parameters:
filename - name of new file to be written
Throws:
IOException, - FitsException
java.io.IOException
FitsException

closeFile

public void closeFile()
Remove all references to associated DataInput files.


getNoHDUnits

public final int getNoHDUnits()
Gets numnber of HDUnits in FITS file


getName

public java.lang.String getName()
Gets Canonical path of FITS file


getFile

public java.io.File getFile()
Gets file identifier for FITS file