Begin versioning.
[fits.git] / src / nom / tam / fits / UndefinedHDU.java
1 package nom.tam.fits;
2 /* Copyright: Thomas McGlynn 1997-1999.
3  * This code may be used for any purpose, non-commercial
4  * or commercial so long as this copyright notice is retained
5  * in the source code or included in or referred to in any
6  * derived software.
7  * Many thanks to David Glowacki (U. Wisconsin) for substantial
8  * improvements, enhancements and bug fixes.
9  */
10
11 import nom.tam.util.ArrayFuncs;
12
13 /** Holder for unknown data types. */
14 public class UndefinedHDU
15         extends BasicHDU {
16
17     /** Build an image HDU using the supplied data.
18      * @param obj the data used to build the image.
19      * @exception FitsException if there was a problem with the data.
20      */
21     public UndefinedHDU(Header h, Data d)
22             throws FitsException {
23         myData = d;
24         myHeader = h;
25
26     }
27
28     /* Check if we can find the length of the data for this
29      * header.
30      * @return <CODE>true</CODE> if this HDU has a valid header.
31      */
32     public static boolean isHeader(Header hdr) {
33         if (hdr.getStringValue("XTENSION") != null
34                 && hdr.getIntValue("NAXIS", -1) >= 0) {
35             return true;
36         }
37         return false;
38     }
39
40     /** Check if we can use the following object as
41      *  in an Undefined FITS block.  We allow this
42      *  so long as computeLSize can get a size.  Note
43      *  that computeLSize may be wrong!
44      *  @param o    The Object being tested.
45      */
46     public static boolean isData(Object o) {
47         return ArrayFuncs.computeLSize(o) > 0;
48     }
49
50     /** Create a Data object to correspond to the header description.
51      * @return An unfilled Data object which can be used to read
52      *         in the data for this HDU.
53      * @exception FitsException if the image extension could not be created.
54      */
55     public Data manufactureData()
56             throws FitsException {
57         return manufactureData(myHeader);
58     }
59
60     public static Data manufactureData(Header hdr)
61             throws FitsException {
62         return new UndefinedData(hdr);
63     }
64
65     /** Create a  header that describes the given
66      * image data.
67      * @param o The image to be described.
68      * @exception FitsException if the object does not contain
69      *          valid image data.
70      */
71     public static Header manufactureHeader(Data d)
72             throws FitsException {
73
74         Header h = new Header();
75         d.fillHeader(h);
76
77         return h;
78     }
79
80     /** Encapsulate an object as an ImageHDU. */
81     public static Data encapsulate(Object o) throws FitsException {
82         return new UndefinedData(o);
83     }
84
85     /** Print out some information about this HDU.
86      */
87     public void info() {
88
89         System.out.println("  Unhandled/Undefined/Unknown Type");
90         System.out.println("  XTENSION=" + myHeader.getStringValue("XTENSION").trim());
91         System.out.println("  Apparent size:" + myData.getTrueSize());
92     }
93 }