source: Sophya/trunk/SophyaExt/FitsIOServer/fitsinoutfile.h@ 2932

Last change on this file since 2932 was 2932, checked in by ansari, 19 years ago

Modifs suggere par Casandjian (suppression espace ds les kw fits et conservation des kw de type STRUCT) et petites corrections, maj commentaires auto-doc - Reza 3/4/2006

  • Property svn:executable set to *
File size: 7.9 KB
Line 
1#ifndef FITSINOUTFILE_H
2#define FITSINOUTFILE_H
3
4#include "machdefs.h"
5#include "pexceptions.h"
6#include "dvlist.h"
7#include "FitsIO/fitsio.h"
8#include <complex>
9
10
11
12namespace SOPHYA {
13
14 class FitsInOutFile;
15 //class FitsInStream;
16 //class FitsOutStream;
17
18/*!
19 \ingroup FitsIOServer
20 \brief Exception class used by FITS file wrapper classes in FitsIOserver module
21*/
22class FitsIOException : public IOExc {
23 public:
24 explicit FitsIOException(const char * m) : IOExc(m) {}
25 explicit FitsIOException(const string& m) : IOExc(m) {}
26};
27
28
29/*!
30 \ingroup FitsIOServer
31 \brief for converting c/c++ types to FITS data types
32*/
33class FitsTypes {
34public:
35 // Conversion de type en constante de type image FITS (XXX_IMG)
36 static int ImageType(uint_1 d) { return BYTE_IMG; }
37 static int ImageType(int_2 d) { return SHORT_IMG; }
38 static int ImageType(int_4 d) { return LONG_IMG; }
39 static int ImageType(r_4 d) { return FLOAT_IMG; }
40 static int ImageType(r_8 d) { return DOUBLE_IMG; }
41
42 // Conversion de type en constante datatype FITS
43 static int DataType(uint_1 d) { return TBYTE; }
44 static int DataType(int_2 d) { return TSHORT; }
45 static int DataType(uint_2 d) { return TUSHORT; }
46
47 static int DataType(const int_4 d)
48 { return (sizeof(long)==4) ? TLONG: TINT; }
49 static int DataType(const uint_4 d)
50 { return (sizeof(long)==4) ? TULONG: TUINT; }
51
52#ifdef TLONGLONG
53 static int DataType(int_8 d) { return TLONGLONG; }
54#else
55 static int DataType(int_8 d)
56 { throw FitsIOException("FitsDataTypes: Unsupported data type int_8"); }
57#endif
58
59 static int DataType(r_4 d) { return TFLOAT; }
60 static int DataType(r_8 d) { return TDOUBLE; }
61
62 static int DataType(complex<r_4> d) { return TCOMPLEX; }
63 static int DataType(complex<r_8> d) { return TDBLCOMPLEX; }
64
65 static int DataType(char* d) { return TSTRING; }
66
67 // Conversion entre type FITS et chaine - exemple TFLOAT -> r_4
68 static string ImageTypeToTypeString(int ityp);
69 static string DataTypeToTypeString(int ityp);
70};
71
72/*!
73 \ingroup FitsIOServer
74 \brief Wrapper class for cfitsio library functions
75*/
76class FitsInOutFile {
77public :
78 //! File access mode (ReadOnly, ReadWrite, Create)
79 enum FitsIOMode { Fits_RO, Fits_RW, Fits_Create };
80
81 FitsInOutFile();
82 FitsInOutFile(string const & name, FitsIOMode mode);
83 FitsInOutFile(const char* name, FitsIOMode mode);
84 FitsInOutFile(FitsInOutFile const& fios);
85 virtual ~FitsInOutFile();
86
87
88 void Open(const char* name, FitsIOMode mode);
89 void Close();
90
91 void ShareFitsPtr(FitsInOutFile const& fios);
92
93 inline fitsfile* FitsPtr() const { return fptr_; }
94 static float cfitsioVersion();
95 //! Return the SOPHYA FitsIOServer version
96 static float Version() { return 2.0; }
97
98 //! Return the file name as specified in the constructor (or Open)
99 inline string FileName() { return fname_; }
100
101 //---- Header manipulation methods
102 //! Return total number of HDU's in file
103 int NbHDUs() const;
104 //! Return current HDU number - starting from 1 , not zero
105 int CurrentHDU() const;
106 //! Return current HDU Type as IMAGE_HDU or BINARY_TBL or ASCII_TBL
107 int CurrentHDUType() const;
108 //! Return current HDU Type as a string IMAGE_HDU or BINARY_TBL or ASCII_TBL
109 string CurrentHDUTypeStr() const;
110
111 //! Move to HDU specified by hdnum - Returns the newly opened HDU type
112 int MoveAbsToHDU(int hdunum);
113 //! Move to HDU specified by relhdu , relative to the current HDU - Returns the newly opened HDU type
114 int MoveRelToHDU(int relhdu);
115 //! Move to the next HDU specified by relhdu. Returns the newly opened HDU type (<0 at EOF)
116 int MoveToNextHDU();
117
118 //---- IMAGE_HDU manipulation methods
119 //! Creates a new HDU of type image (see fits_create_img)
120 void CreateImageHDU(int bitpix, int naxis, long* naxes);
121 //! Get information about the current image HDU. - return the image type TBYTE,TINT ...
122 int GetImageHDUInfo(int& naxis, long* naxes) const;
123
124 //---- BINARY_TBL or ASCII_TBL
125 //! Return number of rows in a table HDU
126 long GetNbRows() const;
127 //! Return number of columns in a table HDU
128 int GetNbCols() const;
129 //! Creation of a new table - tbltyp = BINARY_TBL or ASCII_TBL
130 void CreateTable(int tbltyp, const char * extname, int ncols,
131 char * colnames[], char * tform[],
132 char * tunit[], long ininr=0);
133 //! Creation of a new table - tbltyp = BINARY_TBL or ASCII_TBL
134 void CreateTable(int tbltyp, const string & extname,
135 const vector<string> & colnames,
136 const vector<string> & tform,
137 const vector<string> & tunit,
138 long ininr=0);
139 //! Return number of columns, names, types and repeat count
140 long GetColInfo(vector<string> & colnames,
141 vector<int> & coltypes,
142 vector<long> & repcnt,
143 vector<long> & width);
144
145 //! Defines the extension name for the next table creation
146 inline void SetNextExtensionName(string const & extname)
147 { next_extname_ = extname; }
148 //! Defines the extension name for the next table creation
149 inline void SetNextExtensionName(const char * extname)
150 { next_extname_ = extname; }
151 //! Return the default extension name
152 inline string NextExtensionName() const
153 { return next_extname_; }
154
155 //! Defines default table type for created tables as BINARY_TBL
156 inline void SetDef_BinTable() { def_tbltype = BINARY_TBL; }
157 //! Defines default table type for created tables as ASCII_TBL
158 inline void SetDef_AscTable() { def_tbltype = ASCII_TBL; }
159 //! Return default table type
160 inline int GetDef_TableType() { return def_tbltype; }
161
162 //! Defines default column width for strings (Aw)
163 inline void SetDef_StrColWidth(long w=16) { def_strcolw = w; }
164 //! Return default column width for strings (Aw)
165 inline long GetDef_StrColWidth() { return def_strcolw; }
166
167 //! Insert (add) a new column
168 void InsertColumn(int numcol, const char* colname, const char* fmt);
169 //! Insert (add) a new column
170 inline void InsertColumn(int numcol, const string& colname, const char* fmt)
171 { InsertColumn(numcol, colname.c_str(), fmt); }
172
173
174 // Manipulation des informations de l'entete
175 //! Retrieve a keyword value from the header
176 inline string KeyValue(string const & key)
177 { bool nosk; return KeyValue(key, nosk); }
178 //! Retrieve a keyword value from the header
179 string KeyValue(string const & key, bool& nosk);
180 //! Read header records and appends the information to dvl
181 int GetHeaderRecords(DVList& dvl,
182 bool stripkw= true, bool keepstkey=true);
183 //! Appends a keyword to FITS header
184 void WriteKey(const char * kname, MuTyV const & val,
185 const char *comm=NULL);
186 inline void WriteKey(string const & kname, MuTyV const & val, string const & comm)
187 { WriteKey(kname.c_str(), val, comm.c_str()); }
188 //! Write dvl information to fits header
189 int WriteHeaderRecords(DVList & dvl);
190
191 //! Prints information about the fits file on standard output stream (cout)
192 inline void Print(int lev=0) const { Print(cout, lev); }
193 //! Prints information about the fits file on stream os
194 virtual void Print(ostream& os, int lev=0) const;
195
196protected:
197 fitsfile *fptr_; // pointer to the FITS file, defined in fitsio.h
198 string fname_; // File name as passed to creator
199 FitsIOMode mode_;
200 bool ownfptr; // If true, owns the FitsPointer, which will be closed by the destructor
201
202 // Default extension name
203 string next_extname_;
204 // Default table type
205 int def_tbltype;
206 // default column width for strings
207 long def_strcolw;
208};
209
210/*! Prints FITS file information on stream \b s ( fio.Print(s) ) */
211
212inline ostream& operator << (ostream& s, FitsInOutFile const & fio)
213 { fio.Print(s); return(s); }
214
215} // Fin du namespace
216
217#endif
Note: See TracBrowser for help on using the repository browser.