Changeset 988 for trunk/src/STWriter.cpp
- Timestamp:
- 04/05/06 14:31:47 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STWriter.cpp
r901 r988 48 48 49 49 //#include "SDFITSImageWriter.h" 50 //#include "STAsciiWriter.h"50 #include "STAsciiWriter.h" 51 51 #include "STHeader.h" 52 52 … … 58 58 STWriter::STWriter(const std::string &format) 59 59 { 60 cFormat= format;61 String t( cFormat);60 format_ = format; 61 String t(format_); 62 62 t.upcase(); 63 63 if (t== "MS2") { 64 cWriter= new PKSMS2writer();64 writer_ = new PKSMS2writer(); 65 65 } else if (t== "SDFITS") { 66 cWriter= new PKSSDwriter();66 writer_ = new PKSSDwriter(); 67 67 } else if (t== "FITS") { 68 cWriter= 0;68 writer_ = 0; 69 69 } else if (t== "ASCII") { 70 cWriter = 0; 70 writer_ = 0; 71 } else { 72 throw (AipsError("Unrecognized export format")); 73 } 74 } 75 76 STWriter::~STWriter() 77 { 78 if (writer_) { 79 delete writer_; 80 } 81 } 82 83 Int STWriter::setFormat(const std::string &format) 84 { 85 if (format != format_) { 86 if (writer_) delete writer_; 87 } 88 89 format_ = format; 90 String t(format_); 91 t.upcase(); 92 if (t== "MS2") { 93 writer_ = new PKSMS2writer(); 94 } else if (t== "SDFITS") { 95 writer_ = new PKSSDwriter(); 96 } else if (t== "FITS") { 97 writer_ = 0; 98 } else if (t== "ASCII") { 99 writer_ = 0; 71 100 } else { 72 101 throw (AipsError("Unrecognized Format")); 73 102 } 74 }75 76 STWriter::~STWriter()77 {78 if (cWriter) {79 delete cWriter;80 }81 }82 83 Int STWriter::setFormat(const std::string &format)84 {85 if (format != cFormat) {86 if (cWriter) delete cWriter;87 }88 89 cFormat = format;90 String t(cFormat);91 t.upcase();92 if (t== "MS2") {93 cWriter = new PKSMS2writer();94 } else if (t== "SDFITS") {95 cWriter = new PKSSDwriter();96 } else if (t== "FITS") {97 cWriter = 0;98 } else if (t== "ASCII") {99 cWriter = 0;100 } else {101 throw (AipsError("Unrecognized Format"));102 }103 103 return 0; 104 104 } … … 110 110 // Image FITS 111 111 112 if ( cFormat=="FITS") {112 if (format_=="FITS") { 113 113 // Bool verbose = True; 114 114 // SDFITSImageWriter iw; … … 118 118 // return 1; 119 119 // } 120 } else if ( cFormat=="ASCII") {121 /*SDAsciiWriter iw;120 } else if (format_=="ASCII") { 121 STAsciiWriter iw; 122 122 if (iw.write(*in, filename)) { 123 123 return 0; 124 124 } else { 125 125 return 1; 126 } */126 } 127 127 } 128 128 … … 140 140 // Create the output file and write static data. 141 141 Int status; 142 if (status = cWriter->create(filename, hdr.observer, hdr.project, 142 Bool havexpol = Bool(in->npol() > 2); 143 if (status = writer_->create(filename, hdr.observer, hdr.project, 143 144 hdr.antennaname, hdr.antennaposition, 144 145 hdr.obstype, hdr.equinox, hdr.freqref, 145 nChan, nPol, False, False)) {146 nChan, nPol, False, havexpol)) { 146 147 throw(AipsError("Failed to create output file")); 147 148 } … … 161 162 while (!scanit.pastEnd() ) { 162 163 Table stable = scanit.table(); 163 TableIterator beamit( table, "BEAMNO");164 TableIterator beamit(stable, "BEAMNO"); 164 165 Int beamno = 1; 165 166 while (!beamit.pastEnd() ) { … … 168 169 MDirection::ScalarColumn dirCol(btable, "DIRECTION"); 169 170 Vector<Double> direction = dirCol(0).getAngle("rad").getValue(); 170 TableIterator ifit(btable, "IFNO");171 Int ifno = 1;172 while (! ifit.pastEnd() ) {173 Table itable = ifit.table();174 TableIterator cycit(itable, "CYCLENO");175 Int cycno = 1;176 while (! cycit.pastEnd() ) {177 Table ctable = cycit.table();178 TableRow row( ctable);171 TableIterator cycit(btable, "CYCLENO"); 172 Int cycno = 1; 173 while (!cycit.pastEnd() ) { 174 Table ctable = cycit.table(); 175 TableIterator ifit(ctable, "IFNO"); 176 Int ifno = 1; 177 while (!ifit.pastEnd() ) { 178 Table itable = ifit.table(); 179 TableRow row(itable); 179 180 // use the first row to fill in all the "metadata" 180 181 const TableRecord& rec = row.get(0); 181 ROArrayColumn<Float> specCol( ctable, "SPECTRA");182 ROArrayColumn<Float> specCol(itable, "SPECTRA"); 182 183 uInt nchan = specCol(0).nelements(); 183 184 Double cdelt,crval,crpix, restfreq; 184 185 Float focusAxi, focusTan, focusRot, 185 186 temperature, pressure, humidity, windSpeed, windAz; 187 Float tmp0,tmp1,tmp2,tmp3,tmp4; 186 188 Vector<Float> tcalval; 187 String tmp,tmp2, tcalt;189 String stmp0,stmp1, tcalt; 188 190 in->frequencies().getEntry(crpix,crval,cdelt, rec.asuInt("FREQ_ID")); 189 in->molecules().getEntry(restfreq,tmp,tmp2,rec.asuInt("RESTFREQ_ID")); 191 in->focus().getEntry(focusAxi, focusTan, focusRot, 192 tmp0,tmp1,tmp2,tmp3,tmp4, 193 rec.asuInt("FOCUS_ID")); 194 in->molecules().getEntry(restfreq,stmp0,stmp1,rec.asuInt("MOLECULE_ID")); 190 195 in->tcal().getEntry(tcalt,tcalval,rec.asuInt("TCAL_ID")); 191 196 in->weather().getEntry(temperature, pressure, humidity, … … 198 203 Matrix<uChar> flags; 199 204 Vector<Complex> xpol; 200 polConversion(specs, flags, xpol, ctable);201 Vector<Float> tsys = tsysFromTable( ctable);205 polConversion(specs, flags, xpol, itable); 206 Vector<Float> tsys = tsysFromTable(itable); 202 207 // dummy data 203 208 uInt npol = specs.ncolumn(); 209 204 210 Matrix<Float> baseLin(npol,2, 0.0f); 205 211 Matrix<Float> baseSub(npol,9, 0.0f); … … 208 214 Vector<Float> sigma(npol, 0.0f); 209 215 Vector<Float> calFctr(npol, 0.0f); 210 211 212 if (status = cWriter->write(scanno, cycno, rec.asDouble("TIME"), 216 if (status = writer_->write(scanno, cycno, rec.asDouble("TIME"), 213 217 rec.asDouble("INTERVAL"), 214 218 rec.asString("FIELDNAME"), … … 224 228 rec.asFloat("ELEVATION"), 225 229 rec.asFloat("PARANGLE"), 226 focusAxi, focusTan, focusRot, //230 focusAxi, focusTan, focusRot, 227 231 temperature, 228 232 pressure, humidity, windSpeed, windAz, 229 rec.asInt("REFBEAM "), beamno,233 rec.asInt("REFBEAMNO")+1, beamno, 230 234 direction, 231 235 scanRate,// not in scantable … … 237 241 xpol) 238 242 ) { 239 cerr << "Error writing output file." << endl;240 return 1;243 writer_->close(); 244 throw(AipsError("STWriter: Failed to export Scantable.")); 241 245 } 242 246 243 ++ cycno;244 ++ cycit;247 ++ifno; 248 ++ifit; 245 249 } 246 ++ ifno;247 ++ ifit;250 ++cycno; 251 ++cycit; 248 252 } 249 253 ++beamno; … … 256 260 oss << "STWriter: wrote " << count << " rows to " << filename << endl; 257 261 pushLog(String(oss)); 258 cWriter->close();262 writer_->close(); 259 263 260 264 return 0; … … 267 271 Vector<Float> tmp; 268 272 for (uInt i=0; i<tab.nrow(); ++i) { 273 tmp.resize(); 269 274 tmp = tsysCol(i); 270 275 out[i] = tmp[0]; 271 276 } 277 return out; 272 278 } 273 279 … … 277 283 TableRow row(tab); 278 284 String poltype = tab.keywordSet().asString("POLTYPE"); 279 if ( poltype != "linear") 285 if ( poltype != "linear") { 280 286 String msg = "poltype = " + poltype + " not yet supported in output."; 281 throw(AipsError("msg")); 287 throw(AipsError(msg)); 288 } 282 289 // use the first row to fill in all the "metadata" 283 290 const TableRecord& rec = row.get(0); … … 285 292 ROArrayColumn<uChar> flagCol(tab, "FLAGTRA"); 286 293 uInt nchan = specCol(0).nelements(); 287 uInt ncol s= (tab.nrow()==1 ? 1: 2 );288 specs.resize(nchan, ncol s);289 flags.resize(nchan, ncol s);294 uInt ncol = (tab.nrow()==1 ? 1: 2 ); 295 specs.resize(nchan, ncol); 296 flags.resize(nchan, ncol); 290 297 // the linears 291 for (uInt i=0; i<ncol s; ++i) {298 for (uInt i=0; i<ncol; ++i) { 292 299 specs.column(i) = specCol(i); 293 300 flags.column(i) = flagCol(i);
Note: See TracChangeset
for help on using the changeset viewer.