Changeset 1081 in Sophya for trunk/SophyaLib/TArray/tarray.cc
- Timestamp:
- Jul 24, 2000, 2:51:27 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/tarray.cc
r1072 r1081 131 131 } 132 132 133 //! Constructor with size and contents copied (after conversion) from a different type TArray 134 template <class T> 135 TArray<T>::TArray(const BaseArray& a) 136 : BaseArray() , mNDBlock() 137 { 138 string exmsg = "TArray<T>::TArray(const BaseArray&)"; 139 if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) ); 140 mNDBlock.ReSize(totsize_); 141 // if (a.mInfo) mInfo = new DVList(*(a.mInfo)); - pb protected ! 142 ConvertAndCopyElt(a); 143 } 144 133 145 //! Destructor 134 146 template <class T> … … 155 167 } 156 168 169 //! Set array elements equal to the \b a array elements, after conversion 170 template <class T> 171 TArray<T>& TArray<T>::SetBA(const BaseArray& a) 172 { 173 if (this == &a) return(*this); 174 if (a.NbDimensions() < 1) 175 throw RangeCheckError("TArray<T>::SetBA(a ) - Array a not allocated ! "); 176 if (NbDimensions() < 1) { 177 string exmsg = "TArray<T>::SetBA(const BaseArray& a)"; 178 if (!UpdateSizes(a, exmsg)) throw( ParmError(exmsg) ); 179 mNDBlock.ReSize(totsize_); 180 } 181 ConvertAndCopyElt(a); 182 return(*this); 183 } 184 157 185 //! Clone array \b a 158 186 template <class T> … … 233 261 } 234 262 235 inline double _SqrtRz_(double x) { return sqrt(x); } // Pb avec SGI-CC - $CHECK$ - Reza 04/2000236 237 263 //! Give value (in \b double) for element at position \b ip.. 238 264 template <class T> 239 doubleTArray<T>::ValueAtPosition(uint_8 ip) const265 MuTyV & TArray<T>::ValueAtPosition(uint_8 ip) const 240 266 { 241 267 #ifdef SO_BOUNDCHECKING 242 268 if (ip >= totsize_) throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") ); 243 269 #endif 244 return( (double)(*(mNDBlock.Begin()+Offset(ip))) ); 245 } 246 247 //! Give value (in \b double) for element at position \b ip.. 248 /*! 249 For complex values, we return the module of the complex number 250 */ 251 double TArray< complex<r_4> >::ValueAtPosition(uint_8 ip) const 252 { 253 #ifdef SO_BOUNDCHECKING 254 if (ip >= totsize_) throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") ); 255 #endif 256 complex<r_4> c = *(mNDBlock.Begin()+Offset(ip)); 257 double cr = (double)(c.real()); 258 double ci = (double)(c.imag()); 259 return( _SqrtRz_(cr*cr+ci*ci) ); 260 } 261 262 //! Give value (in \b double) for element at position \b ip.. 263 /*! 264 For complex values, we return the module of the complex number 265 */ 266 double TArray< complex<r_8> >::ValueAtPosition(uint_8 ip) const 267 { 268 #ifdef SO_BOUNDCHECKING 269 if (ip >= totsize_) throw( ParmError("TArray<T>::ValueAtPosition(uint_8 ip) Out-of-bound Error") ); 270 #endif 271 complex<r_8> c = *(mNDBlock.Begin()+Offset(ip)); 272 double cr = (double)(c.real()); 273 double ci = (double)(c.imag()); 274 return( _SqrtRz_(cr*cr+ci*ci) ); 270 my_mtv = *(mNDBlock.Begin()+Offset(ip)); 271 return( my_mtv ); 275 272 } 276 273 … … 754 751 for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = pea[ka]; 755 752 } 753 } 754 return(*this); 755 } 756 757 //! Converts and Copy elements of \b a 758 template <class T> 759 TArray<T>& TArray<T>::ConvertAndCopyElt(const BaseArray& a) 760 { 761 if (NbDimensions() < 1) 762 throw RangeCheckError("TArray<T>::ConvertAndCopyElt(const TArray<T>& ) - Not Allocated Array ! "); 763 if (!CompareSizes(a)) 764 throw(SzMismatchError("TArray<T>::ConvertAndCopyElt(const TArray<T>&) SizeMismatch")) ; 765 766 T * pe; 767 uint_8 j,k,ka; 768 uint_8 offa; 769 // Non regular data spacing ... 770 uint_4 ax = MaxSizeKA(); 771 uint_8 step = Step(ax); 772 uint_8 stepa = a.Step(ax); 773 uint_8 gpas = Size(ax)*step; 774 uint_8 naxa = Size()/Size(ax); 775 for(j=0; j<naxa; j++) { 776 pe = mNDBlock.Begin()+Offset(ax,j); 777 offa = a.Offset(ax,j); 778 for(k=0, ka=0; k<gpas; k+=step, ka+=stepa) pe[k] = a.ValueAtPosition(offa+ka); 756 779 } 757 780 return(*this);
Note:
See TracChangeset
for help on using the changeset viewer.