Changeset 2733


Ignore:
Timestamp:
01/16/13 20:00:01 (12 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-4770

Ready for Test: Yes

Interface Changes: Yes/No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Redefined Interpolator1D and derived classes as template class.


Location:
trunk/src
Files:
6 added
6 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/BufferedLinearInterpolator1D.h

    r2730 r2733  
    2121 * @author TakeshiNakazato
    2222 */
    23 class BufferedLinearInterpolator1D : public Interpolator1D {
     23template <class T, class U>
     24class BufferedLinearInterpolator1D : public Interpolator1D<T, U> {
    2425public:
    2526  // Default constructor.
     
    3435  // @param[in] n number of data.
    3536  // @see Interpolator1D::setData()
    36   void setData(double *x, float *y, unsigned int n);
     37  void setData(T *x, U *y, unsigned int n);
    3738
    3839  // Set horizontal data (x).
     
    4041  // @param[in] n number of data.
    4142  // @see Interpolator1D::setX()
    42   void setX(double *x, unsigned int n);
     43  void setX(T *x, unsigned int n);
    4344
    4445  // Perform interpolation.
     
    4748  // @return interpolated value at x.
    4849  // @see Interpolator1D::interpolate()
    49   float interpolate(double x);
     50  U interpolate(T x);
    5051
    5152private:
    5253  // Numerical factor for linear interpolation.
    53   double factor_;
     54  T factor_;
    5455
    5556  // Previous location.
    56   double xold_;
     57  T xold_;
    5758
    5859  // Previous location as an index
     
    6465
    6566}
     67
     68#include "BufferedLinearInterpolator1D.tcc"
     69
    6670#endif
  • trunk/src/CMakeLists.txt

    r2731 r2733  
    8080     ${SRCDIR}/Calibrator.cpp
    8181     ${SRCDIR}/PSAlmaCalibrator.cpp
    82      ${SRCDIR}/Interpolator1D.cpp
    83      ${SRCDIR}/NearestInterpolator1D.cpp
    84      ${SRCDIR}/LinearInterpolator1D.cpp
    85      ${SRCDIR}/BufferedLinearInterpolator1D.cpp
    86      ${SRCDIR}/CubicSplineInterpolator1D.cpp
    87      ${SRCDIR}/PolynomialInterpolator1D.cpp
    8882     ${SRCDIR}/STBaselineParamTable.cpp )
    8983
  • trunk/src/CubicSplineInterpolator1D.h

    r2730 r2733  
    2121 * @author TakeshiNakazato
    2222 */
    23 class CubicSplineInterpolator1D : public Interpolator1D {
     23template <class T, class U>
     24class CubicSplineInterpolator1D : public Interpolator1D<T, U> {
    2425public:
    2526  // Default constructor.
     
    3132  // Override Interpolator1D::setData.
    3233  // @see Interpolator1D::setData
    33   void setData(double *x, float *y, unsigned int n);
     34  void setData(T *x, U *y, unsigned int n);
    3435
    3536  // Override Interpolator1D::setY.
    3637  // @see Interpolator1D::setY()
    37   void setY(float *y, unsigned int n);
     38  void setY(U *y, unsigned int n);
    3839
    3940  // Perform interpolation.
     
    4142  //              by interpolation.
    4243  // @return interpolated value at x.
    43   float interpolate(double x);
     44  U interpolate(T x);
    4445private:
    4546  // Determine second derivatives of each point based on
     
    5354  // @param[in] i location index for x.
    5455  // @return interpolated value at x.
    55   float dospline(double x, unsigned int i);
     56  U dospline(T x, unsigned int i);
    5657 
    5758  // Array to store second derivatives on the data points.
    58   float *y2_;
     59  U *y2_;
    5960
    6061  // number of data points for second derivatives
     
    6667
    6768}
     69
     70#include "CubicSplineInterpolator1D.tcc"
     71
    6872#endif
  • trunk/src/Interpolator1D.h

    r2731 r2733  
    2121 * @author TakeshiNakazato
    2222 */
    23 class Interpolator1D {
     23template <class T, class U> class Interpolator1D {
    2424public:
    2525  // Default constructor.
     
    3333  // @param[in] y pointer to vertical data.
    3434  // @param[in] n number of data.
    35   void setData(double *x, float *y, unsigned int n);
     35  void setData(T *x, U *y, unsigned int n);
    3636
    3737  // Set horizontal data (x).
    3838  // @param[in] x pointer to horizontal data.
    3939  // @param[in] n number of data.
    40   void setX(double *x, unsigned int n);
     40  void setX(T *x, unsigned int n);
    4141
    4242  // Set vertical data (y).
    4343  // @param[in] y pointer to vertical data.
    4444  // @param[in] n number of data.
    45   void setY(float *y, unsigned int n);
     45  void setY(U *y, unsigned int n);
    4646
    4747  // Reset object.
     
    5858  //              by interpolation.
    5959  // @return interpolated value at x.
    60   virtual float interpolate(double x) = 0;
     60  virtual U interpolate(T x) = 0;
    6161
    6262protected:
     
    6565  // @return location as an index.
    6666  // @see Locator::locate()
    67   unsigned int locate(double x);
     67  unsigned int locate(T x);
    6868
    6969  // Query function whether the object is ready to interpolate.
     
    8181
    8282  // Horizontal data.
    83   double *x_;
     83  T *x_;
    8484
    8585  // Vertical data.
    86   float *y_;
     86  U *y_;
    8787
    8888  // Pointer to the Locator object.
    89   Locator<double> *locator_;
     89  Locator<T> *locator_;
    9090};
    9191
    9292}
     93
     94#include "Interpolator1D.tcc"
     95
    9396#endif
  • trunk/src/LinearInterpolator1D.h

    r2730 r2733  
    2121 * @author TakeshiNakazato
    2222 */
    23 class LinearInterpolator1D : public Interpolator1D {
     23template <class T, class U>
     24class LinearInterpolator1D : public Interpolator1D<T, U> {
    2425public:
    2526  // Default constructor.
     
    3435  // @return interpolated value at x.
    3536  // @see Interpolator1D::interpolate()
    36   float interpolate(double x);
     37  U interpolate(T x);
    3738};
    3839
    3940}
     41
     42#include "LinearInterpolator1D.tcc"
     43
    4044#endif
  • trunk/src/NearestInterpolator1D.h

    r2730 r2733  
    3131 * @author TakeshiNakazato
    3232 */
    33 class NearestInterpolator1D : public Interpolator1D {
     33template <class T, class U>
     34class NearestInterpolator1D : public Interpolator1D<T, U> {
    3435public:
    3536  // Default constructor.
     
    4445  // @return interpolated value at x.
    4546  // @see Interpolator1D::interpolate()
    46   float interpolate(double x);
     47  U interpolate(T x);
    4748};
    4849
    4950}
     51
     52#include "NearestInterpolator1D.tcc"
     53
    5054#endif
  • trunk/src/PolynomialInterpolator1D.h

    r2730 r2733  
    2121 * @author TakeshiNakazato
    2222 */
    23 class PolynomialInterpolator1D : public Interpolator1D {
     23template <class T, class U>
     24class PolynomialInterpolator1D : public Interpolator1D<T, U> {
    2425public:
    2526  // Default constructor.
     
    3334  //              by interpolation.
    3435  // @return interpolated value at x.
    35   float interpolate(double x);
     36  U interpolate(T x);
    3637private:
    3738  // Perform polynomial interpolation.
     
    4445  // @param[in] n number of data points of sub-region.
    4546  // @return interpolated value at x.
    46   float dopoly(double x, unsigned int left, unsigned int n);
     47  U dopoly(T x, unsigned int left, unsigned int n);
    4748};
    4849
    4950}
     51
     52#include "PolynomialInterpolator1D.tcc"
     53
    5054#endif
  • trunk/src/STApplyCal.cpp

    r2727 r2733  
    3333#include "Calibrator.h"
    3434#include "PSAlmaCalibrator.h"
     35#include "Interpolator1D.h"
    3536#include "NearestInterpolator1D.h"
    3637#include "BufferedLinearInterpolator1D.h"
     
    268269  os_ << "skyIdx = " << skyIdx << LogIO::POST;
    269270
    270   double *xa = new double[skyIdx.nelements()];
    271   float *ya = new float[skyIdx.nelements()];
     271  Double *xa = new Double[skyIdx.nelements()];
     272  Float *ya = new Float[skyIdx.nelements()];
    272273  IPosition ipos(1, skyIdx.nelements());
    273   Vector<double> timeSkySorted(ipos, xa, TAKE_OVER);
     274  Vector<Double> timeSkySorted(ipos, xa, TAKE_OVER);
    274275  Vector<Float> tmpOff(ipos, ya, TAKE_OVER);
    275276  for (uInt i = 0 ; i < skyIdx.nelements(); i++) {
    276     timeSkySorted[i] = (double)timeSky[skyIdx[i]];
     277    timeSkySorted[i] = timeSky[skyIdx[i]];
    277278    os_ << "timeSkySorted[" << i << "]-timeSkySorted[0]=" << timeSkySorted[i] - timeSkySorted[0] << LogIO::POST;
    278279  }
     
    285286  Vector<Double> timeTsys(nrowTsys);
    286287  Matrix<Float> tsys;
    287   Vector<double> timeTsysSorted;
     288  Vector<Double> timeTsysSorted;
    288289  Vector<Float> tmpTsys;
    289290  if (doTsys) {
     
    307308    os_ << "tsysIdx = " << tsysIdx << LogIO::POST;
    308309
    309     double *xb = new double[tsysIdx.nelements()];
    310     float *yb = new float[tsysIdx.nelements()];
     310    Double *xb = new Double[tsysIdx.nelements()];
     311    Float *yb = new Float[tsysIdx.nelements()];
    311312    IPosition ipos(1, tsysIdx.nelements());
    312313    timeTsysSorted.takeStorage(ipos, xb, TAKE_OVER);
    313314    tmpTsys.takeStorage(ipos, yb, TAKE_OVER);
    314315    for (uInt i = 0 ; i < tsysIdx.nelements(); i++) {
    315       timeTsysSorted[i] = (double)timeTsys[tsysIdx[i]];
     316      timeTsysSorted[i] = timeTsys[tsysIdx[i]];
    316317      os_ << "timeTsysSorted[" << i << "]-timeTsysSorted[0]=" << timeTsysSorted[i] - timeTsysSorted[0] << LogIO::POST;
    317318    }
     
    333334
    334335    // interpolation
    335     double t0 = (double)timeCol(irow);
     336    Double t0 = timeCol(irow);
    336337    for (uInt ichan = 0; ichan < nchanSp; ichan++) {
    337338      Vector<Float> spOffSlice = spoff.row(ichan);
    338339      //os_ << "spOffSlice = " << spOffSlice << LogIO::POST;
    339340      for (uInt j = 0; j < skyIdx.nelements(); j++) {
    340         tmpOff[j] = (float)spOffSlice[skyIdx[j]];
     341        tmpOff[j] = spOffSlice[skyIdx[j]];
    341342      }
    342343      interpolatorS_->setY(ya, skyIdx.nelements());
     
    350351    if (doTsys) {
    351352      // Tsys correction
    352       float *yt = new float[nchanTsys];
     353      Float *yt = new Float[nchanTsys];
    353354      Vector<Float> iTsysT(IPosition(1,nchanTsys), yt, TAKE_OVER);
    354       float *yb = tmpTsys.data();
     355      Float *yb = tmpTsys.data();
    355356      for (uInt ichan = 0; ichan < nchanTsys; ichan++) {
    356357        Vector<Float> tsysSlice = tsys.row(ichan);
    357358        for (uInt j = 0; j < tsysIdx.nelements(); j++) {
    358           tmpTsys[j] = (float)tsysSlice[tsysIdx[j]];
     359          tmpTsys[j] = tsysSlice[tsysIdx[j]];
    359360        }
    360361        interpolatorT_->setY(yb, tsysIdx.nelements());
     
    373374        interpolatorF_->setY(yt, nchanTsys);
    374375        for (uInt ichan = 0; ichan < nchanSp; ichan++) {
    375           iTsys[ichan] = (Float)interpolatorF_->interpolate(fsp[ichan]);
     376          iTsys[ichan] = interpolatorF_->interpolate(fsp[ichan]);
    376377        }
    377378      }
     
    464465    {
    465466      os_ << "use NearestInterpolator in time axis" << LogIO::POST;
    466       interpolatorS_ = new NearestInterpolator1D();
    467       interpolatorT_ = new NearestInterpolator1D();
     467      interpolatorS_ = new NearestInterpolator1D<Double, Float>();
     468      interpolatorT_ = new NearestInterpolator1D<Double, Float>();
    468469      break;
    469470    }
     
    471472    {
    472473      os_ << "use BufferedLinearInterpolator in time axis" << LogIO::POST;
    473       interpolatorS_ = new BufferedLinearInterpolator1D();
    474       interpolatorT_ = new BufferedLinearInterpolator1D();
     474      interpolatorS_ = new BufferedLinearInterpolator1D<Double, Float>();
     475      interpolatorT_ = new BufferedLinearInterpolator1D<Double, Float>();
    475476      break;     
    476477    }
     
    478479    {
    479480      os_ << "use CubicSplineInterpolator in time axis" << LogIO::POST;
    480       interpolatorS_ = new CubicSplineInterpolator1D();
    481       interpolatorT_ = new CubicSplineInterpolator1D();
     481      interpolatorS_ = new CubicSplineInterpolator1D<Double, Float>();
     482      interpolatorT_ = new CubicSplineInterpolator1D<Double, Float>();
    482483      break;
    483484    }
     
    486487      os_ << "use PolynomialInterpolator in time axis" << LogIO::POST;
    487488      if (order == 0) {
    488         interpolatorS_ = new NearestInterpolator1D();
    489         interpolatorT_ = new NearestInterpolator1D();
     489        interpolatorS_ = new NearestInterpolator1D<Double, Float>();
     490        interpolatorT_ = new NearestInterpolator1D<Double, Float>();
    490491      }
    491492      else {
    492         interpolatorS_ = new PolynomialInterpolator1D();
    493         interpolatorT_ = new PolynomialInterpolator1D();
     493        interpolatorS_ = new PolynomialInterpolator1D<Double, Float>();
     494        interpolatorT_ = new PolynomialInterpolator1D<Double, Float>();
    494495        interpolatorS_->setOrder(order);
    495496        interpolatorT_->setOrder(order);
     
    500501    {
    501502      os_ << "use BufferedLinearInterpolator in time axis" << LogIO::POST;
    502       interpolatorS_ = new BufferedLinearInterpolator1D();
    503       interpolatorT_ = new BufferedLinearInterpolator1D();
     503      interpolatorS_ = new BufferedLinearInterpolator1D<Double, Float>();
     504      interpolatorT_ = new BufferedLinearInterpolator1D<Double, Float>();
    504505      break;     
    505506    }
     
    510511    {
    511512      os_ << "use NearestInterpolator in frequency axis" << LogIO::POST;
    512       interpolatorF_ = new NearestInterpolator1D();
     513      interpolatorF_ = new NearestInterpolator1D<Double, Float>();
    513514      break;
    514515    }
     
    516517    {
    517518      os_ << "use BufferedLinearInterpolator in frequency axis" << LogIO::POST;
    518       interpolatorF_ = new BufferedLinearInterpolator1D();
     519      interpolatorF_ = new BufferedLinearInterpolator1D<Double, Float>();
    519520      break;     
    520521    }
     
    522523    {
    523524      os_ << "use CubicSplineInterpolator in frequency axis" << LogIO::POST;
    524       interpolatorF_ = new CubicSplineInterpolator1D();
     525      interpolatorF_ = new CubicSplineInterpolator1D<Double, Float>();
    525526      break;
    526527    }
     
    529530      os_ << "use PolynomialInterpolator in frequency axis" << LogIO::POST;
    530531      if (order == 0) {
    531         interpolatorF_ = new NearestInterpolator1D();
     532        interpolatorF_ = new NearestInterpolator1D<Double, Float>();
    532533      }
    533534      else {
    534         interpolatorF_ = new PolynomialInterpolator1D();
     535        interpolatorF_ = new PolynomialInterpolator1D<Double, Float>();
    535536        interpolatorF_->setOrder(order);
    536537      }
     
    540541    {
    541542      os_ << "use LinearInterpolator in frequency axis" << LogIO::POST;
    542       interpolatorF_ = new BufferedLinearInterpolator1D();
     543      interpolatorF_ = new BufferedLinearInterpolator1D<Double, Float>();
    543544      break;     
    544545    }
  • trunk/src/STApplyCal.h

    r2727 r2733  
    103103  casa::Bool is2d_;
    104104  casa::Int order_;
    105   casa::CountedPtr<Interpolator1D> interpolatorT_;
    106   casa::CountedPtr<Interpolator1D> interpolatorF_;
    107   casa::CountedPtr<Interpolator1D> interpolatorS_;
     105  casa::CountedPtr<Interpolator1D<casa::Double, casa::Float> > interpolatorT_;
     106  casa::CountedPtr<Interpolator1D<casa::Double, casa::Float> > interpolatorF_;
     107  casa::CountedPtr<Interpolator1D<casa::Double, casa::Float> > interpolatorS_;
    108108
    109109  // IF (spw) mapping for Tsys transfer
Note: See TracChangeset for help on using the changeset viewer.