Changeset 3713 in Sophya for trunk/SophyaPI/PIext/pitvmaad.cc


Ignore:
Timestamp:
Dec 11, 2009, 9:57:10 AM (16 years ago)
Author:
ansari
Message:

Ajout options afichage cdreal,cdimag,cdphas,cdmod,cdmod2 pour tableaux complexes, Reza 11/12/2009

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/pitvmaad.cc

    r3661 r3713  
    77#include <math.h>
    88
    9 /* --Methode-- */
    10 template <class T>
    11 POTVectorAdapter<T>::POTVectorAdapter(TVector<T>* v, bool ad)
     9// -------------------------------------------------------
     10// Decodage de la presence dans la chaine opt des options d'affichage pour tableaux complexes
     11//   cdreal , cdimag , cdphase , cdmod , cdmod2
     12PICmplxDispOption StringToCmplxDispOption( string & opt )
     13{
     14PICmplxDispOption dopt=PICDO_Module;
     15size_t olen = opt.length();
     16if (opt.find("cdmod2")<olen) dopt=PICDO_Module2;
     17else if (opt.find("cdmod")<olen) dopt=PICDO_Module;
     18else if (opt.find("cdphas")<olen) dopt=PICDO_Phase;
     19else if (opt.find("cdimag")<olen) dopt=PICDO_Imag;
     20else if (opt.find("cdreal")<olen) dopt=PICDO_Real;
     21else dopt=PICDO_Module;
     22return dopt; 
     23}
     24
     25/* --- Methodes de calcul inline pour valeurs de retour complexes ---- */
     26static inline double  _z_mod_( complex< r_4 > z)
     27{
     28  return ( sqrt((double)(z.real()*z.real()+z.imag()*z.imag() ) ) );
     29}
     30static inline double  _z_mod_( complex< r_8 > z)
     31{
     32  return ( sqrt(z.real()*z.real()+z.imag()*z.imag() )  );
     33}
     34static inline double  _z_mod2_( complex< r_4 > z)
     35{
     36  return ( (double)(z.real()*z.real()+z.imag()*z.imag() ) );
     37}
     38static inline double  _z_mod2_( complex< r_8 > z)
     39{
     40  return ( z.real()*z.real()+z.imag()*z.imag() );
     41}
     42/* ----------------------------  */
     43
     44/* --Methode-- */
     45template <class T>
     46POTVectorAdapter<T>::POTVectorAdapter(TVector<T>* v, bool ad, PICmplxDispOption dopt)
    1247        : P1DArrayAdapter(v->NElts())
    1348{
     49dOpt = dopt;
    1450aDel = ad;
    1551mVec = v;
     
    2662double POTVectorAdapter<T>::Value(int i)
    2763{
    28 return((*mVec)(i));
     64  return((double)(*mVec)(i));
    2965}
    3066
     
    3369double POTVectorAdapter< complex<float> >::Value(int i)
    3470{
    35 double re,im;
    36 re = (*mVec)(i).real();
    37 im = (*mVec)(i).imag();
    38 return(sqrt(re*re+im*im));
     71switch (dOpt) {
     72 case PICDO_Module:
     73   return _z_mod_( (*mVec)(i) );
     74   break;
     75 case PICDO_Real:
     76   return (double)(((*mVec)(i)).real());
     77   break;
     78 case PICDO_Imag:
     79   return (double)(((*mVec)(i)).imag());
     80   break;
     81 case PICDO_Phase:
     82   return atan2( (double) ((*mVec)(i).real()), (double)((*mVec)(i).imag()) );
     83   break;
     84 case PICDO_Module2:
     85   return _z_mod2_( (*mVec)(i) );
     86   break;
     87 }
    3988}
    4089
     
    4392double POTVectorAdapter< complex<double> >::Value(int i)
    4493{
    45 double re,im;
    46 re = (*mVec)(i).real();
    47 im = (*mVec)(i).imag();
    48 return(sqrt(re*re+im*im));
    49 }
    50 
    51 /* --Methode-- */
    52 template <class T>
    53 POTMatrixAdapter<T>::POTMatrixAdapter(TMatrix<T>* mtx, bool ad)
     94switch (dOpt) {
     95 case PICDO_Module:
     96   return _z_mod_( (*mVec)(i) );
     97   break;
     98 case PICDO_Real:
     99   return (double)(((*mVec)(i)).real());
     100   break;
     101 case PICDO_Imag:
     102   return (double)(((*mVec)(i)).imag());
     103   break;
     104 case PICDO_Phase:
     105   return atan2( (double) ((*mVec)(i).real()), (double)((*mVec)(i).imag()) );
     106   break;
     107 case PICDO_Module2:
     108   return _z_mod2_( (*mVec)(i) );
     109   break;
     110 }
     111}
     112
     113/* --Methode-- */
     114template <class T>
     115POTMatrixAdapter<T>::POTMatrixAdapter(TMatrix<T>* mtx, bool ad, PICmplxDispOption dopt)
    54116        : P2DArrayAdapter(mtx->NCols(), mtx->NRows())
    55117{
     118dOpt = dopt;
    56119aDel = ad;
    57120mMtx = mtx;
     
    89152double POTMatrixAdapter< complex<float> >::Value(int ix, int iy)
    90153{
    91 double re,im;
    92 re = (*mMtx)(iy, ix).real();
    93 im = (*mMtx)(iy, ix).imag();
    94 return(sqrt(re*re+im*im));
     154switch (dOpt) {
     155 case PICDO_Module:
     156   return _z_mod_( (*mMtx)(iy, ix) );
     157   break;
     158 case PICDO_Real:
     159   return (double)(((*mMtx)(iy, ix)).real());
     160   break;
     161 case PICDO_Imag:
     162   return (double)(((*mMtx)(iy, ix)).imag());
     163   break;
     164 case PICDO_Phase:
     165   return atan2( (double) ((*mMtx)(iy, ix)).real(), (double) ((*mMtx)(iy, ix)).imag() );
     166   break;
     167 case PICDO_Module2:
     168   return _z_mod2_( (*mMtx)(iy, ix) );
     169   break;
     170 }
    95171}
    96172
     
    99175double POTMatrixAdapter< complex<double> >::Value(int ix, int iy)
    100176{
    101 double re,im;
    102 re = (*mMtx)(iy, ix).real();
    103 im = (*mMtx)(iy, ix).imag();
    104 return(sqrt(re*re+im*im));
     177switch (dOpt) {
     178 case PICDO_Module:
     179   return _z_mod_( (*mMtx)(iy, ix) );
     180   break;
     181 case PICDO_Real:
     182   return (double)(((*mMtx)(iy, ix)).real());
     183   break;
     184 case PICDO_Imag:
     185   return (double)(((*mMtx)(iy, ix)).imag());
     186   break;
     187 case PICDO_Phase:
     188   return atan2( (double) ((*mMtx)(iy, ix)).real(), (double) ((*mMtx)(iy, ix)).imag() );
     189   break;
     190 case PICDO_Module2:
     191   return _z_mod2_( (*mMtx)(iy, ix) );
     192   break;
     193 }
    105194}
    106195
     
    112201if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; }
    113202if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; }   
    114 complex<float> ss = 0.;
     203complex<float> ssz = complex<float>(0.,0.);
    115204for(int j=jy1; j<=jy2; j++)
    116   for(int i=ix1; i<=ix2; i++)  ss += (*mMtx)(j, i);
    117 ss /= (double)((jy2-jy1+1)*(ix2-ix1+1));
    118 return sqrt(ss.real()*ss.real()+ss.imag()*ss.imag()); 
     205  for(int i=ix1; i<=ix2; i++)  ssz += (*mMtx)(j, i);
     206switch (dOpt) {
     207 case PICDO_Module:
     208   return _z_mod_( ssz / complex<float>((float)((jy2-jy1+1)*(ix2-ix1+1)),(float)0.) );
     209   break;
     210 case PICDO_Real:
     211   return ((double)(ssz.real())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ;
     212   break;
     213 case PICDO_Imag:
     214   return ((double)(ssz.imag())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ;
     215   break;
     216 case PICDO_Phase:
     217   return atan2( (double) ssz.real(), (double) ssz.imag() );
     218   break;
     219 case PICDO_Module2:
     220   return _z_mod2_( ssz / complex<float>((float)((jy2-jy1+1)*(ix2-ix1+1)),(float)0.) );
     221   break;
     222 }
     223return 0.; 
    119224}   
    120225
     
    126231if (ix1>ix2) { ec=ix1; ix1=ix2; ix2=ec; }
    127232if (jy1>jy2) { ec=jy1; jy1=jy2; jy2=ec; }   
    128 complex<double> ss = 0.;
     233complex<double> ssz = complex<double>(0.,0.);
    129234for(int j=jy1; j<=jy2; j++)
    130   for(int i=ix1; i<=ix2; i++)  ss += (*mMtx)(j, i);
    131 ss /= (double)((jy2-jy1+1)*(ix2-ix1+1));
    132 return sqrt(ss.real()*ss.real()+ss.imag()*ss.imag()); 
     235  for(int i=ix1; i<=ix2; i++)  ssz += (*mMtx)(j, i);
     236switch (dOpt) {
     237 case PICDO_Module:
     238   return _z_mod_( ssz / complex<double>((double)((jy2-jy1+1)*(ix2-ix1+1)),(double)0.) );
     239   break;
     240 case PICDO_Real:
     241   return ((double)(ssz.real())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ;
     242   break;
     243 case PICDO_Imag:
     244   return ((double)(ssz.imag())/(double)((jy2-jy1+1)*(ix2-ix1+1)) ) ;
     245   break;
     246 case PICDO_Phase:
     247   return atan2( (double) ssz.real(), (double) ssz.imag() );
     248   break;
     249 case PICDO_Module2:
     250   return _z_mod2_( ssz / complex<double>((double)((jy2-jy1+1)*(ix2-ix1+1)),(double)0.) );
     251   break;
     252 }
     253return 0.; 
    133254}   
     255
     256
     257
     258
    134259
    135260#ifdef __CXX_PRAGMA_TEMPLATES__
Note: See TracChangeset for help on using the changeset viewer.