Changeset 827


Ignore:
Timestamp:
02/17/06 15:01:57 (18 years ago)
Author:
mar637
Message:

First asap2 version which compiles

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STWriter.cpp

    r822 r827  
    4242#include <atnf/PKSIO/PKSSDwriter.h>
    4343
     44#include <tables/Tables/Table.h>
     45#include <tables/Tables/TableIter.h>
     46#include <tables/Tables/TableRow.h>
    4447#include <tables/Tables/ArrayColumn.h>
    4548
    46 
    47 
    48 
     49//#include "SDFITSImageWriter.h"
     50//#include "STAsciiWriter.h"
     51//#include "SDPol.h"
    4952#include "SDContainer.h"
    50 #include "SDMemTable.h"
     53
    5154#include "STWriter.h"
    52 #include "SDFITSImageWriter.h"
    53 #include "SDAsciiWriter.h"
    54 #include "SDPol.h"
    5555
    5656using namespace casa;
    57 using namespace asap;
    58 
    59 //--------------------------------------------------------- STWriter::STWriter
    60 
    61 // Default constructor.
     57namespace asap {
    6258
    6359STWriter::STWriter(const std::string &format)
    6460{
    65   cFormat = format;
    66 //
    67   String t(cFormat);
    68   t.upcase();
    69   if (t== "MS2") {
    70     cWriter = new PKSMS2writer();
    71   } else if (t== "SDFITS") {
    72     cWriter = new PKSSDwriter();
    73   } else if (t== "FITS") {
    74     cWriter = 0;
    75   } else if (t== "ASCII") {
    76     cWriter = 0;
    77   } else {
    78     throw (AipsError("Unrecognized Format"));
    79   }
    80 }
    81 
    82 //-------------------------------------------------------- STWriter::~STWriter
    83 
    84 // Destructor.
    85 
    86 STWriter::~STWriter()
    87 {
    88    if (cWriter) {
    89      delete cWriter;
    90    }
    91 }
    92 
    93 //-------------------------------------------------------- STWriter::setFormat
    94 
    95 // Reset the output format.
    96 
    97 Int STWriter::setFormat(const std::string &format)
    98 {
    99   if (format != cFormat) {
    100     if (cWriter) delete cWriter;
    101   }
    102 //
    10361  cFormat = format;
    10462  String t(cFormat);
     
    11573    throw (AipsError("Unrecognized Format"));
    11674  }
     75}
     76
     77STWriter::~STWriter()
     78{
     79   if (cWriter) {
     80     delete cWriter;
     81   }
     82}
     83
     84Int STWriter::setFormat(const std::string &format)
     85{
     86  if (format != cFormat) {
     87    if (cWriter) delete cWriter;
     88  }
     89
     90  cFormat = format;
     91  String t(cFormat);
     92  t.upcase();
     93  if (t== "MS2") {
     94    cWriter = new PKSMS2writer();
     95  } else if (t== "SDFITS") {
     96    cWriter = new PKSSDwriter();
     97  } else if (t== "FITS") {
     98    cWriter = 0;
     99  } else if (t== "ASCII") {
     100    cWriter = 0;
     101  } else {
     102    throw (AipsError("Unrecognized Format"));
     103  }
    117104  return 0;
    118105}
    119106
    120 //------------------------------------------------------------ STWriter::write
    121 
    122 // Write an SDMemTable to file in the desired format, closing the file when
    123 // finished.
    124 
    125 Int STWriter::write(const CountedPtr<SDMemTable> in,
    126                     const std::string &filename, Bool toStokes)
     107Int STWriter::write(const CountedPtr<Scantable> in,
     108                    const std::string &filename)
    127109{
    128110
     
    130112
    131113  if (cFormat=="FITS") {
    132      Bool verbose = True;
    133      SDFITSImageWriter iw;
    134      if (iw.write(*in, filename, verbose, toStokes)) {
     114//      Bool verbose = True;
     115//      SDFITSImageWriter iw;
     116//      if (iw.write(*in, filename, verbose)) {
     117//         return 0;
     118//      } else {
     119//         return 1;
     120//      }
     121  } else if (cFormat=="ASCII") {
     122     /*SDAsciiWriter iw;
     123     if (iw.write(*in, filename)) {
    135124        return 0;
    136125     } else {
    137126        return 1;
    138      }
    139   } else if (cFormat=="ASCII") {
    140      SDAsciiWriter iw;
    141      if (iw.write(*in, filename, toStokes)) {
    142         return 0;
    143      } else {
    144         return 1;
    145      }
    146   }
    147 
    148 // MS or SDFITS
     127     }*/
     128  }
     129
     130  // MS or SDFITS
    149131
    150132  // Extract the header from the table.
     
    153135  const Int nChan = hdr.nchan;
    154136
    155 // Get Freq table
    156 
    157   SDFrequencyTable sdft = in->getSDFreqTable();
    158   Vector<Double> restFreqs;
    159   String restFreqUnit;
    160   sdft.restFrequencies(restFreqs, restFreqUnit);
    161   Double restFreq = 0.0;
    162   if (restFreqs.nelements()>0) {
    163      Quantum<Double> rF(restFreqs(0), Unit(restFreqUnit));
    164      restFreq = rF.getValue(Unit("Hz"));
    165   }
    166 
    167 // Table columns
    168 
    169137  const Table table = in->table();
    170   ROArrayColumn<uInt> freqIDCol(table, "FREQID");
    171   Vector<uInt> freqIDs;
     138//   ROArrayColumn<uInt> freqIDCol(table, "FREQ_ID");
     139//   Vector<uInt> freqIDs;
    172140
    173141  // Create the output file and write static data.
     
    180148  }
    181149
    182   Vector<Double>  srcPM(2, 0.0);
    183150  Double          srcVel = 0.0;
    184 
    185   Array<Float> spectra, tSys, stokes;
    186   Array<uChar> flags;
    187   Bool doLinear = True;
    188151
    189152  String          fieldName, srcName, tcalTime;
     
    203166    while (!beamit.pastEnd() ) {
    204167      Table btable = beamit.table();
     168      // position only varies by beam
     169      MDirection::ScalarColumn dirCol(btable, "DIRECTION");
     170      Vector<Double> direction = dirCol(0).getAngle("rad").getValue();
    205171      TableIterator ifit(btable, "IFNO");
    206172      Int ifno = 1;
     
    213179          TableRow row(ctable);
    214180          // use the first row to fill in all the "metadata"
    215           const TableRecord& rec = row.record(0);
     181          const TableRecord& rec = row.get(0);
    216182          ROArrayColumn<Float> specCol(ctable, "SPECTRA");
    217183          uInt nchan = specCol(0).nelements();
    218184          Double cdelt,crval,crpix, restfreq;
    219           String tmp,tmp2;
     185          Float focusAxi, focusTan, focusRot,
     186                temperature, pressure, humidity, windSpeed, windAz;
     187          Vector<Float> tcalval;
     188          String tmp,tmp2, tcalt;
    220189          in->frequencies().getEntry(crpix,crval,cdelt, rec.asuInt("FREQ_ID"));
    221190          in->molecules().getEntry(restfreq,tmp,tmp2,rec.asuInt("RESTFREQ_ID"));
     191          in->tcal().getEntry(tcalt,tcalval,rec.asuInt("TCAL_ID"));
     192          in->weather().getEntry(temperature, pressure, humidity,
     193                                 windSpeed, windAz,
     194                                 rec.asuInt("WEATHER_ID"));
    222195          Double pixel = Double(nchan/2);
    223196          Double refFreqNew = (pixel-crpix)*cdelt + crval;
     
    227200          Vector<Complex> xpol;
    228201          polConversion(specs, flags, xpol, ctable);
     202          Vector<Float> tsys = tsysFromTable(ctable);
    229203          // dummy data
    230           uInt nPol = specs.ncolumns();
     204          uInt npol = specs.ncolumn();
    231205          Matrix<Float>   baseLin(npol,2, 0.0f);
    232206          Matrix<Float>   baseSub(npol,9, 0.0f);
     
    237211
    238212
    239           if (status = cWriter->write(scano, cycno, rec.asDouble("TIME"),
     213          if (status = cWriter->write(scanno, cycno, rec.asDouble("TIME"),
    240214                                      rec.asDouble("INTERVAL"),
    241215                                      rec.asString("FIELDNAME"),
    242216                                      rec.asString("SRCNAME"),
    243                                       direction ,//
     217                                      direction,
    244218                                      srcPM, srcVel, // not in scantable yet
    245219                                      ifno,
    246220                                      refFreqNew, nchan*abs(cdelt), cdelt,
    247221                                      restfreq,
    248                                       tcal,//
    249                                       tcaltime,//
     222                                      tcal,
     223                                      tcalt,
    250224                                      rec.asFloat("AZIMUTH"),
    251225                                      rec.asFloat("ELEVATION"),
    252226                                      rec.asFloat("PARANGLE"),
    253227                                      focusAxi, focusTan, focusRot,//
    254                                       temperature,//
    255                                       pressure, humidity, windSpeed, windAz,//
     228                                      temperature,
     229                                      pressure, humidity, windSpeed, windAz,
    256230                                      rec.asInt("REFBEAM"), beamno,
    257                                       direction,//
     231                                      direction,
    258232                                      scanRate,// not in scantable
    259                                       tSys, //
     233                                      tsys,
    260234                                      sigma, calFctr,// not in scantable
    261235                                      baseLin, baseSub,// not in scantable
     
    288262}
    289263
    290 void STWriter::polConversion( Matrix< Float >& specs, Matrix< Float >& flags,
     264Vector<Float> STWriter::tsysFromTable(const Table& tab)
     265{
     266  ROArrayColumn<Float> tsysCol(tab, "TSYS");
     267  Vector<Float> out(tab.nrow());
     268  Vector<Float> tmp;
     269  for (uInt i=0; i<tab.nrow(); ++i) {
     270    tmp = tsysCol(i);
     271    out[i] = tmp[0];
     272  }
     273}
     274
     275void STWriter::polConversion( Matrix< Float >& specs, Matrix< uChar >& flags,
    291276                              Vector< Complex > & xpol, const Table & tab )
    292277{
     
    297282    throw(AipsError("msg"));
    298283  // use the first row to fill in all the "metadata"
    299   const TableRecord& rec = row.record(0);
    300   ROArrayColumn<Float> specCol(ctable, "SPECTRA");
    301   ROArrayColumn<uChar> flagCol(ctable, "FLAGTRA");
     284  const TableRecord& rec = row.get(0);
     285  ROArrayColumn<Float> specCol(tab, "SPECTRA");
     286  ROArrayColumn<uChar> flagCol(tab, "FLAGTRA");
    302287  uInt nchan = specCol(0).nelements();
    303   uInt ncols = ( ctable.nrow()==1 ? 1: 2 );
     288  uInt ncols = (tab.nrow()==1 ? 1: 2 );
    304289  specs.resize(nchan, ncols);
    305290  flags.resize(nchan, ncols);
     
    310295  }
    311296  // now the complex if exists
    312   Vector<Complex> xpol;
    313297  Bool hasxpol = False;
    314298  xpol.resize();
    315   if ( ctable.nrow() == 4 ) {
     299  if ( tab.nrow() == 4 ) {
    316300    hasxpol = True;
    317301    xpol.resize(nchan);
     
    319303    reals = specCol(2); imags = specCol(3);
    320304    for (uInt k=0; k < nchan; ++k) {
    321   `   xpol[k] = Complex(reals[k], imags[k]);
     305      xpol[k] = Complex(reals[k], imags[k]);
    322306    }
    323307  }
    324308}
     309
     310
     311}
  • trunk/src/STWriter.h

    r822 r827  
    3737#include <casa/Utilities/CountedPtr.h>
    3838
    39 #include <SDMemTable.h>
    40 #include <SDMemTableWrapper.h>
    41 
    42 #include <SDLog.h>
     39#include "SDLog.h"
     40#include "Scantable.h"
    4341
    4442class PKSwriter;
     43class casa::Table;
    4544
    4645namespace asap {
     
    5453// Stokes conversion available for FITS and ASCII at present
    5554  casa::Int setFormat(const string &format = "SDFITS");
    56   casa::Int write(const casa::CountedPtr<SDMemTable> table,
    57             const string &filename, casa::Bool toStokes);
     55  casa::Int write(const casa::CountedPtr<Scantable> table,
     56            const string &filename);
    5857
    5958private:
     59  casa::Vector<casa::Float> tsysFromTable(const casa::Table& tab);
     60
    6061  void polConversion( casa::Matrix<casa::Float>& spec,
    61                       casa::Matrix<casa::Float>& flag,
     62                      casa::Matrix<casa::uChar>& flag,
    6263                      casa::Vector<casa::Complex>& xpol,
    63                       const Table& tab);
     64                      const casa::Table& tab);
    6465  std::string     cFormat;
    6566  PKSwriter *cWriter;
Note: See TracChangeset for help on using the changeset viewer.