source: trunk/src/Utils/VOField.cc

Last change on this file was 1153, checked in by MatthewWhiting, 11 years ago

Ticket #173 - Doing the same for the error on the total flux. Also fixing the interface with the VOTable output, and improving the way the catalogue specification handles deleted columns.

File size: 6.8 KB
RevLine 
[917]1// -----------------------------------------------------------------------
2// VOField.cc: Specification of a field for output to a VOTable
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#include <iostream>
29#include <sstream>
30#include <iomanip>
31#include <string>
32#include <duchamp/Utils/VOField.hh>
[1061]33#include <duchamp/Outputs/columns.hh>
[917]34
35namespace duchamp
36{
37
38
39  std::string fixUnitsVOT(std::string oldstring)
40  {
41    ///  @details
42    /// Fix a string containing units to make it acceptable for a VOTable.
43    ///
44    /// This function makes the provided units string acceptable
45    /// according to the standard found at
46    /// http://vizier.u-strasbg.fr/doc/catstd-3.2.htx
47    /// This should then be able to convert the units used in the text
48    /// table to units suitable for putting in a VOTable.
49    ///
50    /// Specifically, it removes any square brackets [] from the
51    /// start/end of the string, and replaces blank spaces (representing
52    /// multiplication) with a '.' (full stop).
53    ///
54    /// \param oldstring Input unit string to be fixed
55    /// \return String with fixed units
56
57    std::string newstring;
58    for(size_t i=0;i<oldstring.size();i++){
59      if((oldstring[i]!='[')&&(oldstring[i]!=']')){
60        if(oldstring[i]==' ') newstring += '.';
61        else newstring += oldstring[i];
62      }
63    }
64    return newstring; 
65  }
66
67  VOField::VOField()
68  {
69  }
70
71  VOField::VOField(const VOField& other)
72  {
73    operator=(other);
74  }
75
76  VOField& VOField::operator= (const VOField& other)
77  {
78    if(this==&other) return *this;
[1075]79    this->itsID = other.itsID;
80    this->itsName = other.itsName;
81    this->itsUCD = other.itsUCD;
82    this->itsUnits = other.itsUnits;
83    this->itsDatatype=other.itsDatatype;
84    this->itsRef = other.itsRef;
85    this->itsWidth = other.itsWidth;
86    this->itsPrecision = other.itsPrecision;
[917]87    return *this;
88  }
89
90
[1075]91  void VOField::define(std::string id, std::string name, std::string ucd, std::string units, std::string datatype, std::string ref, int width, int prec)
[917]92  {
93    /// @details
94    /// A basic definition function, defining each parameter individually.
95    /// \param i The ID parameter
96    /// \param n The name parameter
97    /// \param U The UCD
98    /// \param u The units (fixed by fixUnits())
99    /// \param d The datatype
100    /// \param r The ref
101    /// \param w The width
102    /// \param p The precision
103
[1075]104    this->itsID = id;
105    this->itsName = name;
106    this->itsUCD = ucd;
107    this->itsUnits = fixUnitsVOT(units);
108    this->itsDatatype = datatype;
109    this->itsRef = ref;
110    this->itsWidth = width;
111    this->itsPrecision = prec;
[917]112  }
113
[1075]114  void VOField::define(Catalogues::Column column, std::string id, std::string ucd, std::string datatype, std::string ref)
[917]115  {
116    /// @details
[1061]117    /// Another definition function, using the information in a Catalogues::Column object for some parameters.
118    /// \param column A Catalogues::Column object, used for name, units, width & precision
[917]119    /// \param i The ID parameter
120    /// \param U The UCD
121    /// \param d The datatype
122    /// \param r The ref
123
[1075]124    this->itsID = id;
125    this->itsName = column.getName();
126    this->itsUCD = ucd;
127    this->itsUnits = fixUnitsVOT(column.getUnits());
128    this->itsDatatype = datatype;
129    this->itsRef = ref;
130    this->itsWidth = column.getWidth();
131    this->itsPrecision = column.getPrecision();
[917]132  }
133
[1061]134  void VOField::define(Catalogues::Column column)
[1044]135  {
136    /// @details
[1061]137    /// Another definition function, using the information in a Catalogues::Column object for some parameters.
138    /// \param column A Catalogues::Column object
[1044]139
[1075]140    this->itsID = column.getColID();
141    this->itsName = column.getName();
142    this->itsUCD = column.getUCD();
143    this->itsUnits = fixUnitsVOT(column.getUnits());
144    this->itsDatatype = column.getDatatype();
145    this->itsRef = column.getExtraInfo();
146    this->itsWidth = column.getWidth();
147    this->itsPrecision = column.getPrecision();
[1044]148  }
149
[1061]150  VOField::VOField(Catalogues::Column column)
[917]151  {
152    /// @details
153    /// A more useful definition function, using the Column::COLNAME
154    /// key to specify particular values for each of the parameters for
155    /// different columns.
[1061]156    /// \param column A Catalogues::Column object of a particular type. The
[917]157    /// column.getType() function is used to decide which call to
[1061]158    /// VOField::define(Catalogues::Column column, std::string i, std::string
[917]159    /// U, std::string d, std::string r) to use
160
[1044]161    this->define(column);
162
163    // Adjust some of the names for clarity
[1075]164    if(column.type()=="FINT") this->itsName = "Integrated_Flux";
[1153]165    else if(column.type()=="FINTERR") this->itsName = "Integrated_Flux_Error";
[1075]166    else if(column.type()=="FTOT") this->itsName = "Total_Flux";
[1153]167    else if(column.type()=="FINT") this->itsName = "Total_Flux_Error";
[1075]168    else if(column.type()=="FPEAK") this->itsName = "Peak_Flux";
169    else if(column.type()=="XCENT") this->itsName = "X_Centroid";
170    else if(column.type()=="YCENT") this->itsName = "Y_Centroid";
171    else if(column.type()=="ZCENT") this->itsName = "Z_Centroid";
[1044]172
[917]173  }
174
175  void VOField::printField(std::ostream &stream)
176  {
177    /// @details
178    /// Print the Field entry with appropriate formatting.
179    /// \param stream The output stream to send the text to.
180
[1075]181    stream << "<FIELD name=\"" <<this->itsName
182           << "\" ID=\"" << this->itsID
183           << "\" ucd=\"" << this->itsUCD;
184    if(this->itsRef!="") stream << "\" ref=\"" << this->itsRef;
185    stream << "\" datatype=\"" << this->itsDatatype;
186    stream << "\" unit=\"" << this->itsUnits;
187    if(this->itsDatatype=="char")
188      stream << "\" arraysize=\"" << this->itsWidth;
[917]189    else{
[1075]190      stream << "\" width=\"" << this->itsWidth;
191      if(this->itsDatatype=="float" || this->itsDatatype=="double")
192        stream << "\" precision=\"" << this->itsPrecision;
[917]193    }
194    stream << "\"/>\n";
195
196  }
197
198
199
200
201}
Note: See TracBrowser for help on using the repository browser.