[300] | 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 | // ----------------------------------------------------------------------- |
---|
[93] | 28 | #ifndef COLUMNS_H |
---|
| 29 | #define COLUMNS_H |
---|
| 30 | |
---|
| 31 | #include <iostream> |
---|
| 32 | #include <iomanip> |
---|
| 33 | #include <string> |
---|
| 34 | #include <vector> |
---|
[1411] | 35 | #include <math.h> |
---|
[93] | 36 | |
---|
[378] | 37 | namespace duchamp |
---|
| 38 | { |
---|
[144] | 39 | |
---|
[378] | 40 | class Detection; |
---|
| 41 | class FitsHeader; |
---|
[222] | 42 | |
---|
[528] | 43 | /// A namespace controlling the formatting of columns of output for Duchamp. |
---|
[1061] | 44 | namespace Catalogues |
---|
[378] | 45 | { |
---|
[1047] | 46 | |
---|
| 47 | /// @brief An enumeration designed to cover the different output types |
---|
| 48 | enum DESTINATION {FILE, SCREEN, LOG, VOTABLE}; |
---|
| 49 | |
---|
[528] | 50 | /// @brief Enumerated precision categories |
---|
[439] | 51 | enum PrecType {prFLUX=3, prVEL=3, prXYZ=1, prPOS=6, prWPOS=2, prSNR=2}; |
---|
[221] | 52 | |
---|
[1066] | 53 | /// @brief Base coordinate system reference for VOTables |
---|
[1044] | 54 | const std::string coordRef="J2000"; |
---|
| 55 | |
---|
[528] | 56 | /// @brief Class to store information about a single column. |
---|
| 57 | /// |
---|
| 58 | /// @details This contains information about a given column -- |
---|
| 59 | /// its width, the precision associated with it, its title and |
---|
| 60 | /// the units. Plus the usual array of accessor functions and so |
---|
| 61 | /// on. |
---|
| 62 | |
---|
[1061] | 63 | class Column{ |
---|
[378] | 64 | public: |
---|
[1061] | 65 | Column(); ///< Basic constructor |
---|
| 66 | Column(std::string type); //< calls the default constructor for the given type |
---|
[1064] | 67 | 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 |
---|
[1061] | 68 | Column(const Column& c);///< Assignment constructor |
---|
| 69 | Column& operator=(const Column& c); ///< Copy constructor |
---|
| 70 | virtual ~Column(){}; ///< Default destructor; |
---|
[378] | 71 | //-------------- |
---|
| 72 | // basic accessor functions |
---|
| 73 | // |
---|
[1061] | 74 | int getWidth(){return itsWidth;}; |
---|
| 75 | void setWidth(int i){itsWidth=i;}; |
---|
| 76 | int getPrecision(){return itsPrecision;}; |
---|
| 77 | void setPrecision(int i){itsPrecision=i;}; |
---|
| 78 | std::string getName(){return itsName;}; |
---|
| 79 | void setName(std::string s){itsName=s;}; |
---|
| 80 | std::string getUnits(){return itsUnits;}; |
---|
| 81 | void setUnits(std::string s){itsUnits=s;}; |
---|
| 82 | //? COLNAME getType(){return type;}; |
---|
| 83 | std::string type(){return itsType;}; |
---|
| 84 | void setType(std::string type){itsType=type;}; |
---|
| 85 | std::string getUCD(){return itsUCD;}; |
---|
| 86 | void setUCD(std::string s){itsUCD=s;}; |
---|
| 87 | std::string getDatatype(){return itsDatatype;}; |
---|
| 88 | void setDatatype(std::string s){itsDatatype=s;}; |
---|
| 89 | std::string getColID(){return itsColID;}; |
---|
| 90 | void setColID(std::string s){itsColID=s;}; |
---|
| 91 | std::string getExtraInfo(){return itsExtraInfo;}; |
---|
| 92 | void setExtraInfo(std::string s){itsExtraInfo=s;}; |
---|
[93] | 93 | |
---|
[378] | 94 | //-------------- |
---|
| 95 | // other functions |
---|
| 96 | // |
---|
[528] | 97 | /// @brief Make the column one space wider. |
---|
[1061] | 98 | void widen(){itsWidth++;}; |
---|
[222] | 99 | |
---|
[528] | 100 | /// @brief Increase the precision by one, widening the column if necessary. |
---|
[1061] | 101 | void upPrec(){itsPrecision++; itsWidth++;}; |
---|
[222] | 102 | |
---|
[540] | 103 | void changePrec(int p); |
---|
| 104 | |
---|
[1411] | 105 | //----------- |
---|
| 106 | // managing the width,precision,etc based on a value |
---|
| 107 | void checkPrec(double d); |
---|
| 108 | void checkWidth(int w); |
---|
| 109 | void check(int i) {int negVal=(i<0)?1:0; checkWidth(int(log10(fabs(double(i)))+1)+negVal);}; |
---|
| 110 | void check(long i) {int negVal=(i<0)?1:0; checkWidth(int(log10(fabs(double(i)))+1)+negVal);}; |
---|
| 111 | void check(unsigned int i) {checkWidth(int(log10(double(i))+1));}; |
---|
| 112 | void check(unsigned long i){checkWidth(int(log10(double(i))+1));}; |
---|
| 113 | void check(std::string s){checkWidth(int(s.size()));}; |
---|
| 114 | void check(float f, bool doPrec=true) {if(doPrec) checkPrec(double(f)); int negVal=(f<0)?1:0; checkWidth(int(log10(fabs(f))+1)+1+itsPrecision+negVal); }; |
---|
| 115 | void check(double d, bool doPrec=true){if(doPrec) checkPrec(d); int negVal=(d<0)?1:0; checkWidth(int(log10(fabs(d))+1)+1+itsPrecision+negVal); }; |
---|
| 116 | |
---|
[378] | 117 | //-------------- |
---|
| 118 | // Outputting functions -- all in columns.cc |
---|
| 119 | // |
---|
[528] | 120 | /// @brief write the title of the column to the stream |
---|
[378] | 121 | void printTitle(std::ostream &stream); |
---|
[222] | 122 | |
---|
[528] | 123 | /// @brief write the units of the column to the stream |
---|
[378] | 124 | void printUnits(std::ostream &stream); |
---|
[222] | 125 | |
---|
[528] | 126 | /// @brief write dashes the full width of the column to the stream |
---|
[378] | 127 | void printDash (std::ostream &stream); |
---|
[222] | 128 | |
---|
[528] | 129 | /// @brief write blanks the full width of the column to the stream |
---|
[378] | 130 | void printBlank(std::ostream &stream); |
---|
[222] | 131 | |
---|
[528] | 132 | /// @brief Print a given value in a column with correct width & precision. |
---|
[378] | 133 | template <class T> void printEntry(std::ostream &stream, T value); |
---|
[93] | 134 | |
---|
[528] | 135 | /// @brief Decides whether the column is used for a given table type |
---|
[1061] | 136 | bool doCol(DESTINATION dest, bool flagFint=true); |
---|
[440] | 137 | |
---|
| 138 | |
---|
[378] | 139 | private: |
---|
[1067] | 140 | std::string itsType; ///< The type of the column - for reference purposes |
---|
| 141 | std::string itsName; ///< The title of the column |
---|
| 142 | std::string itsUnits; ///< The units that the values in the column are expressed in. |
---|
[1061] | 143 | int itsWidth; ///< How wide is the column (in ascii spaces) |
---|
| 144 | int itsPrecision; ///< What precision should be used to print the values? (If 0, the setprecision command is not used.) |
---|
| 145 | std::string itsUCD; ///< The UCD associated with the value |
---|
| 146 | std::string itsDatatype; ///< What datatype do the values take? |
---|
[1067] | 147 | std::string itsColID; ///< The column ID |
---|
[1061] | 148 | std::string itsExtraInfo; ///< Any other info? This can be the 'ref' entry for a VOTable field. |
---|
[378] | 149 | }; |
---|
| 150 | |
---|
[1061] | 151 | Column defaultColumn(std::string type); |
---|
| 152 | |
---|
| 153 | |
---|
[378] | 154 | } |
---|
[93] | 155 | |
---|
[378] | 156 | } |
---|
[93] | 157 | |
---|
| 158 | #endif |
---|
| 159 | |
---|