source: tags/release-1.1.5/src/Detection/columns.hh @ 1441

Last change on this file since 1441 was 440, checked in by MatthewWhiting, 16 years ago

Finished the meddling with the output. Now using the new functions to write to the tables, and have moved and revamped the VOTable functions -- they now respond to the precision options.

File size: 8.2 KB
Line 
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
36namespace duchamp
37{
38
39  class Detection;
40  class FitsHeader;
41
42  /**
43   * A namespace controlling the formatting of columns of output for Duchamp.
44   */
45
46  namespace Column
47  {
48    // First, define some basic quantities.
49    // The default values for the columns, and default values for
50    //  the precision of different types of columns.
51
52    /** Total number of columns being considered.*/
53    const int numColumns=34;   
54    /** Enumerated column titles */
55    enum COLNAME {NUM=0, NAME, X, Y, Z,
56                  RA, DEC, RAJD, DECJD, VEL,
57                  WRA, WDEC, WVEL,
58                  FINT, FTOT, FPEAK, SNRPEAK,
59                  X1, X2, Y1, Y2, Z1, Z2, NPIX, FLAG,
60                  XAV, YAV, ZAV, XCENT, YCENT, ZCENT,
61                  XPEAK, YPEAK, ZPEAK,
62                  UNKNOWN};  // the last is for unclassified columns
63
64    /** Guide for which columns are used for the results file */
65    const bool isFile[numColumns+1]=
66      {true,true,true,true,true,
67       true,true,false,false,true,
68       true,true,true,
69       true,true,true,true,
70       true,true,true,true,true,true,true,true,
71       true,true,true,true,true,true,
72       true,true,true,
73       false};
74
75    /** 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,
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};
85
86    /** Guide for which columns are used for the log file */
87    const bool isLog[numColumns+1]=
88      {true,false,true,true,true,
89       false,false,false,false,false,
90       false,false,false,
91       false,true,true,true,
92       true,true,true,true,true,true,true,false,
93       false,false,false,false,false,false,
94       false,false,false,
95       false};
96
97     /** Guide for which columns are used for the VOTable file */
98    const bool isVOTable[numColumns+1]=
99      {true,true,false,false,false,
100       false,false,true,true,true,
101       true,true,true,
102       true,true,true,true,
103       false,false,false,false,false,false,false,true,
104       true,true,true,true,true,true,
105       true,true,true,
106       false};
107
108    /** Total number of columns used in logfile (no WCS ones). */
109    const int numColumnsLog=14;
110    /** Enumerated column titles for logfile*/
111    enum LOGNAME {lNUM=0, lX, lY, lZ,
112                  lFTOT, lFPEAK, lSNRPEAK,
113                  lX1, lX2, lY1, lY2, lZ1, lZ2, lNPIX};
114
115    /** Number of types of precision. */
116    const int numPrec=6;       
117    /** Enumerated precision categories */
118    enum PrecType {prFLUX=3, prVEL=3, prXYZ=1, prPOS=6, prWPOS=2, prSNR=2};
119
120    /** Default widths of all columns.*/
121    const int defaultWidth[numColumns+1]=
122      {5, 8, 6, 6, 6,
123       13, 13, 11, 11, 7, 9, 9, 7,
124       10, 10, 9, 7,
125       4, 4, 4, 4, 4, 4, 6, 5,
126       6, 6, 6, 7, 7, 7, 7, 7, 7,
127       1};
128
129    /** Default precisions for all columns.*/
130    const int defaultPrec[numColumns+1]=
131      {0, 0, prXYZ, prXYZ, prXYZ,
132       0, 0, prPOS, prPOS, prVEL,
133       prWPOS, prWPOS, prVEL,
134       prFLUX, prFLUX, prFLUX,
135       prSNR, 0, 0, 0, 0, 0, 0, 0, 0,
136       prXYZ, prXYZ, prXYZ,
137       prXYZ, prXYZ, prXYZ,
138       prXYZ, prXYZ, prXYZ,
139       0};
140
141    /** Default Titles of all columns. */
142    const std::string defaultName[numColumns+1]=
143      {"Obj#","Name","X","Y","Z",
144       "RA","DEC","RAJD","DECJD","VEL",
145       "w_RA","w_DEC","w_VEL",
146       "F_int","F_tot","F_peak", "S/Nmax",
147       "X1","X2","Y1","Y2","Z1","Z2","Npix","Flag",
148       "X_av", "Y_av", "Z_av", "X_cent", "Y_cent", "Z_cent",
149       "X_peak", "Y_peak", "Z_peak",
150       " "};
151
152    /** Default units of all columns. */
153    const std::string defaultUnits[numColumns+1]=
154      {"","","","","",
155       "","","[deg]","[deg]","",
156       "[arcmin]","[arcmin]","",
157       "","","", "",
158       "","","","","","","[pix]","",
159       "","","","","","","","","",
160       ""};
161
162
163    /** Class to store information about a single column.
164     * This contains information about a given column -- its width, the
165     *  precision associated with it, its title and the units.
166     * Plus the usual array of accessor functions and so on.
167     */
168    class Col{
169    public:
170      Col();          ///< Basic constructor
171      Col(int num, int prec=-1);   ///< Specific constructor
172      Col(const Col& c);///< Assignment constructor
173      Col& operator=(const Col& c); ///< Copy constructor
174      virtual ~Col(); ///< Default destructor;
175      //--------------
176      // basic accessor functions
177      //
178      int    getWidth(){return width;};         
179      void   setWidth(int i){width=i;};   
180      int    getPrecision(){return precision;};     
181      void   setPrecision(int i){precision=i;};
182      std::string getName(){return name;};         
183      void   setName(std::string s){name=s;}; 
184      std::string getUnits(){return units;};         
185      void   setUnits(std::string s){units=s;};
186      COLNAME getType(){return type;};
187      void   setType(COLNAME coltype){type=coltype;};
188
189      //--------------
190      // other functions
191      //
192      /** Make the column one space wider. */
193      void   widen(){width++;};
194
195      /** Increase the precision by one, widening the column if necessary. */
196      void   upPrec(){precision++; width++;};
197
198      //--------------
199      // Outputting functions -- all in columns.cc
200      //
201      /** write the title of the column to the stream */
202      void   printTitle(std::ostream &stream);
203
204      /** write the units of the column to the stream */
205      void   printUnits(std::ostream &stream);
206
207      /** write dashes the full width of the column to the stream */
208      void   printDash (std::ostream &stream);
209
210      /** write blanks the full width of the column to the stream */
211      void   printBlank(std::ostream &stream);
212
213      /** Print a given value in a column with correct width & precision. */
214      template <class T> void printEntry(std::ostream &stream, T value);
215
216      /** Decides whether the column is used for a given table type */
217      bool   doCol(std::string type, bool flagFint=true);
218
219
220    private:
221      int width;          ///< How wide is the column (in ascii spaces)
222      int precision;      ///< What precision should be used to print
223                          ///   the values? (If 0, the setprecision command
224                          ///   is not used.)
225      std::string name;   ///< The title of the column
226      std::string units;  ///< The units that the values in the column
227                          ///   are expressed in.
228      COLNAME type;       ///< The type of the column
229    };
230
231 
232    /** Returns a vector of Col for results file output.*/
233    std::vector<Column::Col> getFullColSet(std::vector<Detection> &objectList,
234                                           FitsHeader &head);
235
236    /** Returns a vector of Col for logfile output.*/
237    std::vector<Column::Col> getLogColSet(std::vector<Detection> &objectList,
238                                          FitsHeader &head);
239
240  }
241
242}
243
244#endif
245
Note: See TracBrowser for help on using the repository browser.