casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
StokesUtil.h
Go to the documentation of this file.
00001 //# StokesUtil.h:
00002 //# Copyright (C) 1996,1999,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$
00028 
00029 #ifndef SYNTHESIS_STOKESUTIL_H
00030 #define SYNTHESIS_STOKESUTIL_H
00031 
00032 
00033 #include <casa/aips.h>
00034 #include <casa/Arrays/Array.h>
00035 #include <synthesis/MSVis/StokesVector.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 // <summary>
00040 // for use with StokesVectors and related classes
00041 // </summary>
00042 
00043 // <use visibility=export>
00044 
00045 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00046 // </reviewed>
00047 
00048 // <prerequisite> <li> StokesVector </prerequisite>
00049 //
00050 // <synopsis>
00051 // Global Functions to operate on StokesVectors. Currently this includes
00052 // functions to convert arrays from/to arrays of StokesVectors and some
00053 // miscellaneous mathematical operations. 
00054 
00055 // The {un,re}packStokes functions convert between an Array of StokesVector
00056 // or CStokesvector into an Array of Float/Double or Complex/DComplex. The
00057 // Float/Double array has one more dimension than the corresponding
00058 // StokesVector array, and this extra dimension (always the slowest moving
00059 // or last one) has a length of 4. The output array is always resized to the
00060 // appropriate size.
00061 
00062 // The StokesVector comparison functions use the the "length" of the
00063 // StokesVector (ie. sqrt(I^2+Q^2+U^2+V^2)) to make a comparison. In
00064 // particular the abs() function returns the "length" of the
00065 // StokesVector. It is called abs rather than say length() to allow
00066 // StokesVectors to utilise other globals functions (like allNearAbs())
00067 // which expect the absolute value function to be defined.
00068 
00069 // </synopsis>
00070 //
00071 // <motivation>
00072 // g++ does not like templated and non-templated code in the same file. So
00073 // the templated stuff was split off and put into this file. Later this
00074 // became a convient place to put all the global functions, and the
00075 // non-templated global functions are also defined here (and the
00076 // implementation is put in a separate .cc file)
00077 // </motivation>
00078 //
00079 //
00080 // <thrown>
00081 //    <li> repackStokes()::AipsError
00082 // </thrown>
00083 //
00084 // <todo asof="yyyy/mm/dd">
00085 //   <li> I am uncertain how efficient any of these functions are.
00086 // </todo>
00087 
00088 // <linkfrom anchor="StokesVector ancillary functions" classes="StokesVector CStokesVector">
00089 //   <here>StokesVector ancillary functions</here> -- Ancillary functions
00090 //   used to manipulate StokesVector and related classes
00091 // </linkfrom>
00092 
00093 
00094 // <group name="StokesVector ancillary Functions">
00095 // <group>
00096 // Convert an Array of StokesVectors to an array of Floats or Doubles
00097 // (depending on the templates). The same function can be used to convert an
00098 // array of CStokesVectors to a Complex or DComplex  Array. I have not
00099 // tested if this works for other template types.
00100 template<class T, class U> void 
00101 unpackStokes(Array<U>& output, const Array<T>& input);
00102 
00103 // Convert an Array of Floats or Doubles to an Array of StokesVectors. The
00104 // same function can be used to convert a Complex/DComplex array to an array
00105 // of CStokesVector. The last non-degenerate axis on the input array MUST be
00106 // of length 4
00107 template<class T, class U> void 
00108 repackStokes(Array<U>& output, const Array<T>& input);
00109 // </group>
00110 
00111 // These Functions to multiply a StokesVector by an Array of Floats. The
00112 // result is an Array of StokesVectors that is the same size as the Array of
00113 // Floats with each polarization being the Array of floats multiplied by the
00114 // corresponding component in the supplied StokesVector.  
00115 // <group>
00116 Array<StokesVector> operator* (const Array<Float> & farray, 
00117                                const StokesVector & sv);
00118 inline Array<StokesVector> operator* (const StokesVector & sv,
00119                                const Array<Float> & farray){
00120   return farray*sv;
00121 }
00122 // </group>
00123 
00124 // Functions to compare stokesVectors with each other. They are all based on
00125 // the norm derived using the "length" of the vector in 4-space.
00126 // <group>
00127 inline Float abs(const StokesVector& sv){
00128   return sqrt(innerProduct(sv,sv));
00129 }
00130 
00131 Bool operator>(const StokesVector& left,const StokesVector& right); 
00132 
00133 inline Bool operator<(const StokesVector& left, const StokesVector& right){
00134   return !(left>right);
00135 }
00136 
00137 // </group>
00138 
00139 // Functions to determine if  one StokesVector is near another
00140 // <group>
00141 Bool nearAbs(const StokesVector& val1, const StokesVector& val2, 
00142               Double tol = 1.0e-5);
00143 
00144 Bool near(const StokesVector& val1, const StokesVector& val2, 
00145           Double tol = 1.0e-5);
00146 // </group>
00147 
00148 
00149 // </group>
00150 
00151 } //# NAMESPACE CASA - END
00152 
00153 #ifndef AIPS_NO_TEMPLATE_SRC
00154 #include <synthesis/MeasurementEquations/StokesUtil.tcc>
00155 #endif //# AIPS_NO_TEMPLATE_SRC
00156 #endif