Ignore:
Timestamp:
06/09/10 19:03:06 (14 years ago)
Author:
Kana Sugimoto
Message:

New Development: Yes

JIRA Issue: Yes (CAS-2211)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: ASAP 3.0.0 interface changes

Test Programs:

Put in Release Notes: Yes

Module(s): all the CASA sd tools and tasks are affected.

Description: Merged ATNF-ASAP 3.0.0 developments to CASA (alma) branch.

Note you also need to update casa/code/atnf.


Location:
branches/alma
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/alma

  • branches/alma/external/atnf/PKSIO/PKSSDwriter.cc

    r1453 r1757  
    22//# PKSSDwriter.cc: Class to write Parkes multibeam data to an SDFITS file.
    33//#---------------------------------------------------------------------------
    4 //# Copyright (C) 2000-2006
    5 //# Associated Universities, Inc. Washington DC, USA.
    6 //#
    7 //# This library is free software; you can redistribute it and/or modify it
    8 //# under the terms of the GNU Library General Public License as published by
    9 //# the Free Software Foundation; either version 2 of the License, or (at your
    10 //# option) any later version.
    11 //#
    12 //# This library is distributed in the hope that it will be useful, but
    13 //# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    14 //# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    15 //# License for more details.
    16 //#
    17 //# You should have received a copy of the GNU Library General Public License
    18 //# along with this library; if not, write to the Free Software Foundation,
    19 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
    20 //#
    21 //# Correspondence concerning AIPS++ should be addressed as follows:
    22 //#        Internet email: aips2-request@nrao.edu.
    23 //#        Postal address: AIPS++ Project Office
    24 //#                        National Radio Astronomy Observatory
    25 //#                        520 Edgemont Road
    26 //#                        Charlottesville, VA 22903-2475 USA
    27 //#
    28 //# $Id$
     4//# livedata - processing pipeline for single-dish, multibeam spectral data.
     5//# Copyright (C) 2000-2009, Australia Telescope National Facility, CSIRO
     6//#
     7//# This file is part of livedata.
     8//#
     9//# livedata is free software: you can redistribute it and/or modify it under
     10//# the terms of the GNU General Public License as published by the Free
     11//# Software Foundation, either version 3 of the License, or (at your option)
     12//# any later version.
     13//#
     14//# livedata is distributed in the hope that it will be useful, but WITHOUT
     15//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     16//# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
     17//# more details.
     18//#
     19//# You should have received a copy of the GNU General Public License along
     20//# with livedata.  If not, see <http://www.gnu.org/licenses/>.
     21//#
     22//# Correspondence concerning livedata may be directed to:
     23//#        Internet email: mcalabre@atnf.csiro.au
     24//#        Postal address: Dr. Mark Calabretta
     25//#                        Australia Telescope National Facility, CSIRO
     26//#                        PO Box 76
     27//#                        Epping NSW 1710
     28//#                        AUSTRALIA
     29//#
     30//# http://www.atnf.csiro.au/computing/software/livedata.html
     31//# $Id: PKSSDwriter.cc,v 19.17 2009-09-29 07:33:38 cal103 Exp $
    2932//#---------------------------------------------------------------------------
    3033
    31 #include <atnf/PKSIO/PKSMBrecord.h>
     34#include <atnf/PKSIO/MBrecord.h>
    3235#include <atnf/PKSIO/PKSSDwriter.h>
    3336
     37#include <casa/Logging/LogIO.h>
     38
     39#include <casa/stdio.h>
    3440#include <casa/Quanta/MVTime.h>
    3541
     42#include <string>
     43#include <cstring>
     44
     45// Class name
     46const string className = "PKSSDwriter" ;
    3647
    3748//--------------------------------------------------- PKSSDwriter::PKSSDwriter
     
    6374        const Vector<Double> antPosition,
    6475        const String obsMode,
     76        const String bunit,
    6577        const Float  equinox,
    6678        const String dopplerFrame,
     
    6880        const Vector<uInt> nPol,
    6981        const Vector<Bool> haveXPol,
    70         const Bool   haveBase,
    71         const String fluxUnit)
    72 {
     82        const Bool   haveBase)
     83{
     84  const string methodName = "create()" ;
     85  LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
     86
    7387  double antPos[3];
    7488  antPos[0] = antPosition(0);
     
    7892  cNIF = nChan.nelements();
    7993  if (nPol.nelements() != cNIF || haveXPol.nelements() != cNIF) {
    80     cerr << "PKSSDwriter::create: "
    81          << "Inconsistent number of IFs for nChan, nPol, and/or haveXPol."
    82          << endl;
     94    os << LogIO::SEVERE << "Inconsistent number of IFs for nChan, nPol, and/or haveXPol." << LogIO::POST ;
    8395    return 1;
    8496  }
     
    102114  Int status = cSDwriter.create((char *)sdName.chars(),
    103115        (char *)observer.chars(), (char *)project.chars(),
    104         (char *)antName.chars(), antPos, (char *)obsMode.chars(), equinox,
    105         (char *)dopplerFrame.chars(), cNIF,
     116        (char *)antName.chars(), antPos, (char *)obsMode.chars(),
     117        (char *)bunit.chars(), equinox, (char *)dopplerFrame.chars(), cNIF,
    106118        (int *)cNChan.getStorage(deleteIt),
    107119        (int *)cNPol.getStorage(deleteIt),
    108120        (int *)cHaveXPol.getStorage(deleteIt), (int)cHaveBase, 1);
     121  //logMsg(cSDwriter.getMsg());
     122  //cSDwriter.clearMsg();
    109123  if (status) {
    110     cSDwriter.reportError();
    111124    cSDwriter.deleteFile();
    112125    close();
     
    121134
    122135Int PKSSDwriter::write(
    123         const Int             scanNo,
    124         const Int             cycleNo,
    125         const Double          mjd,
    126         const Double          interval,
    127         const String          fieldName,
    128         const String          srcName,
    129         const Vector<Double>  srcDir,
    130         const Vector<Double>  srcPM,
    131         const Double          srcVel,
    132         const String          obsMode,
    133         const Int             IFno,
    134         const Double          refFreq,
    135         const Double          bandwidth,
    136         const Double          freqInc,
    137         //const Double          restFreq,
    138         const Vector<Double>  restFreq,
    139         const Vector<Float>   tcal,
    140         const String          tcalTime,
    141         const Float           azimuth,
    142         const Float           elevation,
    143         const Float           parAngle,
    144         const Float           focusAxi,
    145         const Float           focusTan,
    146         const Float           focusRot,
    147         const Float           temperature,
    148         const Float           pressure,
    149         const Float           humidity,
    150         const Float           windSpeed,
    151         const Float           windAz,
    152         const Int             refBeam,
    153         const Int             beamNo,
    154         const Vector<Double>  direction,
    155         const Vector<Double>  scanRate,
    156         const Vector<Float>   tsys,
    157         const Vector<Float>   sigma,
    158         const Vector<Float>   calFctr,
    159         const Matrix<Float>   baseLin,
    160         const Matrix<Float>   baseSub,
    161         const Matrix<Float>   &spectra,
    162         const Matrix<uChar>   &flagged,
    163         const Complex         xCalFctr,
    164         const Vector<Complex> &xPol)
    165 {
     136        const PKSrecord &pksrec)
     137{
     138  const string methodName = "write()" ;
     139  LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
     140
    166141  // Do basic checks.
     142  Int IFno = pksrec.IFno;
    167143  uInt iIF = IFno - 1;
    168144  if (IFno < 1 || Int(cNIF) < IFno) {
    169     cerr << "PKSDwriter::write: "
    170          << "Invalid IF number " << IFno
    171          << " (maximum " << cNIF << ")." << endl;
     145    os << LogIO::SEVERE
     146       << "Invalid IF number " << IFno
     147       << " (maximum " << cNIF << ")." << LogIO::POST ;
    172148    return 1;
    173149  }
    174150
    175   uInt nChan = spectra.nrow();
     151  uInt nChan = pksrec.spectra.nrow();
    176152  if (nChan != cNChan(iIF)) {
    177     cerr << "PKSDwriter::write: "
    178          << "Wrong number of channels for IF " << IFno << "," << endl
    179          << "                   "
     153    os << LogIO::SEVERE << "Wrong number of channels for IF " << IFno << "," << endl
    180154         << "got " << nChan << " should be " << cNChan(iIF) << "." << endl;
     155    os << LogIO::POST ;
    181156    return 1;
    182157  }
    183158
    184   uInt nPol = spectra.ncolumn();
     159  uInt nPol = pksrec.spectra.ncolumn();
    185160  if (nPol != cNPol(iIF)) {
    186     cerr << "PKSDwriter::write: "
    187          << "Wrong number of polarizations for IF " << IFno << "," << endl
    188          << "                   "
    189          << "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 ;
    190164    return 1;
    191165  }
    192166
    193   // Extract calendar information from mjd.
    194   MVTime time(mjd);
     167  // Extract calendar information frrom mjd.
     168  MVTime time(pksrec.mjd);
    195169  Int year  = time.year();
    196170  Int month = time.month();
    197171  Int day   = time.monthday();
    198172
    199   // Transfer data to a single-IF PKSMBrecord.
    200   PKSMBrecord mbrec(1);
     173  // Transfer data to a single-IF MBrecord.
     174  MBrecord mbrec(1);
    201175
    202176  // Start with basic beam- and IF-independent bookkeeping information.
    203   mbrec.scanNo  = scanNo;
    204   mbrec.cycleNo = cycleNo;
     177  mbrec.scanNo  = pksrec.scanNo;
     178  mbrec.cycleNo = pksrec.cycleNo;
    205179
    206180  sprintf(mbrec.datobs, "%4.4d-%2.2d-%2.2d", year, month, day);
    207   mbrec.utc      = fmod(mjd, 1.0) * 86400.0;
    208   mbrec.exposure = float(interval);
    209 
    210   strncpy(mbrec.srcName, (char *)srcName.chars(), 17);
    211   mbrec.srcRA    = srcDir(0);
    212   mbrec.srcDec   = srcDir(1);
    213 
    214   //mbrec.restFreq = restFreq;
    215   mbrec.restFreq = restFreq(0);
    216 
    217   strncpy(mbrec.obsType, (char *)obsMode.chars(), 16);
     181  mbrec.utc      = fmod(pksrec.mjd, 1.0) * 86400.0;
     182  mbrec.exposure = float(pksrec.interval);
     183
     184  strncpy(mbrec.srcName, (char *)pksrec.srcName.chars(), 17);
     185  mbrec.srcRA    = pksrec.srcDir(0);
     186  mbrec.srcDec   = pksrec.srcDir(1);
     187  if (pksrec.restFreq.shape()==0) {
     188     mbrec.restFreq = 0;
     189  }
     190  else {
     191     mbrec.restFreq = pksrec.restFreq(0);
     192  }
     193  strncpy(mbrec.obsType, (char *)pksrec.obsType.chars(), 16);
    218194
    219195  // Now beam-dependent parameters.
    220   mbrec.beamNo   = beamNo;
    221   mbrec.ra       = direction(0);
    222   mbrec.dec      = direction(1);
    223   mbrec.raRate   = scanRate(0);
    224   mbrec.decRate  = scanRate(1);
     196  mbrec.beamNo   = pksrec.beamNo;
     197  mbrec.ra       = pksrec.direction(0);
     198  mbrec.dec      = pksrec.direction(1);
     199  mbrec.raRate   = pksrec.scanRate(0);
     200  mbrec.decRate  = pksrec.scanRate(1);
    225201
    226202  // Now IF-dependent parameters.
     
    231207
    232208  mbrec.fqRefPix[0] = (nChan/2) + 1;
    233   mbrec.fqRefVal[0] = refFreq;
    234   mbrec.fqDelt[0]   = freqInc;
     209  mbrec.fqRefVal[0] = pksrec.refFreq;
     210  mbrec.fqDelt[0]   = pksrec.freqInc;
    235211
    236212  // Now the data itself.
    237   for (uInt i = 0; i < tsys.nelements(); i++) {
    238     mbrec.tsys[0][i] = tsys(i);
     213  for (uInt i = 0; i < pksrec.tsys.nelements(); i++) {
     214    mbrec.tsys[0][i] = pksrec.tsys(i);
    239215  }
    240216
    241217  for (uInt ipol = 0; ipol < nPol; ipol++) {
    242     mbrec.calfctr[0][ipol] = calFctr(ipol);
     218    mbrec.calfctr[0][ipol] = pksrec.calFctr(ipol);
    243219  }
    244220
    245221  if (cHaveXPol(iIF)) {
    246     mbrec.xcalfctr[0][0] = xCalFctr.real();
    247     mbrec.xcalfctr[0][1] = xCalFctr.imag();
     222    mbrec.xcalfctr[0][0] = pksrec.xCalFctr.real();
     223    mbrec.xcalfctr[0][1] = pksrec.xCalFctr.imag();
    248224  } else {
    249225    mbrec.xcalfctr[0][0] = 0.0f;
     
    255231
    256232    for (uInt ipol = 0; ipol < nPol; ipol++) {
    257       mbrec.baseLin[0][ipol][0] = baseLin(0,ipol);
    258       mbrec.baseLin[0][ipol][1] = baseLin(1,ipol);
    259 
    260       for (uInt j = 0; j < baseSub.nrow(); j++) {
    261         mbrec.baseSub[0][ipol][j] = baseSub(j,ipol);
     233      mbrec.baseLin[0][ipol][0] = pksrec.baseLin(0,ipol);
     234      mbrec.baseLin[0][ipol][1] = pksrec.baseLin(1,ipol);
     235
     236      for (uInt j = 0; j < pksrec.baseSub.nrow(); j++) {
     237        mbrec.baseSub[0][ipol][j] = pksrec.baseSub(j,ipol);
    262238      }
    263       for (uInt j = baseSub.nrow(); j < 9; j++) {
     239      for (uInt j = pksrec.baseSub.nrow(); j < 24; j++) {
    264240        mbrec.baseSub[0][ipol][j] = 0.0f;
    265241      }
     
    271247
    272248  Bool delSpectra = False;
    273   const Float *specstor = spectra.getStorage(delSpectra);
     249  const Float *specstor = pksrec.spectra.getStorage(delSpectra);
    274250  mbrec.spectra[0] = (float *)specstor;
    275251
    276252  Bool delFlagged = False;
    277   const uChar *flagstor = flagged.getStorage(delFlagged);
     253  const uChar *flagstor = pksrec.flagged.getStorage(delFlagged);
    278254  mbrec.flagged[0] = (unsigned char *)flagstor;
    279255
     
    281257  const Complex *xpolstor;
    282258  if (cHaveXPol(iIF)) {
    283     xpolstor = xPol.getStorage(delXPol);
     259    xpolstor = pksrec.xPol.getStorage(delXPol);
    284260  } else {
    285261    xpolstor = 0;
     
    289265  // Finish off with system calibration parameters.
    290266  mbrec.extraSysCal = 1;
    291   mbrec.refBeam     = refBeam;
    292   for (uInt i = 0; i < tcal.nelements(); i++) {
    293     mbrec.tcal[0][i] = tcal(i);
    294   }
    295   strncpy(mbrec.tcalTime, (char *)tcalTime.chars(), 16);
    296   mbrec.azimuth   = azimuth;
    297   mbrec.elevation = elevation;
    298   mbrec.parAngle  = parAngle;
    299   mbrec.focusAxi  = focusAxi;
    300   mbrec.focusTan  = focusTan;
    301   mbrec.focusRot  = focusRot;
    302   mbrec.temp      = temperature;
    303   mbrec.pressure  = pressure;
    304   mbrec.humidity  = humidity;
    305   mbrec.windSpeed = windSpeed;
    306   mbrec.windAz    = windAz;
     267  mbrec.refBeam     = pksrec.refBeam;
     268  for (uInt i = 0; i < pksrec.tcal.nelements(); i++) {
     269    mbrec.tcal[0][i] = pksrec.tcal(i);
     270  }
     271  strncpy(mbrec.tcalTime, (char *)pksrec.tcalTime.chars(), 16);
     272  mbrec.azimuth   = pksrec.azimuth;
     273  mbrec.elevation = pksrec.elevation;
     274  mbrec.parAngle  = pksrec.parAngle;
     275  mbrec.focusAxi  = pksrec.focusAxi;
     276  mbrec.focusTan  = pksrec.focusTan;
     277  mbrec.focusRot  = pksrec.focusRot;
     278  mbrec.temp      = pksrec.temperature;
     279  mbrec.pressure  = pksrec.pressure;
     280  mbrec.humidity  = pksrec.humidity;
     281  mbrec.windSpeed = pksrec.windSpeed;
     282  mbrec.windAz    = pksrec.windAz;
    307283
    308284  Int status = cSDwriter.write(mbrec);
     285  //logMsg(cSDwriter.getMsg());
     286  //cSDwriter.clearMsg();
    309287  if (status) {
    310     cSDwriter.reportError();
    311288    status = 1;
    312289  }
    313290
    314   spectra.freeStorage(specstor, delSpectra);
    315   flagged.freeStorage(flagstor, delFlagged);
    316   xPol.freeStorage(xpolstor, delXPol);
     291  pksrec.spectra.freeStorage(specstor, delSpectra);
     292  pksrec.flagged.freeStorage(flagstor, delFlagged);
     293  pksrec.xPol.freeStorage(xpolstor, delXPol);
    317294
    318295  return status;
    319296}
    320297
     298//------------------------------------------------------- PKSSDwriter::history
     299
     300// Write a history record.
     301
     302Int PKSSDwriter::history(const String text)
     303{
     304  return cSDwriter.history((char *)text.chars());
     305}
     306
     307Int PKSSDwriter::history(const char *text)
     308{
     309  return cSDwriter.history((char *)text);
     310}
     311
    321312//--------------------------------------------------------- PKSSDwriter::close
    322313
     
    326317{
    327318  cSDwriter.close();
    328 }
     319  //logMsg(cSDwriter.getMsg());
     320  //cSDwriter.clearMsg();
     321}
Note: See TracChangeset for help on using the changeset viewer.