casa
$Rev:20696$
|
00001 //# SpectralList.h: A set of SpectralElements 00002 //# Copyright (C) 2001 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 //# $Id: SpectralList.h 20229 2008-01-29 15:19:06Z gervandiepen $ 00028 00029 #ifndef COMPONENTS_SPECTRALLIST_H 00030 #define COMPONENTS_SPECTRALLIST_H 00031 00032 //# Includes 00033 #include <casa/aips.h> 00034 #include <casa/Containers/Block.h> 00035 00036 namespace casa { //# NAMESPACE CASA - BEGIN 00037 00038 //# Forward Declarations 00039 class SpectralElement; 00040 class RecordInterface; 00041 class String; 00042 template <class T> class Vector; 00043 00044 // <summary> 00045 // A set of SpectralElements 00046 // </summary> 00047 00048 // <use visibility=export> 00049 00050 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tSpectralFit" demos=""> 00051 // </reviewed> 00052 00053 // <prerequisite> 00054 // <li> <linkto class=SpectralElement>SpectralElement</linkto> class 00055 // </prerequisite> 00056 // 00057 // <etymology> 00058 // From spectral line and element list 00059 // </etymology> 00060 // 00061 // <synopsis> 00062 // The SpectralList class is a container for a set of spectral elements. 00063 // 00064 // The list can be used in the 00065 // <linkto class=SpectralFit>SpectralFit</linkto> class and in the 00066 // <linkto class=SpectralEstimate>SpectralEstimate</linkto> class. 00067 // 00068 // </synopsis> 00069 // 00070 // <example> 00071 // </example> 00072 // 00073 // <motivation> 00074 // To have a container for fitting of spectral profiles to an observed spectrum 00075 // </motivation> 00076 // 00077 // <todo asof="2001/02/04"> 00078 // <li> add more profile types 00079 // </todo> 00080 00081 class SpectralList { 00082 public: 00083 00084 //# Constructors 00085 // Default constructor creates an empty list 00086 SpectralList(); 00087 // Construct a list with a maximum length of n (0: unlimited length) 00088 explicit SpectralList(uInt nmax); 00089 // Construct with an initial element 00090 explicit SpectralList(const SpectralElement &in); 00091 // Copy constructor (deep copy) 00092 SpectralList(const SpectralList &other); 00093 00094 //#Destructor 00095 // Destructor 00096 ~SpectralList(); 00097 00098 //# Operators 00099 // Assignment (copy semantics) 00100 SpectralList &operator=(const SpectralList &other); 00101 // Evaluate the value of the sum of the elements at x 00102 Double operator()(const Double x) const; 00103 // Get element n 00104 // <thrown> 00105 // <li> AipsError if illegal n 00106 // </thrown> 00107 // <group> 00108 const SpectralElement* operator[](const uInt n) const; 00109 SpectralElement* operator[](const uInt n); 00110 // </group> 00111 00112 //# Member functions 00113 // Get the number of elements in list 00114 uInt nelements() const { return list_p.nelements(); }; 00115 00116 // Get the profile values for all elements in list. The evaluation 00117 // is for the length of the given <src>prof</src>, assuming x values of 00118 // 0,1,... if no x given. 00119 // <group> 00120 template <class MT> 00121 void evaluate(Vector<MT> &y) const; 00122 template <class MT> 00123 void evaluate(Vector<MT> &y, const Vector<MT> &x) const; 00124 // </group> 00125 00126 // Calculate the residuals at the points x; by subtracting the model from y. 00127 // x=0,1,2,.. if not given. 00128 // <thrown> 00129 // <li> AipsError if y and x have different lengths 00130 // </thrown> 00131 // <group> 00132 template <class MT> 00133 void residual(Vector<MT> &y) const; 00134 template <class MT> 00135 void residual(Vector<MT> &y, const Vector<MT> &x) const; 00136 // </group> 00137 00138 // Add elements to list (False if list has max length and full) 00139 // <group> 00140 Bool add(const SpectralElement &in); 00141 Bool add(const SpectralList &in); 00142 // </group> 00143 // Insert in sort order in the list 00144 // <group> 00145 void insert(const SpectralElement &in); 00146 void insert(const SpectralList &in); 00147 // </group> 00148 // Set an element in the list. Return False if more than one place beyond 00149 // end of list; or if beyond max size. 00150 Bool set(const SpectralElement &in, const uInt which); 00151 00152 // Clear the list 00153 void clear(); 00154 00155 // Set a maximum size of the list 00156 void set(const uInt nmax); 00157 00158 // Sort the list on the first parameter (i.e. peak value for Gaussian) 00159 void sort(); 00160 00161 // Convert to and from a Record (see details in SpectralElement) 00162 // <group> 00163 Bool fromRecord (String& errMsg, const RecordInterface& container); 00164 Bool toRecord(RecordInterface& container) const; 00165 //</group> 00166 00167 private: 00168 //#Data 00169 // Max length allowed of list 00170 uInt nmax_p; 00171 // List of elements 00172 PtrBlock<SpectralElement *> list_p; 00173 00174 //# Member functions 00175 // Compare two elements 00176 Int compar(const SpectralElement &p1, const SpectralElement &p2) const; 00177 00178 }; 00179 00180 //# Global functions 00181 // <summary> Global functions </summary> 00182 // <group name=Output> 00183 // Output declaration 00184 std::ostream &operator<<(std::ostream &os, const SpectralList &lst); 00185 // </group> 00186 00187 00188 } //# NAMESPACE CASA - END 00189 00190 #ifndef CASACORE_NO_AUTO_TEMPLATES 00191 #include <components/SpectralComponents/SpectralList2.tcc> 00192 #endif //# CASACORE_NO_AUTO_TEMPLATES 00193 #endif