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/Detection/columns.hh> |
---|
34 | |
---|
35 | namespace 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(Column::Col 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 Column::Col object for some parameters. |
---|
118 | /// \param column A Column::Col 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 | VOField::VOField(Column::Col column) |
---|
135 | { |
---|
136 | /// @details |
---|
137 | /// A more useful definition function, using the Column::COLNAME |
---|
138 | /// key to specify particular values for each of the parameters for |
---|
139 | /// different columns. |
---|
140 | /// \param column A Column::Col object of a particular type. The |
---|
141 | /// column.getType() function is used to decide which call to |
---|
142 | /// VOField::define(Column::Col column, std::string i, std::string |
---|
143 | /// U, std::string d, std::string r) to use |
---|
144 | |
---|
145 | switch(column.getType()) |
---|
146 | { |
---|
147 | case Column::NUM: |
---|
148 | this->define(column,"col01","meta.id","int",""); |
---|
149 | break; |
---|
150 | case Column::NAME: |
---|
151 | this->define(column,"col02","meta.id;meta.main","char",""); |
---|
152 | break; |
---|
153 | case Column::RAJD: |
---|
154 | this->define(column,"col03","","float","J2000"); |
---|
155 | break; |
---|
156 | case Column::DECJD: |
---|
157 | this->define(column,"col04","","float","J2000"); |
---|
158 | break; |
---|
159 | case Column::VEL: |
---|
160 | this->define(column,"col05","phys.veloc;src.dopplerVeloc","float",""); |
---|
161 | break; |
---|
162 | case Column::WRA: |
---|
163 | this->define(column,"col06","","float","J2000"); |
---|
164 | break; |
---|
165 | case Column::WDEC: |
---|
166 | this->define(column,"col07","","float","J2000"); |
---|
167 | break; |
---|
168 | case Column::W50: |
---|
169 | this->define(column,"col08","phys.veloc;src.dopplerVeloc;spect.line.width","float",""); |
---|
170 | break; |
---|
171 | case Column::W20: |
---|
172 | this->define(column,"col09","phys.veloc;src.dopplerVeloc;spect.line.width","float",""); |
---|
173 | break; |
---|
174 | case Column::WVEL: |
---|
175 | this->define(column,"col10","phys.veloc;src.dopplerVeloc;spect.line.width","float",""); |
---|
176 | break; |
---|
177 | case Column::FINT: |
---|
178 | this->define(column,"col11","phot.flux;spect.line.intensity","float",""); |
---|
179 | this->name = "Integrated_Flux"; |
---|
180 | break; |
---|
181 | case Column::FTOT: |
---|
182 | this->define(column,"col11","phot.flux;spect.line.intensity","float",""); |
---|
183 | this->name = "Total_Flux"; |
---|
184 | break; |
---|
185 | case Column::FPEAK: |
---|
186 | this->define(column,"col12","phot.flux;spect.line.intensity","float",""); |
---|
187 | this->name = "Peak_Flux"; |
---|
188 | break; |
---|
189 | case Column::SNRPEAK: |
---|
190 | this->define(column,"col13","phot.flux;stat.snr","float",""); |
---|
191 | break; |
---|
192 | case Column::FLAG: |
---|
193 | this->define(column,"col14","meta.code.qual","char",""); |
---|
194 | break; |
---|
195 | case Column::XAV: |
---|
196 | this->define(column,"col15","pos.cartesian.x","float",""); |
---|
197 | break; |
---|
198 | case Column::YAV: |
---|
199 | this->define(column,"col16","pos.cartesian.y","float",""); |
---|
200 | break; |
---|
201 | case Column::ZAV: |
---|
202 | this->define(column,"col17","pos.cartesian.z","float",""); |
---|
203 | break; |
---|
204 | case Column::XCENT: |
---|
205 | this->define(column,"col18","pos.cartesian.x","float",""); |
---|
206 | this->name = "X_Centroid"; |
---|
207 | break; |
---|
208 | case Column::YCENT: |
---|
209 | this->define(column,"col19","pos.cartesian.y","float",""); |
---|
210 | this->name = "Y_Centroid"; |
---|
211 | break; |
---|
212 | case Column::ZCENT: |
---|
213 | this->define(column,"col20","pos.cartesian.z","float",""); |
---|
214 | this->name = "Z_Centroid"; |
---|
215 | break; |
---|
216 | case Column::XPEAK: |
---|
217 | this->define(column,"col21","pos.cartesian.x","int",""); |
---|
218 | break; |
---|
219 | case Column::YPEAK: |
---|
220 | this->define(column,"col22","pos.cartesian.y","int",""); |
---|
221 | break; |
---|
222 | case Column::ZPEAK: |
---|
223 | this->define(column,"col23","pos.cartesian.z","int",""); |
---|
224 | break; |
---|
225 | default: |
---|
226 | break; |
---|
227 | }; |
---|
228 | } |
---|
229 | |
---|
230 | void VOField::printField(std::ostream &stream) |
---|
231 | { |
---|
232 | /// @details |
---|
233 | /// Print the Field entry with appropriate formatting. |
---|
234 | /// \param stream The output stream to send the text to. |
---|
235 | |
---|
236 | stream << "<FIELD name=\"" <<this->name |
---|
237 | << "\" ID=\"" << this->ID |
---|
238 | << "\" ucd=\"" << this->UCD; |
---|
239 | if(this->ref!="") stream << "\" ref=\"" << this->ref; |
---|
240 | stream << "\" datatype=\"" << this->datatype; |
---|
241 | stream << "\" units=\"" << this->units; |
---|
242 | if(datatype=="char") |
---|
243 | stream << "\" arraysize=\"" << this->width; |
---|
244 | else{ |
---|
245 | stream << "\" width=\"" << this->width; |
---|
246 | if(datatype=="float" || datatype=="double") |
---|
247 | stream << "\" precision=\"" << this->precision; |
---|
248 | } |
---|
249 | stream << "\"/>\n"; |
---|
250 | |
---|
251 | } |
---|
252 | |
---|
253 | |
---|
254 | |
---|
255 | |
---|
256 | } |
---|