source: tags/release-1.2.2/src/Utils/VOField.cc

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

Improved parameter output for the annotation files. Tidying up the VOParam & VOField classes, and adding some documentation comments.

File size: 6.7 KB
Line 
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>
33#include <duchamp/Outputs/columns.hh>
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;
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;
87    return *this;
88  }
89
90
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)
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
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;
112  }
113
114  void VOField::define(Catalogues::Column column, std::string id, std::string ucd, std::string datatype, std::string ref)
115  {
116    /// @details
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
119    /// \param i The ID parameter
120    /// \param U The UCD
121    /// \param d The datatype
122    /// \param r The ref
123
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();
132  }
133
134  void VOField::define(Catalogues::Column column)
135  {
136    /// @details
137    /// Another definition function, using the information in a Catalogues::Column object for some parameters.
138    /// \param column A Catalogues::Column object
139
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();
148  }
149
150  VOField::VOField(Catalogues::Column column)
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.
156    /// \param column A Catalogues::Column object of a particular type. The
157    /// column.getType() function is used to decide which call to
158    /// VOField::define(Catalogues::Column column, std::string i, std::string
159    /// U, std::string d, std::string r) to use
160
161    this->define(column);
162
163    // Adjust some of the names for clarity
164    if(column.type()=="FINT") this->itsName = "Integrated_Flux";
165    else if(column.type()=="FTOT") this->itsName = "Total_Flux";
166    else if(column.type()=="FPEAK") this->itsName = "Peak_Flux";
167    else if(column.type()=="XCENT") this->itsName = "X_Centroid";
168    else if(column.type()=="YCENT") this->itsName = "Y_Centroid";
169    else if(column.type()=="ZCENT") this->itsName = "Z_Centroid";
170
171  }
172
173  void VOField::printField(std::ostream &stream)
174  {
175    /// @details
176    /// Print the Field entry with appropriate formatting.
177    /// \param stream The output stream to send the text to.
178
179    stream << "<FIELD name=\"" <<this->itsName
180           << "\" ID=\"" << this->itsID
181           << "\" ucd=\"" << this->itsUCD;
182    if(this->itsRef!="") stream << "\" ref=\"" << this->itsRef;
183    stream << "\" datatype=\"" << this->itsDatatype;
184    stream << "\" unit=\"" << this->itsUnits;
185    if(this->itsDatatype=="char")
186      stream << "\" arraysize=\"" << this->itsWidth;
187    else{
188      stream << "\" width=\"" << this->itsWidth;
189      if(this->itsDatatype=="float" || this->itsDatatype=="double")
190        stream << "\" precision=\"" << this->itsPrecision;
191    }
192    stream << "\"/>\n";
193
194  }
195
196
197
198
199}
Note: See TracBrowser for help on using the repository browser.