Ignore:
Timestamp:
11/27/08 12:47:15 (16 years ago)
Author:
TakTsutsumi
Message:

New Development: No

JIRA Issue: No

Ready to Release: Yes

Interface Changes: Yes

What Interface Changed: many

Test Programs: sd.scantable(), sd.scantable.save()

Put in Release Notes: N/A

Description: copied from current casapy code tree


File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/alma/external/atnf/PKSIO/MBFITSreader.cc

    r1372 r1453  
    22//# MBFITSreader.cc: ATNF single-dish RPFITS reader.
    33//#---------------------------------------------------------------------------
    4 //# Copyright (C) 2000-2007
     4//# Copyright (C) 2000-2006
    55//# Mark Calabretta, ATNF
    66//#
     
    2727//#                        AUSTRALIA
    2828//#
    29 //# $Id: MBFITSreader.cc,v 19.34 2007/07/02 06:12:18 cal103 Exp $
     29//# $Id$
    3030//#---------------------------------------------------------------------------
    3131//# The MBFITSreader class reads single dish RPFITS files (such as Parkes
     
    8181  cRefChan   = 0x0;
    8282
    83   cVis = 0x0;
    84   cWgt = 0x0;
     83  cVis = new float[2*4*8163];
    8584
    8685  cBeamSel   = 0x0;
     
    9291
    9392  cMBopen = 0;
     93  jstat = -3;
    9494}
    9595
     
    127127
    128128  // 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);
    132131
    133132  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);
    135134    return 1;
    136135  }
     
    148147  // Read the first header.
    149148  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);
    152151
    153152  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);
    155154    close();
    156155    return 1;
     
    160159  cMopra = strncmp(names_.instrument, "ATMOPRA", 7) == 0;
    161160
    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.
    178165    cInterp = 0;
    179166  }
     
    189176
    190177  if (cNBeam <= 0) {
    191     fprintf(stderr, "ERROR, couldn't determine number of beams.\n");
     178    fprintf(stderr, "Couldn't determine number of beams.\n");
    192179    close();
    193180    return 1;
     
    250237  }
    251238
    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  }
    257244
    258245  nChan    = cNChan;
     
    291278  // Read the first syscal record.
    292279  if (rpget(1, cEOS)) {
    293     fprintf(stderr, "ERROR, failed to read first syscal record.\n");
     280    fprintf(stderr, "Error: Failed to read first syscal record.\n");
    294281    close();
    295282    return 1;
     
    326313{
    327314  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");
    329316    return 1;
    330317  }
     
    399386  // Time at start of observation.
    400387  sprintf(datobs, "%-10.10s", names_.datobs);
    401   utc = cUTC;
     388  utc = ut;
    402389
    403390  // Spectral parameters.
     
    448435
    449436  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");
    451438    return 1;
    452439  }
     
    576563
    577564          if (cNBin > 1 && cNBeamSel > 1) {
    578             fprintf(stderr, "ERROR, cannot handle binning mode for multiple "
     565            fprintf(stderr, "Cannot handle binning mode for multiple "
    579566                            "beams.\n");
    580567            close();
     
    582569          }
    583570
    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.
    587572          int nBuff = cNBeamSel * cNBin;
    588573          cBuffer = new PKSMBrecord[nBuff];
     
    599584          cScanNo  = 1;
    600585          cCycleNo = 0;
    601           cPrevUTC = 0.0;
     586          cUTC = 0.0;
    602587          cStaleness = new int[cNBeamSel];
    603588          for (int iBeamSel = 0; iBeamSel < cNBeamSel; iBeamSel++) {
     
    610595          cScanNo++;
    611596          cCycleNo = 0;
    612           cPrevUTC = 0.0;
     597          cUTC = 0.0;
    613598        }
    614599
    615600        // Apply beam selection.
    616         beamNo = int(cBaseline / 256.0);
     601        beamNo = int(baseline / 256.0);
    617602        iBeamSel = cBeamSel[beamNo-1];
    618603        if (iBeamSel < 0) continue;
    619604
    620605        // Sanity check (mainly for MOPS).
    621         if (cIFno > cNIF) continue;
     606        if (if_no > cNIF) continue;
    622607
    623608        // Apply IF selection.
    624         iIFSel = cIFSel[cIFno - 1];
     609        iIFSel = cIFSel[if_no - 1];
    625610        if (iIFSel < 0) continue;
    626611
    627612        sprintf(cDateObs, "%-10.10s", names_.datobs);
    628613
    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;
    632624        }
    633625
    634626        if (cNBin > 1) {
    635627          // 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);
    643629        }
    644630
    645631        // Compute buffer number.
    646632        iMBuff = cBuffer + iBeamSel;
    647         if (cNBin > 1) iMBuff += cNBeamSel*(cBin-1);
     633        if (cNBin > 1) iMBuff += cNBeamSel*(bin-1);
    648634
    649635        if (cCycleNo < iMBuff->cycleNo) {
     
    654640
    655641        // Begin flush cycle?
    656         if (cEOS || (iMBuff->nIF && cUTC > iMBuff->utc + 0.0001)) {
     642        if (cEOS || (iMBuff->nIF && ut > iMBuff->utc + 0.0001)) {
    657643          cFlushing = 1;
    658644          cFlushBin = 0;
     
    661647
    662648#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);
    664650        if (cEOS) printf("Start of new scan, flushing previous scan.\n");
    665651#endif
     
    710696
    711697        // 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);
    713699        iBeamSel = cBeamSel[beamNo-1];
    714700
    715701        // Compute buffer number.
    716702        iMBuff = cBuffer + iBeamSel;
    717         if (cNBin > 1) iMBuff += cNBeamSel*(cBin-1);
     703        if (cNBin > 1) iMBuff += cNBeamSel*(bin-1);
    718704      }
    719705    }
     
    735721        // returned as the 'u' and 'v' visibility coordinates, must be
    736722        // 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.
    738724        //
    739725        // 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'
    741727        // continues to increase past 86400.
    742728
    743         double thisRA  = cU;
    744         double thisDec = cV;
    745         double thisUTC = cW;
     729        double thisRA  = u;
     730        double thisDec = v;
     731        double thisUTC = w;
    746732
    747733        if (thisUTC < prevUTC) {
     
    865851        // Signal that all IFs in this buffer location have been flushed.
    866852        iMBuff->nIF = 0;
    867 
    868         // Stop cEOS being set when the next integration is read.
    869         iMBuff->cycleNo = 0;
    870 
    871853      } else {
    872854        // Carry on flushing the other IFs.
     
    877859      if (cFlushBin == cNBin - 1) {
    878860        if (cEOS || cEOF) {
     861          // Stop cEOS being set when the next integration is read.
     862          iMBuff->cycleNo = 0;
     863
    879864          // Carry on flushing other buffers.
    880865          cFlushIF = 0;
     
    884869        cFlushing = 0;
    885870
    886         beamNo = int(cBaseline / 256.0);
     871        beamNo = int(baseline / 256.0);
    887872        iBeamSel = cBeamSel[beamNo-1];
    888873
    889874        // Compute buffer number.
    890875        iMBuff = cBuffer + iBeamSel;
    891         if (cNBin > 1) iMBuff += cNBeamSel*(cBin-1);
     876        if (cNBin > 1) iMBuff += cNBeamSel*(bin-1);
    892877      }
    893878    }
     
    903888      }
    904889
    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 
    912890      iMBuff->scanNo  = cScanNo;
    913891      iMBuff->cycleNo = cCycleNo;
     
    915893      // Times.
    916894      strncpy(iMBuff->datobs, cDateObs, 10);
    917       iMBuff->utc = cUTC;
     895      iMBuff->utc = ut;
    918896      iMBuff->exposure = param_.intbase;
    919897
    920898      // Source identification.
    921899      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];
    925903
    926904      // Rest frequency of the line of interest.
     
    948926
    949927      // Beam position at the specified time.
    950       if (cSUpos) {
    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];
    954932      } 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;
    959937
    960938      // IF-dependent parameters.
    961       int iIF = cIFno - 1;
     939      int iIF = if_no - 1;
    962940      int startChan = cStartChan[iIF];
    963941      int endChan   = cEndChan[iIF];
     
    968946      iIFSel = cIFSel[iIF];
    969947      iMBuff->nIF++;
    970       iMBuff->IFno[iIFSel]  = cIFno;
     948      iMBuff->IFno[iIFSel]  = if_no;
    971949      iMBuff->nChan[iIFSel] = nChan;
    972950      iMBuff->nPol[iIFSel]  = cNPol[iIF];
     
    10271005
    10281006      // The baseline flag may be set independently.
    1029       if (rpflag == 0) rpflag = cFlag;
     1007      if (rpflag == 0) rpflag = flag;
    10301008
    10311009      // Copy and scale data.
     
    11571135  int numErr = 0;
    11581136
    1159   int jstat = 0;
     1137  jstat = 0;
    11601138  while (numErr < 10) {
    11611139    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);
    11641142
    11651143    switch(jstat) {
     
    11741152      // Successful read.
    11751153      if (lastjstat == 0) {
    1176         if (cBaseline == -1) {
     1154        if (baseline == -1) {
    11771155          // Syscal data.
    11781156          if (syscalonly) {
     
    12301208  }
    12311209
    1232   fprintf(stderr, "ERROR, RPFITS read failed too many times.\n");
     1210  fprintf(stderr, "RPFITS read failed too many times.\n");
    12331211  return 2;
    12341212}
     
    12411219{
    12421220  if (cMBopen) {
    1243     int jstat = 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);
    12461224
    12471225    if (cBeams)     delete [] cBeams;
     
    12541232    if (cRefChan)   delete [] cRefChan;
    12551233
    1256     if (cVis) delete [] cVis;
    1257     if (cWgt) delete [] cWgt;
     1234    if (cVis)       delete [] cVis;
    12581235
    12591236    if (cBeamSel)   delete [] cBeamSel;
Note: See TracChangeset for help on using the changeset viewer.