1 | // ----------------------------------------------------------------------- |
---|
2 | // columns.hh: Define the column class that formats Duchamp output. |
---|
3 | // ----------------------------------------------------------------------- |
---|
4 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
5 | // |
---|
6 | // This program is free software; you can redistribute it and/or modify it |
---|
7 | // under the terms of the GNU General Public License as published by the |
---|
8 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
9 | // option) any later version. |
---|
10 | // |
---|
11 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
12 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
13 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
14 | // for more details. |
---|
15 | // |
---|
16 | // You should have received a copy of the GNU General Public License |
---|
17 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
18 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
19 | // |
---|
20 | // Correspondence concerning Duchamp may be directed to: |
---|
21 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
22 | // Postal address: Dr. Matthew Whiting |
---|
23 | // Australia Telescope National Facility, CSIRO |
---|
24 | // PO Box 76 |
---|
25 | // Epping NSW 1710 |
---|
26 | // AUSTRALIA |
---|
27 | // ----------------------------------------------------------------------- |
---|
28 | #ifndef COLUMNS_H |
---|
29 | #define COLUMNS_H |
---|
30 | |
---|
31 | #include <iostream> |
---|
32 | #include <iomanip> |
---|
33 | #include <string> |
---|
34 | #include <vector> |
---|
35 | |
---|
36 | namespace duchamp |
---|
37 | { |
---|
38 | |
---|
39 | class Detection; |
---|
40 | class FitsHeader; |
---|
41 | |
---|
42 | /// A namespace controlling the formatting of columns of output for Duchamp. |
---|
43 | |
---|
44 | namespace Column |
---|
45 | { |
---|
46 | // First, define some basic quantities. |
---|
47 | // The default values for the columns, and default values for |
---|
48 | // the precision of different types of columns. |
---|
49 | |
---|
50 | /// @brief Total number of columns being considered. |
---|
51 | const int numColumns=38; |
---|
52 | /// @brief Enumerated column titles |
---|
53 | enum COLNAME {NUM=0, NAME, X, Y, Z, |
---|
54 | RA, DEC, RAJD, DECJD, VEL, |
---|
55 | WRA, WDEC, W50, W20, WVEL, |
---|
56 | FINT, FTOT, FPEAK, SNRPEAK, |
---|
57 | X1, X2, Y1, Y2, Z1, Z2, NPIX, FLAG, |
---|
58 | XAV, YAV, ZAV, XCENT, YCENT, ZCENT, |
---|
59 | XPEAK, YPEAK, ZPEAK, |
---|
60 | NUMCH, SPATSIZE, |
---|
61 | UNKNOWN}; // the last is for unclassified columns |
---|
62 | |
---|
63 | /// @brief Guide for which columns are used for the results file |
---|
64 | const bool isFile[numColumns+1]= |
---|
65 | {true,true,true,true,true, |
---|
66 | true,true,false,false,true, |
---|
67 | true,true,true,true,true, |
---|
68 | true,true,true,true, |
---|
69 | true,true,true,true,true,true,true,true, |
---|
70 | true,true,true,true,true,true, |
---|
71 | true,true,true, |
---|
72 | false,false, |
---|
73 | false}; |
---|
74 | |
---|
75 | /// @brief Guide for which columns are used for the results printed to screen |
---|
76 | const bool isScreen[numColumns+1]= |
---|
77 | {true,true,true,true,true, |
---|
78 | true,true,false,false,true, |
---|
79 | true,true,true,false,false, |
---|
80 | true,true,true,true, |
---|
81 | true,true,true,true,true,true,true,true, |
---|
82 | false,false,false,false,false,false, |
---|
83 | false,false,false, |
---|
84 | false,false, |
---|
85 | false}; |
---|
86 | |
---|
87 | /// @brief Guide for which columns are used for the log file |
---|
88 | const bool isLog[numColumns+1]= |
---|
89 | {true,false,true,true,true, |
---|
90 | false,false,false,false,false, |
---|
91 | false,false,false,false,false, |
---|
92 | false,true,true,true, |
---|
93 | true,true,true,true,true,true,true,false, |
---|
94 | false,false,false,false,false,false, |
---|
95 | false,false,false, |
---|
96 | true,true, |
---|
97 | false}; |
---|
98 | |
---|
99 | /// @brief Guide for which columns are used for the VOTable file |
---|
100 | const bool isVOTable[numColumns+1]= |
---|
101 | {true,true,false,false,false, |
---|
102 | false,false,true,true,true, |
---|
103 | true,true,true,true,true, |
---|
104 | true,true,true,true, |
---|
105 | false,false,false,false,false,false,false,true, |
---|
106 | true,true,true,true,true,true, |
---|
107 | true,true,true, |
---|
108 | false,false, |
---|
109 | false}; |
---|
110 | |
---|
111 | /// @brief Total number of columns used in logfile (no WCS ones). |
---|
112 | const int numColumnsLog=16; |
---|
113 | /// @brief Enumerated column titles for logfile |
---|
114 | enum LOGNAME {lNUM=0, lX, lY, lZ, |
---|
115 | lFTOT, lFPEAK, lSNRPEAK, |
---|
116 | lX1, lX2, lY1, lY2, lZ1, lZ2, lNPIX, |
---|
117 | lNUMCH, lSPATSIZE}; |
---|
118 | |
---|
119 | /// @brief Number of types of precision. |
---|
120 | const int numPrec=6; |
---|
121 | /// @brief Enumerated precision categories |
---|
122 | enum PrecType {prFLUX=3, prVEL=3, prXYZ=1, prPOS=6, prWPOS=2, prSNR=2}; |
---|
123 | |
---|
124 | /// @brief Default widths of all columns. |
---|
125 | const int defaultWidth[numColumns+1]= |
---|
126 | {5, 8, 6, 6, 6, |
---|
127 | 13, 13, 11, 11, 7, |
---|
128 | 9, 9, 7, 7, 7, |
---|
129 | 10, 10, 9, 7, |
---|
130 | 4, 4, 4, 4, 4, 4, 6, 5, |
---|
131 | 6, 6, 6, 7, 7, 7, |
---|
132 | 7, 7, 7, |
---|
133 | 6, 8, |
---|
134 | 1}; |
---|
135 | |
---|
136 | /// @brief Default precisions for all columns. |
---|
137 | const int defaultPrec[numColumns+1]= |
---|
138 | {0, 0, prXYZ, prXYZ, prXYZ, |
---|
139 | 0, 0, prPOS, prPOS, prVEL, |
---|
140 | prWPOS, prWPOS, prVEL, prVEL, prVEL, |
---|
141 | prFLUX, prFLUX, prFLUX, |
---|
142 | prSNR, 0, 0, 0, 0, 0, 0, 0, 0, |
---|
143 | prXYZ, prXYZ, prXYZ, prXYZ, prXYZ, prXYZ, |
---|
144 | prXYZ, prXYZ, prXYZ, |
---|
145 | 0, 0, |
---|
146 | 0}; |
---|
147 | |
---|
148 | /// @brief Default Titles of all columns. |
---|
149 | const std::string defaultName[numColumns+1]= |
---|
150 | {"Obj#","Name","X","Y","Z", |
---|
151 | "RA","DEC","RAJD","DECJD","VEL", |
---|
152 | "w_RA","w_DEC","w_50","w_20","w_VEL", |
---|
153 | "F_int","F_tot","F_peak", "S/Nmax", |
---|
154 | "X1","X2","Y1","Y2","Z1","Z2","Npix","Flag", |
---|
155 | "X_av", "Y_av", "Z_av", "X_cent", "Y_cent", "Z_cent", |
---|
156 | "X_peak", "Y_peak", "Z_peak", |
---|
157 | "Nch", "Sp_size", |
---|
158 | " "}; |
---|
159 | |
---|
160 | /// @brief Default units of all columns. |
---|
161 | const std::string defaultUnits[numColumns+1]= |
---|
162 | {"","","","","", |
---|
163 | "","","[deg]","[deg]","", |
---|
164 | "[arcmin]","[arcmin]","","","", |
---|
165 | "","","", "", |
---|
166 | "","","","","","","[pix]","", |
---|
167 | "","","","","","","","","", |
---|
168 | "","", |
---|
169 | ""}; |
---|
170 | |
---|
171 | |
---|
172 | /// @brief Class to store information about a single column. |
---|
173 | /// |
---|
174 | /// @details This contains information about a given column -- |
---|
175 | /// its width, the precision associated with it, its title and |
---|
176 | /// the units. Plus the usual array of accessor functions and so |
---|
177 | /// on. |
---|
178 | |
---|
179 | class Col{ |
---|
180 | public: |
---|
181 | Col(); ///< Basic constructor |
---|
182 | Col(int num, int prec=-1); ///< Specific constructor |
---|
183 | Col(std::string name, std::string units, int width, int prec); ///< Generic constructor |
---|
184 | Col(const Col& c);///< Assignment constructor |
---|
185 | Col& operator=(const Col& c); ///< Copy constructor |
---|
186 | virtual ~Col(); ///< Default destructor; |
---|
187 | //-------------- |
---|
188 | // basic accessor functions |
---|
189 | // |
---|
190 | int getWidth(){return width;}; |
---|
191 | void setWidth(int i){width=i;}; |
---|
192 | int getPrecision(){return precision;}; |
---|
193 | void setPrecision(int i){precision=i;}; |
---|
194 | std::string getName(){return name;}; |
---|
195 | void setName(std::string s){name=s;}; |
---|
196 | std::string getUnits(){return units;}; |
---|
197 | void setUnits(std::string s){units=s;}; |
---|
198 | COLNAME getType(){return type;}; |
---|
199 | void setType(COLNAME coltype){type=coltype;}; |
---|
200 | |
---|
201 | //-------------- |
---|
202 | // other functions |
---|
203 | // |
---|
204 | /// @brief Make the column one space wider. |
---|
205 | void widen(){width++;}; |
---|
206 | |
---|
207 | /// @brief Increase the precision by one, widening the column if necessary. |
---|
208 | void upPrec(){precision++; width++;}; |
---|
209 | |
---|
210 | void changePrec(int p); |
---|
211 | |
---|
212 | //-------------- |
---|
213 | // Outputting functions -- all in columns.cc |
---|
214 | // |
---|
215 | /// @brief write the title of the column to the stream |
---|
216 | void printTitle(std::ostream &stream); |
---|
217 | |
---|
218 | /// @brief write the units of the column to the stream |
---|
219 | void printUnits(std::ostream &stream); |
---|
220 | |
---|
221 | /// @brief write dashes the full width of the column to the stream |
---|
222 | void printDash (std::ostream &stream); |
---|
223 | |
---|
224 | /// @brief write blanks the full width of the column to the stream |
---|
225 | void printBlank(std::ostream &stream); |
---|
226 | |
---|
227 | /// @brief Print a given value in a column with correct width & precision. |
---|
228 | template <class T> void printEntry(std::ostream &stream, T value); |
---|
229 | |
---|
230 | /// @brief Decides whether the column is used for a given table type |
---|
231 | bool doCol(std::string type, bool flagFint=true); |
---|
232 | |
---|
233 | |
---|
234 | private: |
---|
235 | int width; ///< How wide is the column (in ascii spaces) |
---|
236 | int precision; ///< What precision should be used to print the values? (If 0, the setprecision command is not used.) |
---|
237 | std::string name; ///< The title of the column |
---|
238 | std::string units; ///< The units that the values in the column are expressed in. |
---|
239 | COLNAME type; ///< The type of the column |
---|
240 | }; |
---|
241 | |
---|
242 | |
---|
243 | /// @brief Returns a vector of Col for results file output. |
---|
244 | std::vector<Column::Col> getFullColSet(std::vector<Detection> &objectList, |
---|
245 | FitsHeader &head); |
---|
246 | |
---|
247 | /// @brief Returns a vector of Col for logfile output. |
---|
248 | std::vector<Column::Col> getLogColSet(std::vector<Detection> &objectList, |
---|
249 | FitsHeader &head); |
---|
250 | |
---|
251 | } |
---|
252 | |
---|
253 | } |
---|
254 | |
---|
255 | #endif |
---|
256 | |
---|