source: trunk/src/Detection/columns.hh @ 350

Last change on this file since 350 was 350, checked in by MatthewWhiting, 17 years ago

Hopefully fixed a bug in the determination of the width of the columns. The width was not always being incremented when the precision was incremented.

Also changed the order of the width and precision determinations, so that the correct precision is used to determine the width.

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