source: trunk/src/Utils/VOField.cc @ 1061

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

Ticket #162 - A large refactoring of the Column-related code. Columns have moved to Outputs, and in a new namespace Catalogues. The interface has changed, using strings to record the type rather
than the enum. Also included is a new class CatalogueSpecification?, that is designed to hold a collection of Columns. This is not yet implemented - everything still uses the full & log column
vectors, and the code still passes the verification script.

File size: 6.4 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->ID = other.ID;
80    this->name = other.name;
81    this->UCD = other.UCD;
82    this->units = other.units;
83    this->datatype=other.datatype;
84    this->ref = other.ref;
85    this->width = other.width;
86    this->precision = other.precision;
87    return *this;
88  }
89
90
91  void VOField::define(std::string i, std::string n, std::string U, std::string u, std::string d, std::string r, int w, int p)
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->ID = i;
105    this->name = n;
106    this->UCD = U;
107    this->units = fixUnitsVOT(u);
108    this->datatype = d;
109    this->ref = r;
110    this->width = w;
111    this->precision = p;
112  }
113
114  void VOField::define(Catalogues::Column column, std::string i, std::string U, std::string d, std::string r)
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->ID = i;
125    this->name = column.getName();
126    this->UCD = U;
127    this->units = fixUnitsVOT(column.getUnits());
128    this->datatype = d;
129    this->ref = r;
130    this->width = column.getWidth();
131    this->precision = 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->ID = column.getColID();
141    this->name = column.getName();
142    this->UCD = column.getUCD();
143    this->units = fixUnitsVOT(column.getUnits());
144    this->datatype = column.getDatatype();
145    this->ref = column.getExtraInfo();
146    this->width = column.getWidth();
147    this->precision = 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->name = "Integrated_Flux";
165    else if(column.type()=="FTOT") this->name = "Total_Flux";
166    else if(column.type()=="FPEAK") this->name = "Peak_Flux";
167    else if(column.type()=="XCENT") this->name = "X_Centroid";
168    else if(column.type()=="YCENT") this->name = "Y_Centroid";
169    else if(column.type()=="ZCENT") this->name = "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->name
180           << "\" ID=\"" << this->ID
181           << "\" ucd=\"" << this->UCD;
182    if(this->ref!="") stream << "\" ref=\"" << this->ref;
183    stream << "\" datatype=\"" << this->datatype;
184    stream << "\" unit=\"" << this->units;
185    if(datatype=="char")
186      stream << "\" arraysize=\"" << this->width;
187    else{
188      stream << "\" width=\"" << this->width;
189      if(datatype=="float" || datatype=="double")
190        stream << "\" precision=\"" << this->precision;
191    }
192    stream << "\"/>\n";
193
194  }
195
196
197
198
199}
Note: See TracBrowser for help on using the repository browser.