Changeset 1453 for branches/alma/external/atnf/PKSIO/MBFITSreader.cc
- Timestamp:
- 11/27/08 12:47:15 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma/external/atnf/PKSIO/MBFITSreader.cc
r1372 r1453 2 2 //# MBFITSreader.cc: ATNF single-dish RPFITS reader. 3 3 //#--------------------------------------------------------------------------- 4 //# Copyright (C) 2000-200 74 //# Copyright (C) 2000-2006 5 5 //# Mark Calabretta, ATNF 6 6 //# … … 27 27 //# AUSTRALIA 28 28 //# 29 //# $Id : MBFITSreader.cc,v 19.34 2007/07/02 06:12:18 cal103 Exp$29 //# $Id$ 30 30 //#--------------------------------------------------------------------------- 31 31 //# The MBFITSreader class reads single dish RPFITS files (such as Parkes … … 81 81 cRefChan = 0x0; 82 82 83 cVis = 0x0; 84 cWgt = 0x0; 83 cVis = new float[2*4*8163]; 85 84 86 85 cBeamSel = 0x0; … … 92 91 93 92 cMBopen = 0; 93 jstat = -3; 94 94 } 95 95 … … 127 127 128 128 // Open the RPFITS file. 129 int jstat = -3; 130 rpfitsin_(&jstat, cVis, cWgt, &cBaseline, &cUTC, &cU, &cV, &cW, &cFlag, 131 &cBin, &cIFno, &cSrcNo); 129 rpfitsin_(&jstat, cVis, weight, &baseline, &ut, &u, &v, &w, &flag, &bin, 130 &if_no, &sourceno); 132 131 133 132 if (jstat) { 134 fprintf(stderr, " ERROR, failed to open MBFITS file: %s\n", rpname);133 fprintf(stderr, "Failed to open MBFITS file: %s\n", rpname); 135 134 return 1; 136 135 } … … 148 147 // Read the first header. 149 148 jstat = -1; 150 rpfitsin_(&jstat, cVis, cWgt, &cBaseline, &cUTC, &cU, &cV, &cW, &cFlag,151 & cBin, &cIFno, &cSrcNo);149 rpfitsin_(&jstat, cVis, weight, &baseline, &ut, &u, &v, &w, &flag, &bin, 150 &if_no, &sourceno); 152 151 153 152 if (jstat) { 154 fprintf(stderr, " ERROR, failed to read MBFITS header: %s\n", rpname);153 fprintf(stderr, "Failed to read MBFITS header: %s\n", rpname); 155 154 close(); 156 155 return 1; … … 160 159 cMopra = strncmp(names_.instrument, "ATMOPRA", 7) == 0; 161 160 162 // Non-ATNF data may not store the position in (u,v,w). 163 if (strncmp(names_.sta, "tid", 3) == 0) { 164 fprintf(stderr, "WARNING, found Tidbinbilla data"); 165 cSUpos = 1; 166 } else if (strncmp(names_.sta, "HOB", 3) == 0) { 167 fprintf(stderr, "WARNING, found Hobart data"); 168 cSUpos = 1; 169 } else if (strncmp(names_.sta, "CED", 3) == 0) { 170 fprintf(stderr, "WARNING, found Ceduna data"); 171 cSUpos = 1; 172 } else { 173 cSUpos = 0; 174 } 175 176 if (cSUpos) { 177 fprintf(stderr, ", using telescope position from SU table.\n"); 161 // Tidbinbilla data has some more. 162 cTid = strncmp(names_.sta, "tid", 3) == 0; 163 if (cTid) { 164 // Telescope position is stored in the source table. 178 165 cInterp = 0; 179 166 } … … 189 176 190 177 if (cNBeam <= 0) { 191 fprintf(stderr, " ERROR, couldn't determine number of beams.\n");178 fprintf(stderr, "Couldn't determine number of beams.\n"); 192 179 close(); 193 180 return 1; … … 250 237 } 251 238 252 // Allocate memory for RPFITSIN subroutine arguments.253 if ( cVis) delete [] cVis;254 if (cWgt) delete [] cWgt;255 cVis = new float[2*maxProd];256 cWgt = new float[maxProd];239 // Is the vis array declared by RPFITS.h large enough? 240 if (8*8193 < maxProd) { 241 // Need to allocate more memory for RPFITSIN. 242 cVis = new float[2*maxProd]; 243 } 257 244 258 245 nChan = cNChan; … … 291 278 // Read the first syscal record. 292 279 if (rpget(1, cEOS)) { 293 fprintf(stderr, "E RROR, failed to read first syscal record.\n");280 fprintf(stderr, "Error: Failed to read first syscal record.\n"); 294 281 close(); 295 282 return 1; … … 326 313 { 327 314 if (!cMBopen) { 328 fprintf(stderr, " ERROR, an MBFITS file has not been opened.\n");315 fprintf(stderr, "An MBFITS file has not been opened.\n"); 329 316 return 1; 330 317 } … … 399 386 // Time at start of observation. 400 387 sprintf(datobs, "%-10.10s", names_.datobs); 401 utc = cUTC;388 utc = ut; 402 389 403 390 // Spectral parameters. … … 448 435 449 436 if (!cMBopen) { 450 fprintf(stderr, " ERROR, an MBFITS file has not been opened.\n");437 fprintf(stderr, "An MBFITS file has not been opened.\n"); 451 438 return 1; 452 439 } … … 576 563 577 564 if (cNBin > 1 && cNBeamSel > 1) { 578 fprintf(stderr, " ERROR, cannot handle binning mode for multiple "565 fprintf(stderr, "Cannot handle binning mode for multiple " 579 566 "beams.\n"); 580 567 close(); … … 582 569 } 583 570 584 // Allocate buffer data storage; the PKSMBrecord constructor zeroes 585 // class members such as cycleNo that are tested in the first pass 586 // below. 571 // Allocate buffer data storage. 587 572 int nBuff = cNBeamSel * cNBin; 588 573 cBuffer = new PKSMBrecord[nBuff]; … … 599 584 cScanNo = 1; 600 585 cCycleNo = 0; 601 c PrevUTC = 0.0;586 cUTC = 0.0; 602 587 cStaleness = new int[cNBeamSel]; 603 588 for (int iBeamSel = 0; iBeamSel < cNBeamSel; iBeamSel++) { … … 610 595 cScanNo++; 611 596 cCycleNo = 0; 612 c PrevUTC = 0.0;597 cUTC = 0.0; 613 598 } 614 599 615 600 // Apply beam selection. 616 beamNo = int( cBaseline / 256.0);601 beamNo = int(baseline / 256.0); 617 602 iBeamSel = cBeamSel[beamNo-1]; 618 603 if (iBeamSel < 0) continue; 619 604 620 605 // Sanity check (mainly for MOPS). 621 if ( cIFno > cNIF) continue;606 if (if_no > cNIF) continue; 622 607 623 608 // Apply IF selection. 624 iIFSel = cIFSel[ cIFno - 1];609 iIFSel = cIFSel[if_no - 1]; 625 610 if (iIFSel < 0) continue; 626 611 627 612 sprintf(cDateObs, "%-10.10s", names_.datobs); 628 613 629 // Check for change-of-day. 630 if (cUTC < cPrevUTC - 85800.0) { 631 cUTC += 86400.0; 614 // Change-of-day; note that the ut variable from RPFITS.h is global 615 // and will be preserved between calls to this function. 616 if (ut < cUTC - 85800.0) { 617 ut += 86400.0; 618 } 619 620 // New integration cycle? 621 if (ut > cUTC) { 622 cCycleNo++; 623 cUTC = ut + 0.0001; 632 624 } 633 625 634 626 if (cNBin > 1) { 635 627 // Binning mode: correct the time. 636 cUTC += param_.intbase * (cBin - (cNBin + 1)/2.0); 637 } 638 639 // New integration cycle? 640 if (cUTC > cPrevUTC) { 641 cCycleNo++; 642 cPrevUTC = cUTC + 0.0001; 628 ut += param_.intbase * (bin - (cNBin + 1)/2.0); 643 629 } 644 630 645 631 // Compute buffer number. 646 632 iMBuff = cBuffer + iBeamSel; 647 if (cNBin > 1) iMBuff += cNBeamSel*( cBin-1);633 if (cNBin > 1) iMBuff += cNBeamSel*(bin-1); 648 634 649 635 if (cCycleNo < iMBuff->cycleNo) { … … 654 640 655 641 // Begin flush cycle? 656 if (cEOS || (iMBuff->nIF && cUTC> iMBuff->utc + 0.0001)) {642 if (cEOS || (iMBuff->nIF && ut > iMBuff->utc + 0.0001)) { 657 643 cFlushing = 1; 658 644 cFlushBin = 0; … … 661 647 662 648 #ifdef PKSIO_DEBUG 663 printf(" In:%4d%4d%3d%3d\n", cScanNo, cCycleNo, beamNo, cIFno);649 printf(" In:%4d%4d%3d%3d\n", cScanNo, cCycleNo, beamNo, if_no); 664 650 if (cEOS) printf("Start of new scan, flushing previous scan.\n"); 665 651 #endif … … 710 696 711 697 // The last record read must have been the first of a new cycle. 712 beamNo = int( cBaseline / 256.0);698 beamNo = int(baseline / 256.0); 713 699 iBeamSel = cBeamSel[beamNo-1]; 714 700 715 701 // Compute buffer number. 716 702 iMBuff = cBuffer + iBeamSel; 717 if (cNBin > 1) iMBuff += cNBeamSel*( cBin-1);703 if (cNBin > 1) iMBuff += cNBeamSel*(bin-1); 718 704 } 719 705 } … … 735 721 // returned as the 'u' and 'v' visibility coordinates, must be 736 722 // interpolated to the integration time which RPFITSIN returns as 737 // ' cUTC', this usually being a second or two later.723 // 'ut', this usually being a second or two later. 738 724 // 739 725 // Note that the time recorded as the 'w' visibility coordinate 740 // cycles through 86400 back to 0 at midnight, whereas that in ' cUTC'726 // cycles through 86400 back to 0 at midnight, whereas that in 'ut' 741 727 // continues to increase past 86400. 742 728 743 double thisRA = cU;744 double thisDec = cV;745 double thisUTC = cW;729 double thisRA = u; 730 double thisDec = v; 731 double thisUTC = w; 746 732 747 733 if (thisUTC < prevUTC) { … … 865 851 // Signal that all IFs in this buffer location have been flushed. 866 852 iMBuff->nIF = 0; 867 868 // Stop cEOS being set when the next integration is read.869 iMBuff->cycleNo = 0;870 871 853 } else { 872 854 // Carry on flushing the other IFs. … … 877 859 if (cFlushBin == cNBin - 1) { 878 860 if (cEOS || cEOF) { 861 // Stop cEOS being set when the next integration is read. 862 iMBuff->cycleNo = 0; 863 879 864 // Carry on flushing other buffers. 880 865 cFlushIF = 0; … … 884 869 cFlushing = 0; 885 870 886 beamNo = int( cBaseline / 256.0);871 beamNo = int(baseline / 256.0); 887 872 iBeamSel = cBeamSel[beamNo-1]; 888 873 889 874 // Compute buffer number. 890 875 iMBuff = cBuffer + iBeamSel; 891 if (cNBin > 1) iMBuff += cNBeamSel*( cBin-1);876 if (cNBin > 1) iMBuff += cNBeamSel*(bin-1); 892 877 } 893 878 } … … 903 888 } 904 889 905 // Sanity check on incomplete integrations within a scan.906 if (iMBuff->nIF && (iMBuff->cycleNo != cCycleNo)) {907 // Force the incomplete integration to be flushed before proceeding.908 cFlushing = 1;909 continue;910 }911 912 890 iMBuff->scanNo = cScanNo; 913 891 iMBuff->cycleNo = cCycleNo; … … 915 893 // Times. 916 894 strncpy(iMBuff->datobs, cDateObs, 10); 917 iMBuff->utc = cUTC;895 iMBuff->utc = ut; 918 896 iMBuff->exposure = param_.intbase; 919 897 920 898 // Source identification. 921 899 sprintf(iMBuff->srcName, "%-16.16s", 922 names_.su_name + ( cSrcNo-1)*16);923 iMBuff->srcRA = doubles_.su_ra[ cSrcNo-1];924 iMBuff->srcDec = doubles_.su_dec[ cSrcNo-1];900 names_.su_name + (sourceno-1)*16); 901 iMBuff->srcRA = doubles_.su_ra[sourceno-1]; 902 iMBuff->srcDec = doubles_.su_dec[sourceno-1]; 925 903 926 904 // Rest frequency of the line of interest. … … 948 926 949 927 // Beam position at the specified time. 950 if (c SUpos) {951 // Non-ATNF data that does not store the position in (u,v,w).952 iMBuff->ra = doubles_.su_ra[ cSrcNo-1];953 iMBuff->dec = doubles_.su_dec[ cSrcNo-1];928 if (cTid) { 929 // Tidbinbilla data. 930 iMBuff->ra = doubles_.su_ra[sourceno-1]; 931 iMBuff->dec = doubles_.su_dec[sourceno-1]; 954 932 } else { 955 iMBuff->ra = cU;956 iMBuff->dec = cV;957 } 958 cPosUTC[iBeamSel] = cW;933 iMBuff->ra = u; 934 iMBuff->dec = v; 935 } 936 cPosUTC[iBeamSel] = w; 959 937 960 938 // IF-dependent parameters. 961 int iIF = cIFno - 1;939 int iIF = if_no - 1; 962 940 int startChan = cStartChan[iIF]; 963 941 int endChan = cEndChan[iIF]; … … 968 946 iIFSel = cIFSel[iIF]; 969 947 iMBuff->nIF++; 970 iMBuff->IFno[iIFSel] = cIFno;948 iMBuff->IFno[iIFSel] = if_no; 971 949 iMBuff->nChan[iIFSel] = nChan; 972 950 iMBuff->nPol[iIFSel] = cNPol[iIF]; … … 1027 1005 1028 1006 // The baseline flag may be set independently. 1029 if (rpflag == 0) rpflag = cFlag;1007 if (rpflag == 0) rpflag = flag; 1030 1008 1031 1009 // Copy and scale data. … … 1157 1135 int numErr = 0; 1158 1136 1159 intjstat = 0;1137 jstat = 0; 1160 1138 while (numErr < 10) { 1161 1139 int lastjstat = jstat; 1162 rpfitsin_(&jstat, cVis, cWgt, &cBaseline, &cUTC, &cU, &cV, &cW, &cFlag,1163 & cBin, &cIFno, &cSrcNo);1140 rpfitsin_(&jstat, cVis, weight, &baseline, &ut, &u, &v, &w, &flag, &bin, 1141 &if_no, &sourceno); 1164 1142 1165 1143 switch(jstat) { … … 1174 1152 // Successful read. 1175 1153 if (lastjstat == 0) { 1176 if ( cBaseline == -1) {1154 if (baseline == -1) { 1177 1155 // Syscal data. 1178 1156 if (syscalonly) { … … 1230 1208 } 1231 1209 1232 fprintf(stderr, " ERROR,RPFITS read failed too many times.\n");1210 fprintf(stderr, "RPFITS read failed too many times.\n"); 1233 1211 return 2; 1234 1212 } … … 1241 1219 { 1242 1220 if (cMBopen) { 1243 intjstat = 1;1244 rpfitsin_(&jstat, cVis, cWgt, &cBaseline, &cUTC, &cU, &cV, &cW, &cFlag,1245 & cBin, &cIFno, &cSrcNo);1221 jstat = 1; 1222 rpfitsin_(&jstat, cVis, weight, &baseline, &ut, &u, &v, &w, &flag, &bin, 1223 &if_no, &sourceno); 1246 1224 1247 1225 if (cBeams) delete [] cBeams; … … 1254 1232 if (cRefChan) delete [] cRefChan; 1255 1233 1256 if (cVis) delete [] cVis; 1257 if (cWgt) delete [] cWgt; 1234 if (cVis) delete [] cVis; 1258 1235 1259 1236 if (cBeamSel) delete [] cBeamSel;
Note: See TracChangeset
for help on using the changeset viewer.