Source
xxxxxxxxxx
//# FluxCalcLogFreqPolynomial.cc: Implementation of FluxCalcLogFreqPolynomial.h
//# Copyright (C) 2010
//# 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 Library 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 Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts 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
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
//#
// Handy for passing anonymous arrays to functions.
using namespace casacore;
namespace casa { //# NAMESPACE CASA - BEGIN
Bool FluxCalcLogFreqPolynomial::operator()(Flux<Double>& value,
Flux<Double>& error,
const MFrequency& mfreq,
const Bool updatecoeffs)
{
LogIO os(LogOrigin("FluxCalcLogFreqPolynomial", "()", WHERE));
Double dt = log10(mfreq.get(freqUnit_p).getValue());
if (updatecoeffs || coeffs_p(0).nelements()==0) {
coeffs_p(0).resize();
coeffs_p(1).resize();
coeffs_p=getCurrentCoeffs();
}
{
validfrange_p=getValidFreqRange();
Double ghzinfreq = mfreq.get("GHz").getValue();
Double minfreq = validfrange_p(0).get("GHz").getValue();
Double maxfreq = validfrange_p(1).get("GHz").getValue();
if (!(minfreq==0.0 && maxfreq ==0.0)) {
//cerr<<" range:"<<minfreq<<","<<maxfreq<<" infreq="<<ghzinfreq<<endl;
if (minfreq > ghzinfreq || maxfreq < ghzinfreq) {
//cerr<<"Input "<<String::toString(mfreq)<<" is out of the valid frequency range of the flux model: "<<String::toString(validfrange_p)<<endl;
os<<LogIO::WARN<<"Input "<<String::toString(mfreq)
<<" (Hz) is out of the valid frequency range of the flux model: "
<<String::toString(validfrange_p)<<" (Hz)"<<LogIO::POST;
}
}
}
Double fluxCoeff = coeffs_p(0)[coeffs_p(0).nelements() - 1];
for(Int order = coeffs_p(0).nelements() - 2; order >= 0; --order)
fluxCoeff = fluxCoeff * dt + coeffs_p(0)[order];
Double coeffErr = 0.0;
Double dtpow = 1.0;
for(uInt order = 0; order < coeffs_p(1).nelements(); ++order){
coeffErr += square(coeffs_p(1)[order] * dtpow);
dtpow *= dt;
}
Double fluxDensity = pow(10.0, fluxCoeff);
Double fluxError = coeffErr > 0.0 ? C::ln10 * fluxDensity * sqrt(coeffErr) : 0.0;
//cerr<<"FluxDensity=="<<fluxDensity<<endl;
value.setValue(fluxDensity);
error.setValue(fluxError);
// In this case the hard part of matching the std and src has already been done.
return true;
}
Bool FluxCalcLogFreqPolynomial::setSource(const String& sourceName, const MDirection& sourceDir)
{
Bool success = FluxCalcVQS::setSource(sourceName, sourceDir);