Ignore:
Timestamp:
12/14/06 11:21:48 (17 years ago)
Author:
mar637
Message:

merge from trunk, to get binary operator changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Release2.1.2/src/STMath.cpp

    r1259 r1310  
    281281                                              bool tsys )
    282282{
    283   // modes are "ADD" and "MUL"
    284283  CountedPtr< Scantable > out = getScantable(in, false);
    285284  Table& tab = out->table();
     
    291290    specCol.get(i, spec);
    292291    tsysCol.get(i, ts);
    293     if (mode == "MUL") {
     292    if (mode == "MUL" || mode == "DIV") {
     293      if (mode == "DIV") val = 1.0/val;
    294294      spec *= val;
    295295      specCol.put(i, spec);
     
    298298        tsysCol.put(i, ts);
    299299      }
    300     } else if ( mode == "ADD" ) {
     300    } else if ( mode == "ADD"  || mode == "SUB") {
     301      if (mode == "SUB") val *= -1.0;
    301302      spec += val;
    302303      specCol.put(i, spec);
     
    309310  return out;
    310311}
     312
     313CountedPtr<Scantable> STMath::binaryOperate(const CountedPtr<Scantable>& left,
     314                                            const CountedPtr<Scantable>& right,
     315                                            const std::string& mode)
     316{
     317  bool insitu = insitu_;
     318  if ( ! left->conformant(*right) ) {
     319    throw(AipsError("'left' and 'right' scantables are not conformant."));
     320  }
     321  setInsitu(false);
     322  CountedPtr< Scantable > out = getScantable(left, false);
     323  setInsitu(insitu);
     324  Table& tout = out->table();
     325  Block<String> coln(5);
     326  coln[0] = "SCANNO";  coln[1] = "CYCLENO";  coln[2] = "BEAMNO";
     327  coln[3] = "IFNO";  coln[4] = "POLNO";
     328  Table tmpl = tout.sort(coln);
     329  Table tmpr = right->table().sort(coln);
     330  ArrayColumn<Float> lspecCol(tmpl,"SPECTRA");
     331  ROArrayColumn<Float> rspecCol(tmpr,"SPECTRA");
     332  ArrayColumn<uChar> lflagCol(tmpl,"FLAGTRA");
     333  ROArrayColumn<uChar> rflagCol(tmpr,"FLAGTRA");
     334
     335  for (uInt i=0; i<tout.nrow(); ++i) {
     336    Vector<Float> lspecvec, rspecvec;
     337    Vector<uChar> lflagvec, rflagvec;
     338    lspecvec = lspecCol(i);    rspecvec = rspecCol(i);
     339    lflagvec = lflagCol(i);    rflagvec = rflagCol(i);
     340    MaskedArray<Float> mleft = maskedArray(lspecvec, lflagvec);
     341    MaskedArray<Float> mright = maskedArray(rspecvec, rflagvec);
     342    if (mode == "ADD") {
     343      mleft += mright;
     344    } else if ( mode == "SUB") {
     345      mleft -= mright;
     346    } else if ( mode == "MUL") {
     347      mleft *= mright;
     348    } else if ( mode == "DIV") {
     349      mleft /= mright;
     350    } else {
     351      throw(AipsError("Illegal binary operator"));
     352    }
     353    lspecCol.put(i, mleft.getArray());
     354  }
     355  return out;
     356}
     357
     358
    311359
    312360MaskedArray<Float> STMath::maskedArray( const Vector<Float>& s,
Note: See TracChangeset for help on using the changeset viewer.