Index: trunk/SophyaLib/TArray/tarray.cc
===================================================================
--- trunk/SophyaLib/TArray/tarray.cc	(revision 2909)
+++ trunk/SophyaLib/TArray/tarray.cc	(revision 2915)
@@ -424,5 +424,5 @@
 /*!
   \param rx,ry,rz,rt,ru : range of extraction along dimensions
-  \sa Range
+  \sa SOPHYA::Range
  */
 template <class T>
@@ -432,4 +432,14 @@
     throw RangeCheckError("TArray<T>::operator () (Range, ...) - Not Allocated Array ! ");
   int_4 ndim = 0;
+
+  // Updating Range objects using actual array size
+  rx.Update(SizeX());
+  ry.Update(SizeY());
+  rz.Update(SizeZ());
+  if (NbDimensions() > 3)  rt.Update(Size(3));
+  else rt.Update(0);
+  if (NbDimensions() > 4)  ru.Update(Size(4));
+  else  ru.Update(0);
+
   sa_size_t size[BASEARRAY_MAXNDIMS];
   sa_size_t step[BASEARRAY_MAXNDIMS];
Index: trunk/SophyaLib/TArray/tarray.h
===================================================================
--- trunk/SophyaLib/TArray/tarray.h	(revision 2909)
+++ trunk/SophyaLib/TArray/tarray.h	(revision 2915)
@@ -77,10 +77,11 @@
   TArray<T> SubArray(Range rx, Range ry, Range rz, Range rt, Range ru) const ;
 
-  //! () operator for Sub arrays extraction
-  /*! \sa SubArray */
+  //! Extract the first 3D subarray specified by rx, ry, rz. (see SubArray() )
   inline TArray<T> operator () (Range rx, Range ry, Range rz) const
-                   { return  SubArray(rx, ry, rz, Range(0), Range(0)); }
+                   { return  SubArray(rx, ry, rz, Range::first(), Range::first()); }
+  //! Extract the first 4D subarray specified by rx, ry, rz. (see SubArray() )
   inline TArray<T> operator () (Range rx, Range ry, Range rz, Range rt) const
-                   { return  SubArray(rx, ry, rz, rt, Range(0)); }
+                   { return  SubArray(rx, ry, rz, rt, Range::first()); }
+  //! Extract the subarray specified by rx, ry, rz. (see SubArray() )
   inline TArray<T> operator () (Range rx, Range ry, Range rz, Range rt, Range ru) const
                    { return  SubArray(rx, ry, rz, rt, ru); }
Index: trunk/SophyaLib/TArray/tmatrix.cc
===================================================================
--- trunk/SophyaLib/TArray/tmatrix.cc	(revision 2909)
+++ trunk/SophyaLib/TArray/tmatrix.cc	(revision 2915)
@@ -1,3 +1,3 @@
-// $Id: tmatrix.cc,v 1.33 2006-01-03 14:17:46 ansari Exp $
+// $Id: tmatrix.cc,v 1.34 2006-02-22 18:17:30 ansari Exp $
 //                         C.Magneville          04/99
 #include "sopnamsp.h"
@@ -249,9 +249,10 @@
 TMatrix<T> TMatrix<T>::SubMatrix(Range rline, Range rcol) const
 {
-  Range rx, ry;
+  Range rx=Range::first();
+  Range ry=Range::first();
   short mm = GetMemoryMapping();
   if (mm == CMemoryMapping)  { rx = rcol;  ry = rline; }
   else { ry = rcol;  rx = rline; }
-  TMatrix sm(SubArray(rx, ry, Range(0), Range(0), Range(0)),true);
+  TMatrix sm(SubArray(rx, ry, Range::first(), Range::first(), Range::first()), true);
   sm.UpdateMemoryMapping(mm);
   return(sm);
Index: trunk/SophyaLib/TArray/tvector.cc
===================================================================
--- trunk/SophyaLib/TArray/tvector.cc	(revision 2909)
+++ trunk/SophyaLib/TArray/tvector.cc	(revision 2915)
@@ -1,3 +1,3 @@
-// $Id: tvector.cc,v 1.20 2006-01-03 14:17:46 ansari Exp $
+// $Id: tvector.cc,v 1.21 2006-02-22 18:17:30 ansari Exp $
 //                         C.Magneville          04/99
 #include "sopnamsp.h"
@@ -188,5 +188,6 @@
 TVector<T> TVector<T>::SubVector(Range relt) const
 {
-  Range rr, cr;
+  Range rr=Range::first();
+  Range cr=Range::first();
   if (GetVectorType() == ColumnVector )  rr = relt; 
   else cr = relt;
Index: trunk/SophyaLib/TArray/utilarr.cc
===================================================================
--- trunk/SophyaLib/TArray/utilarr.cc	(revision 2909)
+++ trunk/SophyaLib/TArray/utilarr.cc	(revision 2915)
@@ -313,17 +313,59 @@
   \class SOPHYA::Range
   \ingroup TArray
-  Class to define a range of indexes
-*/
-
-//! Constructor
-/*!
-  Define a range of indexes
+  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)
+*/
+Range::Range(sa_size_t start)
+{
+  start_ = start;
+  end_ = Range::lastIndex();
+  size_ = 0;
+  step_ = 1;
+}
+
+/*!
+  Constructor defining defining the range of indices, from \b start to \b end
   \param start : start index (inclusive)
   \param end : end index (inclusive)
-  \param size : size (number of elements, used if end \<= start)
-  \param step : step (or stride)
-
-  \warning If \b end \> \b start, \b size is computed automatically
-  \warning If not \b size is fixed and \b end recomputed
+*/
+Range::Range(sa_size_t start, sa_size_t end)
+{
+  start_ = start;
+  end_ = end;
+  if (end >= start)   size_ = end-start+1;
+  else size_ = 0;
+  step_ = 1;
+}
+
+/*!
+  Constructor defining defining the range of indices, from \b start to \b end
+  \param start : start index (inclusive)
+  \param end : end index (inclusive)
+  \param step : step (or stride) = index increment
+*/
+Range::Range(sa_size_t start, sa_size_t end, sa_size_t step)
+{
+  start_ = start;
+  end_ = end;
+  step_ = (step > 0) ? step : 1;
+  if (step < 1) step = 1;
+  if (end >= start) 
+    size_ = (end-start)/step_+1;
+  else size_ = 0;
+}
+
+/*!
+  Define a range of indices
+  \param start : start index (inclusive)
+  \param end : end index (inclusive, used if size \<= 0 and end \>= start)
+  \param size : size (number of elements, used if \>= 1 )
+  \param step : step (or stride) = index increment
+
+  \warning If \b size \>= 1 , \b end index computed automatically. 
+  If \b size \< 1 and \b end < \b start , equivalent to \b end = Range()::lastIndex() 
  */
 Range::Range(sa_size_t start, sa_size_t end, sa_size_t size, sa_size_t step)
@@ -331,13 +373,57 @@
   start_ = start;
   step_ = (step > 0) ? step : 1;
-  if (end > start) {  // Taille calcule automatiquement 
-    end_ = end;
-    if (step_ > ((end_-start_)+1))  size_ = 1;
-    else size_ = ((end-start)+1)/step_;
-  }
-  else {     // Taille fixee
+  if (size > 0) {  // Nb d'elements fixe
     size_ = size;
-    end_ = start_+size_*step_;
-  }
+    if (end == Range::lastIndex())  start_ = end_ = end;
+    else end_ = start_+size_*step_;    
+  }
+  else {
+    if (end >= start) {  // Indice de fin fixe 
+      end_ = end;
+      size_ = (end-start)/step_+1;
+    }
+    else {  // rien fixe
+      size_ = 0;
+      end_ = Range::lastIndex();
+    }
+  }
+}
+
+/*
+Range::Range(Range const& a)
+{
+  start_ = a.start_;
+  end_ = a.end_;
+  size_ = a.size_;
+  step_ = a.step_;
+}
+*/
+
+/*!
+  This method is called to recompute index ranges, specifying the original array size
+  by the TArray<T> (or derived classes) sub array extraction methods
+*/ 
+void Range::Update(sa_size_t osz)
+{
+  if (end_ >= 0)  return;
+  if (osz == 0) {
+    start_ = end_ = 0;
+    size_ = step_ = 1;
+    return;
+  }
+  if (end_ == start_) {
+    end_ = osz-1; 
+    if ((size_ > 0) && (size_ <= osz/step_)) 
+      start_ = end_ - size_*step_;
+    else {
+      start_ = end_; 
+      size_ = 1;
+    }
+  }
+  else {
+    end_ = osz-1; 
+    size_ = (end_-start_)/step_+1;
+  }
+  return;
 }
 
Index: trunk/SophyaLib/TArray/utilarr.h
===================================================================
--- trunk/SophyaLib/TArray/utilarr.h	(revision 2909)
+++ trunk/SophyaLib/TArray/utilarr.h	(revision 2915)
@@ -128,5 +128,12 @@
 class Range {
 public:
-  explicit Range(sa_size_t start=0, sa_size_t end=0, sa_size_t size=1, sa_size_t step=1);
+  //! Index range start \<= index \<= last()
+  Range(sa_size_t start);
+  //! Index range start \<= index \<= end
+  Range(sa_size_t start, sa_size_t end); 
+  //! Index range start \<= index \<= end with increment step 
+  Range(sa_size_t start, sa_size_t end, sa_size_t step);
+  //! General Index range specification, using size or start/end and increment
+  Range(sa_size_t start, sa_size_t end, sa_size_t size, sa_size_t step);
   //! Return the start index
   inline sa_size_t & Start()  {  return start_; }
@@ -137,4 +144,21 @@
   //! Return the step
   inline sa_size_t & Step()   {  return step_; }
+  //! return a constant value defining the first element
+  inline static sa_size_t firstIndex() { return 0; }
+  //! return a constant value as a placeholder for the last valid index 
+  inline static sa_size_t lastIndex() { return -1; }
+  //! return a Range object specifing all indices, from first to last
+  inline static Range all() 
+  { return Range(Range::firstIndex() , Range::lastIndex()); }
+  //! return a Range object specifing the first index
+  inline static Range first()
+  { return Range(Range::firstIndex() , Range::lastIndex(), 1, 1); }
+  //! return a Range object specifing the last valid index
+  inline static Range last()
+  { return Range(Range::lastIndex() , Range::lastIndex(), 1, 1); }
+
+  //! For internal TArray module use.
+  void Update(sa_size_t osz);
+
 protected:
   sa_size_t start_; //!< start index
