Changeset 1779 for branches/mergetest/external/atnf/PKSIO/SDFITSreader.cc
- Timestamp:
- 07/29/10 19:13:46 (14 years ago)
- Location:
- branches/mergetest
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/mergetest
- Property svn:mergeinfo changed
-
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;
Note:
See TracChangeset
for help on using the changeset viewer.