//# Associated Universities, Inc. Washington DC, USA.
//# This library is free software; you can redistribute it and/or modify
//# it under the terms of the GNU General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or
//# (at your option) any later version.
//# This library is distributed in the hope that it will be useful,
//# but WITHOUT ANY WARRANTY; without even the implied warranty of
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//# GNU General Public License for more details.
//# You should have received a copy of the GNU General Public License
//# along with this library; if not, write to the Free Software
//# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: aips2-request@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# Charlottesville, VA 22903-2475 USA
#include <msvis/MSVis/VisBuffer.h>
#include <casacore/casa/Arrays/Cube.h>
namespace casa { //# NAMESPACE CASA - BEGIN
void VisBuffer::chanAveVisCube(casacore::Cube<T>& data, casacore::Int nChanOut)
using casacore::operator*;
casacore::IPosition csh(data.shape());
casacore::Int nChan0 = csh(1);
// It's possible that data has already been averaged. I could try
// refilling data if I knew which column to use, but I don't.
// Chuck it to the caller.
throw(casacore::AipsError("Can't average " + casacore::String(nChan0) + " channels to " +
casacore::String(nChanOut) + " channels!"));
casacore::Vector<casacore::Int>& chans(channel());
casacore::Bool areShifting = true;
if(chans.nelements() > 0 && chans[0] == 0)
if(nChan0 == nChanOut && !areShifting)
casacore::Cube<T> newCube(csh);
casacore::Int nCor = nCorr();
const casacore::Bool doSpWt(visIter_p->existsWeightSpectrum());
// Make sure weightSpectrum() is unaveraged.
if(doSpWt && (areShifting || weightSpectrum().shape()(1) < nChan0))