1 | #ifndef COLUMNS_H |
---|
2 | #define COLUMNS_H |
---|
3 | |
---|
4 | #include <iostream> |
---|
5 | #include <iomanip> |
---|
6 | #include <string> |
---|
7 | #include <vector> |
---|
8 | |
---|
9 | class Detection; |
---|
10 | class FitsHeader; |
---|
11 | |
---|
12 | /** |
---|
13 | * A namespace controlling the formatting of columns of output for Duchamp. |
---|
14 | */ |
---|
15 | |
---|
16 | namespace Column |
---|
17 | { |
---|
18 | // First, define some basic quantities. |
---|
19 | // The default values for the columns, and default values for |
---|
20 | // the precision of different types of columns. |
---|
21 | |
---|
22 | const int numColumns=23; ///< Total number of columns being considered. |
---|
23 | /** Enumerated column titles */ |
---|
24 | enum COLNAME {NUM=0, NAME, X, Y, Z, |
---|
25 | RA, DEC, VEL, |
---|
26 | WRA, WDEC, WVEL, |
---|
27 | FINT, FTOT, FPEAK, SNRPEAK, |
---|
28 | X1, X2, Y1, Y2, Z1, Z2, NPIX, FLAG}; |
---|
29 | |
---|
30 | const int numColumnsLog=14; ///< Total number of columns used in logfile (no WCS ones). |
---|
31 | /** Enumerated column titles for logfile*/ |
---|
32 | enum LOGNAME {lNUM, lX, lY, lZ, |
---|
33 | lFTOT, lFPEAK, lSNRPEAK, |
---|
34 | lX1, lX2, lY1, lY2, lZ1, lZ2, lNPIX}; |
---|
35 | |
---|
36 | |
---|
37 | const int numPrec=6; ///< Number of types of precision |
---|
38 | enum PrecType {prFLUX, prVEL, prXYZ, prPOS, prWPOS, prSNR}; ///< Enumerated precision categories |
---|
39 | const int prec[numPrec]={3, 3, 1, 6, 2, 2}; ///< Precision values in same order as enum list. |
---|
40 | |
---|
41 | const int defaultWidth[numColumns]= |
---|
42 | {5, 8, 6, 6, 6, |
---|
43 | 13, 13, 7, 9, 9, 7, |
---|
44 | 10, 10, 9, 7, |
---|
45 | 4, 4, 4, 4, 4, 4, 6, 5}; ///< Default widths of all columns. |
---|
46 | const int defaultPrec[numColumns]= |
---|
47 | {0, 0, prec[prXYZ], prec[prXYZ], prec[prXYZ], |
---|
48 | 0, 0, prec[prVEL], |
---|
49 | prec[prWPOS], prec[prWPOS], prec[prVEL], |
---|
50 | prec[prFLUX], prec[prFLUX], prec[prFLUX], |
---|
51 | prec[prSNR], 0, 0, 0, 0, 0, 0, 0, 0}; ///< Default precisions for all columns. |
---|
52 | const std::string defaultName[numColumns]= |
---|
53 | {"Obj#","Name","X","Y","Z", |
---|
54 | "RA","DEC","VEL", |
---|
55 | "w_RA","w_DEC","w_VEL", |
---|
56 | "F_int","F_tot","F_peak", "S/Nmax", |
---|
57 | "X1","X2","Y1","Y2","Z1","Z2","Npix","Flag"}; ///< Default Titles of all columns |
---|
58 | const std::string defaultUnits[numColumns]= |
---|
59 | {"","","","","", |
---|
60 | "","","", |
---|
61 | "[arcmin]","[arcmin]","", |
---|
62 | "","","", "", |
---|
63 | "","","","","","","[pix]",""}; ///< Default units of all columns. |
---|
64 | |
---|
65 | |
---|
66 | /** Class to store information about a single column. |
---|
67 | * This contains information about a given column -- its width, the |
---|
68 | * precision associated with it, its title and the units. |
---|
69 | * Plus the usual array of accessor functions and so on. |
---|
70 | */ |
---|
71 | class Col{ |
---|
72 | public: |
---|
73 | Col(); ///< Basic constructor |
---|
74 | Col(int num); ///< Specific constructor |
---|
75 | virtual ~Col(); ///< Default destructor; |
---|
76 | //-------------- |
---|
77 | // basic accessor functions |
---|
78 | // |
---|
79 | int getWidth(){return width;}; |
---|
80 | void setWidth(int i){width=i;}; |
---|
81 | int getPrecision(){return precision;}; |
---|
82 | void setPrecision(int i){precision=i;}; |
---|
83 | std::string getName(){return name;}; |
---|
84 | void setName(std::string s){name=s;}; |
---|
85 | std::string getUnits(){return units;}; |
---|
86 | void setUnits(std::string s){units=s;}; |
---|
87 | |
---|
88 | //-------------- |
---|
89 | // other functions |
---|
90 | // |
---|
91 | /** Make the column one space wider. */ |
---|
92 | int widen(){width++;}; |
---|
93 | |
---|
94 | /** Increase the precision by one, widening the column if necessary. */ |
---|
95 | int upPrec(){precision++; if(width<precision+3) width++;}; |
---|
96 | |
---|
97 | //-------------- |
---|
98 | // Outputting functions -- all in columns.cc |
---|
99 | // |
---|
100 | /** write the title of the column to the stream */ |
---|
101 | void printTitle(std::ostream &stream){ |
---|
102 | stream << std::setw(this->width) << std::setfill(' ') << this->name; |
---|
103 | }; |
---|
104 | |
---|
105 | /** write the units of the column to the stream */ |
---|
106 | void printUnits(std::ostream &stream){ |
---|
107 | stream << std::setw(this->width) << std::setfill(' ') << this->units; |
---|
108 | }; |
---|
109 | |
---|
110 | /** write dashes the full width of the column to the stream */ |
---|
111 | void printDash (std::ostream &stream){ |
---|
112 | stream << std::setw(this->width) << std::setfill('-') |
---|
113 | << "" << std::setfill(' '); |
---|
114 | }; |
---|
115 | |
---|
116 | /** write blanks the full width of the column to the stream */ |
---|
117 | void printBlank(std::ostream &stream){ |
---|
118 | stream << std::setw(this->width) << std::setfill(' ') << ""; |
---|
119 | }; |
---|
120 | |
---|
121 | /** Print a given value in a column with correct width & precision. */ |
---|
122 | template <class T> void printEntry(std::ostream &stream, T value)//; |
---|
123 | { |
---|
124 | stream << std::setprecision(this->precision) |
---|
125 | << std::setw(this->width) |
---|
126 | << std::setfill(' ') |
---|
127 | << value; |
---|
128 | }; |
---|
129 | // template void Col::printEntry<int>(std::ostream &stream, int value); |
---|
130 | // template void Col::printEntry<long>(std::ostream &stream, long value); |
---|
131 | // template void Col::printEntry<unsigned>(std::ostream &stream, unsigned value); |
---|
132 | // template void Col::printEntry<float>(std::ostream &stream, float value); |
---|
133 | // template void Col::printEntry<double>(std::ostream &stream, double value); |
---|
134 | // template void Col::printEntry<std::string>(std::ostream &stream, std::string value); |
---|
135 | |
---|
136 | private: |
---|
137 | int width; ///< How wide is the column (in ascii spaces) |
---|
138 | int precision; ///< What precision should be used to print the values? (If 0, the setprecision command is not used.) |
---|
139 | std::string name; ///< The title of the column |
---|
140 | std::string units; ///< The units that the values in the column are expressed in. |
---|
141 | }; |
---|
142 | |
---|
143 | |
---|
144 | } |
---|
145 | |
---|
146 | /** Returns a vector of Col for results file output.*/ |
---|
147 | std::vector<Column::Col> getFullColSet(std::vector<Detection> &objectList, |
---|
148 | FitsHeader &head); |
---|
149 | |
---|
150 | /** Returns a vector of Col for logfile output.*/ |
---|
151 | std::vector<Column::Col> getLogColSet(std::vector<Detection> &objectList, |
---|
152 | FitsHeader &head); |
---|
153 | |
---|
154 | |
---|
155 | #endif |
---|
156 | |
---|