source: trunk/src/Outputs/columns.hh @ 1064

Last change on this file since 1064 was 1064, checked in by MatthewWhiting, 12 years ago

Continuing Ticket #162 -- moving to the use of CatalogueSpecification?. Also fixing a bug where the VOTable column ID string was not being set (identified via the verification script!).

File size: 12.0 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  /// A namespace controlling the formatting of columns of output for Duchamp.
43  namespace Catalogues
44  {
45
46    /// @brief An enumeration designed to cover the different output types
47    enum DESTINATION {FILE, SCREEN, LOG, VOTABLE};
48
49    // First, define some basic quantities.
50    // The default values for the columns, and default values for
51    //  the precision of different types of columns.
52
53    /// @brief Total number of columns being considered.
54    const int numColumns=38;   
55    /// @brief Enumerated column titles
56    enum COLNAME {NUM=0, NAME, X, Y, Z,
57                  RA, DEC, RAJD, DECJD, VEL,
58                  WRA, WDEC, W50, W20, WVEL,
59                  FINT, FTOT, FPEAK, SNRPEAK,
60                  X1, X2, Y1, Y2, Z1, Z2, NPIX, FLAG,
61                  XAV, YAV, ZAV, XCENT, YCENT, ZCENT,
62                  XPEAK, YPEAK, ZPEAK,
63                  NUMCH, SPATSIZE,
64                  UNKNOWN};  // the last is for unclassified columns
65
66    /// @brief Guide for which columns are used for the results file
67    const bool isFile[numColumns+1]=
68      {true,true,true,true,true,
69       true,true,false,false,true,
70       true,true,true,true,true,
71       true,true,true,true,
72       true,true,true,true,true,true,true,true,
73       true,true,true,true,true,true,
74       true,true,true,
75       false,false,
76       false};
77
78    /// @brief Guide for which columns are used for the results printed to screen
79    const bool isScreen[numColumns+1]=
80      {true,true,true,true,true,
81       true,true,false,false,true,
82       true,true,true,false,false,
83       true,true,true,true,
84       true,true,true,true,true,true,true,true,
85       false,false,false,false,false,false,
86       false,false,false,
87       false,false,
88       false};
89
90    /// @brief Guide for which columns are used for the log file
91    const bool isLog[numColumns+1]=
92      {true,false,true,true,true,
93       false,false,false,false,false,
94       false,false,false,false,false,
95       false,true,true,true,
96       true,true,true,true,true,true,true,false,
97       false,false,false,false,false,false,
98       false,false,false,
99       true,true,
100       false};
101
102     /// @brief Guide for which columns are used for the VOTable file
103    const bool isVOTable[numColumns+1]=
104      {true,true,false,false,false,
105       false,false,true,true,true,
106       true,true,true,true,true,
107       true,true,true,true,
108       false,false,false,false,false,false,false,true,
109       true,true,true,true,true,true,
110       true,true,true,
111       false,false,
112       false};
113
114    /// @brief Total number of columns used in logfile (no WCS ones).
115    const int numColumnsLog=16;
116    /// @brief Enumerated column titles for logfile
117    enum LOGNAME {lNUM=0, lX, lY, lZ,
118                  lFTOT, lFPEAK, lSNRPEAK,
119                  lX1, lX2, lY1, lY2, lZ1, lZ2, lNPIX,
120                  lNUMCH, lSPATSIZE};
121
122    /// @brief Number of types of precision.
123    const int numPrec=6;       
124    /// @brief Enumerated precision categories
125    enum PrecType {prFLUX=3, prVEL=3, prXYZ=1, prPOS=6, prWPOS=2, prSNR=2};
126
127    /// @brief Default widths of all columns.
128    const int defaultWidth[numColumns+1]=
129      {5, 8, 6, 6, 6,
130       11, 10, 11, 11, 7,
131       9, 9, 7, 7, 7,
132       10, 10, 9, 7,
133       4, 4, 4, 4, 4, 4, 6, 5,
134       6, 6, 6, 7, 7, 7,
135       7, 7, 7,
136       6, 8,
137       1};
138
139    /// @brief Default precisions for all columns.
140    const int defaultPrec[numColumns+1]=
141      {0, 0, prXYZ, prXYZ, prXYZ,
142       0, 0, prPOS, prPOS, prVEL,
143       prWPOS, prWPOS, prVEL, prVEL, prVEL,
144       prFLUX, prFLUX, prFLUX,
145       prSNR, 0, 0, 0, 0, 0, 0, 0, 0,
146       prXYZ, prXYZ, prXYZ, prXYZ, prXYZ, prXYZ,
147       prXYZ, prXYZ, prXYZ,
148       0, 0,
149       0};
150
151    /// @brief Default Titles of all columns.
152    const std::string defaultName[numColumns+1]=
153      {"Obj#","Name","X","Y","Z",
154       "RA","DEC","RAJD","DECJD","VEL",
155       "w_RA","w_DEC","w_50","w_20","w_VEL",
156       "F_int","F_tot","F_peak", "S/Nmax",
157       "X1","X2","Y1","Y2","Z1","Z2","Npix","Flag",
158       "X_av", "Y_av", "Z_av", "X_cent", "Y_cent", "Z_cent",
159       "X_peak", "Y_peak", "Z_peak",
160       "Nch", "Sp_size",
161       " "};
162
163    /// @brief The column ID (for use in a VOTable)
164    const std::string defaultColID[numColumns+1]=
165      {"col_objnum","col_name","col_x","col_y","col_z",
166       "col_ra","col_dec","col_rajd","col_decjd","col_vel",
167       "col_wra","col_wdec","col_w50","col_w20","col_wvel",
168       "col_fint","col_ftot","col_fpeak", "col_snrmax",
169       "col_x1","col_x2","col_y1","col_y2","col_z1","col_z2","col_npix","col_flag",
170       "col_xav", "col_yav", "col_zav", "col_xcent", "col_ycent", "col_zcent",
171       "col_xpeak", "col_ypeak", "col_zpeak",
172       "col_nch", "col_spsize",
173       ""};
174
175    /// @brief Default units of all columns.
176    const std::string defaultUnits[numColumns+1]=
177      {"","","","","",
178       "","","[deg]","[deg]","",
179       "[arcmin]","[arcmin]","","","",
180       "","","", "",
181       "","","","","","","[pix]","",
182       "","","","","","","","","",
183       "","",
184       ""};
185
186    /// @brief Default UCDs for all columns
187    const std::string defaultUCDs[numColumns+1] =
188      {"meta.id", "meta.id;meta.main", "pos.cartesian.x", "pos.cartesian.y", "pos.cartesian.z",
189       "", "", "", "", "",
190       "", "", "", "", "",
191       "phot.flux;spect.line.intensity", "phot.flux;spect.line.intensity", "phot.flux;spect.line.intensity", "phot.flux;stat.snr",
192       "pos.cartesian.x;stat.min", "pos.cartesian.y;stat.min", "pos.cartesian.z;stat.min", "pos.cartesian.x;stat.max", "pos.cartesian.y;stat.max", "pos.cartesian.z;stat.max", "", "meta.code.qual",
193       "pos.cartesian.x", "pos.cartesian.y", "pos.cartesian.z", "pos.cartesian.x", "pos.cartesian.y", "pos.cartesian.z",
194       "pos.cartesian.x", "pos.cartesian.y", "pos.cartesian.z",
195       "",""
196       ""};
197
198    ///@brief The datatype of each column
199    const std::string defaultDatatype[numColumns+1] =
200      {"int", "char", "float", "float", "float",
201       "char", "char", "float", "float", "float",
202       "float", "float", "float", "float", "float",
203       "float", "float", "float", "float",
204       "int", "int", "int", "int", "int", "int", "int", "char",
205       "float", "float", "float", "float", "float", "float",
206       "int", "int", "int",
207       "int", "int",
208       ""};
209
210    const std::string coordRef="J2000";
211    /// @brief Default values for the VOTable reference string
212    const std::string defaultExtraInfo[numColumns+1] =
213      {"", "", "", "", "",
214       coordRef, coordRef, coordRef, coordRef, "",
215       coordRef, coordRef, "", "", "",
216       "", "", "", "",
217       "", "", "", "", "", "", "", "",
218       "", "", "", "", "", "",
219       "", "", "",
220       "", "",
221       ""};
222
223    ///  @brief Class to store information about a single column.
224    ///
225    ///  @details This contains information about a given column --
226    ///  its width, the precision associated with it, its title and
227    ///  the units.  Plus the usual array of accessor functions and so
228    ///  on.
229
230    class Column{
231    public:
232      Column();          ///< Basic constructor
233      Column(std::string type); //< calls the default constructor for the given type
234      //?      Col(int num, int prec=-1);   ///< Specific constructor
235      //?      Col(std::string name, std::string units, int width, int prec, std::string ucd="", std::string datatype="", std::string extraInfo=""); ///< Generic constructor
236      Column(std::string type, std::string name, std::string units, int width, int prec, std::string ucd="", std::string datatype="", std::string colID="", std::string extraInfo=""); ///< Generic constructor
237      Column(const Column& c);///< Assignment constructor
238      Column& operator=(const Column& c); ///< Copy constructor
239      virtual ~Column(){}; ///< Default destructor;
240      //--------------
241      // basic accessor functions
242      //
243      int    getWidth(){return itsWidth;};         
244      void   setWidth(int i){itsWidth=i;};   
245      int    getPrecision(){return itsPrecision;};     
246      void   setPrecision(int i){itsPrecision=i;};
247      std::string getName(){return itsName;};         
248      void   setName(std::string s){itsName=s;}; 
249      std::string getUnits(){return itsUnits;};         
250      void   setUnits(std::string s){itsUnits=s;};
251      //? COLNAME getType(){return type;};
252      std::string type(){return itsType;};
253      void   setType(std::string type){itsType=type;};
254      std::string getUCD(){return itsUCD;};
255      void        setUCD(std::string s){itsUCD=s;};
256      std::string getDatatype(){return itsDatatype;};
257      void        setDatatype(std::string s){itsDatatype=s;};
258      std::string getColID(){return itsColID;};
259      void        setColID(std::string s){itsColID=s;};
260      std::string getExtraInfo(){return itsExtraInfo;};
261      void        setExtraInfo(std::string s){itsExtraInfo=s;};
262
263      //--------------
264      // other functions
265      //
266      /// @brief Make the column one space wider.
267      void   widen(){itsWidth++;};
268
269      /// @brief Increase the precision by one, widening the column if necessary.
270      void   upPrec(){itsPrecision++; itsWidth++;};
271
272      void   changePrec(int p);
273
274      //--------------
275      // Outputting functions -- all in columns.cc
276      //
277      /// @brief write the title of the column to the stream
278      void   printTitle(std::ostream &stream);
279
280      /// @brief write the units of the column to the stream
281      void   printUnits(std::ostream &stream);
282
283      /// @brief write dashes the full width of the column to the stream
284      void   printDash (std::ostream &stream);
285
286      /// @brief write blanks the full width of the column to the stream
287      void   printBlank(std::ostream &stream);
288
289      /// @brief Print a given value in a column with correct width & precision.
290      template <class T> void printEntry(std::ostream &stream, T value);
291
292      /// @brief Decides whether the column is used for a given table type
293      bool   doCol(DESTINATION dest, bool flagFint=true);
294
295
296    private:
297      int itsWidth;          ///< How wide is the column (in ascii spaces)
298      int itsPrecision;      ///< What precision should be used to print the values? (If 0, the setprecision command is not used.)
299      std::string itsName;   ///< The title of the column
300      std::string itsUnits;  ///< The units that the values in the column are expressed in.
301      std::string itsUCD;    ///< The UCD associated with the value
302      std::string itsDatatype; ///< What datatype do the values take?
303      std::string itsExtraInfo; ///< Any other info? This can be the 'ref' entry for a VOTable field.
304      std::string itsColID;  ///< The column ID
305      //? COLNAME type;       ///< The type of the column
306      std::string itsType;   ///< The type of the column - for reference purposes
307    };
308
309    Column defaultColumn(std::string type);
310
311
312  }
313
314}
315
316#endif
317
Note: See TracBrowser for help on using the repository browser.