Line data Source code
1 : 2 : //# RFASelector.cc: this defines RFASelector 3 : //# Copyright (C) 2000,2001,2002 4 : //# Associated Universities, Inc. Washington DC, USA. 5 : //# 6 : //# This library is free software; you can redistribute it and/or modify it 7 : //# under the terms of the GNU Library General Public License as published by 8 : //# the Free Software Foundation; either version 2 of the License, or (at your 9 : //# option) any later version. 10 : //# 11 : //# This library is distributed in the hope that it will be useful, but WITHOUT 12 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 14 : //# License for more details. 15 : //# 16 : //# You should have received a copy of the GNU Library General Public License 17 : //# along with this library; if not, write to the Free Software Foundation, 18 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 19 : //# 20 : //# Correspondence concerning AIPS++ should be addressed as follows: 21 : //# Internet email: casa-feedback@nrao.edu. 22 : //# Postal address: AIPS++ Project Office 23 : //# National Radio Astronomy Observatory 24 : //# 520 Edgemont Road 25 : //# Charlottesville, VA 22903-2475 USA 26 : //# 27 : //# $Id$ 28 : #include <casacore/casa/Exceptions/Error.h> 29 : #include <casacore/casa/Arrays/ArrayMath.h> 30 : #include <casacore/casa/Arrays/ArrayLogical.h> 31 : #include <casacore/casa/Arrays/MaskedArray.h> 32 : #include <casacore/casa/Arrays/MaskArrMath.h> 33 : #include <casacore/casa/Quanta/Quantum.h> 34 : #include <casacore/casa/Quanta/MVTime.h> 35 : #include <casacore/casa/Logging/LogIO.h> 36 : #include <msvis/MSVis/VisibilityIterator.h> 37 : #include <msvis/MSVis/VisBuffer.h> 38 : #include <flagging/Flagging/RFASelector.h> 39 : 40 : #include <iomanip> 41 : 42 : namespace casa { //# NAMESPACE CASA - BEGIN 43 : 44 : // ----------------------------------------------------------------------- 45 : // reformRange 46 : // Reforms an array of 2N elements into a [2,N] matrix 47 : // ----------------------------------------------------------------------- 48 0 : template<class T> casacore::Bool RFASelector::reformRange( casacore::Matrix<T> &rng,const casacore::Array<T> &arr ) 49 : { 50 0 : if( arr.ndim()>2 || (arr.nelements()%2) !=0 ) 51 0 : return false; 52 0 : rng = arr.reform(casacore::IPosition(2,2,arr.nelements()/2)); 53 0 : return true; 54 : } 55 : 56 : template<class T> casacore::Array<T> fieldToArray( const casacore::RecordInterface &parm,const casacore::String &id ); 57 : 58 : /* 59 : template<> casacore::Array<casacore::Int> fieldToArray<casacore::Int>( const casacore::RecordInterface &parm,const casacore::String &id ) 60 : { return parm.toArrayInt(id); } 61 : template<> casacore::Array<casacore::Double> fieldToArray<casacore::Double>( const casacore::RecordInterface &parm,const casacore::String &id ) 62 : { return parm.toArrayDouble(id); } 63 : template<> casacore::Array<casacore::String> fieldToArray<casacore::String>( const casacore::RecordInterface &parm,const casacore::String &id ) 64 : { return parm.toArrayString(id); } 65 : */ 66 : 67 : // ----------------------------------------------------------------------- 68 : // RFASelector::parseRange 69 : // Returns a record field of 2N elements as a [2,N] matrix 70 : // ----------------------------------------------------------------------- 71 0 : template<class T> casacore::Bool RFASelector::parseRange( casacore::Matrix<T> &rng,const casacore::RecordInterface &parm,const casacore::String &id ) 72 : { 73 0 : if( isFieldSet(parm,id) ) 74 : { 75 : try 76 : { 77 0 : casacore::Array<T> arr( fieldToArray<T>(parm,id) ); 78 0 : if( !reformRange(rng,arr) ) 79 0 : throw( casacore::AipsError("") ); 80 0 : return true; 81 0 : } 82 0 : catch( casacore::AipsError x ) 83 : { 84 0 : os<<"Illegal \""<<id<<"\" array\n"<<casacore::LogIO::EXCEPTION; 85 : } 86 : } 87 0 : return false; 88 : } 89 : 90 : /* 91 : template casacore::Bool RFASelector::reformRange<casacore::Int>( casacore::Matrix<casacore::Int>&,const casacore::Array<casacore::Int>& ); 92 : template casacore::Bool RFASelector::reformRange<casacore::Double>( casacore::Matrix<casacore::Double>&,const casacore::Array<casacore::Double>& ); 93 : template casacore::Bool RFASelector::reformRange<casacore::String>( casacore::Matrix<casacore::String>&,const casacore::Array<casacore::String>& ); 94 : template casacore::Bool RFASelector::parseRange<casacore::Int>( casacore::Matrix<casacore::Int>&,const casacore::RecordInterface&,const casacore::String&); 95 : template casacore::Bool RFASelector::parseRange<casacore::Double>( casacore::Matrix<casacore::Double>&,const casacore::RecordInterface&,const casacore::String&); 96 : template casacore::Bool RFASelector::parseRange<casacore::String>( casacore::Matrix<casacore::String>&,const casacore::RecordInterface&,const casacore::String&); 97 : */ 98 : 99 : // ----------------------------------------------------------------------- 100 : // RFA_selector::find 101 : // Helper templated method to find an object in an array 102 : // ----------------------------------------------------------------------- 103 0 : template<class T> casacore::Bool RFASelector::find( casacore::uInt &index,const T &obj,const casacore::Vector<T> &arr ) 104 : { 105 0 : for( casacore::uInt i=0; i<arr.nelements(); i++ ) 106 0 : if( obj == arr(i) ) 107 : { 108 0 : index = i; 109 0 : return true; 110 : } 111 0 : return false; 112 : } 113 : /* 114 : template casacore::Bool RFASelector::find<casacore::uInt>(casacore::uInt&,const casacore::uInt&,const casacore::Vector<casacore::uInt>&); 115 : template casacore::Bool RFASelector::find<casacore::Int>(casacore::uInt&,const casacore::Int&,const casacore::Vector<casacore::Int>&); 116 : template casacore::Bool RFASelector::find<casacore::String>(casacore::uInt&,const casacore::String&,const casacore::Vector<casacore::String>&); 117 : */ 118 : } //# NAMESPACE CASA - END 119 :