Index: trunk/SophyaLib/TArray/tarray.cc
===================================================================
--- trunk/SophyaLib/TArray/tarray.cc	(revision 967)
+++ trunk/SophyaLib/TArray/tarray.cc	(revision 970)
@@ -140,9 +140,9 @@
 TArray<T>& TArray<T>::Set(const TArray<T>& a)
 {
-  if (this != &a) { 
-    CloneOrShare(a);
-    if (mInfo) {delete mInfo; mInfo = NULL;}
-    if (a.mInfo) mInfo = new DVList(*(a.mInfo));
-  }
+  if (this == &a) return(*this);
+  if (a.NbDimensions() < 1) 
+    throw RangeCheckError("TArray<T>::Set(a ) - Array a not allocated ! ");
+  if (NbDimensions() < 1) CloneOrShare(a);
+  else CopyElt(a);
   return(*this);
 }
@@ -158,4 +158,23 @@
   if (a.mInfo) mInfo = new DVList(*(a.mInfo));
 }
+
+//! Clone if \b a is not temporary, share if temporary
+template <class T>
+void TArray<T>::CloneOrShare(const TArray<T>& a)
+{
+  string exmsg = "TArray<T>::CloneOrShare()";
+  if (!UpdateSizes(a.ndim_, a.size_, a.step_, a.offset_, exmsg))  throw( ParmError(exmsg) );
+  mNDBlock.CloneOrShare(a.mNDBlock);
+}
+
+//! Share data with a
+template <class T>
+void TArray<T>::Share(const TArray<T>& a)
+{
+  string exmsg = "TArray<T>::Share()";
+  if (!UpdateSizes(a.ndim_, a.size_, a.step_, a.offset_, exmsg))  throw( ParmError(exmsg) );
+  mNDBlock.Share(a.mNDBlock);
+}
+
 
 //! Resize array
@@ -261,5 +280,6 @@
     throw RangeCheckError("TArray<T>::PackElements() - Not Allocated Array ! ");
   if ( !force && (AvgStep() == 1) ) {
-    TArray<T> ra(*this, true);
+    TArray<T> ra;
+    ra.Share(*this);
     ra.SetTemp(true);
     return(ra);
@@ -408,6 +428,10 @@
 
 //! Substract a constant value \b x to an array
-template <class T>
-TArray<T>& TArray<T>::Sub(T x)
+/*! 
+Substract a constant from the *this = *this-x
+\param fginv == true : Perfoms the inverse subtraction (*this = x-(*this)) 
+*/
+template <class T>
+TArray<T>& TArray<T>::Sub(T x, bool fginv)
 {
   if (NbDimensions() < 1) 
@@ -419,5 +443,8 @@
     uint_8 maxx = totsize_*step;
     pe = Data();
-    for(k=0; k<maxx; k+=step )  pe[k] -= x;
+    if (fginv)
+      for(k=0; k<maxx; k+=step )  pe[k] = x-pe[k];
+    else
+      for(k=0; k<maxx; k+=step )  pe[k] -= x;
   }
   else {    // Non regular data spacing ...
@@ -428,5 +455,8 @@
     for(j=0; j<naxa; j++)  {
       pe = mNDBlock.Begin()+Offset(ka,j);
-      for(k=0; k<gpas; k+=step)  pe[k] -= x;
+      if (fginv)
+	for(k=0; k<gpas; k+=step)  pe[k] = x-pe[k];
+      else
+	for(k=0; k<gpas; k+=step)  pe[k] -= x;
     }
   }
@@ -462,10 +492,14 @@
 
 //! Divide an array by a constant value \b x
-template <class T>
-TArray<T>& TArray<T>::Div(T x)
+/*! 
+Divide the array by a constant *this = *this/x
+\param fginv == true : Perfoms the inverse division (*this = x/(*this)) 
+*/
+template <class T>
+TArray<T>& TArray<T>::Div(T x, bool fginv)
 {
   if (NbDimensions() < 1) 
     throw RangeCheckError("TArray<T>::Div(T )  - Not Allocated Array ! ");
-  if (x == (T) 0 ) 
+  if (!fginv && (x == (T) 0) ) 
     throw MathExc("TArray<T>::Div(T )  - Divide by zero ! ");
   T * pe;
@@ -475,5 +509,8 @@
     uint_8 maxx = totsize_*step;
     pe = Data();
-    for(k=0; k<maxx; k+=step )  pe[k] /= x;
+    if (fginv)
+      for(k=0; k<maxx; k+=step )  pe[k] = x/pe[k];
+    else 
+      for(k=0; k<maxx; k+=step )  pe[k] /= x;
   }
   else {    // Non regular data spacing ...
@@ -484,64 +521,14 @@
     for(j=0; j<naxa; j++)  {
       pe = mNDBlock.Begin()+Offset(ka,j);
-      for(k=0; k<gpas; k+=step)  pe[k] /= x;
-    }
-  }
-  return(*this);
-}
-
-
-//! Inverse substract : A = \b x - A
-template <class T>
-TArray<T>& TArray<T>::SubInv(T x)
-{
-  if (NbDimensions() < 1) 
-    throw RangeCheckError("TArray<T>::SubInv(T )  - Not Allocated Array ! ");
-  T * pe;
-  uint_8 j,k;
-  if (AvgStep() > 0)   {  // regularly spaced elements
-    uint_8 step = AvgStep();
-    uint_8 maxx = totsize_*step;
-    pe = Data();
-    for(k=0; k<maxx; k+=step )  pe[k] = x-pe[k];
-  }
-  else {    // Non regular data spacing ...
-    uint_4 ka = MaxSizeKA();
-    uint_8 step = Step(ka);
-    uint_8 gpas = Size(ka)*step;
-    uint_8 naxa = Size()/Size(ka);
-    for(j=0; j<naxa; j++)  {
-      pe = mNDBlock.Begin()+Offset(ka,j);
-      for(k=0; k<gpas; k+=step)  pe[k] = x-pe[k];
-    }
-  }
-  return(*this);
-}
-
-//! Inverse Divide : A(i,j,...) = x / A(i,j,...)
-template <class T>
-TArray<T>& TArray<T>::DivInv(T x)
-{
-  if (NbDimensions() < 1) 
-    throw RangeCheckError("TArray<T>::DivInv(T )  - Not Allocated Array ! ");
-  T * pe;
-  uint_8 j,k;
-  if (AvgStep() > 0)   {  // regularly spaced elements
-    uint_8 step = AvgStep();
-    uint_8 maxx = totsize_*step;
-    pe = Data();
-    for(k=0; k<maxx; k+=step )  pe[k] = x/pe[k];
-  }
-  else {    // Non regular data spacing ...
-    uint_4 ka = MaxSizeKA();
-    uint_8 step = Step(ka);
-    uint_8 gpas = Size(ka)*step;
-    uint_8 naxa = Size()/Size(ka);
-    for(j=0; j<naxa; j++)  {
-      pe = mNDBlock.Begin()+Offset(ka,j);
-      for(k=0; k<gpas; k+=step)  pe[k] = x/pe[k];
-    }
-  }
-  return(*this);
-}
+      if (fginv)
+	for(k=0; k<gpas; k+=step)  pe[k] = x/pe[k];
+      else 
+	for(k=0; k<gpas; k+=step)  pe[k] /= x;
+    }
+  }
+  return(*this);
+}
+
+
 
 
@@ -583,6 +570,10 @@
 
 //! Substract two TArrays
-template <class T>
-TArray<T>& TArray<T>::SubElt(const TArray<T>& a)
+/*! 
+Substract two TArrays *this = *this-a
+\param fginv == true : Perfoms the inverse subtraction (*this = a-(*this)) 
+*/
+template <class T>
+TArray<T>& TArray<T>::SubElt(const TArray<T>& a, bool fginv)
 {
   if (NbDimensions() < 1) 
@@ -600,5 +591,8 @@
     pe = Data();
     pea = a.Data();
-    for(k=0, ka=0;  k<maxx;  k+=step, ka+=stepa )  pe[k] -= pea[ka] ;
+    if (fginv) 
+      for(k=0, ka=0;  k<maxx;  k+=step, ka+=stepa )  pe[k] = pea[ka]-pe[k] ;
+    else 
+      for(k=0, ka=0;  k<maxx;  k+=step, ka+=stepa )  pe[k] -= pea[ka] ;
   }
   else {    // Non regular data spacing ...
@@ -611,9 +605,13 @@
       pe = mNDBlock.Begin()+Offset(ax,j);
       pea = a.DataBlock().Begin()+a.Offset(ax,j);
-      for(k=0, ka=0;  k<gpas;  k+=step, ka+=stepa)  pe[k] -= pea[ka]; 
-    }
-  }
-  return(*this);
-}
+      if (fginv) 
+	for(k=0, ka=0;  k<gpas;  k+=step, ka+=stepa)  pe[k] = pea[ka]-pe[k] ;
+      else
+	for(k=0, ka=0;  k<gpas;  k+=step, ka+=stepa)  pe[k] -= pea[ka]; 
+    }
+  }
+  return(*this);
+}
+
 
 //! Multiply two TArrays (elements by elements)
@@ -654,6 +652,10 @@
 
 //! Divide two TArrays (elements by elements)
-template <class T>
-TArray<T>& TArray<T>::DivElt(const TArray<T>& a)
+/*! 
+Divide two TArrays *this = (*this)/a
+\param fginv == true : Perfoms the inverse division (*this = a/(*this)) 
+*/
+template <class T>
+TArray<T>& TArray<T>::DivElt(const TArray<T>& a, bool fginv)
 {
   if (NbDimensions() < 1) 
@@ -671,5 +673,8 @@
     pe = Data();
     pea = a.Data();
-    for(k=0, ka=0;  k<maxx;  k+=step, ka+=stepa )  pe[k] /= pea[ka] ;
+    if (fginv) 
+      for(k=0, ka=0;  k<maxx;  k+=step, ka+=stepa )  pe[k] = pea[ka]/pe[k];
+    else 
+      for(k=0, ka=0;  k<maxx;  k+=step, ka+=stepa )  pe[k] /= pea[ka] ;
   }
   else {    // Non regular data spacing ...
@@ -682,5 +687,8 @@
       pe = mNDBlock.Begin()+Offset(ax,j);
       pea = a.DataBlock().Begin()+a.Offset(ax,j);
-      for(k=0, ka=0;  k<gpas;  k+=step, ka+=stepa)  pe[k] /= pea[ka]; 
+      if (fginv) 
+	for(k=0, ka=0;  k<gpas;  k+=step, ka+=stepa)  pe[k] = pea[ka]/pe[k]; 
+      else
+	for(k=0, ka=0;  k<gpas;  k+=step, ka+=stepa)  pe[k] /= pea[ka]; 
     }
   }
@@ -835,22 +843,4 @@
 }
 
-//! Clone if \b a is not temporary, share if temporary
-template <class T>
-void TArray<T>::CloneOrShare(const TArray<T>& a)
-{
-  string exmsg = "TArray<T>::CloneOrShare()";
-  if (!UpdateSizes(a.ndim_, a.size_, a.step_, a.offset_, exmsg))  throw( ParmError(exmsg) );
-  mNDBlock.CloneOrShare(a.mNDBlock);
-}
-
-//! Share data with a
-template <class T>
-void TArray<T>::Share(const TArray<T>& a)
-{
-  string exmsg = "TArray<T>::Share()";
-  if (!UpdateSizes(a.ndim_, a.size_, a.step_, a.offset_, exmsg))  throw( ParmError(exmsg) );
-  mNDBlock.Share(a.mNDBlock);
-}
-
 
 
