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

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

debut modifs nouveau fits pour support I/O chaines de caracteres - Reza 18/11/2005

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