Changeset 1779 for branches/mergetest/external/atnf/PKSIO
- Timestamp:
- 07/29/10 19:13:46 (14 years ago)
- Location:
- branches/mergetest
- Files:
-
- 2 deleted
- 23 edited
- 22 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/mergetest
- Property svn:mergeinfo changed
-
branches/mergetest/external/atnf/PKSIO/FITSreader.cc
r1720 r1779 55 55 const int getSpectra, 56 56 const int getXPol, 57 const int getFeedPos, 58 const int getPointing, 57 59 const int coordSys) 58 60 { … … 85 87 cGetSpectra = getSpectra && cHaveSpectra; 86 88 cGetXPol = getXPol && cGetXPol; 89 cGetFeedPos = getFeedPos; 87 90 cCoordSys = coordSys; 91 88 92 89 93 return maxNChan; -
branches/mergetest/external/atnf/PKSIO/FITSreader.h
r1720 r1779 41 41 42 42 #include <atnf/PKSIO/MBrecord.h> 43 #include <atnf/PKSIO/PKSmsg.h>44 43 45 44 using namespace std; 45 46 46 47 47 // <summary> … … 49 49 // </summary> 50 50 51 class FITSreader : public PKSmsg 51 //class FITSreader 52 class FITSreader 52 53 { 53 54 public: … … 106 107 const int refChan[], 107 108 const int getSpectra = 1, 108 const int getXPol = 0, 109 const int getXPol = 0, 110 const int getFeedPos = 0, 111 const int getPointing = 0, 109 112 const int coordSys = 0); 113 110 114 111 115 // Find the range in time and position of the data selected. … … 119 123 // Read the next data record. 120 124 virtual int read( 125 // PKSMBrecord &record) = 0; 121 126 MBrecord &record) = 0; 122 127 … … 125 130 126 131 protected: 127 int *cBeams, *cEndChan, c CoordSys, cGetSpectra, cGetXPol, cHaveBase,128 cHaveSpectra, *cHaveXPol, *cIFs, cNBeam, *cNChan, cNIF, *cNPol,129 *cRefChan, *cStartChan;132 int *cBeams, *cEndChan, cGetFeedPos, cCoordSys, cGetSpectra, cGetXPol, 133 cHaveBase, cHaveSpectra, *cHaveXPol, *cIFs, cNBeam, *cNChan, cNIF, 134 *cNPol, *cRefChan, *cStartChan; 130 135 131 136 // For use in constructing messages. 132 137 char cMsg[256]; 138 133 139 }; 134 140 -
branches/mergetest/external/atnf/PKSIO/MBFITSreader.cc
r1720 r1779 41 41 #include <atnf/PKSIO/MBrecord.h> 42 42 43 #include <casa/Logging/LogIO.h> 44 43 45 #include <casa/math.h> 44 46 #include <casa/iostream.h> … … 57 59 const double HALFPI = PI / 2.0; 58 60 const double R2D = 180.0 / PI; 61 62 // Class name 63 const string className = "MBFITSreader" ; 59 64 60 65 //------------------------------------------------- MBFITSreader::MBFITSreader … … 99 104 100 105 // Tell RPFITSIN not to report errors directly. 101 iostat_.errlun = -1; 102 103 // By default, messages are written to stderr. 104 initMsg(); 106 //iostat_.errlun = -1; 105 107 } 106 108 … … 131 133 int &extraSysCal) 132 134 { 133 // Clear the message stack.134 clearMsg();135 const string methodName = "open()" ; 136 LogIO os( LogOrigin( className, methodName, WHERE ) ) ; 135 137 136 138 if (cMBopen) { … … 143 145 int jstat = -3; 144 146 if (rpfitsin(jstat)) { 145 sprintf(cMsg, " ERROR: Failed to open MBFITS file\n%s", rpname);146 logMsg(cMsg);147 sprintf(cMsg, "Failed to open MBFITS file\n%s", rpname); 148 os << LogIO::SEVERE << cMsg << LogIO::POST ; 147 149 return 1; 148 150 } … … 161 163 jstat = -1; 162 164 if (rpfitsin(jstat)) { 163 sprintf(cMsg, " ERROR:Failed to read MBFITS header in file\n"164 " 165 logMsg(cMsg);165 sprintf(cMsg, "Failed to read MBFITS header in file\n" 166 "%s", rpname); 167 os << LogIO::SEVERE << cMsg << LogIO::POST ; 166 168 close(); 167 169 return 1; … … 173 175 // Non-ATNF data may not store the position in (u,v,w). 174 176 if (strncmp(names_.sta, "tid", 3) == 0) { 175 sprintf(cMsg, " WARNING:Found Tidbinbilla data");177 sprintf(cMsg, "Found Tidbinbilla data"); 176 178 cSUpos = 1; 177 179 } else if (strncmp(names_.sta, "HOB", 3) == 0) { 178 sprintf(cMsg, " WARNING:Found Hobart data");180 sprintf(cMsg, "Found Hobart data"); 179 181 cSUpos = 1; 180 182 } else if (strncmp(names_.sta, "CED", 3) == 0) { 181 sprintf(cMsg, " WARNING:Found Ceduna data");183 sprintf(cMsg, "Found Ceduna data"); 182 184 cSUpos = 1; 183 185 } else { … … 187 189 if (cSUpos) { 188 190 strcat(cMsg, ", using telescope position\n from SU table."); 189 logMsg(cMsg);191 os << LogIO::WARN << cMsg << LogIO::POST ; 190 192 cInterp = 0; 191 193 } … … 207 209 208 210 if (cNBeam <= 0) { 209 logMsg("ERROR: Couldn't determine number of beams.");211 os << LogIO::SEVERE << "Couldn't determine number of beams." << LogIO::POST ; 210 212 close(); 211 213 return 1; … … 232 234 233 235 sprintf(cMsg, 234 " WARNING:RPFITSIN returned beam number %2d for AN table\n"235 " 236 "RPFITSIN returned beam number %2d for AN table\n" 237 "entry %2d with name '%.8s'", beamNo, iBeam+1, sta); 236 238 237 239 char text[8]; … … 245 247 } 246 248 247 logMsg(cMsg);249 os << LogIO::WARN << cMsg << LogIO::POST ; 248 250 } 249 251 … … 339 341 // Read the first syscal record. 340 342 if (rpget(1, cEOS)) { 341 logMsg("ERROR: Failed to read first syscal record.");343 os << LogIO::SEVERE << "Failed to read first syscal record." << LogIO::POST ; 342 344 close(); 343 345 return 1; … … 374 376 double &bandwidth) 375 377 { 378 const string methodName = "getHeader()" ; 379 LogIO os( LogOrigin( className, methodName, WHERE ) ) ; 380 376 381 if (!cMBopen) { 377 logMsg("ERROR: An MBFITS file has not been opened.");382 os << LogIO::SEVERE << "An MBFITS file has not been opened." << LogIO::POST ; 378 383 return 1; 379 384 } … … 511 516 MBrecord &MBrec) 512 517 { 518 const string methodName = "read()" ; 519 LogIO os( LogOrigin( className, methodName, WHERE ) ) ; 520 513 521 int beamNo = -1; 514 522 int haveData, pCode = 0, status; … … 517 525 518 526 if (!cMBopen) { 519 logMsg("ERROR: An MBFITS file has not been opened.");527 os << LogIO::SEVERE << "An MBFITS file has not been opened." << LogIO::POST ; 520 528 return 1; 521 529 } … … 562 570 563 571 #ifdef PKSIO_DEBUG 564 fprintf(stderr, "\nEnd-of-file detected, flushing last cycle.\n");572 os << LogIO::DEBUGGING << "\nEnd-of-file detected, flushing last cycle.\n" << LogIO::POST ; 565 573 #endif 566 574 … … 646 654 647 655 if (cNBin > 1 && cNBeamSel > 1) { 648 logMsg("ERROR: Cannot handle binning mode for multiple beams.\n" 649 " Select a single beam for input."); 656 os << LogIO::SEVERE << "Cannot handle binning mode for multiple beams.\nSelect a single beam for input." << LogIO::POST ; 650 657 close(); 651 658 return 1; … … 717 724 // the start of the next. 718 725 #ifdef PKSIO_DEBUG 719 fprintf(stderr, "Change-of-day on cUTC: %.1f -> %.1f\n", 720 cPrevUTC, cUTC); 726 char buf[256] ; 727 sprintf(buf, "Change-of-day on cUTC: %.1f -> %.1f\n", cPrevUTC, cUTC); 728 os << LogIO::DEBUGGING << buf << LogIO::POST ; 721 729 #endif 722 730 // Can't change the recorded value of cUTC directly (without also … … 724 732 // an offset to be applied when comparing integration timestamps. 725 733 cod = 86400.0; 726 } 734 735 } 727 736 728 737 if ((cUTC+cod) < cPrevUTC - 1.0) { … … 738 747 // All other data should be fully time ordered. 739 748 sprintf(cMsg, 740 " WARNING:Cycle %d:%03d-%03d, UTC went backwards from\n"741 " 742 " 749 "Cycle %d:%03d-%03d, UTC went backwards from\n" 750 "%.1f to %.1f! Incrementing day number,\n" 751 "positions may be unreliable.", cScanNo, cCycleNo, 743 752 cCycleNo+1, cPrevUTC, cUTC); 744 logMsg(cMsg); 753 //logMsg(cMsg); 754 os << LogIO::WARN << cMsg << LogIO::POST ; 745 755 cUTC += 86400.0; 746 756 } … … 782 792 } 783 793 784 fprintf(stderr, "\n In:%4d%4d%3d%3d %.3f %c %.3f (%+.3fs) - "794 sprintf(buf, "\n In:%4d%4d%3d%3d %.3f %c %.3f (%+.3fs) - " 785 795 "%sflushing\n", cScanNo, cCycleNo, beamNo, cIFno, cUTC, rel, cW, dt, 786 796 cFlushing ? "" : "not "); 797 os << LogIO::DEBUGGING << buf << LogIO::POST ; 787 798 if (cEOS) { 788 fprintf(stderr, "Start of new scan, flushing previous scan.\n"); 799 sprintf(buf, "Start of new scan, flushing previous scan.\n"); 800 os << LogIO::DEBUGGING << buf << LogIO::POST ; 789 801 } 790 802 #endif … … 884 896 885 897 #ifdef PKSIO_DEBUG 886 fprintf(stderr, "This (%d) ra, dec, UTC: %9.4f %9.4f %10.3f %9.4f\n",898 sprintf(buf, "This (%d) ra, dec, UTC: %9.4f %9.4f %10.3f %9.4f\n", 887 899 iMBuff->cycleNo, thisRA*R2D, thisDec*R2D, thisUTC, thisPA*R2D); 900 os << LogIO::DEBUGGING << buf << LogIO::POST ; 888 901 #endif 889 902 … … 921 934 922 935 #ifdef PKSIO_DEBUG 923 fprintf(stderr, "Next (%d) ra, dec, UTC: %9.4f %9.4f %10.3f "936 sprintf(buf, "Next (%d) ra, dec, UTC: %9.4f %9.4f %10.3f " 924 937 "(0.000s)\n", cCycleNo, cU*R2D, cV*R2D, cW); 938 os << LogIO::DEBUGGING << buf << LogIO::POST ; 925 939 #endif 926 940 … … 937 951 938 952 #ifdef PKSIO_DEBUG 939 fprintf(stderr, "Next (%d) ra, dec, UTC: %9.4f %9.4f %10.3f "953 sprintf(buf, "Next (%d) ra, dec, UTC: %9.4f %9.4f %10.3f " 940 954 "(%+.3fs)\n", cCycleNo, nextRA*R2D, nextDec*R2D, nextUTC, 941 955 utcDiff(nextUTC, thisUTC)); 956 os << LogIO::DEBUGGING << buf << LogIO::POST ; 942 957 #endif 943 958 … … 1089 1104 #ifdef PKSIO_DEBUG 1090 1105 double avRate = sqrt(cAvRate[0]*cAvRate[0] + cAvRate[1]*cAvRate[1]); 1091 fprintf(stderr, "RA, Dec, Av & PA rates: %8.4f %8.4f %8.4f %8.4f "1106 sprintf(buf, "RA, Dec, Av & PA rates: %8.4f %8.4f %8.4f %8.4f " 1092 1107 "pCode %d\n", raRate*R2D, decRate*R2D, avRate*R2D, paRate*R2D, pCode); 1108 os << LogIO::DEBUGGING << buf << LogIO::POST ; 1093 1109 #endif 1094 1110 … … 1113 1129 1114 1130 #ifdef PKSIO_DEBUG 1115 fprintf(stderr, "Intp (%d) ra, dec, UTC: %9.4f %9.4f %10.3f (pCode, "1131 sprintf(buf, "Intp (%d) ra, dec, UTC: %9.4f %9.4f %10.3f (pCode, " 1116 1132 "age: %d %.1fs)\n", iMBuff->cycleNo, cBuffer[jbuff].ra*R2D, 1117 1133 cBuffer[jbuff].dec*R2D, cBuffer[jbuff].utc, iMBuff->pCode, 1118 1134 iMBuff->rateAge); 1135 os << LogIO::DEBUGGING << buf << LogIO::POST ; 1119 1136 #endif 1120 1137 } … … 1130 1147 1131 1148 #ifdef PKSIO_DEBUG 1132 fprintf(stderr, "Out:%4d%4d%3d%3d\n", MBrec.scanNo, MBrec.cycleNo,1149 sprintf(buf, "Out:%4d%4d%3d%3d\n", MBrec.scanNo, MBrec.cycleNo, 1133 1150 MBrec.beamNo, MBrec.IFno[0]); 1151 os << LogIO::DEBUGGING << buf << LogIO::POST ; 1134 1152 #endif 1135 1153 … … 1172 1190 // Sanity check on the number of IFs in the new scan. 1173 1191 if (if_.n_if != cNIF) { 1174 sprintf(cMsg, " WARNING:Scan %d has %d IFs instead of %d, "1192 sprintf(cMsg, "Scan %d has %d IFs instead of %d, " 1175 1193 "continuing.", cScanNo, if_.n_if, cNIF); 1176 logMsg(cMsg);1194 os << LogIO::WARN << cMsg << LogIO::POST ; 1177 1195 } 1178 1196 } … … 1186 1204 1187 1205 #ifdef PKSIO_DEBUG 1188 fprintf(stderr, "Buf:%4d%4d%3d%3d\n", cScanNo, cCycleNo, beamNo, cIFno); 1206 sprintf(buf, "Buf:%4d%4d%3d%3d\n", cScanNo, cCycleNo, beamNo, cIFno); 1207 os << LogIO::DEBUGGING << buf << LogIO::POST ; 1189 1208 #endif 1190 1209 … … 1265 1284 // Integration cycle written to the output file twice (the only known 1266 1285 // example is 1999-05-22_1914_000-031805_03v.hpf). 1267 sprintf(cMsg, " WARNING:Integration cycle %d:%d, beam %2d, \n"1268 " 1286 sprintf(cMsg, "Integration cycle %d:%d, beam %2d, \n" 1287 "IF %d was duplicated.", cScanNo, cCycleNo-1, 1269 1288 beamNo, cIFno); 1270 logMsg(cMsg);1289 os << LogIO::WARN << cMsg << LogIO::POST ; 1271 1290 } 1272 1291 iMBuff->nChan[iIFSel] = nChan; … … 1454 1473 int MBFITSreader::rpget(int syscalonly, int &EOS) 1455 1474 { 1475 const string methodName = "rpget()" ; 1476 LogIO os( LogOrigin( className, methodName, WHERE ) ) ; 1477 1456 1478 EOS = 0; 1457 1479 … … 1469 1491 // Read failed; retry. 1470 1492 numErr++; 1471 logMsg("WARNING: RPFITS read failed - retrying.");1493 os << LogIO::WARN << "RPFITS read failed - retrying." << LogIO::POST ; 1472 1494 jstat = 0; 1473 1495 break; … … 1525 1547 default: 1526 1548 // Shouldn't reach here. 1527 sprintf(cMsg, " WARNING:Unrecognized RPFITSIN return code: %d "1549 sprintf(cMsg, "Unrecognized RPFITSIN return code: %d " 1528 1550 "(retrying).", jstat); 1529 logMsg(cMsg);1551 os << LogIO::WARN << cMsg << LogIO::POST ; 1530 1552 jstat = 0; 1531 1553 break; … … 1533 1555 } 1534 1556 1535 logMsg("ERROR: RPFITS read failed too many times.");1557 os << LogIO::SEVERE << "RPFITS read failed too many times." << LogIO::POST ; 1536 1558 return 2; 1537 1559 } … … 1549 1571 1550 1572 // Handle messages from RPFITSIN. 1573 /** 1551 1574 if (names_.errmsg[0] != ' ') { 1552 1575 int i; … … 1559 1582 logMsg(cMsg); 1560 1583 } 1561 1584 **/ 1562 1585 return jstat; 1563 1586 } -
branches/mergetest/external/atnf/PKSIO/MBrecord.cc
r1720 r1779 322 322 refBeam = other.refBeam; 323 323 324 polNo = other.polNo ; 325 srcVelocity = other.srcVelocity ; 326 324 327 return *this; 325 328 } … … 436 439 refBeam = other.refBeam; 437 440 441 polNo = other.polNo ; 442 srcVelocity = other.srcVelocity ; 443 438 444 return 0; 439 445 } -
branches/mergetest/external/atnf/PKSIO/MBrecord.h
r1720 r1779 166 166 short refBeam; // Reference beam, in beam-switching (MX) 167 167 // mode (added 1999/03/17). 168 int polNo ; // polarization ID 169 float srcVelocity ; // source velocity w.r.t. reference frame 168 170 169 171 private: -
branches/mergetest/external/atnf/PKSIO/PKSFITSreader.cc
r1720 r1779 34 34 //#--------------------------------------------------------------------------- 35 35 36 #include <atnf/PKSIO/PKSmsg.h>37 36 #include <atnf/PKSIO/MBFITSreader.h> 38 37 #include <atnf/PKSIO/SDFITSreader.h> … … 44 43 #include <casa/BasicMath/Math.h> 45 44 #include <casa/Quanta/MVTime.h> 45 #include <casa/Logging/LogIO.h> 46 46 47 47 //----------------------------------------------- PKSFITSreader::PKSFITSreader … … 61 61 cReader = new MBFITSreader(retry, interpolate ? 1 : 0); 62 62 } 63 64 // By default, messages are written to stderr.65 initMsg();66 63 } 67 64 … … 76 73 } 77 74 78 //------------------------------------------------------ PKSFITSreader::setMsg79 80 // Set message disposition. If fd is non-zero messages will be written81 // to that file descriptor, else stored for retrieval by getMsg().82 83 Int PKSFITSreader::setMsg(FILE *fd)84 {85 PKSmsg::setMsg(fd);86 cReader->setMsg(fd);87 88 return 0;89 }90 91 75 //-------------------------------------------------------- PKSFITSreader::open 92 76 … … 95 79 Int PKSFITSreader::open( 96 80 const String fitsName, 81 const String antenna, 97 82 Vector<Bool> &beams, 98 83 Vector<Bool> &IFs, … … 103 88 Bool &haveSpectra) 104 89 { 105 clearMsg();106 107 90 int extraSysCal, haveBase_, *haveXPol_, haveSpectra_, nBeam, *nChan_, 108 91 nIF, *nPol_, status; … … 110 93 nChan_, nPol_, haveXPol_, haveBase_, haveSpectra_, 111 94 extraSysCal); 112 logMsg(cReader->getMsg());113 cReader->clearMsg();95 //logMsg(cReader->getMsg()); 96 //cReader->clearMsg(); 114 97 if (status) { 115 98 return status; … … 178 161 obsType_, bunit_, equinox_, radecsys, 179 162 dopplerFrame_, datobs, utc, refFreq, bandwidth); 180 logMsg(cReader->getMsg());181 cReader->clearMsg();163 //logMsg(cReader->getMsg()); 164 //cReader->clearMsg(); 182 165 if (status) { 183 166 return 1; … … 218 201 Int status = cReader->getFreqInfo(nIF, startfreq, endfreq); 219 202 220 logMsg(cReader->getMsg());221 cReader->clearMsg();203 //logMsg(cReader->getMsg()); 204 //cReader->clearMsg(); 222 205 if (!status) { 223 206 startFreq.takeStorage(IPosition(1,nIF), startfreq, TAKE_OVER); … … 240 223 const Bool getSpectra, 241 224 const Bool getXPol, 225 const Bool getFeedPos, 226 const Bool getPointing, 242 227 const Int coordSys) 243 228 { … … 307 292 cGetSpectra = getSpectra; 308 293 cGetXPol = getXPol; 294 cGetFeedPos = getFeedPos; 295 cGetPointing = getPointing; 309 296 cCoordSys = coordSys; 310 297 311 298 uInt maxNChan = cReader->select(start, end, ref, cGetSpectra, cGetXPol, 312 c CoordSys);313 logMsg(cReader->getMsg());314 cReader->clearMsg();299 cGetFeedPos, cGetPointing, cCoordSys); 300 //logMsg(cReader->getMsg()); 301 //cReader->clearMsg(); 315 302 316 303 delete [] end; … … 336 323 337 324 Int status = cReader->findRange(nRow, nSel, dateSpan, utcSpan, posns); 338 logMsg(cReader->getMsg());339 cReader->clearMsg();325 //logMsg(cReader->getMsg()); 326 //cReader->clearMsg(); 340 327 341 328 if (!status) { … … 361 348 { 362 349 Int status = cReader->read(cMBrec); 363 logMsg(cReader->getMsg());364 cReader->clearMsg();350 //logMsg(cReader->getMsg()); 351 //cReader->clearMsg(); 365 352 366 353 if (status) { … … 378 365 pksrec.scanNo = cMBrec.scanNo; 379 366 pksrec.cycleNo = cMBrec.cycleNo; 367 pksrec.polNo = cMBrec.polNo ; 380 368 381 369 // Extract MJD. 382 370 Int day, month, year; 383 sscanf(cMBrec.datobs, "%4d-%2d-%2d", &year, &month, &day); 384 pksrec.mjd = MVTime(year, month, Double(day)).day() + cMBrec.utc/86400.0; 371 if ( strstr( cMBrec.datobs, "T" ) == NULL ) { 372 sscanf(cMBrec.datobs, "%4d-%2d-%2d", &year, &month, &day); 373 pksrec.mjd = MVTime(year, month, Double(day)).day() + cMBrec.utc/86400.0; 374 } 375 else { 376 Double dd, hour, min, sec ; 377 sscanf( cMBrec.datobs, "%4d-%2d-%2lfT%lf:%lf:%lf", &year, &month, &dd, &hour, &min, &sec ) ; 378 dd = dd + ( hour * 3600.0 + min * 60.0 + sec ) / 86400.0 ; 379 pksrec.mjd = MVTime(year, month, dd).day() ; 380 } 385 381 386 382 pksrec.interval = cMBrec.exposure; … … 388 384 pksrec.fieldName = trim(cMBrec.srcName); 389 385 pksrec.srcName = pksrec.fieldName; 386 387 int namelen = pksrec.srcName.length() ; 388 if ( namelen > 4 ) { 389 String srcsub = pksrec.srcName.substr( namelen-4, 4 ) ; 390 if ( srcsub.find( "_psc" ) != string::npos ) { 391 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 392 pksrec.srcName = pksrec.fieldName + "_ps_calon" ; 393 } 394 else if ( srcsub.find( "_pso" ) != string::npos ) { 395 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 396 pksrec.srcName = pksrec.fieldName + "_ps" ; 397 } 398 else if ( srcsub.find( "_prc" ) != string::npos ) { 399 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 400 pksrec.srcName = pksrec.fieldName + "_psr_calon" ; 401 } 402 else if ( srcsub.find( "_pro" ) != string::npos ) { 403 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 404 pksrec.srcName = pksrec.fieldName + "_psr" ; 405 } 406 else if ( srcsub.find( "_fsc" ) != string::npos ) { 407 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 408 pksrec.srcName = pksrec.fieldName + "_fs_calon" ; 409 } 410 else if ( srcsub.find( "_fso" ) != string::npos ) { 411 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 412 pksrec.srcName = pksrec.fieldName + "_fs" ; 413 } 414 else if ( srcsub.find( "_frc" ) != string::npos ) { 415 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 416 pksrec.srcName = pksrec.fieldName + "_fsr_calon" ; 417 } 418 else if ( srcsub.find( "_fro" ) != string::npos ) { 419 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 420 pksrec.srcName = pksrec.fieldName + "_fsr" ; 421 } 422 else if ( srcsub.find( "_nsc" ) != string::npos || srcsub.find( "_nrc" ) != string::npos ) { 423 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 424 pksrec.srcName = pksrec.fieldName + "_nod_calon" ; 425 } 426 else if ( srcsub.find( "_nso" ) != string::npos || srcsub.find( "_nro" ) != string::npos ) { 427 pksrec.fieldName = pksrec.srcName.substr( 0, namelen-4 ) ; 428 pksrec.srcName = pksrec.fieldName + "_nod" ; 429 } 430 } 390 431 391 432 pksrec.srcDir.resize(2); … … 396 437 pksrec.srcPM(0) = 0.0; 397 438 pksrec.srcPM(1) = 0.0; 398 pksrec.srcVel = 0.0;439 pksrec.srcVel = cMBrec.srcVelocity; 399 440 pksrec.obsType = trim(cMBrec.obsType); 400 441 … … 404 445 pksrec.bandwidth = chanWidth * nChan; 405 446 pksrec.freqInc = cMBrec.fqDelt[0]; 406 pksrec.restFreq = cMBrec.restFreq; 447 pksrec.restFreq.resize(1) ; 448 pksrec.restFreq(0) = cMBrec.restFreq; 407 449 408 450 pksrec.tcal.resize(nPol); … … 498 540 { 499 541 cReader->close(); 500 logMsg(cReader->getMsg());501 cReader->clearMsg();542 //logMsg(cReader->getMsg()); 543 //cReader->clearMsg(); 502 544 } 503 545 -
branches/mergetest/external/atnf/PKSIO/PKSFITSreader.h
r1720 r1779 70 70 virtual ~PKSFITSreader(); 71 71 72 // Set message disposition.73 virtual Int setMsg(74 FILE *fd = 0x0);75 76 72 // Open the FITS file for reading. 77 73 virtual Int open( 78 74 const String fitsName, 75 const String antenna, 79 76 Vector<Bool> &beams, 80 77 Vector<Bool> &IFs, … … 114 111 const Bool getSpectra = True, 115 112 const Bool getXPol = False, 113 const Bool getFeedPos = False, 114 const Bool getPointing = False, 116 115 const Int coordSys = 0); 117 116 -
branches/mergetest/external/atnf/PKSIO/PKSMS2reader.cc
r1720 r1779 34 34 //#--------------------------------------------------------------------------- 35 35 36 #include <atnf/pks/pks_maths.h> 37 #include <atnf/PKSIO/PKSmsg.h> 38 #include <atnf/PKSIO/PKSrecord.h> 39 #include <atnf/PKSIO/PKSMS2reader.h> 40 36 // AIPS++ includes. 41 37 #include <casa/stdio.h> 42 38 #include <casa/Arrays/ArrayMath.h> … … 44 40 #include <ms/MeasurementSets/MSColumns.h> 45 41 #include <tables/Tables.h> 42 #include <casa/Quanta/MVTime.h> 43 #include <casa/Quanta/MVAngle.h> 44 #include <casa/BasicMath/Math.h> 45 #include <casa/Logging/LogIO.h> 46 #include <casa/Utilities/Sort.h> 47 #include <measures/Measures/MeasConvert.h> 48 #include <measures/Measures/MEpoch.h> 49 #include <measures/Measures/MeasRef.h> 50 51 52 // Parkes includes. 53 #include <atnf/pks/pks_maths.h> 54 #include <atnf/PKSIO/PKSrecord.h> 55 #include <atnf/PKSIO/PKSMS2reader.h> 56 46 57 47 58 //------------------------------------------------- PKSMS2reader::PKSMS2reader … … 52 63 { 53 64 cMSopen = False; 54 55 // By default, messages are written to stderr.56 initMsg();57 65 } 58 66 … … 70 78 Int PKSMS2reader::open( 71 79 const String msName, 80 const String antenna, 72 81 Vector<Bool> &beams, 73 82 Vector<Bool> &IFs, … … 88 97 89 98 cPKSMS = MeasurementSet(msName); 99 100 // data selection by antenna 101 if ( antenna.length() == 0 ) { 102 cAntId.resize( 1 ) ; 103 cAntId[0] = 0 ; 104 } 105 else { 106 setupAntennaList( antenna ) ; 107 if ( cAntId.size() > 1 ) { 108 LogIO os( LogOrigin( "PKSMS2reader", "open()", WHERE ) ) ; 109 os << LogIO::WARN << "PKSMS2reader is not ready for multiple antenna selection. Use first antenna id " << cAntId[0] << "."<< LogIO::POST ; 110 Int tmp = cAntId[0] ; 111 cAntId.resize( 1 ) ; 112 cAntId[0] = tmp ; 113 } 114 stringstream ss ; 115 ss << "SELECT FROM $1 WHERE ANTENNA1 == ANTENNA2 && ANTENNA1 IN [" ; 116 for ( uInt i = 0 ; i < cAntId.size() ; i++ ) { 117 ss << cAntId[i] ; 118 if ( i == cAntId.size()-1 ) { 119 ss << "]" ; 120 } 121 else { 122 ss << "," ; 123 } 124 } 125 string taql = ss.str() ; 126 //cerr << "taql = " << taql << endl ; 127 cPKSMS = MeasurementSet( tableCommand( taql, cPKSMS ) ) ; 128 } 129 130 // taql access to the syscal table 131 cHaveSysCal = False; 132 if (cHaveSysCal=Table::isReadable(cPKSMS.sysCalTableName())) { 133 cSysCalTab = Table(cPKSMS.sysCalTableName()); 134 } 135 136 // Lock the table for read access. 137 cPKSMS.lock(False); 138 90 139 cIdx = 0; 140 lastmjd = 0.0; 91 141 cNRow = cPKSMS.nrow(); 92 142 cMSopen = True; 93 94 // Lock the table for read access.95 cPKSMS.lock(False);96 143 97 144 // Main MS table and subtable column access. … … 107 154 ROMSSysCalColumns sysCalCols(cPKSMS.sysCal()); 108 155 ROMSWeatherColumns weatherCols(cPKSMS.weather()); 156 ROMSAntennaColumns antennaCols(cPKSMS.antenna()); 109 157 110 158 // Column accessors for required columns. … … 115 163 cFieldIdCol.reference(msCols.fieldId()); 116 164 cFieldNameCol.reference(fieldCols.name()); 165 cFieldDelayDirCol.reference(fieldCols.delayDir()); 117 166 118 167 cSrcIdCol.reference(fieldCols.sourceId()); 168 cSrcId2Col.reference(sourceCols.sourceId()); 119 169 cSrcNameCol.reference(sourceCols.name()); 120 170 cSrcDirCol.reference(sourceCols.direction()); … … 124 174 cStateIdCol.reference(msCols.stateId()); 125 175 cObsModeCol.reference(stateCols.obsMode()); 176 cCalCol.reference(stateCols.cal()); 177 cSigStateCol.reference(stateCols.sig()); 178 cRefStateCol.reference(stateCols.ref()); 126 179 127 180 cDataDescIdCol.reference(msCols.dataDescId()); 181 cSpWinIdCol.reference(dataDescCols.spectralWindowId()); 128 182 cChanFreqCol.reference(spWinCols.chanFreq()); 183 cTotBWCol.reference(spWinCols.totalBandwidth()); 129 184 130 185 cWeatherTimeCol.reference(weatherCols.time()); … … 135 190 cBeamNoCol.reference(msCols.feed1()); 136 191 cPointingCol.reference(pointingCols.direction()); 192 cPointingTimeCol.reference(pointingCols.time()); 137 193 cSigmaCol.reference(msCols.sigma()); 138 194 cNumReceptorCol.reference(feedCols.numReceptors()); 139 195 140 196 // Optional columns. 197 cHaveTsys = False; 198 cHaveTcal = False; 141 199 if ((cHaveSrcVel = cPKSMS.source().tableDesc().isColumn("SYSVEL"))) { 142 200 cSrcVelCol.attach(cPKSMS.source(), "SYSVEL"); 143 201 } 144 202 145 if ( (cHaveTsys = cPKSMS.sysCal().tableDesc().isColumn("TSYS"))) {203 if (cHaveSysCal && (cHaveTsys = cPKSMS.sysCal().tableDesc().isColumn("TSYS"))) { 146 204 cTsysCol.attach(cPKSMS.sysCal(), "TSYS"); 205 } 206 207 if (cHaveSysCal && (cHaveTcal = cPKSMS.sysCal().tableDesc().isColumn("TCAL"))) { 208 cTcalCol.attach(cPKSMS.sysCal(), "TCAL"); 147 209 } 148 210 … … 158 220 // Spectral data should always be present. 159 221 haveSpectra = True; 160 cFloatDataCol.reference(msCols.floatData()); 222 cHaveDataCol = False; 223 cHaveCorrectedDataCol = False; 224 ROMSObservationColumns observationCols(cPKSMS.observation()); 225 //String telName = observationCols.telescopeName()(0); 226 cTelName = observationCols.telescopeName()(0); 227 //cATF = cTelName.contains("ATF"); 228 //cOSF = cTelName.contains("OSF"); 229 //cALMA = cTelName.contains("ALMA"); 230 cALMA = cTelName.contains("ATF")||cTelName.contains("OSF")|| 231 cTelName.contains("ALMA"); 232 233 if (cHaveDataCol = cPKSMS.isColumn(MSMainEnums::DATA)) { 234 if (cALMA) { 235 //try to read a single baseline interferometeric data 236 //and treat it as single dish data 237 //maybe extended for ALMA commissioning later 238 cDataCol.reference(msCols.data()); 239 if (cHaveCorrectedDataCol = cPKSMS.isColumn(MSMainEnums::CORRECTED_DATA)) { 240 //cerr<<"Do have CORRECTED_DATA column"<<endl; 241 cCorrectedDataCol.reference(msCols.correctedData()); 242 } 243 } 244 } 245 else { 246 cFloatDataCol.reference(msCols.floatData()); 247 } 161 248 cFlagCol.reference(msCols.flag()); 162 163 if ((cGetXPol = cPKSMS.isColumn(MSMainEnums::DATA))) { 249 cFlagRowCol.reference(msCols.flagRow()); 250 251 if (cGetXPol = (cPKSMS.isColumn(MSMainEnums::DATA) && (!cALMA))) { 164 252 if ((cHaveXCalFctr = cPKSMS.tableDesc().isColumn("XCALFCTR"))) { 165 253 cXCalFctrCol.attach(cPKSMS, "XCALFCTR"); … … 181 269 182 270 // Number of IFs. 183 uInt nIF = dataDescCols.nrow(); 271 //uInt nIF = dataDescCols.nrow(); 272 uInt nIF =spWinCols.nrow(); 273 Vector<Int> spWinIds = cSpWinIdCol.getColumn() ; 184 274 IFs.resize(nIF); 185 275 IFs = True; 276 for ( Int ispw = 0 ; ispw < nIF ; ispw++ ) { 277 if ( allNE( ispw, spWinIds ) ) { 278 IFs(ispw) = False ; 279 } 280 } 186 281 187 282 // Number of polarizations and channels in each IF. 188 ROScalarColumn<Int> spWinIdCol(dataDescCols.spectralWindowId());189 283 ROScalarColumn<Int> numChanCol(spWinCols.numChan()); 190 284 … … 195 289 nPol.resize(nIF); 196 290 for (uInt iIF = 0; iIF < nIF; iIF++) { 197 nChan(iIF) = numChanCol(spWinIdCol(iIF)); 198 nPol(iIF) = numPolCol(polIdCol(iIF)); 291 if ( IFs(iIF) ) { 292 nChan(iIF) = numChanCol(cSpWinIdCol(iIF)) ; 293 nPol(iIF) = numPolCol(polIdCol(iIF)) ; 294 } 295 else { 296 nChan(iIF) = 0 ; 297 nPol(iIF) = 0 ; 298 } 199 299 } 200 300 … … 203 303 haveXPol = False; 204 304 205 if (cGetXPol ) {305 if (cGetXPol && !(cALMA)) { 206 306 for (Int irow = 0; irow < cNRow; irow++) { 207 307 if (cDataCol.isDefined(irow)) { … … 252 352 String &antName, 253 353 Vector<Double> &antPosition, 354 // before merge... 355 //String &obsMode, 254 356 String &obsType, 255 357 String &bunit, … … 258 360 Double &mjd, 259 361 Double &refFreq, 260 Double &bandwidth) 362 Double &bandwidth) 261 363 { 262 364 if (!cMSopen) { … … 271 373 // Antenna name and ITRF coordinates. 272 374 ROMSAntennaColumns antennaCols(cPKSMS.antenna()); 273 antName = antennaCols.name()(0); 274 antPosition = antennaCols.position()(0); 375 //antName = antennaCols.name()(0); 376 antName = antennaCols.name()(cAntId[0]); 377 if (cALMA) { 378 antName = cTelName + "-" + antName; 379 } 380 //antPosition = antennaCols.position()(0); 381 antPosition = antennaCols.position()(cAntId[0]); 275 382 276 383 // Observation type. … … 282 389 } 283 390 284 // Brightness units. 285 bunit = cPKSMS.unit(MSMainEnums::FLOAT_DATA); 286 391 bunit = ""; 392 if (cHaveDataCol) { 393 const TableRecord& keywordSet2 394 = cDataCol.columnDesc().keywordSet(); 395 if(keywordSet2.isDefined("UNIT")) { 396 bunit = keywordSet2.asString("UNIT"); 397 } 398 } else { 399 const TableRecord& keywordSet 400 = cFloatDataCol.columnDesc().keywordSet(); 401 if(keywordSet.isDefined("UNIT")) { 402 bunit = keywordSet.asString("UNIT"); 403 } 404 } 405 406 /*** 407 const TableRecord& keywordSet 408 = cFloatDataCol.columnDesc().keywordSet(); 409 if(keywordSet.isDefined("UNIT")) { 410 fluxunit = keywordSet.asString("UNIT"); 411 } 412 ***/ 287 413 // Coordinate equinox. 288 414 ROMSPointingColumns pointingCols(cPKSMS.pointing()); 289 415 String dirref = pointingCols.direction().keywordSet().asRecord("MEASINFO"). 290 416 asString("Ref"); 417 cDirRef = dirref; 418 if (dirref =="AZELGEO" || dirref == "AZEL") { 419 dirref = "J2000"; 420 } 291 421 sscanf(dirref.chars()+1, "%f", &equinox); 292 422 … … 357 487 const Bool getSpectra, 358 488 const Bool getXPol, 489 const Bool getFeedPos, 490 const Bool getPointing, 359 491 const Int coordSys) 360 492 { … … 436 568 cGetXPol = cGetXPol && getXPol; 437 569 570 // Get feed positions? (Not available.) 571 cGetFeedPos = False; 572 573 // Get Pointing data (for MS) 574 cGetPointing = getPointing; 575 438 576 // Coordinate system? (Only equatorial available.) 439 577 cCoordSys = 0; … … 490 628 // Read the next data record. 491 629 630 /** 631 Int PKSMS2reader::read( 632 Int &scanNo, 633 Int &cycleNo, 634 Double &mjd, 635 Double &interval, 636 String &fieldName, 637 String &srcName, 638 Vector<Double> &srcDir, 639 Vector<Double> &srcPM, 640 Double &srcVel, 641 String &obsMode, 642 Int &IFno, 643 Double &refFreq, 644 Double &bandwidth, 645 Double &freqInc, 646 Vector<Double> &restFreq, 647 Vector<Float> &tcal, 648 String &tcalTime, 649 Float &azimuth, 650 Float &elevation, 651 Float &parAngle, 652 Float &focusAxi, 653 Float &focusTan, 654 Float &focusRot, 655 Float &temperature, 656 Float &pressure, 657 Float &humidity, 658 Float &windSpeed, 659 Float &windAz, 660 Int &refBeam, 661 Int &beamNo, 662 Vector<Double> &direction, 663 Vector<Double> &scanRate, 664 Vector<Float> &tsys, 665 Vector<Float> &sigma, 666 Vector<Float> &calFctr, 667 Matrix<Float> &baseLin, 668 Matrix<Float> &baseSub, 669 Matrix<Float> &spectra, 670 Matrix<uChar> &flagged, 671 uInt &flagrow, 672 Complex &xCalFctr, 673 Vector<Complex> &xPol) 674 **/ 492 675 Int PKSMS2reader::read(PKSrecord &pksrec) 493 676 { 677 LogIO os( LogOrigin( "PKSMS2reader", "read()", WHERE ) ) ; 678 494 679 if (!cMSopen) { 495 680 return 1; … … 504 689 Int ibeam; 505 690 Int iIF; 691 Int iDataDesc; 692 506 693 while (True) { 507 694 ibeam = cBeamNoCol(cIdx); 508 iIF = cDataDescIdCol(cIdx); 695 iDataDesc = cDataDescIdCol(cIdx); 696 iIF =cSpWinIdCol(iDataDesc); 509 697 if (cBeams(ibeam) && cIFs(iIF)) { 510 698 break; … … 516 704 } 517 705 } 518 519 706 // Renumerate scan no. Here still is 1-based 520 pksrec.scanNo = cScanNoCol(cIdx) - cScanNoCol(0) + 1; 707 //scanNo = cScanNoCol(cIdx) - cScanNoCol(0) + 1; 708 //scanNo = cScanNoCol(cIdx); 709 pksrec.scanNo = cScanNoCol(cIdx); 521 710 522 711 if (pksrec.scanNo != cScanNo) { … … 542 731 543 732 Int srcId = cSrcIdCol(fieldId); 544 pksrec.srcName = cSrcNameCol(srcId); 733 //For source with multiple spectral window setting, this is not 734 // correct. Source name of srcId may not be at 'srcId'th row of SrcNameCol 735 //srcName = cSrcNameCol(srcId); 736 for (uInt irow = 0; irow < cSrcId2Col.nrow(); irow++) { 737 if (cSrcId2Col(irow) == srcId) { 738 //srcName = cSrcNameCol(irow); 739 pksrec.srcName = cSrcNameCol(irow); 740 } 741 } 742 545 743 pksrec.srcDir = cSrcDirCol(srcId); 546 744 pksrec.srcPM = cSrcPMCol(srcId); 547 745 548 746 // Systemic velocity. 549 if (!cHaveSrcVel ) {747 if (!cHaveSrcVel || cALMA) { 550 748 pksrec.srcVel = 0.0f; 551 749 } else { … … 553 751 } 554 752 753 ROMSAntennaColumns antennaCols(cPKSMS.antenna()); 754 //String telescope = antennaCols.name()(0); 755 String telescope = antennaCols.name()(cAntId[0]); 756 Bool cGBT = telescope.contains("GBT"); 757 //Bool cPM = telescope.contains("PM"); // ACA TP antenna 758 //Bool cDV = telescope.contains("DV"); // VERTEX 759 //Bool cCM = telescope.contains("CM"); // ACA 7m antenna 760 //Bool cALMA = cPM || cDV || cCM ; 555 761 // Observation type. 556 Int stateId = cStateIdCol(cIdx); 557 pksrec.obsType = cObsModeCol(stateId); 762 // check if State Table exist 763 //Bool cHaveStateTab=Table::isReadable(cPKSMS.stateTableName()); 764 Int stateId = 0; 765 Int StateNRow = 0; 766 StateNRow=cObsModeCol.nrow(); 767 if (Table::isReadable(cPKSMS.stateTableName())) { 768 pksrec.obsType = " "; 769 if (StateNRow > 0) { 770 stateId = cStateIdCol(cIdx); 771 if (stateId == -1) { 772 //pksrec.obsType = " "; 773 } else { 774 pksrec.obsType = cObsModeCol(stateId); 775 Bool sigState =cSigStateCol(stateId); 776 Bool refState =cRefStateCol(stateId); 777 //DEBUG 778 //cerr <<"stateid="<<stateId<<" obsmode="<<pksrec.obsType<<endl; 779 if (cGBT) { 780 // split the obsType string and append a proper label 781 // (these are GBT specific) 782 int epos = pksrec.obsType.find_first_of(':'); 783 int nextpos = pksrec.obsType.find_first_of(':',epos+1); 784 string obsMode1 = pksrec.obsType.substr(0,epos); 785 string obsMode2 = pksrec.obsType.substr(epos+1,nextpos-epos-1); 786 787 //cerr <<"obsMode2= "<<obsMode2<<endl; 788 if (!pksrec.srcName.contains("_ps") 789 &&!pksrec.srcName.contains("_psr") 790 &&!pksrec.srcName.contains("_nod") 791 &&!pksrec.srcName.contains("_fs") 792 &&!pksrec.srcName.contains("_fsr")) { 793 // if Nod mode observation , append '_nod' 794 if (obsMode1 == "Nod") { 795 //pksrec.srcName.append("_nod"); 796 pksrec.srcType = SrcType::NOD ; 797 } else if (obsMode1 == "OffOn") { 798 // for GBT position switch observations (OffOn or OnOff) 799 //if (obsMode2 == "PSWITCHON") pksrec.srcName.append("_ps"); 800 //if (obsMode2 == "PSWITCHOFF") pksrec.srcName.append("_psr"); 801 if (obsMode2 == "PSWITCHON") pksrec.srcType = SrcType::PSON ; 802 if (obsMode2 == "PSWITCHOFF") pksrec.srcType = SrcType::PSOFF ; 803 } else { 804 if (obsMode2 == "FSWITCH") { 805 // for GBT frequency switch mode 806 //if (sigState) pksrec.srcName.append("_fs"); 807 //if (refState) pksrec.srcName.append("_fsr"); 808 if (sigState) pksrec.srcType = SrcType::FSON ; 809 if (refState) pksrec.srcType = SrcType::FSOFF ; 810 } 811 } 812 } 813 } 814 else if (cALMA) { 815 // ALMA tag 816 // split the obsType string and append a proper label 817 string substr[1] ; 818 int numSubstr = split( pksrec.obsType, substr, 1, "," ); 819 String obsType = String( substr[0] ); 820 int epos = obsType.find_first_of('.'); 821 int nextpos = obsType.find_first_of('.',epos+1); 822 string obsMode1 = obsType.substr(0,epos); 823 string obsMode2 = obsType.substr(epos+1,nextpos-epos-1); 824 825 //cerr <<"obsMode2= "<<obsMode2<<endl; 826 // Current OBS_MODE format: 827 // 828 // ON: OBSERVE_TARGET.ON_SOURCE 829 // OFF: OBSERVE_TARGET.OFF_SOURCE 830 // 831 if (obsMode1 == "OBSERVE_TARGET") { 832 //if (obsMode2 == "ON_SOURCE") pksrec.srcName.append("_pson"); 833 //if (obsMode2 == "OFF_SOURCE") pksrec.srcName.append("_psoff"); 834 if (obsMode2 == "ON_SOURCE") pksrec.srcType = SrcType::PSON ; 835 if (obsMode2 == "OFF_SOURCE") pksrec.srcType = SrcType::PSOFF ; 836 } 837 } 838 } 839 } 840 } 841 // CAL state 842 // this should be apply just for GBT data? 843 Double Cal; 844 if (stateId==-1 || StateNRow==0) { 845 Cal = 0; 846 } else { 847 Cal = cCalCol(stateId); 848 } 849 if (cGBT) { 850 if (Cal > 0 && !pksrec.srcName.contains("_calon")) { 851 //pksrec.srcName.append("_calon"); 852 if ( pksrec.srcType == SrcType::NOD ) 853 pksrec.srcType = SrcType::NODCAL ; 854 else if ( pksrec.srcType == SrcType::PSON ) 855 pksrec.srcType = SrcType::PONCAL ; 856 else if ( pksrec.srcType == SrcType::PSOFF ) 857 pksrec.srcType = SrcType::POFFCAL ; 858 else if ( pksrec.srcType == SrcType::FSON ) 859 pksrec.srcType = SrcType::FONCAL ; 860 else if ( pksrec.srcType == SrcType::FSOFF ) 861 pksrec.srcType = SrcType::FOFFCAL ; 862 else 863 pksrec.srcName.append("_calon"); 864 } 865 } 558 866 559 867 pksrec.IFno = iIF + 1; 560 868 Int nChan = abs(cEndChan(iIF) - cStartChan(iIF)) + 1; 561 869 562 870 // Minimal handling on continuum data. 563 871 Vector<Double> chanFreq = cChanFreqCol(iIF); 872 pksrec.nchan = nChan; 564 873 if (nChan == 1) { 565 cout << "The input is continuum data. "<< endl;566 pksrec.freqInc = c hanFreq(0);874 //pksrec.freqInc = chanFreq(0); 875 pksrec.freqInc = cTotBWCol(iIF); 567 876 pksrec.refFreq = chanFreq(0); 568 pksrec.restFreq = 0.0f; 877 pksrec.restFreq.resize(1); 878 pksrec.restFreq[0] = 0.0f; 569 879 } else { 880 570 881 if (cStartChan(iIF) <= cEndChan(iIF)) { 571 882 pksrec.freqInc = chanFreq(1) - chanFreq(0); … … 575 886 576 887 pksrec.refFreq = chanFreq(cRefChan(iIF)-1); 577 pksrec.restFreq = cSrcRestFrqCol(srcId)(IPosition(1,0)); 578 } 579 pksrec.bandwidth = abs(pksrec.freqInc * nChan); 888 889 Bool HaveSrcRestFreq= cSrcRestFrqCol.isDefined(srcId); 890 if (HaveSrcRestFreq) { 891 //restFreq = cSrcRestFrqCol(srcId)(IPosition(1,0)); 892 //restFreq = cSrcRestFrqCol(srcId); 893 pksrec.restFreq = cSrcRestFrqCol(srcId); 894 } else { 895 pksrec.restFreq.resize(1); 896 pksrec.restFreq[0] = 0.0f; 897 } 898 } 899 //pksrec.bandwidth = abs(pksrec.freqInc * nChan); 900 pksrec.bandwidth = abs(cTotBWCol(0)); 580 901 581 902 pksrec.tcal.resize(cNPol(iIF)); 582 903 pksrec.tcal = 0.0f; 583 904 pksrec.tcalTime = ""; 584 pksrec.azimuth = 0.0f;585 pksrec.elevation = 0.0f;905 // pksrec.azimuth = 0.0f; 906 // pksrec.elevation = 0.0f; 586 907 pksrec.parAngle = 0.0f; 587 908 … … 591 912 592 913 // Find the appropriate entry in the WEATHER subtable. 593 Vector<Double> wTimes = cWeatherTimeCol.getColumn(); 594 Int weatherIdx; 595 for (weatherIdx = wTimes.nelements()-1; weatherIdx >= 0; weatherIdx--) { 596 if (cWeatherTimeCol(weatherIdx) <= time) { 597 break; 598 } 599 } 600 601 if (weatherIdx < 0) { 914 //Bool cHaveStateTab=Table::isReadable(cPKSMS.stateTableName()); 915 Bool cHaveWeatherTab = Table::isReadable(cPKSMS.weatherTableName()); 916 Int weatherIdx=-1; 917 if (cHaveWeatherTab) { 918 Vector<Double> wTimes = cWeatherTimeCol.getColumn(); 919 for (weatherIdx = wTimes.nelements()-1; weatherIdx >= 0; weatherIdx--) { 920 if (cWeatherTimeCol(weatherIdx) <= time) { 921 break; 922 } 923 } 924 } 925 926 if (weatherIdx < 0 || !cHaveWeatherTab) { 602 927 // No appropriate WEATHER entry. 603 928 pksrec.temperature = 0.0f; … … 616 941 pksrec.beamNo = ibeam + 1; 617 942 618 Matrix<Double> pointingDir = cPointingCol(fieldId); 619 pksrec.direction = pointingDir.column(0); 943 //pointing/azel 944 MVPosition mvpos(antennaCols.position()(cAntId[0])); 945 MPosition mp(mvpos); 946 Quantum<Double> qt(time,"s"); 947 MVEpoch mvt(qt); 948 MEpoch me(mvt); 949 MeasFrame frame(mp, me); 950 MDirection md; 620 951 pksrec.pCode = 0; 621 952 pksrec.rateAge = 0.0f; 622 uInt ncols = pointingDir.ncolumn();623 if (ncols == 1) {624 pksrec.scanRate = 0.0f;625 } else {626 pksrec.scanRate(0) = pointingDir.column(1)(0);627 pksrec.scanRate(1) = pointingDir.column(1)(1);628 }629 953 pksrec.paRate = 0.0f; 954 if (cGetPointing) { 955 //cerr << "get pointing data ...." << endl; 956 ROScalarColumn<Int> pAntIdCol ; 957 ROScalarColumn<Double> psTimeCol ; 958 Table ptTable = cPKSMS.pointing() ; 959 MSPointing selPtTab( ptTable( ptTable.col("ANTENNA_ID") == cAntId[0] ) ) ; 960 pAntIdCol.attach( selPtTab, "ANTENNA_ID" ) ; 961 Vector<Int> antIds = pAntIdCol.getColumn() ; 962 psTimeCol.attach( selPtTab, "TIME" ) ; 963 Vector<Double> pTimes = psTimeCol.getColumn(); 964 Bool doInterp = False ; 965 Int PtIdx=-1; 966 for (PtIdx = pTimes.nelements()-1; PtIdx >= 0; PtIdx--) { 967 if ( pTimes[PtIdx] == time ) { 968 break ; 969 } 970 else if ( pTimes[PtIdx] < time ) { 971 if ( PtIdx != pTimes.nelements()-1 ) { 972 doInterp = True ; 973 } 974 break ; 975 } 976 } 977 if ( PtIdx == -1 ) { 978 PtIdx = 0 ; 979 } 980 //cerr << "got index=" << PtIdx << endl; 981 Matrix<Double> pointingDir = cPointingCol(PtIdx); 982 ROMSPointingColumns PtCols( selPtTab ) ; 983 Vector<Double> pointingDirVec ; 984 if ( doInterp ) { 985 Double dt1 = time - pTimes[PtIdx] ; 986 Double dt2 = pTimes[PtIdx+1] - time ; 987 Vector<Double> dirVec1 = pointingDir.column(0) ; 988 Matrix<Double> pointingDir2 = cPointingCol(PtIdx+1) ; 989 Vector<Double> dirVec2 = pointingDir2.column(0) ; 990 pointingDirVec = (dt1*dirVec2+dt2*dirVec1)/(dt1+dt2) ; 991 Vector<MDirection> vmd1(1) ; 992 Vector<MDirection> vmd2(1) ; 993 PtCols.directionMeasCol().get(PtIdx,vmd1) ; 994 Vector<Double> angle1 = vmd1(0).getAngle().getValue("rad") ; 995 PtCols.directionMeasCol().get(PtIdx+1,vmd2) ; 996 Vector<Double> angle2 = vmd2(0).getAngle().getValue("rad") ; 997 Vector<Double> angle = (dt1*angle2+dt2*angle1)/(dt1+dt2) ; 998 Quantum< Vector<Double> > qangle( angle, "rad" ) ; 999 String typeStr = vmd1(0).getRefString() ; 1000 //cerr << "vmd1.getRefString()=" << typeStr << endl ; 1001 MDirection::Types mdType ; 1002 MDirection::getType( mdType, typeStr ) ; 1003 //cerr << "mdType=" << mdType << endl ; 1004 md = MDirection( qangle, mdType ) ; 1005 //cerr << "md=" << md.getAngle().getValue("rad") << endl ; 1006 } 1007 else { 1008 pointingDirVec = pointingDir.column(0) ; 1009 Vector<MDirection> vmd(1); 1010 PtCols.directionMeasCol().get(PtIdx,vmd); 1011 md = vmd[0]; 1012 } 1013 // put J2000 coordinates in "direction" 1014 if (cDirRef =="J2000") { 1015 pksrec.direction = pointingDirVec ; 1016 } 1017 else { 1018 pksrec.direction = 1019 MDirection::Convert(md, MDirection::Ref(MDirection::J2000, 1020 frame) 1021 )().getAngle("rad").getValue(); 1022 1023 } 1024 uInt ncols = pointingDir.ncolumn(); 1025 pksrec.scanRate.resize(2); 1026 if (ncols == 1) { 1027 pksrec.scanRate = 0.0f; 1028 } else { 1029 pksrec.scanRate(0) = pointingDir.column(1)(0); 1030 pksrec.scanRate(1) = pointingDir.column(1)(1); 1031 } 1032 } 1033 else { 1034 // Get direction from FIELD table 1035 // here, assume direction to be the field direction not pointing 1036 Matrix<Double> delayDir = cFieldDelayDirCol(fieldId); 1037 pksrec.direction = delayDir.column(0); 1038 uInt ncols = delayDir.ncolumn(); 1039 pksrec.scanRate.resize(2); 1040 if (ncols == 1) { 1041 pksrec.scanRate = 0.0f; 1042 } else { 1043 pksrec.scanRate(0) = delayDir.column(1)(0); 1044 pksrec.scanRate(1) = delayDir.column(1)(1); 1045 } 1046 } 1047 // caluculate azimuth and elevation 1048 // first, get the reference frame 1049 /** 1050 MVPosition mvpos(antennaCols.position()(0)); 1051 MPosition mp(mvpos); 1052 Quantum<Double> qt(time,"s"); 1053 MVEpoch mvt(qt); 1054 MEpoch me(mvt); 1055 MeasFrame frame(mp, me); 1056 **/ 1057 // 1058 ROMSFieldColumns fldCols(cPKSMS.field()); 1059 Vector<MDirection> vmd(1); 1060 //MDirection md; 1061 fldCols.delayDirMeasCol().get(fieldId,vmd); 1062 md = vmd[0]; 1063 //Vector<Double> dircheck = md.getAngle("rad").getValue(); 1064 //cerr<<"dircheck="<<dircheck<<endl; 1065 1066 Vector<Double> azel = 1067 MDirection::Convert(md, MDirection::Ref(MDirection::AZEL, 1068 frame) 1069 )().getAngle("rad").getValue(); 1070 //cerr<<"azel="<<azel<<endl; 1071 pksrec.azimuth = azel[0]; 1072 pksrec.elevation = azel[1]; 630 1073 631 1074 // Get Tsys assuming that entries in the SYSCAL table match the main table. … … 646 1089 cSigmaCol.get(cIdx, pksrec.sigma, True); 647 1090 1091 //get Tcal if available 1092 if (cHaveTcal) { 1093 Int nTcalColRow = cTcalCol.nrow(); 1094 uInt nBeam = cBeams.nelements(); 1095 uInt nIF = cIFs.nelements(); 1096 uInt nrws = nBeam * nIF; 1097 if (nTcalColRow > 0) { 1098 // find tcal match with the data with the data time stamp 1099 Double mjds = pksrec.mjd*(24*3600); 1100 Double dtcalTime; 1101 if ( pksrec.mjd > lastmjd || cIdx==0 ) { 1102 //Table tmptab = cSysCalTab(near(cSysCalTab.col("TIME"),mjds)); 1103 tmptab = cSysCalTab(near(cSysCalTab.col("TIME"),mjds), nrws); 1104 //DEBUG 1105 //if (cIdx == 0) { 1106 // cerr<<"inital table retrieved"<<endl; 1107 //} 1108 1109 } 1110 1111 if (nBeam == 1) { 1112 tmptab2 = tmptab( tmptab.col("SPECTRAL_WINDOW_ID") == iIF, 1); 1113 } else { 1114 tmptab2 = tmptab( tmptab.col("SPECTRAL_WINDOW_ID") == iIF && 1115 tmptab.col("FEED_ID") == ibeam , 1); 1116 } 1117 //cerr<<"first subtab rows="<<tmptab.nrow()<<endl; 1118 int syscalrow = tmptab2.nrow(); 1119 ROArrayColumn<Float> tcalCol(tmptab2, "TCAL"); 1120 ROScalarColumn<Double> tcalTimeCol(tmptab2, "TIME"); 1121 if (syscalrow==0) { 1122 os << LogIO::NORMAL 1123 <<"Cannot find any matching Tcal at/near the data timestamp." 1124 << " Set Tcal=0.0" << LogIO::POST ; 1125 } else { 1126 tcalCol.get(0, pksrec.tcal); 1127 tcalTimeCol.get(0,dtcalTime); 1128 pksrec.tcalTime = MVTime(dtcalTime/(24*3600)).string(MVTime::YMD); 1129 //DEBUG 1130 //cerr<<"cIdx:"<<cIdx<<" tcal="<<tcal<<" tcalTime="<<tcalTime<<endl; 1131 tmptab.markForDelete(); 1132 tmptab2.markForDelete(); 1133 } 1134 } 1135 lastmjd = pksrec.mjd; 1136 } 1137 648 1138 // Calibration factors (if available). 649 1139 pksrec.calFctr.resize(cNPol(iIF)); … … 672 1162 Matrix<Float> tmpData; 673 1163 Matrix<Bool> tmpFlag; 674 cFloatDataCol.getSlice(cIdx, cDataSel(iIF), tmpData, True); 1164 if (cHaveDataCol) { 1165 Matrix<Complex> tmpCmplxData; 1166 Matrix<Float> tmpReData; 1167 Matrix<Float> tmpImData; 1168 //cerr<<"reading spectra..."<<endl; 1169 //# TODO - should have a flag to user to select DATA or CORRECTED_DATA 1170 //# currently just automatically determined, --- read CORRECTED one 1171 //# if the column exist. 1172 if (cHaveCorrectedDataCol) { 1173 cCorrectedDataCol.getSlice(cIdx, cDataSel(iIF), tmpCmplxData, True); 1174 } else { 1175 cDataCol.getSlice(cIdx, cDataSel(iIF), tmpCmplxData, True); 1176 } 1177 tmpReData = real(tmpCmplxData); 1178 tmpImData = imag(tmpCmplxData); 1179 tmpData = sqrt(tmpReData*tmpReData + tmpImData*tmpImData); 1180 } else { 1181 cFloatDataCol.getSlice(cIdx, cDataSel(iIF), tmpData, True); 1182 } 675 1183 cFlagCol.getSlice(cIdx, cDataSel(iIF), tmpFlag, True); 676 1184 … … 698 1206 } 699 1207 } 1208 1209 // Row-based flagging info. (True:1, False:0) 1210 pksrec.flagrow = (cFlagRowCol(cIdx) ? 1 : 0); 700 1211 } 701 1212 702 1213 // Get cross-polarization data. 703 1214 if (cGetXPol) { 1215 //cerr<<"cGetXPol="<<cGetXPol<<endl; 1216 //cerr<<"cHaveXCalFctr="<<cHaveXCalFctr<<endl; 1217 704 1218 if (cHaveXCalFctr) { 705 1219 cXCalFctrCol.get(cIdx, pksrec.xCalFctr); … … 708 1222 } 709 1223 710 cDataCol.get(cIdx, pksrec.xPol, True); 711 712 if (cEndChan(iIF) < cStartChan(iIF)) { 713 Complex ctmp; 1224 if(!cALMA) { 1225 cDataCol.get(cIdx, pksrec.xPol, True); 1226 1227 if (cEndChan(iIF) < cStartChan(iIF)) { 1228 Complex ctmp; 1229 Int jchan = nChan - 1; 1230 for (Int ichan = 0; ichan < nChan/2; ichan++, jchan--) { 1231 ctmp = pksrec.xPol(ichan); 1232 pksrec.xPol(ichan) = pksrec.xPol(jchan); 1233 pksrec.xPol(jchan) = ctmp; 1234 } 1235 } 1236 } 1237 } 1238 /** 1239 cerr<<"scanNo="<<scanNo<<endl; 1240 cerr<<"cycleNo="<<cycleNo<<endl; 1241 cerr<<"mjd="<<mjd<<endl; 1242 cerr<<"interval="<<interval<<endl; 1243 cerr<<"fieldName="<<fieldName<<endl; 1244 cerr<<"srcNmae="<<srcName<<endl; 1245 cerr<<"srcDir="<<srcDir<<endl; 1246 cerr<<"srcPM="<<srcPM<<endl; 1247 cerr<<"srcVel="<<srcVel<<endl; 1248 cerr<<"obsMode="<<obsMode<<endl; 1249 cerr<<"IFno="<<IFno<<endl; 1250 cerr<<"refFreq="<<refFreq<<endl; 1251 cerr<<"tcal="<<tcal<<endl; 1252 cerr<<"direction="<<direction<<endl; 1253 cerr<<"scanRate="<<scanRate<<endl; 1254 cerr<<"tsys="<<tsys<<endl; 1255 cerr<<"sigma="<<sigma<<endl; 1256 cerr<<"calFctr="<<calFctr<<endl; 1257 cerr<<"baseLin="<<baseLin<<endl; 1258 cerr<<"baseSub="<<baseSub<<endl; 1259 cerr<<"spectra="<<spectra.shape()<<endl; 1260 cerr<<"flagged="<<flagged.shape()<<endl; 1261 cerr<<"xCalFctr="<<xCalFctr<<endl; 1262 cerr<<"xPol="<<xPol<<endl; 1263 **/ 1264 cIdx++; 1265 1266 return 0; 1267 } 1268 1269 //--------------------------------------------------------- PKSMS2reader::read 1270 1271 // Read the next data record, just the basics. 1272 1273 Int PKSMS2reader::read( 1274 Int &IFno, 1275 Vector<Float> &tsys, 1276 Vector<Float> &calFctr, 1277 Matrix<Float> &baseLin, 1278 Matrix<Float> &baseSub, 1279 Matrix<Float> &spectra, 1280 Matrix<uChar> &flagged) 1281 { 1282 if (!cMSopen) { 1283 return 1; 1284 } 1285 1286 // Check for EOF. 1287 if (cIdx >= cNRow) { 1288 return -1; 1289 } 1290 1291 // Find the next selected beam and IF. 1292 Int ibeam; 1293 Int iIF; 1294 Int iDataDesc; 1295 while (True) { 1296 ibeam = cBeamNoCol(cIdx); 1297 //iIF = cDataDescIdCol(cIdx); 1298 iDataDesc = cDataDescIdCol(cIdx); 1299 iIF = cSpWinIdCol(iDataDesc); 1300 if (cBeams(ibeam) && cIFs(iIF)) { 1301 break; 1302 } 1303 1304 // Check for EOF. 1305 if (++cIdx >= cNRow) { 1306 return -1; 1307 } 1308 } 1309 1310 IFno = iIF + 1; 1311 // Get Tsys assuming that entries in the SYSCAL table match the main table. 1312 cTsysCol.get(cIdx, tsys, True); 1313 1314 // Calibration factors (if available). 1315 if (cHaveCalFctr) { 1316 cCalFctrCol.get(cIdx, calFctr, True); 1317 } else { 1318 calFctr.resize(cNPol(iIF)); 1319 calFctr = 0.0f; 1320 } 1321 1322 // Baseline parameters (if available). 1323 if (cHaveBaseLin) { 1324 baseLin.resize(2,cNPol(iIF)); 1325 cBaseLinCol.get(cIdx, baseLin); 1326 1327 baseSub.resize(24,cNPol(iIF)); 1328 cBaseSubCol.get(cIdx, baseSub); 1329 1330 } else { 1331 baseLin.resize(0,0); 1332 baseSub.resize(0,0); 1333 } 1334 1335 if (cGetSpectra) { 1336 // Get spectral data. 1337 Matrix<Float> tmpData; 1338 Matrix<Bool> tmpFlag; 1339 if (cHaveDataCol) { 1340 Matrix<Complex> tmpCmplxData; 1341 cDataCol.getSlice(cIdx, cDataSel(iIF), tmpCmplxData, True); 1342 tmpData = real(tmpCmplxData); 1343 } else { 1344 cFloatDataCol.getSlice(cIdx, cDataSel(iIF), tmpData, True); 1345 } 1346 cFlagCol.getSlice(cIdx, cDataSel(iIF), tmpFlag, True); 1347 1348 // Transpose spectra. 1349 Int nChan = tmpData.ncolumn(); 1350 Int nPol = tmpData.nrow(); 1351 spectra.resize(nChan, nPol); 1352 flagged.resize(nChan, nPol); 1353 if (cEndChan(iIF) >= cStartChan(iIF)) { 1354 // Simple transposition. 1355 for (Int ipol = 0; ipol < nPol; ipol++) { 1356 for (Int ichan = 0; ichan < nChan; ichan++) { 1357 spectra(ichan,ipol) = tmpData(ipol,ichan); 1358 flagged(ichan,ipol) = tmpFlag(ipol,ichan); 1359 } 1360 } 1361 1362 } else { 1363 // Transpose with inversion. 714 1364 Int jchan = nChan - 1; 715 for (Int ichan = 0; ichan < nChan/2; ichan++, jchan--) { 716 ctmp = pksrec.xPol(ichan); 717 pksrec.xPol(ichan) = pksrec.xPol(jchan); 718 pksrec.xPol(jchan) = ctmp; 1365 for (Int ipol = 0; ipol < nPol; ipol++) { 1366 for (Int ichan = 0; ichan < nChan; ichan++, jchan--) { 1367 spectra(ichan,ipol) = tmpData(ipol,jchan); 1368 flagged(ichan,ipol) = tmpFlag(ipol,jchan); 1369 } 719 1370 } 720 1371 } … … 735 1386 cMSopen = False; 736 1387 } 1388 1389 //-------------------------------------------------------- PKSMS2reader::splitAntenanSelectionString 1390 1391 // split antenna selection string 1392 // delimiter is ',' 1393 1394 Vector<String> PKSMS2reader::splitAntennaSelectionString( const String s ) 1395 { 1396 Char delim = ',' ; 1397 Int n = s.freq( delim ) + 1 ; 1398 Vector<String> antlist ; 1399 string sl[n] ; 1400 Int numSubstr = split( s, sl, n, "," ); 1401 antlist.resize( numSubstr ) ; 1402 for ( Int i = 0 ; i < numSubstr ; i++ ) { 1403 antlist[i] = String( sl[i] ) ; 1404 antlist[i].trim() ; 1405 } 1406 //cerr << "antlist = " << antlist << endl ; 1407 return antlist ; 1408 } 1409 1410 //-------------------------------------------------------- PKSMS2reader::setupAntennaList 1411 1412 // Fill cAntenna and cAntId 1413 1414 void PKSMS2reader::setupAntennaList( const String s ) 1415 { 1416 LogIO os( LogOrigin( "PKSMS2reader", "setupAntennaList()", WHERE ) ) ; 1417 //cerr << "antenna specification: " << s << endl ; 1418 ROMSAntennaColumns antennaCols(cPKSMS.antenna()); 1419 ROScalarColumn<String> antNames = antennaCols.name(); 1420 Int nrow = antNames.nrow() ; 1421 Vector<String> antlist = splitAntennaSelectionString( s ) ; 1422 Int len = antlist.size() ; 1423 Vector<Int> AntId( len ) ; 1424 Regex re( "[0-9]+" ) ; 1425 for ( Int i = 0 ; i < len ; i++ ) { 1426 if ( antlist[i].matches( re ) ) { 1427 AntId[i] = atoi( antlist[i].c_str() ) ; 1428 if ( AntId[i] >= nrow ) { 1429 os << LogIO::SEVERE << "Antenna index out of range: " << AntId[i] << LogIO::EXCEPTION ; 1430 } 1431 } 1432 else { 1433 AntId[i] = -1 ; 1434 for ( uInt j = 0 ; j < antNames.nrow() ; j++ ) { 1435 if ( antlist[i] == antNames(j) ) { 1436 AntId[i] = j ; 1437 break ; 1438 } 1439 } 1440 if ( AntId[i] == -1 ) { 1441 os << LogIO::SEVERE << "Specified antenna name not found: " << antlist[i] << LogIO::EXCEPTION ; 1442 } 1443 } 1444 } 1445 //cerr << "AntId = " << AntId << endl ; 1446 vector<Int> uniqId ; 1447 uniqId.push_back( AntId(0) ) ; 1448 for ( uInt i = 1 ; i < AntId.size() ; i++ ) { 1449 if ( count(uniqId.begin(),uniqId.end(),AntId[i]) == 0 ) { 1450 uniqId.push_back( AntId[i] ) ; 1451 } 1452 } 1453 Vector<Int> newAntId( uniqId ) ; 1454 cAntId.assign( newAntId ) ; 1455 //cerr << "cAntId = " << cAntId << endl ; 1456 } -
branches/mergetest/external/atnf/PKSIO/PKSMS2reader.h
r1720 r1779 68 68 virtual Int open( 69 69 const String msName, 70 const String antenna, 70 71 Vector<Bool> &beams, 71 72 Vector<Bool> &IFs, … … 85 86 String &bunit, 86 87 Float &equinox, 88 //String &freqRef, 87 89 String &dopplerFrame, 88 90 Double &mjd, … … 105 107 const Bool getSpectra = True, 106 108 const Bool getXPol = False, 109 const Bool getFeedPos = False, 110 const Bool getPointing = False, 107 111 const Int coordSys = 0); 112 108 113 109 114 // Find the range of the data selected in time and position. … … 115 120 116 121 // Read the next data record. 122 /** 123 virtual Int read( 124 Int &scanNo, 125 Int &cycleNo, 126 Double &mjd, 127 Double &interval, 128 String &fieldName, 129 String &srcName, 130 Vector<Double> &srcDir, 131 Vector<Double> &srcPM, 132 Double &srcVel, 133 String &obsMode, 134 Int &IFno, 135 Double &refFreq, 136 Double &bandwidth, 137 Double &freqInc, 138 Vector<Double> &restFreq, 139 Vector<Float> &tcal, 140 String &tcalTime, 141 Float &azimuth, 142 Float &elevation, 143 Float &parAngle, 144 Float &focusAxi, 145 Float &focusTan, 146 Float &focusRot, 147 Float &temperature, 148 Float &pressure, 149 Float &humidity, 150 Float &windSpeed, 151 Float &windAz, 152 Int &refBeam, 153 Int &beamNo, 154 Vector<Double> &direction, 155 Vector<Double> &scanRate, 156 Vector<Float> &tsys, 157 Vector<Float> &sigma, 158 Vector<Float> &calFctr, 159 Matrix<Float> &baseLin, 160 Matrix<Float> &baseSub, 161 Matrix<Float> &spectra, 162 Matrix<uChar> &flagged, 163 Complex &xCalFctr, 164 Vector<Complex> &xPol); 165 **/ 117 166 virtual Int read(PKSrecord &pksrec); 167 168 169 // Read the next data record, just the basics. 170 virtual Int read( 171 Int &IFno, 172 Vector<Float> &tsys, 173 Vector<Float> &calFctr, 174 Matrix<Float> &baseLin, 175 Matrix<Float> &baseSub, 176 Matrix<Float> &spectra, 177 Matrix<uChar> &flagged); 118 178 119 179 // Close the MS. … … 121 181 122 182 private: 183 Vector<String> splitAntennaSelectionString( const String s ); 184 void setupAntennaList( const String s ) ; 185 123 186 Bool cHaveBaseLin, cHaveCalFctr, cHaveSrcVel, cHaveTsys, cHaveXCalFctr, 124 cMSopen ;187 cMSopen, cHaveTcal, cHaveDataCol, cALMA, cHaveSysCal, cHaveCorrectedDataCol; 125 188 Int cCycleNo, cIdx, cNRow, cScanNo; 126 Double cTime ;189 Double cTime, lastmjd; 127 190 Vector<Int> cEndChan, cRefChan, cStartChan; 128 191 Vector<Bool> cBeams, cIFs; 129 192 Vector<Slicer> cDataSel; 193 String cDirRef, cTelName; 130 194 MeasurementSet cPKSMS; 195 Table cSysCalTab, tmptab, tmptab2; 196 197 //Vector<String> cAntenna; 198 Vector<Int> cAntId; 131 199 132 200 ROScalarColumn<Int> cScanNoCol; … … 135 203 ROScalarColumn<Int> cFieldIdCol; 136 204 ROScalarColumn<String> cFieldNameCol; 205 ROArrayColumn<Double> cFieldDelayDirCol; 137 206 ROScalarColumn<Int> cSrcIdCol; 207 ROScalarColumn<Int> cSrcId2Col; 138 208 ROScalarColumn<String> cSrcNameCol; 139 209 ROArrayColumn<Double> cSrcDirCol; … … 141 211 ROArrayColumn<Double> cSrcVelCol; 142 212 ROScalarColumn<Int> cStateIdCol; 213 ROScalarColumn<Double> cCalCol; 143 214 ROScalarColumn<String> cObsModeCol; 144 215 ROArrayColumn<Double> cSrcRestFrqCol; 145 216 ROScalarColumn<Int> cDataDescIdCol; 217 ROScalarColumn<Int> cSpWinIdCol; 146 218 ROArrayColumn<Double> cChanFreqCol; 219 ROScalarColumn<Double> cTotBWCol; 147 220 ROScalarColumn<Double> cWeatherTimeCol; 148 221 ROScalarColumn<Float> cTemperatureCol; 149 222 ROScalarColumn<Float> cPressureCol; 150 223 ROScalarColumn<Float> cHumidityCol; 224 ROArrayColumn<Float> cTcalCol; 151 225 ROScalarColumn<Int> cBeamNoCol; 152 226 ROArrayColumn<Double> cPointingCol; 227 ROScalarColumn<Double> cPointingTimeCol; 153 228 ROArrayColumn<Float> cTsysCol; 154 229 ROArrayColumn<Float> cSigmaCol; … … 158 233 ROArrayColumn<Float> cFloatDataCol; 159 234 ROArrayColumn<Bool> cFlagCol; 235 ROScalarColumn<Bool> cFlagRowCol; 160 236 ROScalarColumn<Complex> cXCalFctrCol; 161 237 ROArrayColumn<Complex> cDataCol; 238 ROArrayColumn<Complex> cCorrectedDataCol; 162 239 ROScalarColumn<Int> cNumReceptorCol; 240 ROScalarColumn<Bool> cSigStateCol; 241 ROScalarColumn<Bool> cRefStateCol; 242 163 243 }; 164 244 -
branches/mergetest/external/atnf/PKSIO/PKSMS2writer.cc
r1720 r1779 42 42 #include <casa/BasicSL/Constants.h> 43 43 #include <casa/Quanta/QC.h> 44 #include <casa/Logging/LogIO.h> 44 45 #include <measures/Measures/Stokes.h> 45 46 #include <tables/Tables/ArrColDesc.h> … … 52 53 #include <tables/Tables/TiledShapeStMan.h> 53 54 55 // Class name 56 const string className = "PKSMS2writer" ; 57 54 58 //------------------------------------------------- PKSMS2writer::PKSMS2writer 55 59 … … 59 63 { 60 64 cPKSMS = 0x0; 61 62 // By default, messages are written to stderr.63 initMsg();64 65 } 65 66 … … 92 93 const Bool haveBase) 93 94 { 95 const string methodName = "create()" ; 96 LogIO os( LogOrigin( className, methodName, WHERE ) ) ; 97 94 98 if (cPKSMS) { 95 logMsg("ERROR: Output MS already open, close it first.");99 os << LogIO::SEVERE << "Output MS already open, close it first." << LogIO::POST ; 96 100 return 1; 97 101 } 98 99 // Clear the message stack.100 clearMsg();101 102 102 103 // Open a MS table. … … 108 109 109 110 Int maxNPol = max(cNPol); 110 111 111 cGBT = cAPEX = cSMT = cALMA = cATF = False; 112 113 String telName = antName; 114 // check if it is GBT data 115 if (antName.contains("GBT")) { 116 cGBT = True; 117 } 118 else if (antName.contains("APEX")) { 119 cAPEX = True; 120 } 121 else if (antName.contains("HHT") || antName.contains("SMT")) { 122 cSMT = True; 123 } 124 else if (antName.contains("ALMA")) { 125 cALMA = True; 126 } 127 else if (antName.contains("ATF")) { 128 cATF = True; 129 telName="ATF"; 130 } 131 112 132 // Add the non-standard CALFCTR column. 113 133 pksDesc.addColumn(ArrayColumnDesc<Float>("CALFCTR", "Calibration factors", … … 116 136 // Add the optional FLOAT_DATA column. 117 137 MS::addColumnToDesc(pksDesc, MS::FLOAT_DATA, 2); 138 //pksDesc.rwColumnDesc(MS::columnName(MS::FLOAT_DATA)).rwKeywordSet(). 139 // define("UNIT", String("Jy")); 118 140 pksDesc.rwColumnDesc(MS::columnName(MS::FLOAT_DATA)).rwKeywordSet(). 119 141 define("UNIT", bunit); … … 136 158 137 159 MS::addColumnToDesc(pksDesc, MS::DATA, 2); 160 //pksDesc.rwColumnDesc(MS::columnName(MS::DATA)).rwKeywordSet(). 161 // define("UNIT", "Jy"); 138 162 pksDesc.rwColumnDesc(MS::columnName(MS::DATA)).rwKeywordSet(). 139 163 define("UNIT", bunit); … … 152 176 newtab.bindAll(incrStMan, True); 153 177 154 // Use TiledShapeStMan for the FLOAT_DATA hypercube with tile size 1 6 kiB.155 TiledShapeStMan tiledStMan("TiledData", IPosition(3,1,128, 32));178 // Use TiledShapeStMan for the FLOAT_DATA hypercube with tile size 1 MB. 179 TiledShapeStMan tiledStMan("TiledData", IPosition(3,1,128,2048)); 156 180 newtab.bindColumn(MS::columnName(MS::FLOAT_DATA), tiledStMan); 157 181 … … 367 391 } else if (dopplerFrame == "SOURCE") { 368 392 MFrequency::getType(cDopplerFrame, "REST"); 393 } else if (dopplerFrame == "LSRK") { 394 MFrequency::getType(cDopplerFrame, "LSRK"); 369 395 } 370 396 … … 374 400 addDopplerEntry(); 375 401 addFeedEntry(); 376 addObservationEntry(observer, project); 402 //addObservationEntry(observer, project); 403 addObservationEntry(observer, project, telName); 377 404 addProcessorEntry(); 378 405 … … 384 411 // Write the next data record. 385 412 413 /** 414 Int PKSMS2writer::write( 415 const Int scanNo, 416 const Int cycleNo, 417 const Double mjd, 418 const Double interval, 419 const String fieldName, 420 const String srcName, 421 const Vector<Double> srcDir, 422 const Vector<Double> srcPM, 423 const Double srcVel, 424 const String obsMode, 425 const Int IFno, 426 const Double refFreq, 427 const Double bandwidth, 428 const Double freqInc, 429 //const Double restFreq, 430 const Vector<Double> restFreq, 431 const Vector<Float> tcal, 432 const String tcalTime, 433 const Float azimuth, 434 const Float elevation, 435 const Float parAngle, 436 const Float focusAxi, 437 const Float focusTan, 438 const Float focusRot, 439 const Float temperature, 440 const Float pressure, 441 const Float humidity, 442 const Float windSpeed, 443 const Float windAz, 444 const Int refBeam, 445 const Int beamNo, 446 const Vector<Double> direction, 447 const Vector<Double> scanRate, 448 const Vector<Float> tsys, 449 const Vector<Float> sigma, 450 const Vector<Float> calFctr, 451 const Matrix<Float> baseLin, 452 const Matrix<Float> baseSub, 453 const Matrix<Float> &spectra, 454 const Matrix<uChar> &flagged, 455 const uInt flagrow, 456 const Complex xCalFctr, 457 const Vector<Complex> &xPol) 458 **/ 386 459 Int PKSMS2writer::write( 387 460 const PKSrecord &pksrec) … … 415 488 pksrec.restFreq, pksrec.srcVel); 416 489 417 // Find or add the obs Type to the STATE subtable.490 // Find or add the obsMode to the STATE subtable. 418 491 Int stateId = addStateEntry(pksrec.obsType); 419 492 420 493 // FIELD subtable. 421 Vector<Double> scanRate(2);422 scanRate(0) = pksrec.scanRate(0);423 scanRate(1) = pksrec.scanRate(1);494 //Vector<Double> scanRate(2); 495 //scanRate(0) = pksrec.scanRate(0); 496 //scanRate(1) = pksrec.scanRate(1); 424 497 Int fieldId = addFieldEntry(pksrec.fieldName, time, pksrec.direction, 425 scanRate, srcId);498 pksrec.scanRate, srcId); 426 499 427 500 // POINTING subtable. 428 501 addPointingEntry(time, pksrec.interval, pksrec.fieldName, pksrec.direction, 429 scanRate);502 pksrec.scanRate); 430 503 431 504 // SYSCAL subtable. 432 505 addSysCalEntry(pksrec.beamNo, iIF, time, pksrec.interval, pksrec.tcal, 433 pksrec.tsys );506 pksrec.tsys, nPol); 434 507 435 508 // Handle weather information. … … 508 581 cMSCols->sigma().put(irow, pksrec.sigma); 509 582 510 Vector<Float> weight(1, 1.0f); 583 //Vector<Float> weight(1, 1.0f); 584 Vector<Float> weight(nPol, 1.0f); 511 585 cMSCols->weight().put(irow, weight); 586 //imaging weight 587 //Vector<Float> imagingWeight(nChan); 588 //cMSCols->imagingWeight().put(irow, imagingWeight); 512 589 513 590 // Flag information. 514 591 Cube<Bool> flags(nPol, nChan, 1, False); 515 cMSCols->flag().put(irow, flags.xyPlane(0));592 //cMSCols->flag().put(irow, flags.xyPlane(0)); 516 593 cMSCols->flagCategory().put(irow, flags); 517 cMSCols->flagRow().put(irow, False); 594 // Row-based flagging info. (True:>0, False:0) 595 cMSCols->flagRow().put(irow, (pksrec.flagrow > 0)); 596 518 597 519 598 return 0; … … 571 650 cSysCal = MSSysCal(); 572 651 cWeather = MSWeather(); 573 574 652 // Release the main table. 575 delete cPKSMS; 576 cPKSMS =0x0;653 delete cPKSMS; 654 cPKSMS=0x0; 577 655 } 578 656 … … 589 667 Int n = cAntenna.nrow() - 1; 590 668 669 // do specific things for GBT 591 670 // Data. 671 // plus some more telescopes 592 672 cAntennaCols->name().put(n, antName); 593 cAntennaCols->station().put(n, "ATNF_PARKES"); 673 //cAntennaCols->station().put(n, "ATNF_PARKES"); 674 if (cGBT) { 675 cAntennaCols->station().put(n, "GREENBANK"); 676 cAntennaCols->dishDiameter().put(n, 110.0); 677 } 678 else if (cAPEX) { 679 cAntennaCols->station().put(n, "CHAJNANTOR"); 680 cAntennaCols->dishDiameter().put(n, 12.0); 681 } 682 else if (cALMA) { 683 // this needs to be changed in future... 684 cAntennaCols->station().put(n, "CHAJNANTOR"); 685 cAntennaCols->dishDiameter().put(n, 12.0); 686 } 687 else if (cATF) { 688 //pad name for the antenna is static... 689 String stname="unknown"; 690 if (antName.contains("DV")) { 691 stname="PAD001"; 692 } 693 if (antName.contains("DA")) { 694 stname="PAD002"; 695 } 696 cAntennaCols->station().put(n, stname); 697 cAntennaCols->dishDiameter().put(n, 12.0); 698 } 699 else if (cSMT) { 700 cAntennaCols->station().put(n, "MT_GRAHAM"); 701 cAntennaCols->dishDiameter().put(n, 10.0); 702 } 703 else { 704 cAntennaCols->station().put(n, "ATNF_PARKES"); 705 cAntennaCols->dishDiameter().put(n, 64.0); 706 } 594 707 cAntennaCols->type().put(n, "GROUND-BASED"); 595 708 cAntennaCols->mount().put(n, "ALT-AZ"); … … 597 710 Vector<Double> antOffset(3, 0.0); 598 711 cAntennaCols->offset().put(n, antOffset); 599 cAntennaCols->dishDiameter().put(n, 64.0); 600 712 //cAntennaCols->dishDiameter().put(n, 64.0); 713 //if (cGBT) { 714 // cAntennaCols->dishDiameter().put(n, 110.0); 715 //} 716 //else { 717 // cAntennaCols->dishDiameter().put(n, 64.0); 718 //} 601 719 // Flags. 602 720 cAntennaCols->flagRow().put(n, False); … … 711 829 const Int srcId) 712 830 { 831 832 ROScalarColumn<String> fldn(cField, "NAME"); 833 ROScalarColumn<Int> sourceid(cField, "SOURCE_ID"); 834 Int n; 835 Int nFld = cField.nrow(); 836 for (n = 0; n < nFld; n++) { 837 if (fldn(n) == fieldName && sourceid(n) == srcId) { 838 break; 839 } 840 } 841 713 842 // Extend the FIELD subtable. 714 cField.addRow(); 715 Int n = cField.nrow() - 1; 716 717 // Data. 718 cFieldCols->name().put(n, fieldName); 719 cFieldCols->code().put(n, "DRIFT"); 720 cFieldCols->time().put(n, time); 721 722 Matrix<Double> track(2, 2); 723 track.column(0) = direction; 724 track.column(1) = scanRate; 725 cFieldCols->numPoly().put(n, 1); 726 cFieldCols->delayDir().put(n, track); 727 cFieldCols->phaseDir().put(n, track); 728 cFieldCols->referenceDir().put(n, track); 729 cFieldCols->sourceId().put(n, srcId); 730 731 // Flags. 732 cFieldCols->flagRow().put(n, False); 843 if (n == nFld) { 844 cField.addRow(); 845 //Int n = cField.nrow() - 1; 846 847 // Data. 848 cFieldCols->name().put(n, fieldName); 849 if (cGBT) { 850 cFieldCols->code().put(n, " "); 851 } 852 else { 853 cFieldCols->code().put(n, "DRIFT"); 854 } 855 cFieldCols->time().put(n, time); 856 857 //Matrix<Double> track(2, 2); 858 Matrix<Double> track(2, 1); 859 track.column(0) = direction; 860 //track.column(1) = scanRate; 861 cFieldCols->numPoly().put(n, 1); 862 cFieldCols->delayDir().put(n, track); 863 cFieldCols->phaseDir().put(n, track); 864 cFieldCols->referenceDir().put(n, track); 865 cFieldCols->sourceId().put(n, srcId); 866 867 // Flags. 868 cFieldCols->flagRow().put(n, False); 869 } 733 870 734 871 return n; … … 741 878 Int PKSMS2writer::addObservationEntry( 742 879 const String observer, 743 const String project) 880 const String project, 881 const String antName) 744 882 { 745 883 // Extend the OBSERVATION subtable. … … 748 886 749 887 // Data. 750 cObservationCols->telescopeName().put(n, "Parkes"); 888 //cObservationCols->telescopeName().put(n, "Parkes"); 889 cObservationCols->telescopeName().put(n, antName); 751 890 Vector<Double> timerange(2, 0.0); 752 891 cObservationCols->timeRange().put(n, timerange); … … 754 893 Vector<String> log(1, "none"); 755 894 cObservationCols->log().put(n, log); 756 cObservationCols->scheduleType().put(n, "ATNF"); 895 //cObservationCols->scheduleType().put(n, "ATNF"); 896 cObservationCols->scheduleType().put(n, ""); 757 897 Vector<String> schedule(1, "Not available"); 758 898 cObservationCols->schedule().put(n, schedule); … … 767 907 768 908 //--------------------------------------------- PKSMS2writer::addPointingEntry 909 910 // Modified to fill pointing data if the direction is the pointing direction. 911 // So the following comment is no longer true. 769 912 770 913 // Add an entry to the POINTING subtable. This compulsory subtable simply … … 778 921 const Vector<Double> scanRate) 779 922 { 780 // Extend the POINTING subtable. 781 cPointing.addRow(); 782 Int n = cPointing.nrow() - 1; 783 784 // Keys. 785 cPointingCols->antennaId().put(n, 0); 786 cPointingCols->time().put(n, time); 787 cPointingCols->interval().put(n, interval); 788 789 // Data. 790 cPointingCols->name().put(n, fieldName); 791 cPointingCols->numPoly().put(n, 1); 792 cPointingCols->timeOrigin().put(n, time); 793 794 Matrix<Double> track(2, 2); 795 track.column(0) = direction; 796 track.column(1) = scanRate; 797 cPointingCols->direction().put(n, track); 798 cPointingCols->target().put(n, track); 799 cPointingCols->tracking().put(n, True); 800 923 924 ROScalarColumn<Double> tms(cPointing, "TIME"); 925 Int n; 926 Int ntm = cPointing.nrow(); 927 for (n = 0; n < ntm; n++) { 928 if (tms(n) == time) { 929 break; 930 } 931 } 932 933 if (n == ntm) { 934 // Extend the POINTING subtable. 935 cPointing.addRow(); 936 //Int n = cPointing.nrow() - 1; 937 938 // Keys. 939 cPointingCols->antennaId().put(n, 0); 940 cPointingCols->time().put(n, time); 941 cPointingCols->interval().put(n, interval); 942 943 // Data. 944 cPointingCols->name().put(n, fieldName); 945 cPointingCols->numPoly().put(n, 1); 946 cPointingCols->timeOrigin().put(n, time); 947 948 //Matrix<Double> track(2, 2); 949 Matrix<Double> track(2, 1); 950 track.column(0) = direction; 951 //track.column(1) = scanRate; 952 cPointingCols->direction().put(n, track); 953 cPointingCols->target().put(n, track); 954 cPointingCols->tracking().put(n, True); 955 } 801 956 return n; 802 957 } … … 821 976 // Data. 822 977 Vector<Int> corrType(2); 978 if (nPol == 1) { 979 corrType.resize(1); 980 corrType(0) = Stokes::XX; 981 } 982 else { 983 //Vector<Int> corrType(2); 823 984 corrType(0) = Stokes::XX; 824 985 corrType(1) = Stokes::YY; 986 } 825 987 cPolarizationCols->corrType().put(n, corrType); 826 988 827 989 Matrix<Int> corrProduct(2,2,1); 990 if (nPol == 1) { 991 corrProduct.resize(2,1,1); 992 corrProduct(1,0) = 0; 993 } 828 994 if (nPol == 2) { 829 995 corrProduct(1,0) = 0; … … 869 1035 const Vector<Double> direction, 870 1036 const Vector<Double> properMotion, 871 const Double restFreq, 1037 //const Double restFreq, 1038 const Vector<Double> restFreq, 872 1039 const Double radialVelocity) 873 1040 { … … 903 1070 // cSourceCols->position().put(n, position); 904 1071 cSourceCols->properMotion().put(n, properMotion); 905 Vector<Double> restFrequency(1, restFreq); 906 cSourceCols->restFrequency().put(n, restFrequency); 1072 // Vector<Double> restFrequency(1, restFreq); 1073 // cSourceCols->restFrequency().put(n, restFrequency); 1074 cSourceCols->restFrequency().put(n, restFreq); 907 1075 Vector<Double> sysvel(1, radialVelocity); 908 1076 cSourceCols->sysvel().put(n, sysvel); … … 933 1101 934 1102 // Data. 935 cSpWindowCols->name().put(n, "L-band"); 1103 //cSpWindowCols->name().put(n, "L-band"); 1104 cSpWindowCols->name().put(n, " "); 936 1105 cSpWindowCols->refFrequency().put(n, refFreq); 937 1106 … … 1015 1184 const Double interval, 1016 1185 const Vector<Float> tcal, 1017 const Vector<Float> tsys) 1018 { 1186 const Vector<Float> tsys, 1187 const Int nPol) 1188 { 1189 LogIO os(LogOrigin("PKSMS2writer", "addSysCalEntry()", WHERE)); 1190 1019 1191 // Extend the SYSCAL subtable. 1020 1192 cSysCal.addRow(); 1021 1193 Int n = cSysCal.nrow() - 1; 1022 1194 1195 //check fo consistency with n pol 1196 //here assume size of Tcal vector = npol 1197 Vector<Float> inTcal(nPol,0); 1198 Int ndim = tcal.shape()(0); 1199 Vector<Float> tmpTcal = tcal; 1200 if (nPol != ndim) { 1201 os << LogIO::WARN 1202 << "Found "<< ndim <<" Tcal value(s) for the data with "<<nPol<<" polarization(s)" 1203 << "(expecting one Tcal per pol)."<<endl 1204 << "First "<< nPol << " Tcal value(s) will be filled." << LogIO::POST; 1205 tmpTcal.resize(nPol, True); 1206 inTcal = tmpTcal; 1207 } 1023 1208 // Keys. 1024 1209 cSysCalCols->antennaId().put(n, 0); … … 1029 1214 1030 1215 // Data. 1031 cSysCalCols->tcal().put(n, tcal); 1216 //cSysCalCols->tcal().put(n, tcal); 1217 cSysCalCols->tcal().put(n, inTcal); 1032 1218 cSysCalCols->tsys().put(n, tsys); 1033 1219 -
branches/mergetest/external/atnf/PKSIO/PKSMS2writer.h
r1720 r1779 78 78 79 79 // Write the next data record. 80 /** 81 virtual Int write( 82 const Int scanNo, 83 const Int cycleNo, 84 const Double mjd, 85 const Double interval, 86 const String fieldName, 87 const String srcName, 88 const Vector<Double> srcDir, 89 const Vector<Double> srcPM, 90 const Double srcVel, 91 const String obsMode, 92 const Int IFno, 93 const Double refFreq, 94 const Double bandwidth, 95 const Double freqInc, 96 //const Double restFreq, 97 const Vector<Double> restFreq, 98 const Vector<Float> tcal, 99 const String tcalTime, 100 const Float azimuth, 101 const Float elevation, 102 const Float parAngle, 103 const Float focusAxi, 104 const Float focusTan, 105 const Float focusRot, 106 const Float temperature, 107 const Float pressure, 108 const Float humidity, 109 const Float windSpeed, 110 const Float windAz, 111 const Int refBeam, 112 const Int beamNo, 113 const Vector<Double> direction, 114 const Vector<Double> scanRate, 115 const Vector<Float> tsys, 116 const Vector<Float> sigma, 117 const Vector<Float> calFctr, 118 const Matrix<Float> baseLin, 119 const Matrix<Float> baseSub, 120 const Matrix<Float> &spectra, 121 const Matrix<uChar> &flagged, 122 const uInt flagrow, 123 const Complex xCalFctr, 124 const Vector<Complex> &xPol); 125 **/ 80 126 virtual Int write( 81 127 const PKSrecord &pksrec); … … 131 177 ScalarColumn<Complex> *cXCalFctrCol; 132 178 179 // for handling parameters specific to GBT and other telescopes 180 Bool cGBT, cSMT, cAPEX, cALMA, cATF; 133 181 134 182 // Add an entry to the ANTENNA subtable. … … 164 212 Int addObservationEntry( 165 213 const String observer, 166 const String project); 214 const String project, 215 const String antName); 167 216 168 217 // Add an entry to the POINTING subtable. … … 187 236 const Vector<Double> direction, 188 237 const Vector<Double> properMotion, 189 const Double restFreq, 238 //const Double restFreq, 239 const Vector<Double> restFreq, 190 240 const Double radialVelocity); 191 241 … … 209 259 const Double interval, 210 260 const Vector<Float> Tcal, 211 const Vector<Float> Tsys); 261 const Vector<Float> Tsys, 262 const Int nPol); 212 263 213 264 // Add an entry to the WEATHER subtable. -
branches/mergetest/external/atnf/PKSIO/PKSSDwriter.cc
r1735 r1779 35 35 #include <atnf/PKSIO/PKSSDwriter.h> 36 36 37 #include <casa/Logging/LogIO.h> 38 37 39 #include <casa/stdio.h> 38 40 #include <casa/Quanta/MVTime.h> … … 41 43 #include <cstring> 42 44 45 // Class name 46 const string className = "PKSSDwriter" ; 47 43 48 //--------------------------------------------------- PKSSDwriter::PKSSDwriter 44 49 … … 47 52 PKSSDwriter::PKSSDwriter() 48 53 { 49 // By default, messages are written to stderr.50 initMsg();51 54 } 52 55 … … 58 61 { 59 62 close(); 60 }61 62 //-------------------------------------------------------- PKSSDwriter::setMsg63 64 // Set message disposition. If fd is non-zero messages will be written65 // to that file descriptor, else stored for retrieval by getMsg().66 67 Int PKSSDwriter::setMsg(FILE *fd)68 {69 PKSmsg::setMsg(fd);70 cSDwriter.setMsg(fd);71 72 return 0;73 63 } 74 64 … … 92 82 const Bool haveBase) 93 83 { 94 // Clear the message stack.95 clearMsg();84 const string methodName = "create()" ; 85 LogIO os( LogOrigin( className, methodName, WHERE ) ) ; 96 86 97 87 double antPos[3]; … … 102 92 cNIF = nChan.nelements(); 103 93 if (nPol.nelements() != cNIF || haveXPol.nelements() != cNIF) { 104 cerr << "PKSSDwriter::create: " 105 << "Inconsistent number of IFs for nChan, nPol, and/or haveXPol." 106 << endl; 94 os << LogIO::SEVERE << "Inconsistent number of IFs for nChan, nPol, and/or haveXPol." << LogIO::POST ; 107 95 return 1; 108 96 } … … 131 119 (int *)cNPol.getStorage(deleteIt), 132 120 (int *)cHaveXPol.getStorage(deleteIt), (int)cHaveBase, 1); 133 logMsg(cSDwriter.getMsg());134 cSDwriter.clearMsg();121 //logMsg(cSDwriter.getMsg()); 122 //cSDwriter.clearMsg(); 135 123 if (status) { 136 124 cSDwriter.deleteFile(); … … 148 136 const PKSrecord &pksrec) 149 137 { 138 const string methodName = "write()" ; 139 LogIO os( LogOrigin( className, methodName, WHERE ) ) ; 140 150 141 // Do basic checks. 151 142 Int IFno = pksrec.IFno; 152 143 uInt iIF = IFno - 1; 153 144 if (IFno < 1 || Int(cNIF) < IFno) { 154 cerr << "PKSDwriter::write: "155 156 << " (maximum " << cNIF << ")." << endl;145 os << LogIO::SEVERE 146 << "Invalid IF number " << IFno 147 << " (maximum " << cNIF << ")." << LogIO::POST ; 157 148 return 1; 158 149 } … … 160 151 uInt nChan = pksrec.spectra.nrow(); 161 152 if (nChan != cNChan(iIF)) { 162 cerr << "PKSDwriter::write: " 163 << "Wrong number of channels for IF " << IFno << "," << endl 164 << " " 153 os << LogIO::SEVERE << "Wrong number of channels for IF " << IFno << "," << endl 165 154 << "got " << nChan << " should be " << cNChan(iIF) << "." << endl; 155 os << LogIO::POST ; 166 156 return 1; 167 157 } … … 169 159 uInt nPol = pksrec.spectra.ncolumn(); 170 160 if (nPol != cNPol(iIF)) { 171 cerr << "PKSDwriter::write: " 172 << "Wrong number of polarizations for IF " << IFno << "," << endl 173 << " " 174 << "got " << nPol << " should be " << cNPol(iIF) << "." << endl; 161 os << LogIO::SEVERE << "Wrong number of polarizations for IF " << IFno << "," << endl 162 << "got " << nPol << " should be " << cNPol(iIF) << "." << endl; 163 os << LogIO::POST ; 175 164 return 1; 176 165 } 177 166 178 // Extract calendar information fr om mjd.167 // Extract calendar information frrom mjd. 179 168 MVTime time(pksrec.mjd); 180 169 Int year = time.year(); … … 196 185 mbrec.srcRA = pksrec.srcDir(0); 197 186 mbrec.srcDec = pksrec.srcDir(1); 198 199 mbrec.restFreq = pksrec.restFreq; 200 187 if (pksrec.restFreq.shape()==0) { 188 mbrec.restFreq = 0; 189 } 190 else { 191 mbrec.restFreq = pksrec.restFreq(0); 192 } 201 193 strncpy(mbrec.obsType, (char *)pksrec.obsType.chars(), 16); 202 194 … … 291 283 292 284 Int status = cSDwriter.write(mbrec); 293 logMsg(cSDwriter.getMsg());294 cSDwriter.clearMsg();285 //logMsg(cSDwriter.getMsg()); 286 //cSDwriter.clearMsg(); 295 287 if (status) { 296 288 status = 1; … … 325 317 { 326 318 cSDwriter.close(); 327 logMsg(cSDwriter.getMsg());328 cSDwriter.clearMsg();329 } 319 //logMsg(cSDwriter.getMsg()); 320 //cSDwriter.clearMsg(); 321 } -
branches/mergetest/external/atnf/PKSIO/PKSSDwriter.h
r1720 r1779 62 62 virtual ~PKSSDwriter(); 63 63 64 // Set message disposition.65 virtual Int setMsg(66 FILE *fd = 0x0);67 68 64 // Create the SDFITS file and write static data. 69 65 virtual Int create( -
branches/mergetest/external/atnf/PKSIO/PKSreader.cc
r1720 r1779 85 85 reader = new PKSFITSreader("SDFITS"); 86 86 87 } else {88 // Assume it's MBFITS.89 format = "MBFITS";90 reader = new PKSFITSreader("MBFITS", retry, interpolate);91 }87 } else { 88 // Assume it's MBFITS. 89 format = "MBFITS"; 90 reader = new PKSFITSreader("MBFITS", retry, interpolate); 91 } 92 92 } 93 93 … … 106 106 format = "UNRECOGNIZED INPUT FORMAT"; 107 107 } 108 109 108 return reader; 110 109 } … … 113 112 114 113 // Search a list of directories for a Parkes Multibeam dataset and return an 115 // appropriate PKSreader for it.116 114 117 115 PKSreader* getPKSreader( … … 145 143 PKSreader* getPKSreader( 146 144 const String name, 145 const String antenna, 147 146 const Int retry, 148 147 const Int interpolate, … … 160 159 // Try to open it. 161 160 if (reader) { 162 if (reader->open(name, beams, IFs, nChan, nPol, haveXPol, haveBase,163 have Spectra)) {161 if (reader->open(name, antenna, beams, IFs, nChan, nPol, haveXPol, 162 haveBase, haveSpectra)) { 164 163 format += " OPEN ERROR"; 165 164 delete reader; … … 173 172 //--------------------------------------------------------------- getPKSreader 174 173 175 // Search a list of directories for a Parkes Multibeam dataset and open an174 // Search a list of directories for a Parkes Multibeam dataset and return an 176 175 // appropriate PKSreader for it. 177 178 PKSreader* getPKSreader( 179 const String name,176 PKSreader* getPKSreader( 177 const String name, 178 const String antenna, 180 179 const Vector<String> directories, 181 180 const Int retry, … … 196 195 // Try to open it. 197 196 if (reader) { 198 if (reader->open(name, beams, IFs, nChan, nPol, haveXPol, haveBase,199 have Spectra)) {197 if (reader->open(name, antenna, beams, IFs, nChan, nPol, haveXPol, 198 haveBase, haveSpectra)) { 200 199 format += " OPEN ERROR"; 201 200 delete reader; -
branches/mergetest/external/atnf/PKSIO/PKSreader.h
r1720 r1779 37 37 #define ATNF_PKSREADER_H 38 38 39 #include <atnf/PKSIO/PKSmsg.h>40 39 #include <atnf/PKSIO/PKSrecord.h> 40 #include <atnf/PKSIO/SrcType.h> 41 41 42 42 #include <casa/aips.h> 43 43 #include <casa/Arrays/Matrix.h> 44 44 #include <casa/Arrays/Vector.h> 45 #include <casa/BasicSL/Complex.h> 45 46 #include <casa/BasicSL/String.h> 46 47 … … 70 71 class PKSreader* getPKSreader( 71 72 const String name, 73 const String antenna, 72 74 const Int retry, 73 75 const Int interpolate, … … 84 86 class PKSreader* getPKSreader( 85 87 const String name, 88 const String antenna, 86 89 const Vector<String> directories, 87 90 const Int retry, … … 97 100 Bool &haveSpectra); 98 101 99 class PKSreader : public PKSmsg 102 103 class PKSreader 100 104 { 101 105 public: … … 106 110 virtual Int open( 107 111 const String inName, 112 const String antenna, 108 113 Vector<Bool> &beams, 109 114 Vector<Bool> &IFs, … … 148 153 const Bool getSpectra = True, 149 154 const Bool getXPol = False, 155 const Bool getFeedPos = False, 156 const Bool getPointing = False, 150 157 const Int coordSys = 0) = 0; 158 151 159 152 160 // Find the range of the data selected in time and position. … … 157 165 Matrix<Double> &positions) = 0; 158 166 159 // Read the next data record. 167 // Read the next data record. 168 /** 169 virtual Int read( 170 Int &scanNo, 171 Int &cycleNo, 172 Double &mjd, 173 Double &interval, 174 String &fieldName, 175 String &srcName, 176 Vector<Double> &srcDir, 177 Vector<Double> &srcPM, 178 Double &srcVel, 179 String &obsType, 180 Int &IFno, 181 Double &refFreq, 182 Double &bandwidth, 183 Double &freqInc, 184 Vector<Double> &restFreq, 185 Vector<Float> &tcal, 186 String &tcalTime, 187 Float &azimuth, 188 Float &elevation, 189 Float &parAngle, 190 Float &focusAxi, 191 Float &focusTan, 192 Float &focusRot, 193 Float &temperature, 194 Float &pressure, 195 Float &humidity, 196 Float &windSpeed, 197 Float &windAz, 198 Int &refBeam, 199 Int &beamNo, 200 Vector<Double> &direction, 201 Vector<Double> &scanRate, 202 Vector<Float> &tsys, 203 Vector<Float> &sigma, 204 Vector<Float> &calFctr, 205 Matrix<Float> &baseLin, 206 Matrix<Float> &baseSub, 207 Matrix<Float> &spectra, 208 Matrix<uChar> &flagged, 209 Complex &xCalFctr, 210 Vector<Complex> &xPol) = 0; 211 **/ 212 /** 213 // Read the next data record, just the basics. 214 virtual Int read( 215 Int &IFno, 216 Vector<Float> &tsys, 217 Vector<Float> &calFctr, 218 Matrix<Float> &baseLin, 219 Matrix<Float> &baseSub, 220 Matrix<Float> &spectra, 221 Matrix<uChar> &flagged) = 0; 222 **/ 160 223 virtual Int read(PKSrecord &pksrec) = 0; 161 224 … … 164 227 165 228 protected: 166 Bool cGetSpectra, cGetXPol;229 Bool cGetFeedPos, cGetSpectra, cGetXPol, cGetPointing; 167 230 Int cCoordSys; 168 231 -
branches/mergetest/external/atnf/PKSIO/PKSrecord.h
r1720 r1779 67 67 Double bandwidth; 68 68 Double freqInc; 69 Double restFreq; 69 Int nchan; 70 Vector<Double> restFreq; 70 71 Vector<Float> tcal; 71 72 String tcalTime; … … 86 87 Int pCode; 87 88 Float rateAge; 88 Vector< Float>scanRate;89 Vector<Double> scanRate; 89 90 Float paRate; 90 91 Vector<Float> tsys; … … 95 96 Matrix<Float> spectra; 96 97 Matrix<uChar> flagged; 98 uInt flagrow; 97 99 Complex xCalFctr; 98 100 Vector<Complex> xPol; 101 Int polNo ; 102 Int srcType ; 99 103 }; 100 104 -
branches/mergetest/external/atnf/PKSIO/PKSwriter.h
r1720 r1779 35 35 #define ATNF_PKSWRITER_H 36 36 37 #include <atnf/PKSIO/PKSmsg.h>38 37 #include <atnf/PKSIO/PKSrecord.h> 39 38 … … 50 49 // </summary> 51 50 52 class PKSwriter : public PKSmsg51 class PKSwriter 53 52 { 54 53 public: -
branches/mergetest/external/atnf/PKSIO/SDFITSreader.cc
r1737 r1779 38 38 39 39 #include <atnf/pks/pks_maths.h> 40 #include <atnf/PKSIO/PKSmsg.h>41 40 #include <atnf/PKSIO/MBrecord.h> 42 41 #include <atnf/PKSIO/SDFITSreader.h> 43 42 43 #include <casa/Logging/LogIO.h> 44 #include <casa/Quanta/MVTime.h> 44 45 #include <casa/math.h> 45 46 #include <casa/stdio.h> … … 67 68 const double D2R = PI / 180.0; 68 69 70 // Class name 71 const string className = "SDFITSreader" ; 72 69 73 //---------------------------------------------------- SDFITSreader::(statics) 70 74 … … 97 101 cEndChan = 0x0; 98 102 cRefChan = 0x0; 99 100 // By default, messages are written to stderr. 101 initMsg(); 103 cPols = 0x0; 102 104 } 103 105 … … 128 130 int &extraSysCal) 129 131 { 130 // Clear the message stack. 131 clearMsg(); 132 const string methodName = "open()" ; 132 133 133 134 if (cSDptr) { … … 139 140 if (fits_open_file(&cSDptr, sdName, READONLY, &cStatus)) { 140 141 sprintf(cMsg, "ERROR: Failed to open SDFITS file\n %s", sdName); 141 log Msg(cMsg);142 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, cMsg); 142 143 return 1; 143 144 } … … 162 163 163 164 } else { 164 log Msg("ERROR:Failed to locate SDFITS binary table.");165 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to locate SDFITS binary table."); 165 166 close(); 166 167 return 1; … … 201 202 cNAxes = 5; 202 203 if (readDim(DATA, 1, &cNAxes, cNAxis)) { 203 log Msg();204 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 204 205 close(); 205 206 return 1; … … 220 221 if (cNAxes < 4) { 221 222 // Need at least four axes (for now). 222 log Msg("ERROR:DATA array contains fewer than four axes.");223 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "DATA array contains fewer than four axes."); 223 224 close(); 224 225 return 1; 225 226 } else if (cNAxes > 5) { 226 227 // We support up to five axes. 227 log Msg("ERROR:DATA array contains more than five axes.");228 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "DATA array contains more than five axes."); 228 229 close(); 229 230 return 1; … … 236 237 findData(DATAXED, "DATAXED", TSTRING); 237 238 if (cData[DATAXED].colnum < 0) { 238 log Msg("ERROR:DATA array column absent from binary table.");239 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "DATA array column absent from binary table."); 239 240 close(); 240 241 return 1; … … 266 267 267 268 if (cStatus) { 268 log Msg();269 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 269 270 close(); 270 271 return 1; … … 280 281 char *timeCRPIX = 0; 281 282 char *beamCRVAL = 0; 283 char *polCRVAL = 0; 282 284 283 285 cFreqAxis = -1; … … 297 299 } else if (strncmp(ctype[iaxis], "STOKES", 6) == 0) { 298 300 cStokesAxis = iaxis; 301 polCRVAL = CRVAL[iaxis]; 299 302 300 303 } else if (strncmp(ctype[iaxis], "RA", 2) == 0) { … … 318 321 sprintf(cMsg, "DATA array contains a TIME axis of length %ld.", 319 322 cNAxisTime); 320 logMsg(cMsg); 323 //logMsg(cMsg); 324 log(LogOrigin( className, methodName, WHERE ), LogIO::NORMAL, cMsg); 321 325 } 322 326 … … 337 341 } 338 342 343 339 344 // Check that required axes are present. 340 345 if (cFreqAxis < 0 || cStokesAxis < 0 || cRaAxis < 0 || cDecAxis < 0) { 341 log Msg("ERROR:Could not find required DATA array axes.");346 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Could not find required DATA array axes."); 342 347 close(); 343 348 return 1; … … 403 408 findData(WINDDIRE, "WINDDIRE", TFLOAT); // Shared. 404 409 410 findData(STOKES, polCRVAL, TINT); 411 findData(SIG, "SIG", TSTRING); 412 findData(CAL, "CAL", TSTRING); 413 414 findData(RVSYS, "RVSYS", TDOUBLE); 415 findData(VFRAME, "VFRAME", TDOUBLE); 416 findData(VELDEF, "VELDEF", TSTRING); 417 405 418 if (cStatus) { 406 log Msg();419 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 407 420 close(); 408 421 return 1; … … 433 446 cCycleNo = 0; 434 447 cLastUTC = 0.0; 448 for ( int i = 0 ; i < 4 ; i++ ) { 449 cGLastUTC[i] = 0.0 ; 450 cGLastScan[i] = -1 ; 451 cGCycleNo[i] = 0 ; 452 } 435 453 436 454 // Beam number, 1-relative by default. … … 536 554 fits_get_num_rows(cSDptr, &cNRow, &cStatus); 537 555 if (!cNRow) { 538 log Msg("ERROR:Table contains no entries.");556 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Table contains no entries."); 539 557 close(); 540 558 return 1; … … 550 568 &beamNul, beamCol, &anynul, &cStatus)) { 551 569 delete [] beamCol; 552 log Msg();570 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 553 571 close(); 554 572 return 1; … … 565 583 if (beamCol[irow] < cBeam_1rel) { 566 584 delete [] beamCol; 567 log Msg("ERROR:SDFITS file contains invalid beam number.");585 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "SDFITS file contains invalid beam number."); 568 586 close(); 569 587 return 1; … … 606 624 &IFNul, IFCol, &anynul, &cStatus)) { 607 625 delete [] IFCol; 608 log Msg();626 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 609 627 close(); 610 628 return 1; … … 621 639 if (IFCol[irow] < cIF_1rel) { 622 640 delete [] IFCol; 623 log Msg("ERROR:SDFITS file contains invalid IF number.");641 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "SDFITS file contains invalid IF number."); 624 642 close(); 625 643 return 1; … … 653 671 // Variable dimension array. 654 672 if (readDim(DATA, irow+1, &cNAxes, cNAxis)) { 655 log Msg();673 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 656 674 close(); 657 675 return 1; … … 681 699 682 700 if (readDim(XPOLDATA, irow+1, &nAxis, nAxes)) { 683 log Msg();701 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE ); 684 702 close(); 685 703 return 1; … … 719 737 cNPol[0] = cNIF; 720 738 cNIF = 1; 739 } 740 741 // For GBT data that stores spectra for each polarization in separate rows 742 if ( cData[STOKES].colnum > 0 ) { 743 int *stokesCol = new int[cNRow]; 744 int stokesNul = 1; 745 int anynul; 746 if (fits_read_col(cSDptr, TINT, cData[STOKES].colnum, 1, 1, cNRow, 747 &stokesNul, stokesCol, &anynul, &cStatus)) { 748 delete [] stokesCol; 749 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 750 close(); 751 return 1; 752 } 753 754 vector<int> pols ; 755 pols.push_back( stokesCol[0] ) ; 756 for ( int i = 0 ; i < cNRow ; i++ ) { 757 bool pmatch = false ; 758 for ( uint j = 0 ; j < pols.size() ; j++ ) { 759 if ( stokesCol[i] == pols[j] ) { 760 pmatch = true ; 761 break ; 762 } 763 } 764 if ( !pmatch ) { 765 pols.push_back( stokesCol[i] ) ; 766 } 767 } 768 769 cPols = new int[pols.size()] ; 770 for ( uint i = 0 ; i < pols.size() ; i++ ) { 771 cPols[i] = pols[i] ; 772 } 773 774 for ( int i = 0 ; i < cNIF ; i++ ) { 775 cNPol[i] = pols.size() ; 776 } 777 778 delete [] stokesCol ; 721 779 } 722 780 … … 806 864 double &bandwidth) 807 865 { 866 const string methodName = "getHeader()" ; 867 808 868 // Has the file been opened? 809 869 if (!cSDptr) { … … 879 939 880 940 // Look for VELFRAME, written by earlier versions of Livedata. 941 // 942 // Added few more codes currently (as of 2009 Oct) used in the GBT 943 // SDFITS (based io_sdfits_define.pro of GBTIDL). - TT 881 944 if (readParm("VELFRAME", TSTRING, dopplerFrame)) { // Additional. 882 945 // No, try digging it out of the CTYPE card (AIPS convention). … … 890 953 // LSR unqualified usually means LSR (kinematic). 891 954 strcpy(dopplerFrame, "LSRK"); 955 } else if (strcmp(dopplerFrame, "LSD") == 0) { 956 // LSR as a dynamical defintion 957 strcpy(dopplerFrame, "LSRD"); 892 958 } else if (strcmp(dopplerFrame, "HEL") == 0) { 893 959 // Almost certainly barycentric. 894 960 strcpy(dopplerFrame, "BARYCENT"); 961 } else if (strcmp(dopplerFrame, "BAR") == 0) { 962 // barycentric. 963 strcpy(dopplerFrame, "BARYCENT"); 964 } else if (strcmp(dopplerFrame, "OBS") == 0) { 965 // observed or topocentric. 966 strcpy(dopplerFrame, "TOPO"); 967 } else if (strcmp(dopplerFrame, "GEO") == 0) { 968 // geocentric 969 strcpy(dopplerFrame, "GEO"); 970 } else if (strcmp(dopplerFrame, "GAL") == 0) { 971 // galactic 972 strcpy(dopplerFrame, "GAL"); 973 } else if (strcmp(dopplerFrame, "LGR") == 0) { 974 // Local group 975 strcpy(dopplerFrame, "LGROUP"); 976 } else if (strcmp(dopplerFrame, "CMB") == 0) { 977 // Cosimic Microwave Backgroup 978 strcpy(dopplerFrame, "CMB"); 895 979 } 896 980 } else { … … 898 982 } 899 983 } 900 901 984 // Translate to FITS standard names. 902 985 if (strncmp(dopplerFrame, "TOP", 3) == 0) { … … 908 991 } else if (strncmp(dopplerFrame, "BARY", 4) == 0) { 909 992 strcpy(dopplerFrame, "BARYCENT"); 910 } 911 } 912 993 } else if (strncmp(dopplerFrame, "GAL", 3) == 0) { 994 strcpy(dopplerFrame, "GALACTOC"); 995 } else if (strncmp(dopplerFrame, "LGROUP", 6) == 0) { 996 strcpy(dopplerFrame, "LOCALGRP"); 997 } else if (strncmp(dopplerFrame, "CMB", 3) == 0) { 998 strcpy(dopplerFrame, "CMBDIPOL"); 999 } 1000 } 1001 913 1002 if (cStatus) { 914 log Msg();1003 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 915 1004 return 1; 916 1005 } … … 922 1011 923 1012 if (cStatus) { 924 log Msg();1013 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 925 1014 return 1; 926 1015 } … … 938 1027 double* &endFreq) 939 1028 { 1029 const string methodName = "getFreqInfo()" ; 1030 940 1031 float fqRefPix; 941 1032 double fqDelt, fqRefVal; … … 952 1043 &IFNul, IFCol, &anynul, &cStatus)) { 953 1044 delete [] IFCol; 954 log Msg();1045 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 955 1046 close(); 956 1047 return 1; … … 1015 1106 double* &positions) 1016 1107 { 1108 const string methodName = "findRange()" ; 1109 1017 1110 // Has the file been opened? 1018 1111 if (!cSDptr) { … … 1036 1129 delete [] beamCol; 1037 1130 delete [] sel; 1038 log Msg();1131 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 1039 1132 return 1; 1040 1133 } … … 1056 1149 delete [] IFCol; 1057 1150 delete [] sel; 1058 log Msg();1151 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 1059 1152 return 1; 1060 1153 } … … 1088 1181 if (cData[AZIMUTH].colnum < 0 || 1089 1182 cData[ELEVATIO].colnum < 0) { 1090 log Msg("WARNING:Azimuth/elevation information absent.");1183 log(LogOrigin( className, methodName, WHERE ), LogIO::WARN, "Azimuth/elevation information absent."); 1091 1184 cStatus = -1; 1092 1185 … … 1115 1208 cData[FOCUSROT].colnum < 0 || 1116 1209 cData[ELEVATIO].colnum < 0) { 1117 log Msg("WARNING:ZPA/elevation information absent.");1210 log(LogOrigin( className, methodName, WHERE ), LogIO::WARN, "ZPA/elevation information absent."); 1118 1211 cStatus = -1; 1119 1212 … … 1191 1284 cData[PARANGLE].colnum < 0 || 1192 1285 cData[FOCUSROT].colnum < 0) { 1193 logMsg("WARNING: Insufficient information to compute feed-plane\n" 1194 " coordinates."); 1286 log( LogOrigin( className, methodName, WHERE ), LogIO::WARN, 1287 "Insufficient information to compute feed-plane\n" 1288 " coordinates."); 1195 1289 cStatus = -1; 1196 1290 … … 1241 1335 nSel = 0; 1242 1336 delete [] positions; 1243 log Msg();1337 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 1244 1338 cStatus = 0; 1245 1339 return 1; … … 1257 1351 MBrecord &mbrec) 1258 1352 { 1353 const string methodName = "read()" ; 1354 1259 1355 // Has the file been opened? 1260 1356 if (!cSDptr) { 1261 1357 return 1; 1262 1358 } 1263 1264 1359 // Find the next selected beam and IF. 1265 1360 short iBeam = 0, iIF = 0; 1361 int iPol = -1 ; 1266 1362 while (1) { 1267 1363 if (++cTimeIdx > cNAxisTime) { … … 1321 1417 sprintf(cMsg, "ALFA cal factors for beam %d: %.3e, %.3e", 1322 1418 iBeam+1, sALFAcal[iBeam][0], sALFAcal[iBeam][1]); 1323 logMsg(cMsg); 1419 log(LogOrigin( className, methodName, WHERE ), LogIO::NORMAL, cMsg); 1420 //logMsg(cMsg); 1324 1421 } 1325 1422 } 1326 1423 } 1327 1424 1425 // for GBT SDFITS 1426 if (cData[STOKES].colnum > 0 ) { 1427 readData(STOKES, cRow, &iPol ) ; 1428 for ( int i = 0 ; i < cNPol[iIF] ; i++ ) { 1429 if ( cPols[i] == iPol ) { 1430 iPol = i ; 1431 break ; 1432 } 1433 } 1434 } 1328 1435 break; 1329 1436 } … … 1370 1477 } 1371 1478 1479 if ( iPol != -1 ) { 1480 if ( mbrec.scanNo != cGLastScan[iPol] ) { 1481 cGLastScan[iPol] = mbrec.scanNo ; 1482 cGCycleNo[iPol] = 0 ; 1483 mbrec.cycleNo = ++cGCycleNo[iPol] ; 1484 } 1485 else { 1486 mbrec.cycleNo = ++cGCycleNo[iPol] ; 1487 } 1488 } 1489 1372 1490 readData(EXPOSURE, cRow, &mbrec.exposure); 1373 1491 1374 1492 // Source identification. 1375 1493 readData(OBJECT, cRow, mbrec.srcName); 1494 1495 if ( iPol != -1 ) { 1496 char obsmode[32] ; 1497 readData( OBSMODE, cRow, obsmode ) ; 1498 char sig[1] ; 1499 char cal[1] ; 1500 readData( SIG, cRow, sig ) ; 1501 readData( CAL, cRow, cal ) ; 1502 if ( strstr( obsmode, "PSWITCH" ) != NULL ) { 1503 // position switch 1504 strcat( mbrec.srcName, "_p" ) ; 1505 if ( strstr( obsmode, "PSWITCHON" ) != NULL ) { 1506 strcat( mbrec.srcName, "s" ) ; 1507 } 1508 else if ( strstr( obsmode, "PSWITCHOFF" ) != NULL ) { 1509 strcat( mbrec.srcName, "r" ) ; 1510 } 1511 } 1512 else if ( strstr( obsmode, "Nod" ) != NULL ) { 1513 // nod 1514 strcat( mbrec.srcName, "_n" ) ; 1515 if ( sig[0] == 'T' ) { 1516 strcat( mbrec.srcName, "s" ) ; 1517 } 1518 else { 1519 strcat( mbrec.srcName, "r" ) ; 1520 } 1521 } 1522 else if ( strstr( obsmode, "FSWITCH" ) != NULL ) { 1523 // frequency switch 1524 strcat( mbrec.srcName, "_f" ) ; 1525 if ( sig[0] == 'T' ) { 1526 strcat( mbrec.srcName, "s" ) ; 1527 } 1528 else { 1529 strcat( mbrec.srcName, "r" ) ; 1530 } 1531 } 1532 if ( cal[0] == 'T' ) { 1533 strcat( mbrec.srcName, "c" ) ; 1534 } 1535 else { 1536 strcat( mbrec.srcName, "o" ) ; 1537 } 1538 } 1376 1539 1377 1540 readData(OBJ_RA, cRow, &mbrec.srcRA); … … 1421 1584 int nPol = cNPol[iIF]; 1422 1585 1586 if ( cData[STOKES].colnum > 0 ) 1587 nPol = 1 ; 1588 1423 1589 if (cGetSpectra || cGetXPol) { 1424 1590 int nxpol = cGetXPol ? 2*nChan : 0; … … 1430 1596 mbrec.nChan[0] = nChan; 1431 1597 mbrec.nPol[0] = nPol; 1598 mbrec.polNo = iPol ; 1432 1599 1433 1600 readData(FqRefPix, cRow, mbrec.fqRefPix); … … 1448 1615 1449 1616 if (cStatus) { 1450 log Msg();1617 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 1451 1618 return 1; 1452 1619 } … … 1485 1652 1486 1653 if (cStatus) { 1487 log Msg();1654 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 1488 1655 return 1; 1489 1656 } … … 1535 1702 1536 1703 if ((status = readDim(DATA, cRow, &naxes, cNAxis))) { 1537 log Msg();1704 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 1538 1705 1539 1706 } else if ((status = (naxes != cNAxes))) { 1540 log Msg("ERROR:DATA array dimensions changed.");1707 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "DATA array dimensions changed."); 1541 1708 } 1542 1709 … … 1552 1719 blc, trc, inc, 0, mbrec.spectra[0] + iPol*nChan, &anynul, 1553 1720 &cStatus)) { 1554 log Msg();1721 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 1555 1722 delete [] blc; 1556 1723 delete [] trc; … … 1613 1780 cNAxis, blc, trc, inc, 0, mbrec.flagged[0] + iPol*nChan, &anynul, 1614 1781 &cStatus)) { 1615 log Msg();1782 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 1616 1783 delete [] blc; 1617 1784 delete [] trc; … … 1664 1831 if (fits_read_subset_flt(cSDptr, cData[XPOLDATA].colnum, nAxis, nAxes, 1665 1832 blc, trc, inc, 0, mbrec.xpol[0], &anynul, &cStatus)) { 1666 log Msg();1833 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 1667 1834 delete [] blc; 1668 1835 delete [] trc; … … 1695 1862 1696 1863 if (cStatus) { 1697 log Msg();1864 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 1698 1865 return 1; 1699 1866 } … … 1729 1896 mbrec.windAz *= D2R; 1730 1897 1898 // For GBT data, source velocity can be evaluated 1899 if ( cData[RVSYS].colnum > 0 && cData[VFRAME].colnum > 0 ) { 1900 float vframe; 1901 readData(VFRAME, cRow, &vframe); 1902 float rvsys; 1903 readData(RVSYS, cRow, &rvsys); 1904 //mbrec.srcVelocity = rvsys - vframe ; 1905 mbrec.srcVelocity = rvsys ; 1906 } 1907 1731 1908 if (cStatus) { 1732 log Msg();1909 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 1733 1910 return 1; 1734 1911 } … … 1756 1933 } 1757 1934 1758 //------------------------------------------------------- SDFITSreader::log Msg1935 //------------------------------------------------------- SDFITSreader::log 1759 1936 1760 1937 // Log a message. If the current CFITSIO status value is non-zero, also log 1761 1938 // the corresponding error message and the CFITSIO message stack. 1762 1939 1763 void SDFITSreader::log Msg(const char *msg)1940 void SDFITSreader::log(LogOrigin origin, LogIO::Command cmd, const char *msg) 1764 1941 { 1765 FITSreader::logMsg(msg); 1942 LogIO os( origin ) ; 1943 1944 os << msg << endl ; 1766 1945 1767 1946 if (cStatus > 0) { 1768 1947 fits_get_errstatus(cStatus, cMsg); 1769 FITSreader::logMsg(cMsg);1948 os << cMsg << endl ; 1770 1949 1771 1950 while (fits_read_errmsg(cMsg)) { 1772 FITSreader::logMsg(cMsg); 1773 } 1774 } 1951 os << cMsg << endl ; 1952 } 1953 } 1954 os << LogIO::POST ; 1775 1955 } 1776 1956 … … 2107 2287 if (cData[TIME].colnum >= 0) { 2108 2288 readData(TIME, iRow, &utc); 2289 } else if (cGBT) { 2290 Int yy, mm ; 2291 Double dd, hour, min, sec ; 2292 sscanf( datobs, "%d-%d-%lfT%lf:%lf:%lf", &yy, &mm, &dd, &hour, &min, &sec ) ; 2293 dd = dd + ( hour * 3600.0 + min * 60.0 + sec ) / 86400.0 ; 2294 MVTime mvt( yy, mm, dd ) ; 2295 dd = mvt.day() ; 2296 utc = fmod( dd, 1.0 ) * 86400.0 ; 2109 2297 } else if (cNAxisTime > 1) { 2110 2298 double timeDelt, timeRefPix, timeRefVal; … … 2153 2341 short iPol) 2154 2342 { 2343 const string methodName = "alfaCal()" ; 2344 2155 2345 int calOn; 2156 2346 char chars[32]; … … 2205 2395 if (fits_read_subset_flt(cSDptr, cData[DATA].colnum, cNAxes, cNAxis, 2206 2396 blc, trc, inc, 0, spectrum, &anynul, &cStatus)) { 2207 log Msg();2397 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE); 2208 2398 delete [] blc; 2209 2399 delete [] trc; -
branches/mergetest/external/atnf/PKSIO/SDFITSreader.h
r1720 r1779 43 43 #include <atnf/PKSIO/MBrecord.h> 44 44 45 #include <casa/Logging/LogIO.h> 46 45 47 #include <fitsio.h> 46 48 47 49 using namespace std; 50 using namespace casa; 48 51 49 52 // <summary> … … 121 124 int cBeam_1rel, cIF_1rel; 122 125 126 // for GBT 127 int *cPols ; 128 123 129 enum {SCAN, CYCLE, DATE_OBS, TIME, EXPOSURE, OBJECT, OBJ_RA, OBJ_DEC, 124 130 RESTFRQ, OBSMODE, BEAM, IF, FqRefVal, FqDelt, FqRefPix, RA, DEC, … … 126 132 BASELIN, BASESUB, DATA, FLAGGED, DATAXED, XPOLDATA, REFBEAM, TCAL, 127 133 TCALTIME, AZIMUTH, ELEVATIO, PARANGLE, FOCUSAXI, FOCUSTAN, FOCUSROT, 128 TAMBIENT, PRESSURE, HUMIDITY, WINDSPEE, WINDDIRE, NDATA}; 134 TAMBIENT, PRESSURE, HUMIDITY, WINDSPEE, WINDDIRE, STOKES, SIG, CAL, 135 VFRAME, RVSYS, VELDEF, NDATA}; 129 136 130 137 // Message handling. 131 v irtual void logMsg(const char *msg = 0x0);138 void log(LogOrigin origin, LogIO::Command cmd, const char *msg = 0x0); 132 139 133 140 void findData(int iData, char *name, int type); … … 153 160 // These are for GBT data. 154 161 int cGBT, cFirstScanNo; 162 double cGLastUTC[4] ; 163 int cGLastScan[4] ; 164 int cGCycleNo[4] ; 155 165 }; 156 166 -
branches/mergetest/external/atnf/PKSIO/SDFITSwriter.cc
r1736 r1779 35 35 36 36 #include <atnf/PKSIO/MBrecord.h> 37 #include <atnf/PKSIO/PKSmsg.h>38 37 #include <atnf/PKSIO/SDFITSwriter.h> 38 39 #include <casa/Logging/LogIO.h> 39 40 40 41 #include <casa/iostream.h> … … 51 52 // Factor to convert radians to degrees. 52 53 const double R2D = 180.0 / PI; 54 55 // Class name 56 const string className = "SDFITSwriter" ; 53 57 54 58 //------------------------------------------------- SDFITSwriter::SDFITSwriter … … 58 62 // Default constructor. 59 63 cSDptr = 0x0; 60 61 // By default, messages are written to stderr.62 initMsg();63 64 } 64 65 … … 91 92 int extraSysCal) 92 93 { 94 const string methodName = "create()" ; 95 93 96 if (cSDptr) { 94 log Msg("ERROR:Output file already open, close it first.");97 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Output file already open, close it first."); 95 98 return 1; 96 99 } 97 98 // Clear the message stack.99 clearMsg();100 100 101 101 // Prepend an '!' to the output name to force it to be overwritten. … … 107 107 cStatus = 0; 108 108 if (fits_create_file(&cSDptr, sdname, &cStatus)) { 109 sprintf(cMsg, " ERROR:Failed to create SDFITS file\n %s", sdName);110 log Msg(cMsg);109 sprintf(cMsg, "Failed to create SDFITS file\n %s", sdName); 110 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, cMsg); 111 111 return cStatus; 112 112 } … … 156 156 // Write required primary header keywords. 157 157 if (fits_write_imghdr(cSDptr, 8, 0, 0, &cStatus)) { 158 log Msg("ERROR:Failed to write required primary header keywords.");158 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to write required primary header keywords."); 159 159 return cStatus; 160 160 } … … 188 188 189 189 if (cStatus) { 190 log Msg("ERROR:Failed in writing primary header.");190 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing primary header."); 191 191 return cStatus; 192 192 } … … 198 198 if (fits_create_tbl(cSDptr, BINARY_TBL, nrow, ncol, NULL, NULL, NULL, 199 199 "SINGLE DISH", &cStatus)) { 200 log Msg("ERROR:Failed to create a binary table extension.");200 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to create a binary table extension."); 201 201 return 1; 202 202 } … … 548 548 549 549 if (cStatus) { 550 log Msg("ERROR:Failed in writing binary table header.");550 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing binary table header."); 551 551 } 552 552 … … 560 560 int SDFITSwriter::write(MBrecord &mbrec) 561 561 { 562 const string methodName = "write()" ; 563 LogIO os( LogOrigin( className, methodName, WHERE ) ) ; 564 562 565 char *cptr; 563 566 … … 565 568 int IFno = mbrec.IFno[0]; 566 569 if (IFno < 1 || cNIF < IFno) { 567 cerr << "SDFITSwriter::write: " 568 << "Invalid IF number " << IFno 569 << " (maximum " << cNIF << ")." << endl; 570 os << LogIO::WARN 571 << "SDFITSwriter::write: " 572 << "Invalid IF number " << IFno 573 << " (maximum " << cNIF << ")." << LogIO::POST ; 570 574 return 1; 571 575 } … … 574 578 int nChan = cNChan[iIF]; 575 579 if (mbrec.nChan[0] != nChan) { 576 cerr << "SDFITSriter::write: " 577 << "Wrong number of channels for IF " << IFno << "," << endl 578 << " " 579 << "got " << nChan << " should be " << mbrec.nChan[0] << "." << endl; 580 os << LogIO::WARN 581 << "SDFITSriter::write: " 582 << "Wrong number of channels for IF " << IFno << "," << endl 583 << " " 584 << "got " << nChan << " should be " << mbrec.nChan[0] << "." << endl; 585 os << LogIO::POST ; 580 586 return 1; 581 587 } … … 583 589 int nPol = cNPol[iIF]; 584 590 if (mbrec.nPol[0] != nPol) { 585 cerr << "SDFITSriter::write: " 586 << "Wrong number of polarizations for IF " << IFno << "," << endl 587 << " " 588 << "got " << nPol << " should be " << mbrec.nPol[0] << "." << endl; 591 os << LogIO::WARN 592 << "SDFITSriter::write: " 593 << "Wrong number of polarizations for IF " << IFno << "," << endl 594 << " " 595 << "got " << nPol << " should be " << mbrec.nPol[0] << "." << endl; 596 os << LogIO::POST ; 589 597 return 1; 590 598 } … … 768 776 769 777 if (cStatus) { 770 log Msg("ERROR:Failed in writing binary table entry.");778 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing binary table entry."); 771 779 } 772 780 … … 782 790 783 791 { 792 const string methodName = "history()" ; 793 784 794 if (!cSDptr) { 785 795 return 1; … … 787 797 788 798 if (fits_write_history(cSDptr, text, &cStatus)) { 789 log Msg("ERROR:Failed in writing HISTORY records.");799 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed in writing HISTORY records."); 790 800 } 791 801 … … 799 809 void SDFITSwriter::close() 800 810 { 811 const string methodName = "close()" ; 812 801 813 if (cSDptr) { 802 814 cStatus = 0; 803 815 if (fits_close_file(cSDptr, &cStatus)) { 804 log Msg("ERROR:Failed to close file.");816 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to close file."); 805 817 } 806 818 … … 815 827 void SDFITSwriter::deleteFile() 816 828 { 829 const string methodName = "deleteFile()" ; 830 817 831 if (cSDptr) { 818 832 cStatus = 0; 819 833 if (fits_delete_file(cSDptr, &cStatus)) { 820 log Msg("ERROR:Failed to close and delete file.");834 log(LogOrigin( className, methodName, WHERE ), LogIO::SEVERE, "Failed to close and delete file."); 821 835 } 822 836 … … 825 839 } 826 840 827 //------------------------------------------------------- SDFITSwriter::log Msg841 //------------------------------------------------------- SDFITSwriter::log 828 842 829 843 // Log a message. If the current CFITSIO status value is non-zero, also log 830 844 // the corresponding error message and dump the CFITSIO message stack. 831 845 832 void SDFITSwriter::log Msg(const char *msg)846 void SDFITSwriter::log(LogOrigin origin, LogIO::Command cmd, const char *msg) 833 847 { 834 PKSmsg::logMsg(msg); 848 LogIO os( origin ) ; 849 850 os << cmd << msg << endl ; 835 851 836 852 if (cStatus) { 837 853 fits_get_errstatus(cStatus, cMsg); 838 PKSmsg::logMsg(cMsg);854 os << cMsg << endl ; 839 855 840 856 while (fits_read_errmsg(cMsg)) { 841 PKSmsg::logMsg(cMsg); 842 } 843 } 857 os << cMsg << endl ; 858 } 859 } 860 861 os << LogIO::POST ; 844 862 } -
branches/mergetest/external/atnf/PKSIO/SDFITSwriter.h
r1720 r1779 38 38 39 39 #include <atnf/PKSIO/MBrecord.h> 40 #include < atnf/PKSIO/PKSmsg.h>40 #include <casa/Logging/LogIO.h> 41 41 42 42 #include <fitsio.h> 43 43 44 44 using namespace std; 45 using namespace casa; 45 46 46 47 // <summary> … … 48 49 // </summary> 49 50 50 class SDFITSwriter : public PKSmsg51 class SDFITSwriter 51 52 { 52 53 public: … … 95 96 // Message handling. 96 97 char cMsg[256]; 97 v irtual void logMsg(const char *msg = 0x0);98 void log(LogOrigin origin, LogIO::Command cmd, const char *msg = 0x0); 98 99 }; 99 100 -
branches/mergetest/external/atnf/PKSIO/makefile
r1452 r1779 1 # $Id : makefile,v 19.0 2003-07-16 03:34:05 aips2adm Exp$1 # $Id$ 2 2 3 3 XLIBLIST := CFITSIO RPFITS … … 5 5 # Use the generic AIPS++ class implementation makefile. 6 6 #------------------------------------------------------ 7 include $(word 1, $( AIPSPATH))/code/install/makefile.imp7 include $(word 1, $(CASAPATH))/code/install/makefile.imp
Note:
See TracChangeset
for help on using the changeset viewer.