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

Last change on this file since 2860 was 2860, checked in by ansari, 20 years ago

Ajout constructeur de copie (pas parfait) pour FitsInOutFile + modifs classes FitsFile/FitsInFile/FitsOutFile pour heriter de FitsInOutFile avec constructeur a partir de FitsInOutFile - Reza 20/12/2005

  • Property svn:executable set to *
File size: 7.7 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 inline fitsfile* FitsPtr() const { return fptr_; }
92 static float cfitsioVersion();
93 //! Return the SOPHYA FitsIOServer version
94 static float Version() { return 2.0; }
95
96 //---- Header manipulation methods
97 //! Return total number of HDU's in file
98 int NbHDUs() const;
99 //! Return current HDU number - starting from 1 , not zero
100 int CurrentHDU() const;
101 //! Return current HDU Type as IMAGE_HDU or BINARY_TBL or ASCII_TBL
102 int CurrentHDUType() const;
103 //! Return current HDU Type as a string IMAGE_HDU or BINARY_TBL or ASCII_TBL
104 string CurrentHDUTypeStr() const;
105
106 //! Move to HDU specified by hdnum - Returns the newly opened HDU type
107 int MoveAbsToHDU(int hdunum);
108 //! Move to HDU specified by relhdu , relative to the current HDU - Returns the newly opened HDU type
109 int MoveRelToHDU(int relhdu);
110 //! Move to the next HDU specified by relhdu. Returns the newly opened HDU type (<0 at EOF)
111 int MoveToNextHDU();
112
113 //---- IMAGE_HDU manipulation methods
114 //! Creates a new HDU of type image (see fits_create_img)
115 void CreateImageHDU(int bitpix, int naxis, long* naxes);
116 //! Get information about the current image HDU. - return the image type TBYTE,TINT ...
117 int GetImageHDUInfo(int& naxis, long* naxes) const;
118
119 //---- BINARY_TBL or ASCII_TBL
120 //! Return number of rows in a table HDU
121 long GetNbRows() const;
122 //! Return number of columns in a table HDU
123 int GetNbCols() const;
124 //! Creation of a new table - tbltyp = BINARY_TBL or ASCII_TBL
125 void CreateTable(int tbltyp, const char * extname, int ncols,
126 char * colnames[], char * tform[],
127 char * tunit[], long ininr=0);
128 //! Creation of a new table - tbltyp = BINARY_TBL or ASCII_TBL
129 void CreateTable(int tbltyp, const string & extname,
130 const vector<string> & colnames,
131 const vector<string> & tform,
132 const vector<string> & tunit,
133 long ininr=0);
134 //! Return number of columns, names, types and repeat count
135 long GetColInfo(vector<string> & colnames,
136 vector<int> & coltypes,
137 vector<long> & repcnt,
138 vector<long> & width);
139
140 //! Defines the extension name for the next table creation
141 inline void SetNextExtensionName(string const & extname)
142 { next_extname_ = extname; }
143 //! Defines the extension name for the next table creation
144 inline void SetNextExtensionName(const char * extname)
145 { next_extname_ = extname; }
146 //! Return the default extension name
147 inline string NextExtensionName() const
148 { return next_extname_; }
149
150 //! Defines default table type for created tables as BINARY_TBL
151 inline void SetDef_BinTable() { def_tbltype = BINARY_TBL; }
152 //! Defines default table type for created tables as ASCII_TBL
153 inline void SetDef_AscTable() { def_tbltype = ASCII_TBL; }
154 //! Return default table type
155 inline int GetDef_TableType() { return def_tbltype; }
156
157 //! Defines default column width for strings (Aw)
158 inline void SetDef_StrColWidth(long w=16) { def_strcolw = w; }
159 //! Return default column width for strings (Aw)
160 inline long GetDef_StrColWidth() { return def_strcolw; }
161
162 //! Insert (add) a new column
163 void InsertColumn(int numcol, const char* colname, const char* fmt);
164 //! Insert (add) a new column
165 inline void InsertColumn(int numcol, const string& colname, const char* fmt)
166 { InsertColumn(numcol, colname.c_str(), fmt); }
167
168
169 // Manipulation des informations de l'entete
170 //! Retrieve a keyword value from the header
171 inline string KeyValue(string const & key)
172 { bool nosk; return KeyValue(key, nosk); }
173 //! Retrieve a keyword value from the header
174 string KeyValue(string const & key, bool& nosk);
175 //! Read header records and appends the information to dvl
176 int GetHeaderRecords(DVList& dvl);
177 //! Appends a keyword to FITS header
178 void WriteKey(const char * kname, MuTyV const & val,
179 const char *comm=NULL);
180 inline void WriteKey(string const & kname, MuTyV const & val, string const & comm)
181 { WriteKey(kname.c_str(), val, comm.c_str()); }
182 //! Write dvl information to fits header
183 int WriteHeaderRecords(DVList & dvl);
184
185 //! Prints information about the fits file on standard output stream (cout)
186 inline void Print(int lev=0) const { Print(cout, lev); }
187 //! Prints information about the fits file on stream os
188 virtual void Print(ostream& os, int lev=0) const;
189
190protected:
191 fitsfile *fptr_; // pointer to the FITS file, defined in fitsio.h
192 string fname_; // File name as passed to creator
193 FitsIOMode mode_;
194 bool ownfptr; // If true, owns the FitsPointer, which will be closed by the destructor
195
196 // Default extension name
197 string next_extname_;
198 // Default table type
199 int def_tbltype;
200 // default column width for strings
201 long def_strcolw;
202};
203
204/*! Prints FITS file information on stream \b s ( fio.Print(s) ) */
205
206inline ostream& operator << (ostream& s, FitsInOutFile const & fio)
207 { fio.Print(s); return(s); }
208
209} // Fin du namespace
210
211#endif
Note: See TracBrowser for help on using the repository browser.