Index: trunk/SophyaLib/TArray/basarr.cc
===================================================================
--- trunk/SophyaLib/TArray/basarr.cc	(revision 2915)
+++ trunk/SophyaLib/TArray/basarr.cc	(revision 2917)
@@ -360,5 +360,5 @@
 }
 
-//! Change dimension if some size == 1
+//! Compact arrays - supresses size=1 axes.
 void BaseArray::CompactAllDim()
 {
@@ -383,5 +383,5 @@
 }
 
-//! Change dimension if some trailed size == 1
+//! Compact array taling dimensions, for size=1 traling axes.
 void BaseArray::CompactTrailingDim()
 {
@@ -391,7 +391,7 @@
   sa_size_t step[BASEARRAY_MAXNDIMS];
   for(int_4 k=0; k<ndim_; k++) {
-    size[ndim] = size_[k];
-    step[ndim] = step_[k];
-    if (size_[k] > 1)  ndim=k;
+    size[k] = size_[k];
+    step[k] = step_[k];
+    if (size_[k] > 1)  ndim=k+1;
   }
   if (ndim == 0)  ndim = 1;
@@ -714,12 +714,11 @@
 
 
-//! Update sizes and information relative to array \b a
-/*!
-  \param a : array to be compare with
-  \param ndim : could be change (but should be less than the ndim of the current class)
-  \param siz[ndim],pos[ndim],step[ndim] : could be changed but must be
-             compatible within the memory size with those of the current class.
-  \return true if all OK, false if problems appear
-  \return string \b exmsg for explanation in case of problems
+//! Update sizes information for sub-array \b ra
+/*!
+  \param ra : sub-array for which size information has to be computed 
+  \param ndim : number of dimensions for \b ra
+  \param siz[ndim],pos[ndim],step[ndim] : number of elements, offset and step along each dimension,
+   relative to the original array.
+  \warning throw SzMismatchError in case of incompatible dimensions.
  */
 void BaseArray::UpdateSubArraySizes(BaseArray & ra, int_4 ndim, sa_size_t * siz, sa_size_t * pos, sa_size_t * step) const
@@ -729,5 +728,5 @@
   int_4 k;
   for(k=0; k<ndim; k++) 
-    if ( (siz[k]*step[k]+pos[k]) > size_[k] )  
+    if ( ((siz[k]-1)*step[k]+pos[k]) >= size_[k] )  
       throw(SzMismatchError("BaseArray::UpdateSubArraySizes( ... ) Size/Pos Error") );
   sa_size_t offset = offset_;
Index: trunk/SophyaLib/TArray/basarr.h
===================================================================
--- trunk/SophyaLib/TArray/basarr.h	(revision 2915)
+++ trunk/SophyaLib/TArray/basarr.h	(revision 2917)
@@ -68,8 +68,4 @@
   virtual bool CompareSizes(const BaseArray& a, bool& smo) const;
 
-  // Compacts \b size=1 array dimensions
-  virtual void CompactAllDim(); // suppresses all size==1 dimensions 
-  virtual void CompactTrailingDim(); // suppresses size==1 dimensions after the last size>1 dimension
-
   // Array dimensions
   //! Return true if the array was allocated ( Rank() > 0 )
@@ -170,4 +166,7 @@
   inline int_4 CheckDI(int_4 ka, int msg) const ;
   inline void CheckBound(sa_size_t ix, sa_size_t iy, sa_size_t iz, sa_size_t it, sa_size_t iu, int msg) const ;
+  // Compacts size=1 array dimensions
+  void CompactAllDim(); // suppresses all size==1 dimensions 
+  void CompactTrailingDim(); // suppresses size==1 dimensions after the last size>1 dimension
   // Changing Sizes/NDim ... return true if OK
   bool UpdateSizes(int_4 ndim, const sa_size_t * siz, sa_size_t step, sa_size_t offset, string & exmsg);
Index: trunk/SophyaLib/TArray/sopemtx.h
===================================================================
--- trunk/SophyaLib/TArray/sopemtx.h	(revision 2915)
+++ trunk/SophyaLib/TArray/sopemtx.h	(revision 2917)
@@ -20,6 +20,11 @@
   \class SimpleMatrixOperation
   \ingroup TArray
-  Class for simple operation on TMatrix
-  \sa TMatrix TArray
+  \brief Class for simple operation on TMatrix
+  This class provides presently a basic implementation of the Gauss 
+  pivoting for linear system solving and matrix inversion. 
+
+  \warning For large or ill conditioned matrices, use the methods 
+  from LinAlg module. 
+  \sa SOPHYA::LapackServer  SOPHYA::TMatrix 
 */
 //! Class for simple operation on TMatrix
Index: trunk/SophyaLib/TArray/tarray.cc
===================================================================
--- trunk/SophyaLib/TArray/tarray.cc	(revision 2915)
+++ trunk/SophyaLib/TArray/tarray.cc	(revision 2917)
@@ -17,13 +17,35 @@
   Class for template arrays with numerical data types (int, float, complex).
 
-  This class implements arrays with number of dimensions up to
-  \ref BASEARRAY_MAXNDIMS "BASEARRAY_MAXNDIMS"
-
-  Standard arithmetic operations on numerical arrays are implemented,
-  as well as sub-array manipulation services.
+  This class handles arrays with number of dimensions up to
+  \ref BASEARRAY_MAXNDIMS "BASEARRAY_MAXNDIMS" (=5). The class has a performant 
+  memory management system, including reference sharing for the array data.
+  (copy constructor and sub-arrays (or slices)). 
+
+  An important feature of this class is the transparent handling of sub-arrays,
+  or slices. Arbitrary sub-arrays or slices can be defined, provided regular 
+  spacing along each array axe (or dimension). 
+  The second example below illustrate the use of this possibility.
+  
+  Standard arithmetic operations, sum or product as well as application of usual
+  math functions (Sin, Cos ...) on numerical arrays are implemented.
+  These operations usually provide high performance, despite of the complex 
+  memory management pattern.
+
+  ASCII input/output (or read write) and binary I/O (persistence) in different
+  formats are also provided through helper (or handler) classes.
+
+  This class is mainly intented for arrays with large number of data elements.
+  (Size() \> 100 .. 1000). Arrays with few data elements (\< 10) have significant 
+  memory overhead, due to variables describing array shape and memory organisation.
+  However, a single higher dimensional array can be used to represent a large number 
+  of identical size small arrays. For example, TArray<T> tab(2,2, 1000) can be used
+  to hold 1000 2x2 matrices.
+
   \b Array is a typedef for double precision floating point arrays ( TArray<r_8> )
+
   \sa SOPHYA::Range
   \sa SOPHYA::Sequence
   \sa SOPHYA::MathArray
+  \sa SOPHYA::NDataBlock
 
   \code
@@ -35,5 +57,5 @@
   es = 24, 35, 46, 57, 68;
   ia = es;
-  cout << "Array<int> ia = " << ia;
+  cout << "Array<int> ia = \n" << ia;
   // 2-D array of floats 
   TArray<r_4> b(6,4), c(6,4);
@@ -44,7 +66,21 @@
   // Arithmetic operations
   TArray<r_4> d = b+0.3f*c;
-  cout << "Array<float> d = " << d;  
+  cout << "Array<float> d = \n" << d;  
   \endcode
 
+  Example for sub-arrays, or slices
+  \code 
+  // Creating and initialising a 2-D (6 x 4) array of integers
+  TArray<int> iaa(6, 4);
+  iaa = RegularSequence(1,2);
+  cout << "Array<int> iaa = \n" << iaa;
+  // We extract a sub-array - data is shared with iaa
+  TArray<int> iae = iaa(Range(1, Range::lastIndex(), 3) ,
+                        Range::all(), Range::first() );
+  cout << "Array<int> iae=subarray(iaa) = \n" << iae;
+  // Changing iae elements changes corresponding iaa elements
+  iae = 0;
+  cout << "Array<int> iae=0 --> iaa = \n" << iaa;
+  \endcode 
 */
 
@@ -344,5 +380,10 @@
 
 
-//! Compact dimensions in one or more is equal to 1.
+/*!
+  \brief Compact arrays - supresses size=1 axes.
+  Changes the array rank (number of dimensions), suppressing all axes with size equal 1.
+  Example: 
+  Compacting Rank=NDim=5  Sizes=3x1x6x1x1  =====\>  Rank=NDim=2  Sizes=3x6 
+*/
 template <class T>
 TArray<T>& TArray<T>::CompactAllDimensions()
@@ -352,5 +393,11 @@
 }
 
-//! Compact dimensions if the last one is equal to 1.
+/*!
+  \brief Compact array taling dimensions, for size=1 traling axes.
+  Changes the array rank (number of dimensions), suppressing all axes with size equal 1,
+  after the last axe with size \> 1
+  Example: 
+  Compacting Rank=NDim=5  Sizes=3x1x6x1x1  =====\>  Rank=NDim=3  Sizes=3x1x6 
+*/
 template <class T>
 TArray<T>& TArray<T>::CompactTrailingDimensions()
@@ -393,6 +440,8 @@
 }
 
-//! Return array with elements packed
-/*!
+/*!
+  \brief Return a new array with elements packed in memory
+
+
   \param force : if true, pack elements in a new array.
                  If false and array is already packed, return
@@ -424,8 +473,10 @@
 /*!
   \param rx,ry,rz,rt,ru : range of extraction along dimensions
+  \param compact : if \b compact == true, compact trailing dimensions (suppressed if =1)
+  (See CompactTrailingDimensions() )
   \sa SOPHYA::Range
  */
 template <class T>
-TArray<T> TArray<T>::SubArray(Range rx, Range ry, Range rz, Range rt, Range ru) const
+TArray<T> TArray<T>::SubArray(Range rx, Range ry, Range rz, Range rt, Range ru, bool compact) const
 {
   if (NbDimensions() < 1) 
@@ -467,4 +518,5 @@
   UpdateSubArraySizes(ra, ndim, size, pos, step); 
   ra.DataBlock().Share(this->DataBlock());
+  if (compact) ra.CompactTrailingDim();
   ra.SetTemp(true);
   return(ra);
Index: trunk/SophyaLib/TArray/tarray.h
===================================================================
--- trunk/SophyaLib/TArray/tarray.h	(revision 2915)
+++ trunk/SophyaLib/TArray/tarray.h	(revision 2917)
@@ -75,5 +75,5 @@
 
   // SubArrays - $CHECK$ Reza 03/2000 je ne sais pas s'il faut declarer ca const ??
-  TArray<T> SubArray(Range rx, Range ry, Range rz, Range rt, Range ru) const ;
+  TArray<T> SubArray(Range rx, Range ry, Range rz, Range rt, Range ru, bool compact=true) const ;
 
   //! Extract the first 3D subarray specified by rx, ry, rz. (see SubArray() )
Index: trunk/SophyaLib/TArray/tmatrix.cc
===================================================================
--- trunk/SophyaLib/TArray/tmatrix.cc	(revision 2915)
+++ trunk/SophyaLib/TArray/tmatrix.cc	(revision 2917)
@@ -1,3 +1,3 @@
-// $Id: tmatrix.cc,v 1.34 2006-02-22 18:17:30 ansari Exp $
+// $Id: tmatrix.cc,v 1.35 2006-02-23 13:50:26 ansari Exp $
 //                         C.Magneville          04/99
 #include "sopnamsp.h"
@@ -17,9 +17,17 @@
   two dimensional arrays as matrices. Matrix and vector operations,
   such as matrix multiplication or transposition is implemented.
+
+  Sub-matrices, in particular matrix rows and columns can easily and 
+  efficiently be extracted and manipulated.
+  It should be noted that a significant memory overhead is associated with
+  small matrices (typically less than 10x10=100 elements).However, 
+  higher dimension arrays (3D for examples) can be used to represent large 
+  number of small matrices or vectors.
+
   \b Matrix is a typedef for double precision floating point matrix ( TMatrix<r_8> ).
 
   \sa SOPHYA::TArray  SOPHYA::TVector
-  \sa SOPHYA::Range  \sa SOPHYA::Sequence
-  \sa SOPHYA::MathArray  \sa SOPHYA::SimpleMatrixOperation
+  \sa SOPHYA::Range   SOPHYA::Sequence
+  \sa SOPHYA::MathArray  SOPHYA::SimpleMatrixOperation
 
   The following sample code illustrates vector-matrix multiplication 
@@ -254,5 +262,5 @@
   if (mm == CMemoryMapping)  { rx = rcol;  ry = rline; }
   else { ry = rcol;  rx = rline; }
-  TMatrix sm(SubArray(rx, ry, Range::first(), Range::first(), Range::first()), true);
+  TMatrix sm(SubArray(rx, ry, Range::first(), Range::first(), Range::first(), false), true);
   sm.UpdateMemoryMapping(mm);
   return(sm);
Index: trunk/SophyaLib/TArray/utilarr.cc
===================================================================
--- trunk/SophyaLib/TArray/utilarr.cc	(revision 2915)
+++ trunk/SophyaLib/TArray/utilarr.cc	(revision 2917)
@@ -313,16 +313,18 @@
   \class SOPHYA::Range
   \ingroup TArray
-  Class to define a range of indices, to be used with TArra<T> TMatrix<T> TVector<T> ...
-*/
-
-/*!
-  Constructor defining defining the range of indices, starting from \b start to the last.
-  \param start : start index (inclusive)
+  This class can be used to define a range of indices. Range objects are used to extract 
+  sub-arrays and slices, from arrays and matrices. 
+  \sa SOPHYA::TArray SOPHYA::TMatrix
+*/
+
+/*!
+  Constructor defining a range corresponding to the single index \b start
+  \param start : start=end index 
 */
 Range::Range(sa_size_t start)
 {
   start_ = start;
-  end_ = Range::lastIndex();
-  size_ = 0;
+  end_ = start;
+  size_ = 1;
   step_ = 1;
 }
@@ -375,6 +377,6 @@
   if (size > 0) {  // Nb d'elements fixe
     size_ = size;
-    if (end == Range::lastIndex())  start_ = end_ = end;
-    else end_ = start_+size_*step_;    
+    if ( (start == end) && (end == Range::lastIndex()) ) start_ = end_ = end;
+    else end_ = start_+(size_-1)*step_;    
   }
   else {
@@ -406,5 +408,5 @@
 void Range::Update(sa_size_t osz)
 {
-  if (end_ >= 0)  return;
+  if (end_ >= 0)  return; 
   if (osz == 0) {
     start_ = end_ = 0;
@@ -415,5 +417,5 @@
     end_ = osz-1; 
     if ((size_ > 0) && (size_ <= osz/step_)) 
-      start_ = end_ - size_*step_;
+      start_ = end_ - (size_-1)*step_;
     else {
       start_ = end_; 
@@ -425,4 +427,6 @@
     size_ = (end_-start_)/step_+1;
   }
+  //DBG  cout << ">>> DBG/Update start=" << start_ << " end=" << end_ 
+  //DBG     << " size=" << size_ << " step=" << step_ << endl;
   return;
 }
@@ -443,8 +447,9 @@
   \class SOPHYA::IdentityMatrix
   \ingroup TArray
-  Class to define an identity matrix
-*/
-
-//! Constructor of a (n,n) diagonal matrix with value diag on the diagonal
+  Class to define an identity matrix. This class is mainly intented for 
+  initializing TMatrix<T> objects, proportional to the identity matrix. 
+*/
+
+//! Constructor representing a square matrix (\b n x \b n) with value \b diag on the diagonal
 IdentityMatrix::IdentityMatrix(double diag, sa_size_t n)
 {
Index: trunk/SophyaLib/TArray/utilarr.h
===================================================================
--- trunk/SophyaLib/TArray/utilarr.h	(revision 2915)
+++ trunk/SophyaLib/TArray/utilarr.h	(revision 2917)
@@ -128,5 +128,5 @@
 class Range {
 public:
-  //! Index range start \<= index \<= last()
+  //! Index range containing a single index = \b start 
   Range(sa_size_t start);
   //! Index range start \<= index \<= end
@@ -153,5 +153,5 @@
   //! return a Range object specifing the first index
   inline static Range first()
-  { return Range(Range::firstIndex() , Range::lastIndex(), 1, 1); }
+  { return Range(Range::firstIndex() , Range::firstIndex(), 1, 1); }
   //! return a Range object specifing the last valid index
   inline static Range last()
