[1069] | 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 | // ----------------------------------------------------------------------- |
---|
[1048] | 28 | #include <duchamp/Outputs/VOTableCatalogueWriter.hh> |
---|
| 29 | #include <duchamp/Outputs/CatalogueWriter.hh> |
---|
[1070] | 30 | #include <duchamp/Outputs/FileCatalogueWriter.hh> |
---|
[1061] | 31 | #include <duchamp/Outputs/columns.hh> |
---|
[1048] | 32 | #include <duchamp/Detection/detection.hh> |
---|
| 33 | #include <duchamp/Utils/utils.hh> |
---|
| 34 | #include <duchamp/Utils/VOField.hh> |
---|
| 35 | #include <duchamp/Utils/VOParam.hh> |
---|
[1049] | 36 | #include <ios> |
---|
[1048] | 37 | #include <iostream> |
---|
| 38 | #include <fstream> |
---|
| 39 | |
---|
| 40 | namespace duchamp { |
---|
| 41 | |
---|
| 42 | VOTableCatalogueWriter::VOTableCatalogueWriter(): |
---|
[1070] | 43 | FileCatalogueWriter() |
---|
[1048] | 44 | { |
---|
| 45 | this->itsTableName=""; |
---|
| 46 | this->itsTableDescription=""; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | VOTableCatalogueWriter::VOTableCatalogueWriter(std::string name): |
---|
[1070] | 50 | FileCatalogueWriter(name) |
---|
[1048] | 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; |
---|
[1070] | 64 | ((FileCatalogueWriter &) *this) = other; |
---|
[1048] | 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::writeParameters() |
---|
| 103 | { |
---|
| 104 | if(this->itsOpenFlag){ |
---|
| 105 | std::vector<VOParam> paramList = this->itsParam->getVOParams(); |
---|
| 106 | for(std::vector<VOParam>::iterator param=paramList.begin();param<paramList.end();param++){ |
---|
| 107 | this->itsFileStream << " "; |
---|
| 108 | param->printParam(this->itsFileStream); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | |
---|
[1050] | 113 | void VOTableCatalogueWriter::writeStats() |
---|
| 114 | { |
---|
| 115 | if(this->itsOpenFlag){ |
---|
| 116 | |
---|
| 117 | VOParam threshParam("thresholdActual","","float",this->itsStats->getThreshold(),0,this->itsHead->getFluxUnits()); |
---|
| 118 | this->itsFileStream << " "; |
---|
| 119 | threshParam.printParam(this->itsFileStream); |
---|
| 120 | if(!this->itsParam->getFlagUserThreshold()){ |
---|
| 121 | VOParam middleParam("noiseMeanActual","","float",this->itsStats->getMiddle(),0,this->itsHead->getFluxUnits()); |
---|
| 122 | this->itsFileStream << " "; |
---|
| 123 | middleParam.printParam(this->itsFileStream); |
---|
| 124 | VOParam spreadParam("noiseSpreadActual","","float",this->itsStats->getSpread(),0,this->itsHead->getFluxUnits()); |
---|
| 125 | this->itsFileStream << " "; |
---|
| 126 | spreadParam.printParam(this->itsFileStream); |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
[1048] | 131 | void VOTableCatalogueWriter::writeTableHeader() |
---|
| 132 | { |
---|
| 133 | std::map<std::string,std::string> posUCDmap; |
---|
| 134 | posUCDmap.insert(std::pair<std::string,std::string>("ra","pos.eq.ra")); |
---|
| 135 | posUCDmap.insert(std::pair<std::string,std::string>("dec","pos.eq.dec")); |
---|
| 136 | posUCDmap.insert(std::pair<std::string,std::string>("glon","pos.galactic.lng")); |
---|
| 137 | posUCDmap.insert(std::pair<std::string,std::string>("glat","pos.galactic.lat")); |
---|
[1064] | 138 | Catalogues::Column &raCol=this->itsColumnSpecification->column("RAJD"); |
---|
[1048] | 139 | std::string lngUCDbase = posUCDmap[makelower(raCol.getName())]; |
---|
[1064] | 140 | Catalogues::Column &decCol=this->itsColumnSpecification->column("DECJD"); |
---|
[1048] | 141 | std::string latUCDbase = posUCDmap[makelower(decCol.getName())]; |
---|
| 142 | |
---|
| 143 | std::map<std::string,std::string> specUCDmap; |
---|
| 144 | specUCDmap.insert(std::pair<std::string,std::string>("VELO","phys.veloc;spect.dopplerVeloc")); |
---|
| 145 | specUCDmap.insert(std::pair<std::string,std::string>("VOPT","phys.veloc;spect.dopplerVeloc.opt")); |
---|
| 146 | specUCDmap.insert(std::pair<std::string,std::string>("VRAD","phys.veloc;spect.dopplerVeloc.rad")); |
---|
| 147 | specUCDmap.insert(std::pair<std::string,std::string>("FREQ","em.freq")); |
---|
| 148 | specUCDmap.insert(std::pair<std::string,std::string>("ENER","em.energy")); |
---|
| 149 | specUCDmap.insert(std::pair<std::string,std::string>("WAVN","em.wavenumber")); |
---|
| 150 | specUCDmap.insert(std::pair<std::string,std::string>("WAVE","em.wl")); |
---|
| 151 | specUCDmap.insert(std::pair<std::string,std::string>("AWAV","em.wl")); |
---|
| 152 | specUCDmap.insert(std::pair<std::string,std::string>("ZOPT","src.redshift")); |
---|
| 153 | specUCDmap.insert(std::pair<std::string,std::string>("BETA","src.redshift; spect.dopplerVeloc")); |
---|
[1064] | 154 | std::string specUCDbase = specUCDmap[this->itsColumnSpecification->column("VEL").getName()]; |
---|
[1048] | 155 | |
---|
[1064] | 156 | for(size_t i=0;i<this->itsColumnSpecification->size();i++){ |
---|
| 157 | |
---|
| 158 | Catalogues::Column *col = this->itsColumnSpecification->pCol(i); |
---|
[1061] | 159 | if(col->doCol(Catalogues::VOTABLE,this->itsHead->isSpecOK())){ |
---|
[1048] | 160 | VOField field(*col); |
---|
[1061] | 161 | if(col->type()=="RAJD") field.setUCD(lngUCDbase+";meta.main"); |
---|
| 162 | if(col->type()=="WRA") field.setUCD("phys.angSize;"+lngUCDbase); |
---|
| 163 | if(col->type()=="DECJD") field.setUCD(latUCDbase+";meta.main"); |
---|
| 164 | if(col->type()=="WDEC") field.setUCD("phys.angSize;"+latUCDbase); |
---|
| 165 | if(col->type()=="VEL") field.setUCD(specUCDbase+";meta.main"); |
---|
| 166 | if(col->type()=="W20") field.setUCD("spect.line.width;"+specUCDbase); |
---|
| 167 | if(col->type()=="W50") field.setUCD("spect.line.width;"+specUCDbase); |
---|
| 168 | if(col->type()=="WVEL") field.setUCD("spect.line.width;"+specUCDbase); |
---|
[1048] | 169 | this->itsFileStream << " "; |
---|
| 170 | field.printField(this->itsFileStream); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | this->itsFileStream<<" <DATA>\n" |
---|
| 176 | <<" <TABLEDATA>\n"; |
---|
| 177 | |
---|
| 178 | } |
---|
| 179 | |
---|
[1072] | 180 | void VOTableCatalogueWriter::writeEntry(Detection *object) |
---|
[1048] | 181 | { |
---|
| 182 | this->itsFileStream.setf(std::ios::fixed); |
---|
| 183 | |
---|
| 184 | this->itsFileStream<<" <TR>\n"; |
---|
| 185 | this->itsFileStream<<" "; |
---|
[1064] | 186 | for(size_t i=0;i<this->itsColumnSpecification->size();i++){ |
---|
| 187 | Catalogues::Column *col = this->itsColumnSpecification->pCol(i); |
---|
[1061] | 188 | if(col->doCol(Catalogues::VOTABLE,this->itsHead->isSpecOK())){ |
---|
[1048] | 189 | this->itsFileStream<<"<TD>"; |
---|
| 190 | object->printTableEntry(this->itsFileStream, *col); |
---|
| 191 | this->itsFileStream<<"</TD>"; |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | this->itsFileStream<<"\n"; |
---|
| 195 | this->itsFileStream<<" </TR>\n"; |
---|
| 196 | |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | void VOTableCatalogueWriter::writeFooter() |
---|
| 200 | { |
---|
| 201 | this->itsFileStream<<" </TABLEDATA>\n"; |
---|
| 202 | this->itsFileStream<<" </DATA>\n"; |
---|
| 203 | this->itsFileStream<<" </TABLE>\n"; |
---|
| 204 | this->itsFileStream<<" </RESOURCE>\n"; |
---|
| 205 | this->itsFileStream<<"</VOTABLE>\n"; |
---|
| 206 | resetiosflags(std::ios::fixed); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | |
---|
| 210 | |
---|
| 211 | |
---|
| 212 | } |
---|