org.eso.fits
Class FitsFile

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

public class FitsFile
extends 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.

Version:
$Revision: 1.10 $ $Date: 2003/04/11 08:41:15 $
Author:
P.Grosbol, DMD/ESO, http://www.eso.org/~pgrosbol/fits_java/jfits.html

Constructor Summary
FitsFile()
          Default constructor for FitsFile class
FitsFile(DataInput file)
          Constructor for FitsFile class given a FITS stream.
FitsFile(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(File file)
          Constructor specifying a name of a disk file.
FitsFile(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
 File getFile()
          Gets file identifier for FITS file
 FitsHDUnit getHDUnit(int no)
          Get HDUnit in FitsFile by its position.
 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(File file)
          Static method to test if a disk file possibly is in FITS format.
static boolean isFitsFile(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(DataOutput file)
          Write FITS file to a DataOutput stream.
 void writeFile(File file)
          Write FITS file on a new diskfile.
 void writeFile(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(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(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 where as 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(File file)
         throws 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
IOException
FitsException

FitsFile

public FitsFile(String filename)
         throws 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
IOException
FitsException
Method Detail

finalize

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

Overrides:
finalize in class Object
Throws:
IOException

isFitsFile

public static boolean isFitsFile(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(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 IOException,
                     FitsException
Save changes made to a FITS file on disk. The FitsFile must have been creaded 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
IOException
FitsException

writeFile

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

Parameters:
file - the data output to be written
Throws:
IOException, - FitsException
IOException
FitsException

writeFile

public void writeFile(File file)
               throws 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
IOException
FitsException

writeFile

public void writeFile(String filename)
               throws 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
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 String getName()
Gets Canonical path of FITS file


getFile

public File getFile()
Gets file identifier for FITS file