casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Jones.h
Go to the documentation of this file.
00001 //# Jones.h: Definition of Jones
00002 //# Copyright (C) 1996,1997,2000,2001,2002,2003
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 adressed 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 
00028 #ifndef SYNTHESIS_JONES_H
00029 #define SYNTHESIS_JONES_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/BasicSL/Complex.h>
00033 #include <casa/iostream.h>
00034 #include <casa/Exceptions/Error.h>
00035 //#include <synthesis/MeasurementComponents/Mueller.h>
00036 #include <synthesis/MeasurementComponents/VisVector.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 class Jones {
00041   
00042 public:
00043   
00044   enum JonesType{General=4,GenLinear=3,Diagonal=2,Scalar=1};
00045 
00046   // Construct 
00047   Jones();
00048   
00049   // Dtor
00050   virtual ~Jones() {};
00051   
00052   // Return type id
00053   inline virtual JonesType type() const { return Jones::General; };
00054   inline virtual Int typesize() const { return 4; };
00055 
00056   // Set scalardata_ 
00057   //  TBD: Handle this better; for now, we need to set this from
00058   //       an external call so we handle single-corr data properly
00059   //       when setting non-corr-dep flags
00060   inline void setScalarData(Bool scalardata) const { scalardata_=scalardata; };
00061   
00062   // Synchronize with leading element in external array
00063   inline void sync(Complex& mat) { j0_=&mat; origin(); };
00064   inline void sync(Complex& mat, Bool& ok) { j0_=&mat; ok0_=&ok; origin(); };
00065   
00066   // Reset to origin
00067   inline void origin() {j_=j0_; ok_=ok0_;};
00068   
00069   // Increment to next matrix (according to type)
00070   inline void operator++()    { j_+=typesize(); if (ok_) ok_+=typesize();};
00071   inline void operator++(int) { j_+=typesize(); if (ok_) ok_+=typesize();};
00072 
00073   // Advance step matrices forward (according to typesize)
00074   inline void advance(const Int& step) { j_+=(step*typesize()); if (ok_) ok_+=(step*typesize());};
00075 
00076   // In-place invert
00077   virtual void invert();
00078 
00079   // Set matrix elements according to ok flag
00080   //   (so we don't have to check ok flags atomically in apply)
00081   virtual void setMatByOk();
00082 
00083   // In-place multipication with another Jones
00084   virtual void operator*=(const Jones& other);
00085 
00086   // Apply rightward to a VisVector
00087   virtual void applyRight(VisVector& v) const;
00088   virtual void applyRight(VisVector& v, Bool& vflag) const;
00089 
00090   // Apply leftward (transposed) to a VisVector 
00091   virtual void applyLeft(VisVector& v) const;
00092   virtual void applyLeft(VisVector& v, Bool& vflag) const;
00093 
00094   // Set flags according to solution flags
00095   virtual void applyFlag(Bool& vflag) const;
00096 
00097   // print it out
00098   friend ostream& operator<<(ostream& os, const Jones& mat);
00099 
00100   // Give access to Mueller formation method
00101   friend class Mueller;
00102   friend class MuellerDiag;
00103   friend class MuellerDiag2;
00104   friend class MuellerScal;
00105     
00106   friend class JonesDiag;
00107   friend class JonesScal;
00108 
00109 protected:
00110   
00111   // Copy ctor protected 
00112   Jones(const Jones& mat);
00113 
00114   // Pointer to origin
00115   Complex *j0_;
00116   Bool *ok0_;
00117   
00118   // Moving pointer
00119   Complex *j_, *ji_;
00120   Bool *ok_, *oki_;
00121 
00122   // Complex unity, zero
00123   const Complex cOne_,cZero_;
00124 
00125   // Is data scalar?
00126   mutable Bool scalardata_;
00127 
00128 private:
00129 
00130   // Zero the Jones matrix
00131   virtual void zero();
00132 
00133   // Temporary VisVector
00134   VisVector vtmp_;
00135   
00136 };
00137 
00138 
00139 class JonesGenLin : public Jones {
00140   
00141 public:
00142   
00143   // Construct 
00144   JonesGenLin();
00145   
00146   // Dtor
00147   virtual ~JonesGenLin() {};
00148   
00149   // Return type id
00150   inline virtual JonesType type() const { return Jones::GenLinear; };
00151   inline virtual Int typesize() const { return 2; };
00152 
00153   // In-place invert
00154   virtual void invert();
00155 
00156   // Set matrix elements according to ok flag
00157   //   (so we don't have to check ok flags atomically in apply)
00158   virtual void setMatByOk();
00159 
00160   // In-place multipication with another Jones
00161   virtual void operator*=(const Jones& other);
00162 
00163   // Apply rightward to a VisVector
00164   virtual void applyRight(VisVector& v) const;
00165   virtual void applyRight(VisVector& v, Bool& vflag) const;
00166 
00167   // Apply leftward (transposed) to a VisVector
00168   virtual void applyLeft(VisVector& v) const;
00169   virtual void applyLeft(VisVector& v, Bool& vflag) const;
00170 
00171   // Set flags according to solution flags
00172   virtual void applyFlag(Bool& vflag) const;
00173 
00174   // Give access to Mueller formation methods
00175   friend class MuellerDiag;
00176   friend class MuellerDiag2;
00177     
00178 protected:
00179   
00180   // Copy ctor protected 
00181   JonesGenLin(const JonesGenLin& mat);
00182 
00183 private:
00184 
00185   // Zero the Jones matrix
00186   virtual void zero();
00187 
00188 };
00189 
00190 
00191 class JonesDiag : public Jones {
00192   
00193 public:
00194   
00195   // Construct 
00196   JonesDiag();
00197   
00198   // Dtor
00199   virtual ~JonesDiag() {};
00200   
00201   // Return type id
00202   inline virtual JonesType type() const { return Jones::Diagonal; };
00203   inline virtual Int typesize() const { return 2; };
00204 
00205   // In-place invert
00206   virtual void invert();
00207 
00208   // Set matrix elements according to ok flag
00209   //   (so we don't have to check ok flags atomically in apply)
00210   virtual void setMatByOk();
00211 
00212   // In-place multipication with another Jones
00213   virtual void operator*=(const Jones& other);
00214 
00215   // Apply rightward to a VisVector
00216   virtual void applyRight(VisVector& v) const;
00217   virtual void applyRight(VisVector& v, Bool& vflag) const;
00218 
00219   // Apply leftward (transposed) to a VisVector
00220   virtual void applyLeft(VisVector& v) const;
00221   virtual void applyLeft(VisVector& v, Bool& vflag) const;
00222 
00223   // Set flags according to solution flags
00224   virtual void applyFlag(Bool& vflag) const;
00225 
00226   // Give access to Mueller formation methods
00227   friend class MuellerDiag;
00228   friend class MuellerDiag2;
00229     
00230 protected:
00231   
00232   // Copy ctor protected 
00233   JonesDiag(const JonesDiag& mat);
00234 
00235 private:
00236 
00237   // Zero the Jones matrix
00238   virtual void zero();
00239 
00240 };
00241 
00242 
00243 class JonesScal : public JonesDiag {
00244   
00245 public:
00246   
00247   // Construct 
00248   JonesScal();
00249   
00250   // Dtor
00251   virtual ~JonesScal() {};
00252   
00253   // Return type id
00254   inline virtual JonesType type() const { return Jones::Scalar; };
00255   inline virtual Int typesize() const { return 1; };
00256 
00257   // In-place invert
00258   virtual void invert();
00259 
00260   // Set matrix elements according to ok flag
00261   //   (so we don't have to check ok flags atomically in apply)
00262   virtual void setMatByOk();
00263 
00264   // In-place multipication with another Jones
00265   virtual void operator*=(const Jones& other);
00266 
00267   // Apply rightward to a VisVector
00268   virtual void applyRight(VisVector& v) const;
00269   virtual void applyRight(VisVector& v, Bool& vflag) const;
00270 
00271   // Apply leftward (transposed) to a VisVector
00272   virtual void applyLeft(VisVector& v) const;
00273   virtual void applyLeft(VisVector& v, Bool& vflag) const;
00274 
00275   // Set flags according to solution flags
00276   virtual void applyFlag(Bool& vflag) const;
00277 
00278   // Give access to Mueller formation methods
00279   friend class MuellerScal;
00280     
00281 protected:
00282   
00283   // Copy ctor protected 
00284   JonesScal(const JonesScal& mat);
00285 
00286 private:
00287 
00288   // Zero the Jones matrix
00289   virtual void zero();
00290 
00291 };
00292 
00293 
00294 // Global methods:
00295 
00296 // Factory method for creation of Jones
00297 Jones* createJones(const Jones::JonesType& jtype);
00298 
00299 // Apply a pair of Jones to a VisVector:
00300 void apply(const Jones& j1, VisVector& v, const Jones& j2);
00301 void apply(const Jones& j1, VisVector& v, const Jones& j2, Bool& vflag);
00302 
00303 // Return enum from integer
00304 Jones::JonesType jonesType(const Int& n);
00305 
00306 // Return parameter count from 
00307 inline Int jonesNPar(const Jones::JonesType& jtype) {
00308   switch (jtype) {
00309   case Jones::General:
00310     return 4;
00311     break;
00312   case Jones::GenLinear:
00313   case Jones::Diagonal:
00314     return 2;
00315     break;
00316   case Jones::Scalar:
00317     return 1;
00318     break;
00319   }
00320   // must return something
00321   return 0;
00322 }
00323 
00324 
00325 } //# NAMESPACE CASA - END
00326 
00327 #endif
00328 
00329