Changeset 1603 for branches/alma/src/STWriter.cpp
- Timestamp:
- 07/18/09 06:35:47 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma/src/STWriter.cpp
r1446 r1603 39 39 #include <casa/Utilities/Assert.h> 40 40 41 #include <atnf/PKSIO/PKSrecord.h> 41 42 #include <atnf/PKSIO/PKSMS2writer.h> 42 43 #include <atnf/PKSIO/PKSSDwriter.h> … … 47 48 #include <tables/Tables/ArrayColumn.h> 48 49 49 //#include "SDFITSImageWriter.h"50 #include "STFITSImageWriter.h" 50 51 #include "STAsciiWriter.h" 51 52 #include "STHeader.h" … … 58 59 STWriter::STWriter(const std::string &format) 59 60 { 61 format_ = format; 62 String t(format_); 63 t.upcase(); 64 if (t == "MS2") { 65 writer_ = new PKSMS2writer(); 66 } else if (t == "SDFITS") { 67 writer_ = new PKSSDwriter(); 68 } else if (t == "ASCII" || t == "FITS" || t == "CLASS") { 69 writer_ = 0; 70 } else { 71 throw (AipsError("Unrecognized export format")); 72 } 73 } 74 75 STWriter::~STWriter() 76 { 77 if (writer_) { 78 delete writer_; 79 } 80 } 81 82 Int STWriter::setFormat(const std::string &format) 83 { 84 if (format != format_) { 85 if (writer_) delete writer_; 86 } 87 60 88 format_ = format; 61 89 String t(format_); … … 65 93 } else if (t== "SDFITS") { 66 94 writer_ = new PKSSDwriter(); 67 } else if (t== "ASCII") { 68 writer_ = 0; 69 } else { 70 throw (AipsError("Unrecognized export format")); 71 } 72 } 73 74 STWriter::~STWriter() 75 { 76 if (writer_) { 77 delete writer_; 78 } 79 } 80 81 Int STWriter::setFormat(const std::string &format) 82 { 83 if (format != format_) { 84 if (writer_) delete writer_; 85 } 86 87 format_ = format; 88 String t(format_); 89 t.upcase(); 90 if (t== "MS2") { 91 writer_ = new PKSMS2writer(); 92 } else if (t== "SDFITS") { 93 writer_ = new PKSSDwriter(); 94 } else if (t== "ASCII") { 95 } else if (t == "ASCII" || t == "FITS" || t == "CLASS") { 95 96 writer_ = 0; 96 97 } else { … … 110 111 } else { 111 112 return 1; 113 } 114 } else if ( format_ == "FITS" || format_ == "CLASS") { 115 STFITSImageWriter iw; 116 if (format_ == "CLASS") { 117 iw.setClass(True); 118 } 119 if (iw.write(*in, filename)) { 120 return 0; 112 121 } 113 122 } … … 139 148 Int status; 140 149 status = writer_->create(String(filename), hdr.observer, hdr.project, 141 hdr.antennaname, hdr.antennaposition, 142 hdr.obstype, hdr.equinox, hdr.freqref, 143 nChan, nPol, havexpol, False, fluxUnit); 150 hdr.antennaname, hdr.antennaposition, 151 hdr.obstype, hdr.fluxunit, 152 hdr.equinox, hdr.freqref, 153 nChan, nPol, havexpol, False); 144 154 if ( status ) { 145 155 throw(AipsError("Failed to create output file")); 146 156 } 147 157 148 Double srcVel; 149 150 String fieldName, srcName, tcalTime; 151 Vector<Float> calFctr, sigma, tcal, tsys; 152 Vector<Double> direction(2), scanRate(2), srcDir(2), srcPM(2); 153 Matrix<Float> spectra; 154 Matrix<uChar> flagtra; 155 Complex xCalFctr; 158 156 159 Int count = 0; 157 Int scanno = 1; 160 PKSrecord pksrec; 161 pksrec.scanNo = 1; 158 162 // use spearate iterators to ensure renumbering of all numbers 159 163 TableIterator scanit(table, "SCANNO"); … … 161 165 Table stable = scanit.table(); 162 166 TableIterator beamit(stable, "BEAMNO"); 163 Int beamno = 1;167 pksrec.beamNo = 1; 164 168 while (!beamit.pastEnd() ) { 165 169 Table btable = beamit.table(); 166 // position only varies by beam167 // No, we want to pointing data which varies by cycle!168 170 MDirection::ScalarColumn dirCol(btable, "DIRECTION"); 169 Vector<Double>direction = dirCol(0).getAngle("rad").getValue();171 pksrec.direction = dirCol(0).getAngle("rad").getValue(); 170 172 TableIterator cycit(btable, "CYCLENO"); 171 173 ROArrayColumn<Double> srateCol(btable, "SCANRATE"); 172 srateCol.get(0, scanRate); 174 Vector<Double> sratedbl; 175 srateCol.get(0, sratedbl); 176 Vector<Float> srateflt(sratedbl.nelements()); 177 convertArray(srateflt, sratedbl); 178 //pksrec.scanRate = srateflt; 179 pksrec.scanRate = sratedbl; 173 180 ROArrayColumn<Double> spmCol(btable, "SRCPROPERMOTION"); 174 spmCol.get(0, srcPM);181 spmCol.get(0, pksrec.srcPM); 175 182 ROArrayColumn <Double> sdirCol(btable, "SRCDIRECTION"); 176 sdirCol.get(0, srcDir);183 sdirCol.get(0, pksrec.srcDir); 177 184 ROScalarColumn<Double> svelCol(btable, "SRCVELOCITY"); 178 svelCol.get(0, srcVel);185 svelCol.get(0, pksrec.srcVel); 179 186 ROScalarColumn<uInt> bCol(btable, "BEAMNO"); 180 beamno = bCol(0)+1;181 Int cycno = 1;187 pksrec.beamNo = bCol(0)+1; 188 pksrec.cycleNo = 1; 182 189 while (!cycit.pastEnd() ) { 183 190 Table ctable = cycit.table(); 191 TableIterator ifit(ctable, "IFNO"); 184 192 //MDirection::ScalarColumn dirCol(ctable, "DIRECTION"); 185 //Vector<Double> direction = dirCol(0).getAngle("rad").getValue(); 186 TableIterator ifit(ctable, "IFNO"); 187 Int ifno = 1; 193 //pksrec.direction = dirCol(0).getAngle("rad").getValue(); 194 pksrec.IFno = 1; 188 195 while (!ifit.pastEnd() ) { 189 196 Table itable = ifit.table(); … … 192 199 const TableRecord& rec = row.get(0); 193 200 ROArrayColumn<Float> specCol(itable, "SPECTRA"); 194 ifno = rec.asuInt("IFNO")+1;201 pksrec.IFno = rec.asuInt("IFNO")+1; 195 202 uInt nchan = specCol(0).nelements(); 196 //Double cdelt,crval,crpix, restfreq; 197 Double cdelt,crval,crpix; 198 Vector<Double> restfreq; 199 Float focusAxi, focusTan, focusRot, 200 temperature, pressure, humidity, windSpeed, windAz; 203 Double crval,crpix; 204 //Vector<Double> restfreq; 201 205 Float tmp0,tmp1,tmp2,tmp3,tmp4; 202 Vector<Float> tcalval;203 //String stmp0,stmp1, tcalt;204 206 String tcalt; 205 207 Vector<String> stmp0, stmp1; 206 in->frequencies().getEntry(crpix,crval,cdelt, rec.asuInt("FREQ_ID")); 207 in->focus().getEntry(focusAxi, focusTan, focusRot, 208 tmp0,tmp1,tmp2,tmp3,tmp4, 208 in->frequencies().getEntry(crpix,crval, pksrec.freqInc, 209 rec.asuInt("FREQ_ID")); 210 in->focus().getEntry(pksrec.focusAxi, pksrec.focusTan, 211 pksrec.focusRot, tmp0,tmp1,tmp2,tmp3,tmp4, 209 212 rec.asuInt("FOCUS_ID")); 210 in->molecules().getEntry(restfreq,stmp0,stmp1,rec.asuInt("MOLECULE_ID")); 211 in->tcal().getEntry(tcalt,tcalval,rec.asuInt("TCAL_ID")); 212 in->weather().getEntry(temperature, pressure, humidity, 213 windSpeed, windAz, 214 rec.asuInt("WEATHER_ID")); 213 in->molecules().getEntry(pksrec.restFreq,stmp0,stmp1, 214 rec.asuInt("MOLECULE_ID")); 215 in->tcal().getEntry(pksrec.tcalTime, pksrec.tcal, 216 rec.asuInt("TCAL_ID")); 217 in->weather().getEntry(pksrec.temperature, pksrec.pressure, 218 pksrec.humidity, pksrec.windSpeed, 219 pksrec.windAz, rec.asuInt("WEATHER_ID")); 215 220 Double pixel = Double(nchan/2); 216 Double refFreqNew = (pixel-crpix)*cdelt+ crval;221 pksrec.refFreq = (pixel-crpix)*pksrec.freqInc + crval; 217 222 // ok, now we have nrows for the n polarizations in this table 218 Matrix<Float> specs; 219 Matrix<uChar> flags; 220 Vector<Complex> xpol; 221 polConversion(specs, flags, xpol, itable); 222 Vector<Float> tsys = tsysFromTable(itable); 223 polConversion(pksrec.spectra, pksrec.flagged, pksrec.xPol, itable); 224 pksrec.tsys = tsysFromTable(itable); 223 225 // dummy data 224 //uInt npol; 225 //if ( hdr.antennaname == "GBT" ) { 226 // npol = nPolUsed; 227 //} 228 //else { 229 // npol = specs.ncolumn(); 230 //} 231 uInt npol = specs.ncolumn(); 232 233 Matrix<Float> baseLin(npol,2, 0.0f); 234 Matrix<Float> baseSub(npol,9, 0.0f); 235 Complex xCalFctr; 236 Vector<Double> scanRate(2, 0.0); 237 Vector<Float> sigma(npol, 0.0f); 238 Vector<Float> calFctr(npol, 0.0f); 239 status = writer_->write(scanno, cycno, rec.asDouble("TIME"), 240 rec.asDouble("INTERVAL"), 241 rec.asString("FIELDNAME"), 242 rec.asString("SRCNAME"), 243 srcDir, srcPM, srcVel,hdr.obstype, 244 ifno, 245 refFreqNew, nchan*abs(cdelt), cdelt, 246 restfreq, 247 tcalval, 248 tcalt, 249 rec.asFloat("AZIMUTH"), 250 rec.asFloat("ELEVATION"), 251 rec.asFloat("PARANGLE"), 252 focusAxi, focusTan, focusRot, 253 temperature, 254 pressure, humidity, windSpeed, windAz, 255 rec.asInt("REFBEAMNO")+1, beamno, 256 direction, 257 scanRate, 258 tsys, 259 sigma, calFctr,// not in scantable 260 baseLin, baseSub,// not in scantable 261 specs, flags, 262 xCalFctr,// 263 xpol); 226 uInt npol = pksrec.spectra.ncolumn(); 227 228 pksrec.mjd = rec.asDouble("TIME"); 229 pksrec.interval = rec.asDouble("INTERVAL"); 230 pksrec.fieldName = rec.asString("FIELDNAME"); 231 pksrec.srcName = rec.asString("SRCNAME"); 232 pksrec.obsType = hdr.obstype; 233 pksrec.bandwidth = nchan * abs(pksrec.freqInc); 234 pksrec.azimuth = rec.asFloat("AZIMUTH"); 235 pksrec.elevation = rec.asFloat("ELEVATION"); 236 pksrec.parAngle = rec.asFloat("PARANGLE"); 237 pksrec.refBeam = rec.asInt("REFBEAMNO") + 1; 238 pksrec.sigma.resize(npol); 239 pksrec.sigma = 0.0f; 240 pksrec.calFctr.resize(npol); 241 pksrec.calFctr = 0.0f; 242 pksrec.baseLin.resize(npol,2); 243 pksrec.baseLin = 0.0f; 244 pksrec.baseSub.resize(npol,9); 245 pksrec.baseSub = 0.0f; 246 pksrec.xCalFctr = 0.0; 247 248 status = writer_->write(pksrec); 264 249 if ( status ) { 265 250 writer_->close(); … … 267 252 } 268 253 ++count; 269 ++ifno;254 //++pksrec.IFno; 270 255 ++ifit; 271 256 } 272 ++ cycno;257 ++pksrec.cycleNo; 273 258 ++cycit; 274 259 } 275 ++beamno;260 //++pksrec.beamNo; 276 261 ++beamit; 277 262 } 278 ++ scanno;263 ++pksrec.scanNo; 279 264 ++scanit; 280 265 } … … 286 271 if ( format_ == "MS2" ) { 287 272 replacePtTab(table, filename); 288 } 273 } 289 274 return 0; 290 275 }
Note: See TracChangeset
for help on using the changeset viewer.