Changeset 988 for trunk/src/STWriter.cpp


Ignore:
Timestamp:
04/05/06 14:31:47 (18 years ago)
Author:
mar637
Message:

implemented data export for the asap2 Scantable as in Ticket #4.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STWriter.cpp

    r901 r988  
    4848
    4949//#include "SDFITSImageWriter.h"
    50 //#include "STAsciiWriter.h"
     50#include "STAsciiWriter.h"
    5151#include "STHeader.h"
    5252
     
    5858STWriter::STWriter(const std::string &format)
    5959{
    60   cFormat = format;
    61   String t(cFormat);
     60  format_ = format;
     61  String t(format_);
    6262  t.upcase();
    6363  if (t== "MS2") {
    64     cWriter = new PKSMS2writer();
     64    writer_ = new PKSMS2writer();
    6565  } else if (t== "SDFITS") {
    66     cWriter = new PKSSDwriter();
     66    writer_ = new PKSSDwriter();
    6767  } else if (t== "FITS") {
    68     cWriter = 0;
     68    writer_ = 0;
    6969  } else if (t== "ASCII") {
    70     cWriter = 0;
     70    writer_ = 0;
     71  } else {
     72    throw (AipsError("Unrecognized export format"));
     73  }
     74}
     75
     76STWriter::~STWriter()
     77{
     78   if (writer_) {
     79     delete writer_;
     80   }
     81}
     82
     83Int STWriter::setFormat(const std::string &format)
     84{
     85  if (format != format_) {
     86    if (writer_) delete writer_;
     87  }
     88
     89  format_ = format;
     90  String t(format_);
     91  t.upcase();
     92  if (t== "MS2") {
     93    writer_ = new PKSMS2writer();
     94  } else if (t== "SDFITS") {
     95    writer_ = new PKSSDwriter();
     96  } else if (t== "FITS") {
     97    writer_ = 0;
     98  } else if (t== "ASCII") {
     99    writer_ = 0;
    71100  } else {
    72101    throw (AipsError("Unrecognized Format"));
    73102  }
    74 }
    75 
    76 STWriter::~STWriter()
    77 {
    78    if (cWriter) {
    79      delete cWriter;
    80    }
    81 }
    82 
    83 Int STWriter::setFormat(const std::string &format)
    84 {
    85   if (format != cFormat) {
    86     if (cWriter) delete cWriter;
    87   }
    88 
    89   cFormat = format;
    90   String t(cFormat);
    91   t.upcase();
    92   if (t== "MS2") {
    93     cWriter = new PKSMS2writer();
    94   } else if (t== "SDFITS") {
    95     cWriter = new PKSSDwriter();
    96   } else if (t== "FITS") {
    97     cWriter = 0;
    98   } else if (t== "ASCII") {
    99     cWriter = 0;
    100   } else {
    101     throw (AipsError("Unrecognized Format"));
    102   }
    103103  return 0;
    104104}
     
    110110// Image FITS
    111111
    112   if (cFormat=="FITS") {
     112  if (format_=="FITS") {
    113113//      Bool verbose = True;
    114114//      SDFITSImageWriter iw;
     
    118118//         return 1;
    119119//      }
    120   } else if (cFormat=="ASCII") {
    121      /*SDAsciiWriter iw;
     120  } else if (format_=="ASCII") {
     121     STAsciiWriter iw;
    122122     if (iw.write(*in, filename)) {
    123123        return 0;
    124124     } else {
    125125        return 1;
    126      }*/
     126     }
    127127  }
    128128
     
    140140  // Create the output file and write static data.
    141141  Int status;
    142   if (status = cWriter->create(filename, hdr.observer, hdr.project,
     142  Bool havexpol = Bool(in->npol() > 2);
     143  if (status = writer_->create(filename, hdr.observer, hdr.project,
    143144                               hdr.antennaname, hdr.antennaposition,
    144145                               hdr.obstype, hdr.equinox, hdr.freqref,
    145                                nChan, nPol, False, False)) {
     146                               nChan, nPol, False, havexpol)) {
    146147    throw(AipsError("Failed to create output file"));
    147148  }
     
    161162  while (!scanit.pastEnd() ) {
    162163    Table stable = scanit.table();
    163     TableIterator beamit(table, "BEAMNO");
     164    TableIterator beamit(stable, "BEAMNO");
    164165    Int beamno = 1;
    165166    while (!beamit.pastEnd() ) {
     
    168169      MDirection::ScalarColumn dirCol(btable, "DIRECTION");
    169170      Vector<Double> direction = dirCol(0).getAngle("rad").getValue();
    170       TableIterator ifit(btable, "IFNO");
    171       Int ifno = 1;
    172       while (!ifit.pastEnd() ) {
    173         Table itable = ifit.table();
    174         TableIterator cycit(itable, "CYCLENO");
    175         Int cycno = 1;
    176         while (!cycit.pastEnd() ) {
    177           Table ctable = cycit.table();
    178           TableRow row(ctable);
     171      TableIterator cycit(btable, "CYCLENO");
     172      Int cycno = 1;
     173      while (!cycit.pastEnd() ) {
     174        Table ctable = cycit.table();
     175        TableIterator ifit(ctable, "IFNO");
     176        Int ifno = 1;
     177        while (!ifit.pastEnd() ) {
     178          Table itable = ifit.table();
     179          TableRow row(itable);
    179180          // use the first row to fill in all the "metadata"
    180181          const TableRecord& rec = row.get(0);
    181           ROArrayColumn<Float> specCol(ctable, "SPECTRA");
     182          ROArrayColumn<Float> specCol(itable, "SPECTRA");
    182183          uInt nchan = specCol(0).nelements();
    183184          Double cdelt,crval,crpix, restfreq;
    184185          Float focusAxi, focusTan, focusRot,
    185186                temperature, pressure, humidity, windSpeed, windAz;
     187          Float tmp0,tmp1,tmp2,tmp3,tmp4;
    186188          Vector<Float> tcalval;
    187           String tmp,tmp2, tcalt;
     189          String stmp0,stmp1, tcalt;
    188190          in->frequencies().getEntry(crpix,crval,cdelt, rec.asuInt("FREQ_ID"));
    189           in->molecules().getEntry(restfreq,tmp,tmp2,rec.asuInt("RESTFREQ_ID"));
     191          in->focus().getEntry(focusAxi, focusTan, focusRot,
     192                               tmp0,tmp1,tmp2,tmp3,tmp4,
     193                               rec.asuInt("FOCUS_ID"));
     194          in->molecules().getEntry(restfreq,stmp0,stmp1,rec.asuInt("MOLECULE_ID"));
    190195          in->tcal().getEntry(tcalt,tcalval,rec.asuInt("TCAL_ID"));
    191196          in->weather().getEntry(temperature, pressure, humidity,
     
    198203          Matrix<uChar> flags;
    199204          Vector<Complex> xpol;
    200           polConversion(specs, flags, xpol, ctable);
    201           Vector<Float> tsys = tsysFromTable(ctable);
     205          polConversion(specs, flags, xpol, itable);
     206          Vector<Float> tsys = tsysFromTable(itable);
    202207          // dummy data
    203208          uInt npol = specs.ncolumn();
     209
    204210          Matrix<Float>   baseLin(npol,2, 0.0f);
    205211          Matrix<Float>   baseSub(npol,9, 0.0f);
     
    208214          Vector<Float>   sigma(npol, 0.0f);
    209215          Vector<Float>   calFctr(npol, 0.0f);
    210 
    211 
    212           if (status = cWriter->write(scanno, cycno, rec.asDouble("TIME"),
     216          if (status = writer_->write(scanno, cycno, rec.asDouble("TIME"),
    213217                                      rec.asDouble("INTERVAL"),
    214218                                      rec.asString("FIELDNAME"),
     
    224228                                      rec.asFloat("ELEVATION"),
    225229                                      rec.asFloat("PARANGLE"),
    226                                       focusAxi, focusTan, focusRot,//
     230                                      focusAxi, focusTan, focusRot,
    227231                                      temperature,
    228232                                      pressure, humidity, windSpeed, windAz,
    229                                       rec.asInt("REFBEAM"), beamno,
     233                                      rec.asInt("REFBEAMNO")+1, beamno,
    230234                                      direction,
    231235                                      scanRate,// not in scantable
     
    237241                                      xpol)
    238242                                      ) {
    239             cerr << "Error writing output file." << endl;
    240             return 1;
     243            writer_->close();
     244            throw(AipsError("STWriter: Failed to export Scantable."));
    241245          }
    242246
    243           ++cycno;
    244           ++cycit;
     247          ++ifno;
     248          ++ifit;
    245249        }
    246         ++ifno;
    247         ++ifit;
     250        ++cycno;
     251        ++cycit;
    248252      }
    249253      ++beamno;
     
    256260  oss << "STWriter: wrote " << count << " rows to " << filename << endl;
    257261  pushLog(String(oss));
    258   cWriter->close();
     262  writer_->close();
    259263
    260264  return 0;
     
    267271  Vector<Float> tmp;
    268272  for (uInt i=0; i<tab.nrow(); ++i) {
     273    tmp.resize();
    269274    tmp = tsysCol(i);
    270275    out[i] = tmp[0];
    271276  }
     277  return out;
    272278}
    273279
     
    277283  TableRow row(tab);
    278284  String poltype = tab.keywordSet().asString("POLTYPE");
    279   if ( poltype != "linear")
     285  if ( poltype != "linear") {
    280286    String msg = "poltype = " + poltype + " not yet supported in output.";
    281     throw(AipsError("msg"));
     287    throw(AipsError(msg));
     288  }
    282289  // use the first row to fill in all the "metadata"
    283290  const TableRecord& rec = row.get(0);
     
    285292  ROArrayColumn<uChar> flagCol(tab, "FLAGTRA");
    286293  uInt nchan = specCol(0).nelements();
    287   uInt ncols = (tab.nrow()==1 ? 1: 2 );
    288   specs.resize(nchan, ncols);
    289   flags.resize(nchan, ncols);
     294  uInt ncol = (tab.nrow()==1 ? 1: 2 );
     295  specs.resize(nchan, ncol);
     296  flags.resize(nchan, ncol);
    290297  // the linears
    291   for (uInt i=0; i<ncols; ++i) {
     298  for (uInt i=0; i<ncol; ++i) {
    292299    specs.column(i) = specCol(i);
    293300    flags.column(i) = flagCol(i);
Note: See TracChangeset for help on using the changeset viewer.