source: trunk/src/Outputs/VOTableCatalogueWriter.cc @ 1295

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

Adding an extra function to VOTableCatalogueWriter so that we can write a single parameter to the file.

File size: 8.7 KB
Line 
1// -----------------------------------------------------------------------
2// VOTableCatalogueWriter.cc: Writing output catalogues to VOTable files
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 <duchamp/Outputs/VOTableCatalogueWriter.hh>
29#include <duchamp/Outputs/CatalogueWriter.hh>
30#include <duchamp/Outputs/FileCatalogueWriter.hh>
31#include <duchamp/Outputs/columns.hh>
32#include <duchamp/Detection/detection.hh>
33#include <duchamp/Utils/utils.hh>
34#include <duchamp/Utils/VOField.hh>
35#include <duchamp/Utils/VOParam.hh>
36#include <ios>
37#include <iostream>
38#include <fstream>
39
40namespace duchamp {
41
42   VOTableCatalogueWriter::VOTableCatalogueWriter():
43    FileCatalogueWriter()
44  {
45    this->itsTableName="";
46    this->itsTableDescription="";
47  }
48
49  VOTableCatalogueWriter::VOTableCatalogueWriter(std::string name):
50    FileCatalogueWriter(name)
51  {
52    this->itsTableName="";
53    this->itsTableDescription="";
54  }
55
56  VOTableCatalogueWriter::VOTableCatalogueWriter(const VOTableCatalogueWriter& other)
57  {
58    this->operator=(other);
59  }
60
61  VOTableCatalogueWriter& VOTableCatalogueWriter::operator= (const VOTableCatalogueWriter& other)
62  {
63    if(this==&other) return *this;
64    ((FileCatalogueWriter &) *this) = other;
65    this->itsTableName=other.itsTableName;
66    this->itsTableDescription=other.itsTableDescription;
67    return *this;
68  }
69 
70  void VOTableCatalogueWriter::writeHeader()
71  {
72    if(this->itsOpenFlag){
73
74      this->itsFileStream<<"<?xml version=\"1.0\"?>\n";
75      this->itsFileStream<<"<VOTABLE version=\"1.1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
76      this->itsFileStream<<" xsi:noNamespaceSchemaLocation=\"http://www.ivoa.net/xml/VOTable/VOTable/v1.1\">\n";
77     
78      std::string ID,equinox,system;
79      if(std::string(this->itsHead->WCS().lngtyp)=="RA") { //J2000 or B1950
80        if(this->itsHead->WCS().equinox==2000.){
81          ID=equinox= "J2000";
82          system="eq_FK5";
83        }
84        else{
85          ID=equinox="B1950";
86          system="eq_FK4";
87        }
88        this->itsFileStream <<"  <COOSYS ID=\""<<ID<<"\" equinox=\""<<equinox<<"\" system=\""<<system<<"\"/>\n";
89      }
90      else{
91        ID=system="galactic";
92        this->itsFileStream <<"  <COOSYS ID=\""<<ID<<"\" system=\""<<system<<"\"/>\n";
93      }
94      this->itsFileStream<<"  <RESOURCE name=\"Duchamp Output\">\n";
95      this->itsFileStream<<"    <TABLE name=\""<<this->itsTableName<<"\">\n";
96      this->itsFileStream<<"      <DESCRIPTION>"<<this->itsTableDescription<<"</DESCRIPTION>\n";
97
98     
99    }
100  }
101
102    void VOTableCatalogueWriter::writeParameter(VOParam param)
103    {
104        if(this->itsOpenFlag){
105            this->itsFileStream << "      ";
106            param.printParam(this->itsFileStream);
107        }
108    }
109
110  void VOTableCatalogueWriter::writeParameters()
111  {
112    if(this->itsOpenFlag){
113      std::vector<VOParam> paramList = this->itsParam->getVOParams();
114      for(std::vector<VOParam>::iterator param=paramList.begin();param<paramList.end();param++){
115          this->writeParameter(*param);
116      }   
117    }
118  }
119
120  void VOTableCatalogueWriter::writeStats()
121  {
122    if(this->itsOpenFlag){
123     
124      VOParam threshParam("thresholdActual","","float",this->itsStats->getThreshold(),0,this->itsHead->getFluxUnits());
125      this->itsFileStream << "      ";
126      threshParam.printParam(this->itsFileStream);
127      if(!this->itsParam->getFlagUserThreshold()){
128        VOParam middleParam("noiseMeanActual","","float",this->itsStats->getMiddle(),0,this->itsHead->getFluxUnits());
129        this->itsFileStream << "      ";
130        middleParam.printParam(this->itsFileStream);
131        VOParam spreadParam("noiseSpreadActual","","float",this->itsStats->getSpread(),0,this->itsHead->getFluxUnits());
132        this->itsFileStream << "      ";
133        spreadParam.printParam(this->itsFileStream);
134      }
135    }
136  }
137
138  void VOTableCatalogueWriter::writeTableHeader()
139  {
140    std::map<std::string,std::string> posUCDmap;
141    posUCDmap.insert(std::pair<std::string,std::string>("ra","pos.eq.ra"));
142    posUCDmap.insert(std::pair<std::string,std::string>("dec","pos.eq.dec"));
143    posUCDmap.insert(std::pair<std::string,std::string>("glon","pos.galactic.lng"));
144    posUCDmap.insert(std::pair<std::string,std::string>("glat","pos.galactic.lat"));
145    Catalogues::Column &raCol=this->itsColumnSpecification->column("RAJD");
146    std::string lngUCDbase = posUCDmap[makelower(raCol.getName())];
147    Catalogues::Column &decCol=this->itsColumnSpecification->column("DECJD");
148    std::string latUCDbase = posUCDmap[makelower(decCol.getName())];
149
150    std::map<std::string,std::string> specUCDmap;
151    specUCDmap.insert(std::pair<std::string,std::string>("VELO","phys.veloc;spect.dopplerVeloc"));
152    specUCDmap.insert(std::pair<std::string,std::string>("VOPT","phys.veloc;spect.dopplerVeloc.opt"));
153    specUCDmap.insert(std::pair<std::string,std::string>("VRAD","phys.veloc;spect.dopplerVeloc.rad"));
154    specUCDmap.insert(std::pair<std::string,std::string>("FREQ","em.freq"));
155    specUCDmap.insert(std::pair<std::string,std::string>("ENER","em.energy"));
156    specUCDmap.insert(std::pair<std::string,std::string>("WAVN","em.wavenumber"));
157    specUCDmap.insert(std::pair<std::string,std::string>("WAVE","em.wl"));
158    specUCDmap.insert(std::pair<std::string,std::string>("AWAV","em.wl"));
159    specUCDmap.insert(std::pair<std::string,std::string>("ZOPT","src.redshift"));
160    specUCDmap.insert(std::pair<std::string,std::string>("BETA","src.redshift; spect.dopplerVeloc"));
161    std::string specUCDbase = specUCDmap[this->itsColumnSpecification->column("VEL").getName()];
162
163    for(size_t i=0;i<this->itsColumnSpecification->size();i++){
164     
165      Catalogues::Column *col = this->itsColumnSpecification->pCol(i);
166      bool useFint=this->itsHead->isSpecOK();
167      if(col->doCol(Catalogues::VOTABLE,useFint)){
168        VOField field(*col);
169        if(col->type()=="RA")    field.setUCD(lngUCDbase);
170        if(col->type()=="RAJD")  field.setUCD(lngUCDbase+";meta.main");
171        if(col->type()=="WRA")   field.setUCD("phys.angSize;"+lngUCDbase);
172        if(col->type()=="DEC")   field.setUCD(latUCDbase);
173        if(col->type()=="DECJD") field.setUCD(latUCDbase+";meta.main");
174        if(col->type()=="WDEC")  field.setUCD("phys.angSize;"+latUCDbase);     
175        if(col->type()=="VEL")   field.setUCD(specUCDbase+";meta.main");
176        if(col->type()=="W20")   field.setUCD("spect.line.width.20;"+specUCDbase);
177        if(col->type()=="W50")   field.setUCD("spect.line.width.50;"+specUCDbase);
178        if(col->type()=="WVEL")  field.setUCD("spect.line.width.full;"+specUCDbase);
179        if(!this->itsHead->is2D()){
180          if(col->type()=="FINT") field.setUCD(field.UCD()+"spect.line.intensity");
181          if(col->type()=="FTOT") field.setUCD(field.UCD()+"spect.line.intensity");
182          if(col->type()=="FPEAK") field.setUCD(field.UCD()+"spect.line.intensity");
183        }
184        this->itsFileStream << "      ";
185        field.printField(this->itsFileStream);
186      }
187
188    }
189
190    this->itsFileStream<<"      <DATA>\n"
191                        <<"        <TABLEDATA>\n";
192
193  }
194
195  void VOTableCatalogueWriter::writeEntry(Detection *object)
196  {
197    this->itsFileStream.setf(std::ios::fixed); 
198
199    this->itsFileStream<<"        <TR>\n";
200    this->itsFileStream<<"          ";
201    for(size_t i=0;i<this->itsColumnSpecification->size();i++){
202      Catalogues::Column *col = this->itsColumnSpecification->pCol(i);
203      if(col->doCol(Catalogues::VOTABLE,this->itsHead->isSpecOK())){
204        this->itsFileStream<<"<TD>";
205        object->printTableEntry(this->itsFileStream, *col);
206        this->itsFileStream<<"</TD>";
207      }
208    }
209    this->itsFileStream<<"\n";
210    this->itsFileStream<<"        </TR>\n";
211
212  }
213
214  void VOTableCatalogueWriter::writeFooter()
215  {
216    this->itsFileStream<<"        </TABLEDATA>\n";
217    this->itsFileStream<<"      </DATA>\n";
218    this->itsFileStream<<"    </TABLE>\n";
219    this->itsFileStream<<"  </RESOURCE>\n";
220    this->itsFileStream<<"</VOTABLE>\n";
221    resetiosflags(std::ios::fixed);
222  }
223
224
225
226
227}
Note: See TracBrowser for help on using the repository browser.