[805] | 1 | // |
---|
| 2 | // C++ Implementation: STFiller |
---|
| 3 | // |
---|
| 4 | // Description: |
---|
| 5 | // |
---|
| 6 | // |
---|
[1410] | 7 | // Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2006-2007 |
---|
[805] | 8 | // |
---|
| 9 | // Copyright: See COPYING file that comes with this distribution |
---|
| 10 | // |
---|
| 11 | // |
---|
[404] | 12 | #include <casa/iostream.h> |
---|
| 13 | #include <casa/iomanip.h> |
---|
| 14 | |
---|
[125] | 15 | #include <casa/Exceptions.h> |
---|
[284] | 16 | #include <casa/OS/Path.h> |
---|
[290] | 17 | #include <casa/OS/File.h> |
---|
[338] | 18 | #include <casa/Quanta/Unit.h> |
---|
[805] | 19 | #include <casa/Arrays/ArrayMath.h> |
---|
[1060] | 20 | #include <casa/Arrays/ArrayLogical.h> |
---|
[805] | 21 | #include <casa/Utilities/Regex.h> |
---|
| 22 | |
---|
| 23 | #include <casa/Containers/RecordField.h> |
---|
| 24 | |
---|
| 25 | #include <tables/Tables/TableRow.h> |
---|
| 26 | |
---|
[1819] | 27 | #include <measures/Measures/MDirection.h> |
---|
| 28 | #include <measures/Measures/MeasConvert.h> |
---|
| 29 | |
---|
[1450] | 30 | #include <atnf/PKSIO/PKSrecord.h> |
---|
[2] | 31 | #include <atnf/PKSIO/PKSreader.h> |
---|
[1438] | 32 | #ifdef HAS_ALMA |
---|
| 33 | #include <casa/System/ProgressMeter.h> |
---|
| 34 | #endif |
---|
[1819] | 35 | #include <casa/System/ProgressMeter.h> |
---|
| 36 | #include <atnf/PKSIO/NROReader.h> |
---|
| 37 | #include <casa/Logging/LogIO.h> |
---|
[2657] | 38 | #include <fits/FITS/FITSSpectralUtil.h> |
---|
[125] | 39 | |
---|
[1819] | 40 | #include <time.h> |
---|
| 41 | |
---|
| 42 | |
---|
[835] | 43 | #include "STDefs.h" |
---|
[878] | 44 | #include "STAttr.h" |
---|
[2] | 45 | |
---|
[805] | 46 | #include "STFiller.h" |
---|
[901] | 47 | #include "STHeader.h" |
---|
[805] | 48 | |
---|
[125] | 49 | using namespace casa; |
---|
[2] | 50 | |
---|
[805] | 51 | namespace asap { |
---|
| 52 | |
---|
| 53 | STFiller::STFiller() : |
---|
[2] | 54 | reader_(0), |
---|
[405] | 55 | header_(0), |
---|
[1504] | 56 | table_(0), |
---|
[1819] | 57 | refRx_(".*(e|w|_R)$"), |
---|
| 58 | nreader_(0) |
---|
[420] | 59 | { |
---|
[2] | 60 | } |
---|
[805] | 61 | |
---|
| 62 | STFiller::STFiller( CountedPtr< Scantable > stbl ) : |
---|
[46] | 63 | reader_(0), |
---|
[405] | 64 | header_(0), |
---|
[1504] | 65 | table_(stbl), |
---|
[1819] | 66 | refRx_(".*(e|w|_R)$"), |
---|
| 67 | nreader_(0) |
---|
[420] | 68 | { |
---|
[46] | 69 | } |
---|
[2] | 70 | |
---|
[855] | 71 | STFiller::STFiller(const std::string& filename, int whichIF, int whichBeam ) : |
---|
[2] | 72 | reader_(0), |
---|
[405] | 73 | header_(0), |
---|
[1504] | 74 | table_(0), |
---|
[1819] | 75 | refRx_(".*(e|w|_R)$"), |
---|
| 76 | nreader_(0) |
---|
[420] | 77 | { |
---|
[1819] | 78 | open(filename, "", whichIF, whichBeam); |
---|
[2] | 79 | } |
---|
| 80 | |
---|
[805] | 81 | STFiller::~STFiller() |
---|
| 82 | { |
---|
| 83 | close(); |
---|
[2] | 84 | } |
---|
| 85 | |
---|
[1819] | 86 | void STFiller::open( const std::string& filename, const std::string& antenna, int whichIF, int whichBeam, casa::Bool getPt ) |
---|
[805] | 87 | { |
---|
[846] | 88 | if (table_.null()) { |
---|
| 89 | table_ = new Scantable(); |
---|
| 90 | } |
---|
[805] | 91 | if (reader_) { delete reader_; reader_ = 0; } |
---|
| 92 | Bool haveBase, haveSpectra; |
---|
[2] | 93 | |
---|
| 94 | String inName(filename); |
---|
[284] | 95 | Path path(inName); |
---|
| 96 | inName = path.expandedName(); |
---|
[405] | 97 | |
---|
[290] | 98 | File file(inName); |
---|
[805] | 99 | if ( !file.exists() ) { |
---|
[290] | 100 | throw(AipsError("File does not exist")); |
---|
| 101 | } |
---|
[87] | 102 | filename_ = inName; |
---|
[332] | 103 | |
---|
[405] | 104 | // Create reader and fill in values for arguments |
---|
[2] | 105 | String format; |
---|
[1060] | 106 | Vector<Bool> beams, ifs; |
---|
| 107 | Vector<uInt> nchans,npols; |
---|
[1819] | 108 | |
---|
| 109 | // |
---|
| 110 | // if isNRO_ is true, try NROReader |
---|
| 111 | // |
---|
| 112 | // 2008/11/11 Takeshi Nakazato |
---|
| 113 | isNRO_ = fileCheck() ; |
---|
| 114 | if ( isNRO_ ) { |
---|
| 115 | if ( (nreader_ = getNROReader( inName, format )) == 0 ) { |
---|
| 116 | throw(AipsError("Creation of NROReader failed")) ; |
---|
| 117 | } |
---|
| 118 | else { |
---|
| 119 | openNRO( whichIF, whichBeam ) ; |
---|
| 120 | return ; |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | // |
---|
| 124 | |
---|
| 125 | if ( (reader_ = getPKSreader(inName, antenna, 0, 0, format, beams, ifs, |
---|
[1060] | 126 | nchans, npols, haveXPol_,haveBase, haveSpectra |
---|
| 127 | )) == 0 ) { |
---|
[405] | 128 | throw(AipsError("Creation of PKSreader failed")); |
---|
[2] | 129 | } |
---|
| 130 | if (!haveSpectra) { |
---|
| 131 | delete reader_; |
---|
| 132 | reader_ = 0; |
---|
[87] | 133 | throw(AipsError("No spectral data in file.")); |
---|
[2] | 134 | return; |
---|
| 135 | } |
---|
| 136 | nBeam_ = beams.nelements(); |
---|
[1060] | 137 | nIF_ = ifs.nelements(); |
---|
[2] | 138 | // Get basic parameters. |
---|
[1060] | 139 | if ( anyEQ(haveXPol_, True) ) { |
---|
| 140 | for (uInt i=0; i< npols.nelements();++i) { |
---|
| 141 | if (npols[i] < 3) npols[i] += 2;// Convert Complex -> 2 Floats |
---|
| 142 | } |
---|
[110] | 143 | } |
---|
[405] | 144 | if (header_) delete header_; |
---|
[901] | 145 | header_ = new STHeader(); |
---|
[1060] | 146 | header_->nchan = max(nchans); |
---|
| 147 | header_->npol = max(npols); |
---|
[405] | 148 | header_->nbeam = nBeam_; |
---|
[1819] | 149 | |
---|
[405] | 150 | Int status = reader_->getHeader(header_->observer, header_->project, |
---|
| 151 | header_->antennaname, header_->antennaposition, |
---|
[1410] | 152 | header_->obstype, |
---|
| 153 | header_->fluxunit, |
---|
| 154 | header_->equinox, |
---|
[405] | 155 | header_->freqref, |
---|
| 156 | header_->utc, header_->reffreq, |
---|
| 157 | header_->bandwidth); |
---|
| 158 | |
---|
[2] | 159 | if (status) { |
---|
| 160 | delete reader_; |
---|
| 161 | reader_ = 0; |
---|
[805] | 162 | delete header_; |
---|
| 163 | header_ = 0; |
---|
[87] | 164 | throw(AipsError("Failed to get header.")); |
---|
[2] | 165 | } |
---|
[2658] | 166 | LogIO os( casa::LogOrigin( "STFiller") ); |
---|
| 167 | |
---|
[405] | 168 | if ((header_->obstype).matches("*SW*")) { |
---|
[2] | 169 | // need robust way here - probably read ahead of next timestamp |
---|
[2658] | 170 | os << "Header indicates frequency switched observation.\n" |
---|
| 171 | << "setting # of IFs = 1 " << LogIO::POST; |
---|
[2] | 172 | nIF_ = 1; |
---|
[805] | 173 | header_->obstype = String("fswitch"); |
---|
[2] | 174 | } |
---|
[405] | 175 | // Determine Telescope and set brightness unit |
---|
[342] | 176 | |
---|
[1391] | 177 | |
---|
[342] | 178 | Bool throwIt = False; |
---|
[878] | 179 | Instrument inst = STAttr::convertInstrument(header_->antennaname, throwIt); |
---|
[1410] | 180 | |
---|
[342] | 181 | if (inst==ATMOPRA || inst==TIDBINBILLA) { |
---|
[1410] | 182 | header_->fluxunit = "K"; |
---|
| 183 | } else { |
---|
| 184 | // downcase for use with Quanta |
---|
| 185 | if (header_->fluxunit == "JY") { |
---|
| 186 | header_->fluxunit = "Jy"; |
---|
| 187 | } |
---|
[342] | 188 | } |
---|
[1188] | 189 | STAttr stattr; |
---|
| 190 | header_->poltype = stattr.feedPolType(inst); |
---|
[405] | 191 | header_->nif = nIF_; |
---|
| 192 | header_->epoch = "UTC"; |
---|
[805] | 193 | // *** header_->frequnit = "Hz" |
---|
[2] | 194 | // Apply selection criteria. |
---|
| 195 | Vector<Int> ref; |
---|
[332] | 196 | ifOffset_ = 0; |
---|
| 197 | if (whichIF>=0) { |
---|
| 198 | if (whichIF>=0 && whichIF<nIF_) { |
---|
[1060] | 199 | ifs = False; |
---|
| 200 | ifs(whichIF) = True; |
---|
[805] | 201 | header_->nif = 1; |
---|
| 202 | nIF_ = 1; |
---|
| 203 | ifOffset_ = whichIF; |
---|
[332] | 204 | } else { |
---|
[805] | 205 | delete reader_; |
---|
| 206 | reader_ = 0; |
---|
| 207 | delete header_; |
---|
| 208 | header_ = 0; |
---|
| 209 | throw(AipsError("Illegal IF selection")); |
---|
[332] | 210 | } |
---|
| 211 | } |
---|
| 212 | beamOffset_ = 0; |
---|
| 213 | if (whichBeam>=0) { |
---|
[805] | 214 | if (whichBeam>=0 && whichBeam<nBeam_) { |
---|
[1060] | 215 | beams = False; |
---|
| 216 | beams(whichBeam) = True; |
---|
[805] | 217 | header_->nbeam = 1; |
---|
| 218 | nBeam_ = 1; |
---|
| 219 | beamOffset_ = whichBeam; |
---|
| 220 | } else { |
---|
| 221 | delete reader_; |
---|
| 222 | reader_ = 0; |
---|
| 223 | delete header_; |
---|
| 224 | header_ = 0; |
---|
| 225 | throw(AipsError("Illegal Beam selection")); |
---|
| 226 | } |
---|
[332] | 227 | } |
---|
| 228 | Vector<Int> start(nIF_, 1); |
---|
| 229 | Vector<Int> end(nIF_, 0); |
---|
[2657] | 230 | reader_->select(beams, ifs, start, end, ref, True, haveXPol_[0], False, |
---|
| 231 | getPt); |
---|
[846] | 232 | table_->setHeader(*header_); |
---|
[1391] | 233 | //For MS, add the location of POINTING of the input MS so one get |
---|
| 234 | //pointing data from there, if necessary. |
---|
[1819] | 235 | //Also find nrow in MS |
---|
[1391] | 236 | nInDataRow = 0; |
---|
| 237 | if (format == "MS2") { |
---|
[1819] | 238 | Path datapath(inName); |
---|
[1391] | 239 | String ptTabPath = datapath.absoluteName(); |
---|
| 240 | Table inMS(ptTabPath); |
---|
| 241 | nInDataRow = inMS.nrow(); |
---|
| 242 | ptTabPath.append("/POINTING"); |
---|
| 243 | table_->table().rwKeywordSet().define("POINTING", ptTabPath); |
---|
| 244 | if ((header_->antennaname).matches("GBT")) { |
---|
| 245 | String GOTabPath = datapath.absoluteName(); |
---|
| 246 | GOTabPath.append("/GBT_GO"); |
---|
| 247 | table_->table().rwKeywordSet().define("GBT_GO", GOTabPath); |
---|
| 248 | } |
---|
| 249 | } |
---|
[1819] | 250 | String freqFrame = header_->freqref; |
---|
| 251 | //translate frequency reference frame back to |
---|
| 252 | //MS style (as PKSMS2reader converts the original frame |
---|
| 253 | //in FITS standard style) |
---|
[2657] | 254 | MFrequency::Types fframe; |
---|
| 255 | FITSSpectralUtil::frameFromSpecsys(fframe, freqFrame); |
---|
[1819] | 256 | // set both "FRAME" and "BASEFRAME" |
---|
[2657] | 257 | table_->frequencies().setFrame(fframe, false); |
---|
| 258 | table_->frequencies().setFrame(fframe,true); |
---|
| 259 | |
---|
[1586] | 260 | //table_->focus().setParallactify(true); |
---|
[805] | 261 | } |
---|
[405] | 262 | |
---|
[805] | 263 | void STFiller::close( ) |
---|
| 264 | { |
---|
| 265 | delete reader_;reader_=0; |
---|
[1819] | 266 | delete nreader_;nreader_=0; |
---|
[805] | 267 | delete header_;header_=0; |
---|
| 268 | table_ = 0; |
---|
[2] | 269 | } |
---|
| 270 | |
---|
[805] | 271 | int asap::STFiller::read( ) |
---|
| 272 | { |
---|
[87] | 273 | int status = 0; |
---|
| 274 | |
---|
[1819] | 275 | // |
---|
| 276 | // for NRO data |
---|
| 277 | // |
---|
| 278 | // 2008/11/12 Takeshi Nakazato |
---|
| 279 | if ( isNRO_ ) { |
---|
| 280 | status = readNRO() ; |
---|
| 281 | return status ; |
---|
| 282 | } |
---|
| 283 | // |
---|
| 284 | |
---|
| 285 | /** |
---|
| 286 | Int beamNo, IFno, refBeam, scanNo, cycleNo; |
---|
| 287 | Float azimuth, elevation, focusAxi, focusRot, focusTan, |
---|
| 288 | humidity, parAngle, pressure, temperature, windAz, windSpeed; |
---|
| 289 | Double bandwidth, freqInc, interval, mjd, refFreq, srcVel; |
---|
| 290 | String fieldName, srcName, tcalTime, obsType; |
---|
| 291 | Vector<Float> calFctr, sigma, tcal, tsys; |
---|
| 292 | Matrix<Float> baseLin, baseSub; |
---|
| 293 | Vector<Double> direction(2), scanRate(2), srcDir(2), srcPM(2), restFreq(1); |
---|
| 294 | Matrix<Float> spectra; |
---|
| 295 | Matrix<uChar> flagtra; |
---|
| 296 | Complex xCalFctr; |
---|
| 297 | Vector<Complex> xPol; |
---|
| 298 | **/ |
---|
| 299 | |
---|
[2163] | 300 | #ifdef HAS_ALMA |
---|
[1391] | 301 | Double min = 0.0; |
---|
| 302 | Double max = nInDataRow; |
---|
[1438] | 303 | ProgressMeter fillpm(min, max, "Data importing progress"); |
---|
| 304 | #endif |
---|
[1450] | 305 | PKSrecord pksrec; |
---|
[1819] | 306 | pksrec.srcType=-1; |
---|
[1391] | 307 | int n = 0; |
---|
[1819] | 308 | bool isGBTFITS = false ; |
---|
| 309 | if ((header_->antennaname.find( "GBT" ) != String::npos) && File(filename_).isRegular()) { |
---|
| 310 | FILE *fp = fopen( filename_.c_str(), "r" ) ; |
---|
| 311 | fseek( fp, 640, SEEK_SET ) ; |
---|
| 312 | char buf[81] ; |
---|
[2163] | 313 | size_t tmpret = fread( buf, 80, 1, fp ) ; |
---|
| 314 | (void) tmpret; |
---|
[1819] | 315 | buf[80] = '\0' ; |
---|
| 316 | if ( strstr( buf, "NRAO_GBT" ) != NULL ) { |
---|
| 317 | isGBTFITS = true ; |
---|
| 318 | } |
---|
| 319 | fclose( fp ) ; |
---|
| 320 | } |
---|
[805] | 321 | while ( status == 0 ) { |
---|
[1450] | 322 | status = reader_->read(pksrec); |
---|
[805] | 323 | if ( status != 0 ) break; |
---|
[1391] | 324 | n += 1; |
---|
[1081] | 325 | Regex filterrx(".*[SL|PA]$"); |
---|
[1110] | 326 | Regex obsrx("^AT.+"); |
---|
[1450] | 327 | if ( header_->antennaname.matches(obsrx) && |
---|
| 328 | pksrec.obsType.matches(filterrx)) { |
---|
[1110] | 329 | //cerr << "ignoring paddle scan" << endl; |
---|
[1081] | 330 | continue; |
---|
| 331 | } |
---|
[805] | 332 | TableRow row(table_->table()); |
---|
| 333 | TableRecord& rec = row.record(); |
---|
[999] | 334 | // fields that don't get used and are just passed through asap |
---|
| 335 | RecordFieldPtr<Array<Double> > srateCol(rec, "SCANRATE"); |
---|
[1462] | 336 | // MRC changed type from double to float |
---|
[1467] | 337 | Vector<Double> sratedbl(pksrec.scanRate.nelements()); |
---|
[1462] | 338 | convertArray(sratedbl, pksrec.scanRate); |
---|
| 339 | *srateCol = sratedbl; |
---|
[999] | 340 | RecordFieldPtr<Array<Double> > spmCol(rec, "SRCPROPERMOTION"); |
---|
[1450] | 341 | *spmCol = pksrec.srcPM; |
---|
[999] | 342 | RecordFieldPtr<Array<Double> > sdirCol(rec, "SRCDIRECTION"); |
---|
[1450] | 343 | *sdirCol = pksrec.srcDir; |
---|
[999] | 344 | RecordFieldPtr<Double> svelCol(rec, "SRCVELOCITY"); |
---|
[1450] | 345 | *svelCol = pksrec.srcVel; |
---|
[999] | 346 | // the real stuff |
---|
[972] | 347 | RecordFieldPtr<Int> fitCol(rec, "FIT_ID"); |
---|
| 348 | *fitCol = -1; |
---|
[805] | 349 | RecordFieldPtr<uInt> scanoCol(rec, "SCANNO"); |
---|
[1450] | 350 | *scanoCol = pksrec.scanNo-1; |
---|
[805] | 351 | RecordFieldPtr<uInt> cyclenoCol(rec, "CYCLENO"); |
---|
[1450] | 352 | *cyclenoCol = pksrec.cycleNo-1; |
---|
[805] | 353 | RecordFieldPtr<Double> mjdCol(rec, "TIME"); |
---|
[1450] | 354 | *mjdCol = pksrec.mjd; |
---|
[805] | 355 | RecordFieldPtr<Double> intCol(rec, "INTERVAL"); |
---|
[1450] | 356 | *intCol = pksrec.interval; |
---|
[805] | 357 | RecordFieldPtr<String> srcnCol(rec, "SRCNAME"); |
---|
| 358 | RecordFieldPtr<Int> srctCol(rec, "SRCTYPE"); |
---|
[1391] | 359 | RecordFieldPtr<String> fieldnCol(rec, "FIELDNAME"); |
---|
[1450] | 360 | *fieldnCol = pksrec.fieldName; |
---|
[805] | 361 | // try to auto-identify if it is on or off. |
---|
[1504] | 362 | Regex rx(refRx_); |
---|
[942] | 363 | Regex rx2("_S$"); |
---|
[1450] | 364 | Int match = pksrec.srcName.matches(rx); |
---|
[805] | 365 | if (match) { |
---|
[1450] | 366 | *srcnCol = pksrec.srcName; |
---|
[805] | 367 | } else { |
---|
[1450] | 368 | *srcnCol = pksrec.srcName.before(rx2); |
---|
[805] | 369 | } |
---|
[1450] | 370 | //*srcnCol = pksrec.srcName;//.before(rx2); |
---|
[805] | 371 | *srctCol = match; |
---|
[1819] | 372 | if ( pksrec.srcType != -1 ) { |
---|
| 373 | *srctCol = pksrec.srcType ; |
---|
| 374 | } |
---|
[805] | 375 | RecordFieldPtr<uInt> beamCol(rec, "BEAMNO"); |
---|
[1450] | 376 | *beamCol = pksrec.beamNo-beamOffset_-1; |
---|
[805] | 377 | RecordFieldPtr<Int> rbCol(rec, "REFBEAMNO"); |
---|
| 378 | Int rb = -1; |
---|
[1450] | 379 | if (nBeam_ > 1 ) rb = pksrec.refBeam-1; |
---|
[805] | 380 | *rbCol = rb; |
---|
| 381 | RecordFieldPtr<uInt> ifCol(rec, "IFNO"); |
---|
[1450] | 382 | *ifCol = pksrec.IFno-ifOffset_- 1; |
---|
[1819] | 383 | uInt id = table_->frequencies().addEntry(Double(pksrec.spectra.nrow()/2), |
---|
| 384 | pksrec.refFreq, pksrec.freqInc); |
---|
[805] | 385 | RecordFieldPtr<uInt> mfreqidCol(rec, "FREQ_ID"); |
---|
| 386 | *mfreqidCol = id; |
---|
[1819] | 387 | //*ifCol = id; |
---|
[25] | 388 | |
---|
[1450] | 389 | id = table_->molecules().addEntry(pksrec.restFreq); |
---|
[805] | 390 | RecordFieldPtr<uInt> molidCol(rec, "MOLECULE_ID"); |
---|
| 391 | *molidCol = id; |
---|
[414] | 392 | |
---|
[1450] | 393 | id = table_->tcal().addEntry(pksrec.tcalTime, pksrec.tcal); |
---|
[805] | 394 | RecordFieldPtr<uInt> mcalidCol(rec, "TCAL_ID"); |
---|
| 395 | *mcalidCol = id; |
---|
[1450] | 396 | id = table_->weather().addEntry(pksrec.temperature, pksrec.pressure, |
---|
| 397 | pksrec.humidity, pksrec.windSpeed, |
---|
| 398 | pksrec.windAz); |
---|
[805] | 399 | RecordFieldPtr<uInt> mweatheridCol(rec, "WEATHER_ID"); |
---|
| 400 | *mweatheridCol = id; |
---|
[1586] | 401 | |
---|
[805] | 402 | RecordFieldPtr<uInt> mfocusidCol(rec, "FOCUS_ID"); |
---|
[1819] | 403 | id = table_->focus().addEntry(pksrec.parAngle, pksrec.focusAxi, |
---|
[1586] | 404 | pksrec.focusTan, pksrec.focusRot); |
---|
[805] | 405 | *mfocusidCol = id; |
---|
| 406 | RecordFieldPtr<Array<Double> > dirCol(rec, "DIRECTION"); |
---|
[1450] | 407 | *dirCol = pksrec.direction; |
---|
[922] | 408 | RecordFieldPtr<Float> azCol(rec, "AZIMUTH"); |
---|
[1450] | 409 | *azCol = pksrec.azimuth; |
---|
[922] | 410 | RecordFieldPtr<Float> elCol(rec, "ELEVATION"); |
---|
[1450] | 411 | *elCol = pksrec.elevation; |
---|
[405] | 412 | |
---|
[805] | 413 | RecordFieldPtr< Array<Float> > specCol(rec, "SPECTRA"); |
---|
| 414 | RecordFieldPtr< Array<uChar> > flagCol(rec, "FLAGTRA"); |
---|
| 415 | RecordFieldPtr< uInt > polnoCol(rec, "POLNO"); |
---|
[405] | 416 | |
---|
[805] | 417 | RecordFieldPtr< Array<Float> > tsysCol(rec, "TSYS"); |
---|
| 418 | // Turn the (nchan,npol) matrix and possible complex xPol vector |
---|
| 419 | // into 2-4 rows in the scantable |
---|
| 420 | Vector<Float> tsysvec(1); |
---|
[1819] | 421 | // Why is spectra.ncolumn() == 3 for haveXPol_ == True |
---|
[1450] | 422 | uInt npol = (pksrec.spectra.ncolumn()==1 ? 1: 2); |
---|
[805] | 423 | for ( uInt i=0; i< npol; ++i ) { |
---|
[1450] | 424 | tsysvec = pksrec.tsys(i); |
---|
[805] | 425 | *tsysCol = tsysvec; |
---|
[1819] | 426 | if (isGBTFITS) |
---|
| 427 | *polnoCol = pksrec.polNo ; |
---|
| 428 | else |
---|
| 429 | *polnoCol = i; |
---|
[405] | 430 | |
---|
[1450] | 431 | *specCol = pksrec.spectra.column(i); |
---|
[1462] | 432 | *flagCol = pksrec.flagged.column(i); |
---|
[805] | 433 | table_->table().addRow(); |
---|
| 434 | row.put(table_->table().nrow()-1, rec); |
---|
[2] | 435 | } |
---|
[1819] | 436 | |
---|
| 437 | RecordFieldPtr< uInt > flagrowCol(rec, "FLAGROW"); |
---|
| 438 | *flagrowCol = pksrec.flagrow; |
---|
| 439 | |
---|
[1060] | 440 | if ( haveXPol_[0] ) { |
---|
[805] | 441 | // no tsys given for xpol, so emulate it |
---|
[1450] | 442 | tsysvec = sqrt(pksrec.tsys[0]*pksrec.tsys[1]); |
---|
[805] | 443 | *tsysCol = tsysvec; |
---|
| 444 | // add real part of cross pol |
---|
| 445 | *polnoCol = 2; |
---|
[1450] | 446 | Vector<Float> r(real(pksrec.xPol)); |
---|
[805] | 447 | *specCol = r; |
---|
| 448 | // make up flags from linears |
---|
| 449 | /// @fixme this has to be a bitwise or of both pols |
---|
[1462] | 450 | *flagCol = pksrec.flagged.column(0);// | pksrec.flagged.column(1); |
---|
[805] | 451 | table_->table().addRow(); |
---|
| 452 | row.put(table_->table().nrow()-1, rec); |
---|
| 453 | // ad imaginary part of cross pol |
---|
| 454 | *polnoCol = 3; |
---|
[1450] | 455 | Vector<Float> im(imag(pksrec.xPol)); |
---|
[805] | 456 | *specCol = im; |
---|
| 457 | table_->table().addRow(); |
---|
| 458 | row.put(table_->table().nrow()-1, rec); |
---|
[2] | 459 | } |
---|
[1438] | 460 | #ifdef HAS_ALMA |
---|
| 461 | fillpm._update(n); |
---|
| 462 | #endif |
---|
[805] | 463 | } |
---|
| 464 | if (status > 0) { |
---|
| 465 | close(); |
---|
| 466 | throw(AipsError("Reading error occured, data possibly corrupted.")); |
---|
| 467 | } |
---|
[1438] | 468 | #ifdef HAS_ALMA |
---|
| 469 | fillpm.done(); |
---|
| 470 | #endif |
---|
[2] | 471 | return status; |
---|
| 472 | } |
---|
[805] | 473 | |
---|
[1819] | 474 | /** |
---|
| 475 | * For NRO data |
---|
| 476 | * |
---|
| 477 | * 2008/11/11 Takeshi Nakazato |
---|
| 478 | **/ |
---|
| 479 | void STFiller::openNRO( int whichIF, int whichBeam ) |
---|
| 480 | { |
---|
| 481 | // open file |
---|
| 482 | // DEBUG |
---|
| 483 | time_t t0 ; |
---|
| 484 | time( &t0 ) ; |
---|
| 485 | tm *ttm = localtime( &t0 ) ; |
---|
| 486 | LogIO os( LogOrigin( "STFiller", "openNRO()", WHERE ) ) ; |
---|
| 487 | // cout << "STFiller::openNRO() Start time = " << t0 |
---|
| 488 | // << " (" |
---|
| 489 | // << ttm->tm_year + 1900 << "/" << ttm->tm_mon + 1 << "/" << ttm->tm_mday |
---|
| 490 | // << " " |
---|
| 491 | // << ttm->tm_hour << ":" << ttm->tm_min << ":" << ttm->tm_sec |
---|
| 492 | // << ")" << endl ; |
---|
| 493 | os << "Start time = " << t0 |
---|
| 494 | << " (" |
---|
| 495 | << ttm->tm_year + 1900 << "/" << ttm->tm_mon + 1 << "/" << ttm->tm_mday |
---|
| 496 | << " " |
---|
| 497 | << ttm->tm_hour << ":" << ttm->tm_min << ":" << ttm->tm_sec |
---|
| 498 | << ")" << LogIO::POST ; |
---|
| 499 | |
---|
| 500 | // fill STHeader |
---|
| 501 | header_ = new STHeader() ; |
---|
| 502 | |
---|
| 503 | if ( nreader_->getHeaderInfo( header_->nchan, |
---|
| 504 | header_->npol, |
---|
| 505 | nIF_, |
---|
| 506 | nBeam_, |
---|
| 507 | header_->observer, |
---|
| 508 | header_->project, |
---|
| 509 | header_->obstype, |
---|
| 510 | header_->antennaname, |
---|
| 511 | header_->antennaposition, |
---|
| 512 | header_->equinox, |
---|
| 513 | header_->freqref, |
---|
| 514 | header_->reffreq, |
---|
| 515 | header_->bandwidth, |
---|
| 516 | header_->utc, |
---|
| 517 | header_->fluxunit, |
---|
| 518 | header_->epoch, |
---|
| 519 | header_->poltype ) ) { |
---|
| 520 | // cout << "STFiller::openNRO() Failed to get header information." << endl ; |
---|
| 521 | // return ; |
---|
| 522 | throw( AipsError("Failed to get header information.") ) ; |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | // set FRAME and BASEFRAME keyword of FREQUENCIES table |
---|
| 526 | if ( header_->freqref != "TOPO" ) { |
---|
| 527 | table_->frequencies().setFrame( header_->freqref, false ) ; |
---|
| 528 | table_->frequencies().setFrame( header_->freqref, true ) ; |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | ifOffset_ = 0; |
---|
| 532 | vector<Bool> ifs = nreader_->getIFs() ; |
---|
| 533 | if ( whichIF >= 0 ) { |
---|
| 534 | if ( whichIF >= 0 && whichIF < nIF_ ) { |
---|
| 535 | for ( int i = 0 ; i < nIF_ ; i++ ) |
---|
| 536 | ifs[i] = False ; |
---|
| 537 | ifs[whichIF] = True ; |
---|
| 538 | header_->nif = 1; |
---|
| 539 | nIF_ = 1; |
---|
| 540 | ifOffset_ = whichIF; |
---|
| 541 | } else { |
---|
| 542 | delete reader_; |
---|
| 543 | reader_ = 0; |
---|
| 544 | delete header_; |
---|
| 545 | header_ = 0; |
---|
| 546 | throw(AipsError("Illegal IF selection")); |
---|
| 547 | } |
---|
| 548 | } |
---|
| 549 | |
---|
| 550 | beamOffset_ = 0; |
---|
| 551 | vector<Bool> beams = nreader_->getBeams() ; |
---|
| 552 | if (whichBeam>=0) { |
---|
| 553 | if (whichBeam>=0 && whichBeam<nBeam_) { |
---|
| 554 | for ( int i = 0 ; i < nBeam_ ; i++ ) |
---|
| 555 | beams[i] = False ; |
---|
| 556 | beams[whichBeam] = True; |
---|
| 557 | header_->nbeam = 1; |
---|
| 558 | nBeam_ = 1; |
---|
| 559 | beamOffset_ = whichBeam; |
---|
| 560 | } else { |
---|
| 561 | delete reader_; |
---|
| 562 | reader_ = 0; |
---|
| 563 | delete header_; |
---|
| 564 | header_ = 0; |
---|
| 565 | throw(AipsError("Illegal Beam selection")); |
---|
| 566 | } |
---|
| 567 | } |
---|
| 568 | |
---|
| 569 | header_->nbeam = nBeam_ ; |
---|
| 570 | header_->nif = nIF_ ; |
---|
| 571 | |
---|
| 572 | // set header |
---|
| 573 | table_->setHeader( *header_ ) ; |
---|
| 574 | |
---|
| 575 | // DEBUG |
---|
| 576 | time_t t1 ; |
---|
| 577 | time( &t1 ) ; |
---|
| 578 | ttm = localtime( &t1 ) ; |
---|
| 579 | // cout << "STFiller::openNRO() End time = " << t1 |
---|
| 580 | // << " (" |
---|
| 581 | // << ttm->tm_year + 1900 << "/" << ttm->tm_mon + 1 << "/" << ttm->tm_mday |
---|
| 582 | // << " " |
---|
| 583 | // << ttm->tm_hour << ":" << ttm->tm_min << ":" << ttm->tm_sec |
---|
| 584 | // << ")" << endl ; |
---|
| 585 | // cout << "STFiller::openNRO() Elapsed time = " << t1 - t0 << " sec" << endl ; |
---|
| 586 | os << "End time = " << t1 |
---|
| 587 | << " (" |
---|
| 588 | << ttm->tm_year + 1900 << "/" << ttm->tm_mon + 1 << "/" << ttm->tm_mday |
---|
| 589 | << " " |
---|
| 590 | << ttm->tm_hour << ":" << ttm->tm_min << ":" << ttm->tm_sec |
---|
| 591 | << ")" << endl ; |
---|
| 592 | os << "Elapsed time = " << t1 - t0 << " sec" << endl ; |
---|
| 593 | os.post() ; |
---|
| 594 | // |
---|
| 595 | |
---|
| 596 | return ; |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | int STFiller::readNRO() |
---|
| 600 | { |
---|
| 601 | // DEBUG |
---|
| 602 | time_t t0 ; |
---|
| 603 | time( &t0 ) ; |
---|
| 604 | tm *ttm = localtime( &t0 ) ; |
---|
| 605 | LogIO os( LogOrigin( "STFiller", "readNRO()", WHERE ) ) ; |
---|
| 606 | // cout << "STFiller::readNRO() Start time = " << t0 |
---|
| 607 | // << " (" |
---|
| 608 | // << ttm->tm_year + 1900 << "/" << ttm->tm_mon + 1 << "/" << ttm->tm_mday |
---|
| 609 | // << " " |
---|
| 610 | // << ttm->tm_hour << ":" << ttm->tm_min << ":" << ttm->tm_sec |
---|
| 611 | // << ")" << endl ; |
---|
| 612 | os << "Start time = " << t0 |
---|
| 613 | << " (" |
---|
| 614 | << ttm->tm_year + 1900 << "/" << ttm->tm_mon + 1 << "/" << ttm->tm_mday |
---|
| 615 | << " " |
---|
| 616 | << ttm->tm_hour << ":" << ttm->tm_min << ":" << ttm->tm_sec |
---|
| 617 | << ")" << LogIO::POST ; |
---|
| 618 | // |
---|
| 619 | |
---|
| 620 | // fill row |
---|
| 621 | uInt id ; |
---|
| 622 | uInt imax = nreader_->getRowNum() ; |
---|
| 623 | vector< vector<double > > freqs ; |
---|
| 624 | uInt i = 0 ; |
---|
| 625 | int count = 0 ; |
---|
| 626 | uInt scanno ; |
---|
| 627 | uInt cycleno ; |
---|
[2201] | 628 | uInt iftmp ; |
---|
[1819] | 629 | uInt beamno ; |
---|
| 630 | uInt polno ; |
---|
| 631 | vector<double> fqs ; |
---|
| 632 | Vector<Double> restfreq ; |
---|
| 633 | uInt refbeamno ; |
---|
| 634 | Double scantime ; |
---|
| 635 | Double interval ; |
---|
| 636 | String srcname ; |
---|
| 637 | String fieldname ; |
---|
[2289] | 638 | Vector<Float> spectra ; |
---|
| 639 | Vector<uChar> flagtra ; |
---|
| 640 | Vector<Float> tsys ; |
---|
| 641 | Vector<Double> direction ; |
---|
[1819] | 642 | Float azimuth ; |
---|
| 643 | Float elevation ; |
---|
| 644 | Float parangle ; |
---|
| 645 | Float opacity ; |
---|
| 646 | uInt tcalid ; |
---|
| 647 | Int fitid ; |
---|
| 648 | uInt focusid ; |
---|
| 649 | Float temperature ; |
---|
| 650 | Float pressure ; |
---|
| 651 | Float humidity ; |
---|
| 652 | Float windvel ; |
---|
| 653 | Float winddir ; |
---|
| 654 | Double srcvel ; |
---|
[2289] | 655 | Vector<Double> propermotion( 2, 0.0 ) ; |
---|
[1819] | 656 | Vector<Double> srcdir ; |
---|
[2289] | 657 | Vector<Double> scanrate( 2, 0.0 ) ; |
---|
[1819] | 658 | for ( i = 0 ; i < imax ; i++ ) { |
---|
| 659 | string scanType = nreader_->getScanType( i ) ; |
---|
| 660 | Int srcType = -1 ; |
---|
| 661 | if ( scanType.compare( 0, 2, "ON") == 0 ) { |
---|
| 662 | // os << "ON srcType: " << i << LogIO::POST ; |
---|
| 663 | srcType = 0 ; |
---|
| 664 | } |
---|
| 665 | else if ( scanType.compare( 0, 3, "OFF" ) == 0 ) { |
---|
| 666 | //os << "OFF srcType: " << i << LogIO::POST ; |
---|
| 667 | srcType = 1 ; |
---|
| 668 | } |
---|
| 669 | else if ( scanType.compare( 0, 4, "ZERO" ) == 0 ) { |
---|
| 670 | //os << "ZERO srcType: " << i << LogIO::POST ; |
---|
| 671 | srcType = 2 ; |
---|
| 672 | } |
---|
| 673 | else { |
---|
| 674 | //os << "Undefined srcType: " << i << LogIO::POST ; |
---|
| 675 | srcType = 3 ; |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | // if srcType is 2 (ZERO scan), ignore scan |
---|
| 679 | if ( srcType != 2 && srcType != -1 && srcType != 3 ) { |
---|
| 680 | TableRow row( table_->table() ) ; |
---|
| 681 | TableRecord& rec = row.record(); |
---|
| 682 | |
---|
| 683 | if ( nreader_->getScanInfo( i, |
---|
| 684 | scanno, |
---|
| 685 | cycleno, |
---|
[2201] | 686 | iftmp, |
---|
[1819] | 687 | beamno, |
---|
| 688 | polno, |
---|
| 689 | fqs, |
---|
| 690 | restfreq, |
---|
| 691 | refbeamno, |
---|
| 692 | scantime, |
---|
| 693 | interval, |
---|
| 694 | srcname, |
---|
| 695 | fieldname, |
---|
| 696 | spectra, |
---|
| 697 | flagtra, |
---|
| 698 | tsys, |
---|
| 699 | direction, |
---|
| 700 | azimuth, |
---|
| 701 | elevation, |
---|
| 702 | parangle, |
---|
| 703 | opacity, |
---|
| 704 | tcalid, |
---|
| 705 | fitid, |
---|
| 706 | focusid, |
---|
| 707 | temperature, |
---|
| 708 | pressure, |
---|
| 709 | humidity, |
---|
| 710 | windvel, |
---|
| 711 | winddir, |
---|
| 712 | srcvel, |
---|
| 713 | propermotion, |
---|
| 714 | srcdir, |
---|
| 715 | scanrate ) ) { |
---|
| 716 | // cerr << "STFiller::readNRO() Failed to get scan information." << endl ; |
---|
| 717 | // return 1 ; |
---|
| 718 | throw( AipsError("Failed to get scan information.") ) ; |
---|
| 719 | } |
---|
| 720 | |
---|
| 721 | RecordFieldPtr<uInt> scannoCol( rec, "SCANNO" ) ; |
---|
| 722 | *scannoCol = scanno ; |
---|
| 723 | RecordFieldPtr<uInt> cyclenoCol(rec, "CYCLENO") ; |
---|
| 724 | *cyclenoCol = cycleno ; |
---|
| 725 | RecordFieldPtr<uInt> beamCol(rec, "BEAMNO") ; |
---|
| 726 | *beamCol = beamno ; |
---|
| 727 | RecordFieldPtr<uInt> ifCol(rec, "IFNO") ; |
---|
| 728 | RecordFieldPtr< uInt > polnoCol(rec, "POLNO") ; |
---|
| 729 | *polnoCol = polno ; |
---|
| 730 | RecordFieldPtr<uInt> mfreqidCol(rec, "FREQ_ID") ; |
---|
| 731 | if ( freqs.size() == 0 ) { |
---|
| 732 | id = table_->frequencies().addEntry( Double( fqs[0] ), |
---|
| 733 | Double( fqs[1] ), |
---|
| 734 | Double( fqs[2] ) ) ; |
---|
| 735 | *mfreqidCol = id ; |
---|
| 736 | *ifCol = id ; |
---|
| 737 | freqs.push_back( fqs ) ; |
---|
| 738 | } |
---|
| 739 | else { |
---|
| 740 | int iadd = -1 ; |
---|
| 741 | for ( uInt iif = 0 ; iif < freqs.size() ; iif++ ) { |
---|
| 742 | //os << "freqs[" << iif << "][1] = " << freqs[iif][1] << LogIO::POST ; |
---|
| 743 | double fdiff = abs( freqs[iif][1] - fqs[1] ) / freqs[iif][1] ; |
---|
| 744 | //os << "fdiff = " << fdiff << LogIO::POST ; |
---|
| 745 | if ( fdiff < 1.0e-8 ) { |
---|
| 746 | iadd = iif ; |
---|
| 747 | break ; |
---|
| 748 | } |
---|
| 749 | } |
---|
| 750 | if ( iadd == -1 ) { |
---|
| 751 | id = table_->frequencies().addEntry( Double( fqs[0] ), |
---|
| 752 | Double( fqs[1] ), |
---|
| 753 | Double( fqs[2] ) ) ; |
---|
| 754 | *mfreqidCol = id ; |
---|
| 755 | *ifCol = id ; |
---|
| 756 | freqs.push_back( fqs ) ; |
---|
| 757 | } |
---|
| 758 | else { |
---|
| 759 | *mfreqidCol = iadd ; |
---|
| 760 | *ifCol = iadd ; |
---|
| 761 | } |
---|
| 762 | } |
---|
| 763 | RecordFieldPtr<uInt> molidCol(rec, "MOLECULE_ID") ; |
---|
| 764 | id = table_->molecules().addEntry( restfreq ) ; |
---|
| 765 | *molidCol = id ; |
---|
| 766 | RecordFieldPtr<Int> rbCol(rec, "REFBEAMNO") ; |
---|
| 767 | *rbCol = refbeamno ; |
---|
| 768 | RecordFieldPtr<Double> mjdCol( rec, "TIME" ) ; |
---|
| 769 | *mjdCol = scantime ; |
---|
| 770 | RecordFieldPtr<Double> intervalCol( rec, "INTERVAL" ) ; |
---|
| 771 | *intervalCol = interval ; |
---|
| 772 | RecordFieldPtr<String> srcnCol(rec, "SRCNAME") ; |
---|
| 773 | *srcnCol = srcname ; |
---|
| 774 | RecordFieldPtr<Int> srctCol(rec, "SRCTYPE") ; |
---|
| 775 | *srctCol = srcType ; |
---|
| 776 | RecordFieldPtr<String> fieldnCol(rec, "FIELDNAME"); |
---|
| 777 | *fieldnCol = fieldname ; |
---|
| 778 | RecordFieldPtr< Array<Float> > specCol(rec, "SPECTRA") ; |
---|
| 779 | *specCol = spectra ; |
---|
| 780 | RecordFieldPtr< Array<uChar> > flagCol(rec, "FLAGTRA") ; |
---|
| 781 | *flagCol = flagtra ; |
---|
| 782 | RecordFieldPtr< Array<Float> > tsysCol(rec, "TSYS") ; |
---|
| 783 | *tsysCol = tsys ; |
---|
| 784 | RecordFieldPtr< Array<Double> > dirCol(rec, "DIRECTION") ; |
---|
| 785 | *dirCol = direction ; |
---|
| 786 | RecordFieldPtr<Float> azCol(rec, "AZIMUTH") ; |
---|
| 787 | *azCol = azimuth ; |
---|
| 788 | RecordFieldPtr<Float> elCol(rec, "ELEVATION") ; |
---|
| 789 | *elCol = elevation ; |
---|
[1837] | 790 | //RecordFieldPtr<Float> parCol(rec, "PARANGLE") ; |
---|
| 791 | //*parCol = parangle ; |
---|
[1819] | 792 | RecordFieldPtr<Float> tauCol(rec, "OPACITY") ; |
---|
| 793 | *tauCol = opacity ; |
---|
[1841] | 794 | id = table_->tcal().addEntry("",Vector<Float>(1,0.0)); |
---|
| 795 | RecordFieldPtr<uInt> mcalidCol(rec, "TCAL_ID"); |
---|
| 796 | *mcalidCol = id; |
---|
| 797 | //RecordFieldPtr<uInt> mcalidCol(rec, "TCAL_ID") ; |
---|
| 798 | //*mcalidCol = tcalid ; |
---|
[1819] | 799 | RecordFieldPtr<Int> fitCol(rec, "FIT_ID") ; |
---|
| 800 | *fitCol = fitid ; |
---|
[1837] | 801 | //RecordFieldPtr<uInt> mfocusidCol(rec, "FOCUS_ID") ; |
---|
| 802 | //*mfocusidCol = focusid ; |
---|
| 803 | RecordFieldPtr<uInt> mfocusidCol(rec, "FOCUS_ID"); |
---|
| 804 | id = table_->focus().addEntry(parangle, 0.0, 0.0, 0.0 ) ; |
---|
| 805 | *mfocusidCol = id; |
---|
[1819] | 806 | RecordFieldPtr<uInt> mweatheridCol(rec, "WEATHER_ID") ; |
---|
| 807 | id = table_->weather().addEntry( temperature, |
---|
| 808 | pressure, |
---|
| 809 | humidity, |
---|
| 810 | windvel, |
---|
| 811 | winddir ) ; |
---|
| 812 | *mweatheridCol = id ; |
---|
| 813 | RecordFieldPtr<Double> svelCol(rec, "SRCVELOCITY") ; |
---|
| 814 | *svelCol = srcvel ; |
---|
| 815 | RecordFieldPtr<Array<Double> > spmCol(rec, "SRCPROPERMOTION") ; |
---|
| 816 | *spmCol = propermotion ; |
---|
| 817 | RecordFieldPtr<Array<Double> > sdirCol(rec, "SRCDIRECTION") ; |
---|
| 818 | *sdirCol = srcdir ; |
---|
| 819 | RecordFieldPtr<Array<Double> > srateCol(rec, "SCANRATE"); |
---|
| 820 | *srateCol = scanrate ; |
---|
| 821 | |
---|
| 822 | table_->table().addRow() ; |
---|
| 823 | row.put(table_->table().nrow()-1, rec) ; |
---|
| 824 | } |
---|
| 825 | else { |
---|
| 826 | count++ ; |
---|
| 827 | } |
---|
| 828 | // DEBUG |
---|
| 829 | //int rownum = nreader_->getRowNum() ; |
---|
| 830 | //os << "Finished row " << i << "/" << rownum << LogIO::POST ; |
---|
| 831 | // |
---|
| 832 | } |
---|
| 833 | |
---|
| 834 | // DEBUG |
---|
| 835 | time_t t1 ; |
---|
| 836 | time( &t1 ) ; |
---|
| 837 | ttm = localtime( &t1 ) ; |
---|
| 838 | // cout << "STFiller::readNRO() Processed " << i << " rows" << endl ; |
---|
| 839 | // cout << "STFiller::readNRO() Added " << i - count << " rows (ignored " |
---|
| 840 | // << count << " \"ZERO\" scans)" << endl ; |
---|
| 841 | // cout << "STFiller::readNRO() End time = " << t1 |
---|
| 842 | // << " (" |
---|
| 843 | // << ttm->tm_year + 1900 << "/" << ttm->tm_mon + 1 << "/" << ttm->tm_mday |
---|
| 844 | // << " " |
---|
| 845 | // << ttm->tm_hour << ":" << ttm->tm_min << ":" << ttm->tm_sec |
---|
| 846 | // << ")" << endl ; |
---|
| 847 | // cout << "STFiller::readNRO() Elapsed time = " << t1 - t0 << " sec" << endl ; |
---|
| 848 | os << "Processed " << i << " rows" << endl ; |
---|
| 849 | os << "Added " << i - count << " rows (ignored " |
---|
| 850 | << count << " \"ZERO\" scans)" << endl ; |
---|
| 851 | os.post() ; |
---|
| 852 | os << "End time = " << t1 |
---|
| 853 | << " (" |
---|
| 854 | << ttm->tm_year + 1900 << "/" << ttm->tm_mon + 1 << "/" << ttm->tm_mday |
---|
| 855 | << " " |
---|
| 856 | << ttm->tm_hour << ":" << ttm->tm_min << ":" << ttm->tm_sec |
---|
| 857 | << ")" << endl ; |
---|
| 858 | os << "Elapsed time = " << t1 - t0 << " sec" << endl ; |
---|
| 859 | os.post() ; |
---|
| 860 | // |
---|
| 861 | |
---|
| 862 | return 0 ; |
---|
| 863 | } |
---|
| 864 | |
---|
| 865 | Bool STFiller::fileCheck() |
---|
| 866 | { |
---|
| 867 | bool bval = false ; |
---|
| 868 | |
---|
| 869 | // if filename_ is directory, return false |
---|
| 870 | File inFile( filename_ ) ; |
---|
| 871 | if ( inFile.isDirectory() ) |
---|
| 872 | return bval ; |
---|
| 873 | |
---|
| 874 | // if beginning of header data is "RW", return true |
---|
| 875 | // otherwise, return false ; |
---|
| 876 | FILE *fp = fopen( filename_.c_str(), "r" ) ; |
---|
| 877 | char buf[9] ; |
---|
| 878 | char buf2[80] ; |
---|
[2163] | 879 | size_t tmpret; |
---|
| 880 | tmpret = fread( buf, 4, 1, fp ) ; |
---|
[1819] | 881 | buf[4] = '\0' ; |
---|
| 882 | fseek( fp, 640, SEEK_SET ) ; |
---|
[2163] | 883 | tmpret = fread( buf2, 80, 1, fp ) ; |
---|
| 884 | (void) tmpret; //suppress unused warning |
---|
[1819] | 885 | if ( ( strncmp( buf, "RW", 2 ) == 0 ) || ( strstr( buf2, "NRO45M" ) != NULL ) ) { |
---|
| 886 | bval = true ; |
---|
| 887 | } |
---|
| 888 | fclose( fp ) ; |
---|
| 889 | return bval ; |
---|
| 890 | } |
---|
| 891 | |
---|
[805] | 892 | }//namespace asap |
---|