00001 
00002 
00003 
00004 
00005 
00006 
00007 #ifndef FITSFILE_H
00008 #define FITSFILE_H
00009 
00010 extern "C"
00011 {
00012   #include "fitsio.h"
00013 }
00014 
00015 #include <list>
00016 #include <string>
00017 #include <vector>
00018 
00019 #include "MyException.h"
00020 
00025 
00026 class FitsFile
00027 {
00028 public:
00029   enum FitsHdr
00030   {
00031     Primary,
00032     Secondary,
00033     Catalogue
00034   };
00035 
00036   enum ExpectKeys
00037   {
00038     UTDATE,
00039     MJD,
00040     PROJECT,
00041     FILTER,
00042     FLATCOR,
00043     CIRCPM,
00044     SKYSUB,
00045     ARC_MFID,
00046     ARC_TIME,
00047     OBSNUM,
00048     XTENSION,
00049     ZNAXIS,
00050     ZNAXIS1,
00051     ZNAXIS2,
00052     NAXIS,
00053     NAXIS1,
00054     NAXIS2,
00055     CRVAL1,
00056     CRVAL2,
00057     CD11,
00058     CD12,
00059     CD21,
00060     CD22,
00061     CAMNUM,
00062     TEXPTIME,
00063     cAMSTART,
00064     cAMEND,
00065     cMAGZPT,
00066     cMAGZRR,
00067     cEXTINCT,
00068     cEXP_TIME,
00069     cCRVAL1,
00070     cCRVAL2,
00071     cCTYPE1,
00072     cCTYPE2,
00073     cCRPIX1,
00074     cCRPIX2,
00075     cCD11,
00076     cCD12,
00077     cCD21,
00078     cCD22,
00079     cPV21,
00080     cPV22,
00081     cPV23,
00082     cPV24,
00083     cPV25,
00084     NumKeys   
00085   };          
00086 
00088   FitsFile();
00089 
00091   FitsFile(const std::string& filename);
00092 
00095   ~FitsFile();
00096 
00098   void openFile(const std::string& filename);
00099 
00101   void closeFile();
00102 
00104   const std::string& getFileName() const;
00105 
00107   bool isTile() const;
00108 
00109   
00110   
00111   
00112 
00114   bool testExpectedKeys(const std::string& fitsType);
00115   int checkKeys(const std::string& aKeyname);
00116 
00118   bool hasKey(const std::string& keyname) const;
00119 
00121   void readKey(const std::string& keyname, int&    value) const;
00122 
00124   void readKey(const std::string& keyname, float&  value) const;
00125 
00127   void readKey(const std::string& keyname, double& value) const;
00128 
00130   void readKey(const std::string& keyname, std::string& value) const;
00131 
00133   template <typename AnyDataType>
00134   void readKey(ExpectKeys keyname, AnyDataType& value) const
00135   {
00136     readKey(mExpectedKeys.at(keyname).first, value);
00137   }
00138 
00141   void readKeyUnit(const std::string& keyname, std::string& unit);
00142 
00144   void readHistory(std::list<std::string>& values);
00145 
00147   int getNumCards();
00148 
00150   void readCard(int keyNo, char* card);
00151 
00153   std::string readKeyname(int keyNo);
00154 
00155   
00156   
00157   
00158 
00160   int getNumHdus() const;
00161 
00165   int getHduNum();
00166 
00168   int movabsHdu(int hdunum) const;
00169 
00171   int movrelHdu(int nmove);
00172 
00175   int getHduType();
00176 
00178   bool isImageHdu();
00179 
00181   bool isAsciiTable();
00182 
00184   bool isBinaryTable();
00185 
00186   
00187   
00188   
00189 
00191   int getNumRows();
00192 
00194   int getNumCols();
00195 
00198   int getColnum(const std::string& name);
00199 
00202   void readColumn(const std::string& name, float* data);
00203 
00206   void readColumn(const std::string& name, double* data);
00207 
00212   void readColumn(const std::string& name, std::string* data) {}
00213 
00215   std::string readColumnUnit(const std::string& name);
00216 
00217   
00218   
00219 
00220 private:
00221   typedef std::pair<std::string, FitsHdr> FitsKeysPair;
00222   typedef std::vector<FitsKeysPair> FitsKeysList;
00223 
00225   static FitsKeysList mExpectedKeys;
00226 
00228   std::string fileName;
00229 
00231   fitsfile *fptr;
00232 
00234   void initExpectedKeysList();
00235 
00237   void handleError(int status, bool throwException = true) const;
00238 
00239 };
00240 
00242 class FitsIOException : public MyException
00243 {
00244 public:
00245   FitsIOException(const std::string& aMsg)
00246     : MyException("FitsIOException: ", aMsg) { }
00247 };
00248 
00250 class FitsColNotFound : public FitsIOException
00251 {
00252 public:
00253   FitsColNotFound(const std::string& aMsg)
00254     : FitsIOException("FitsColNotFound: " + aMsg) { }
00255 };
00256 
00258 class FitsKeyNotExist : public FitsIOException
00259 {
00260 public:
00261   FitsKeyNotExist(const std::string& aMsg)
00262     : FitsIOException("FitsKeyNotExist: " + aMsg) { }
00263 };
00264 
00265 #endif