Index: trunk/SophyaLib/TArray/basarr.cc
===================================================================
--- trunk/SophyaLib/TArray/basarr.cc	(revision 804)
+++ trunk/SophyaLib/TArray/basarr.cc	(revision 813)
@@ -14,10 +14,21 @@
 				 "Stride(int )", "ElemCheckBound()", "operator()" };
 uint_4 BaseArray::max_nprt_ = 50;
+uint_4 BaseArray::prt_lev_ = 0;
 short  BaseArray::default_memory_mapping = CMemoryMapping;
-
-// Methodes statiques globales
-void BaseArray::SetMaxPrint(uint_4 nprt)
+short  BaseArray::default_vector_type = ColumnVector;
+uint_8 BaseArray::openmp_size_threshold = 200000;
+
+// ------ Methodes statiques globales --------
+
+//  1/ Gestion des impressions 
+void BaseArray::SetMaxPrint(uint_4 nprt, uint_4 lev)
 {
   max_nprt_ = nprt;
+  prt_lev_ = (lev < 3) ? lev : 3;
+}
+
+void BaseArray::SetOpenMPSizeThreshold(uint_8 thr)
+{
+  openmp_size_threshold = thr;
 }
 
@@ -32,9 +43,15 @@
 short BaseArray::SetDefaultMemoryMapping(short mm)
 {
-  default_memory_mapping = ( (mm == CMemoryMapping) ? CMemoryMapping : FortranMemoryMapping) ; 
+  default_memory_mapping = (mm != CMemoryMapping) ? FortranMemoryMapping : CMemoryMapping; 
   return default_memory_mapping;
 }
 
-
+short BaseArray::SetDefaultVectorType(short vt)
+{
+  default_vector_type = (vt != ColumnVector) ? RowVector : ColumnVector ; 
+  return default_vector_type;
+}
+
+// Memory organisation 
 short BaseArray::SelectMemoryMapping(short mm)
 // si mm == CMemoryMapping, elements d'une ligne suivant X (consecutif)
@@ -44,31 +61,88 @@
   else return (default_memory_mapping);
 }
-
-void BaseArray::UpdateMemoryMapping(short mm, uint_4 & nx, uint_4 & ny)
-{
+short BaseArray::SelectVectorType(short vt)
+{
+  if ((vt == ColumnVector) || (vt == RowVector))  return(vt);
+  else return(default_vector_type);
+}
+
+void BaseArray::UpdateMemoryMapping(short mm)
+{
+  short vt = default_vector_type;
   if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) mm = default_memory_mapping;
   if (mm == CMemoryMapping) {
-    marowi_ = veceli_ = 1;  macoli_ = 0;
-    uint_4 nr = nx;
-    nx = ny;   ny = nr;
-  }
-  else {
-    marowi_ = veceli_ = 0;  macoli_ = 1;
-  }  
+    marowi_  = 1;  macoli_ = 0;
+  }
+  else {
+    marowi_ = 0;  macoli_ = 1;
+  }
+
+  if ( (ndim_ == 2) && ((size_[0] == 1) || (size_[1] == 1)) ) {
+    // Choix automatique Vecteur ligne ou colonne
+    if ( size_[macoli_] == 1)  veceli_ = marowi_;
+    else veceli_ = macoli_;
+  }
+  else veceli_ = (vt ==  ColumnVector ) ?  marowi_ : macoli_;
+  ck_memo_vt_ = true;   // Check MemMapping and VectorType for CompareSize  
 }
 
 void BaseArray::UpdateMemoryMapping(BaseArray const & a, short mm)
 {
-  if (mm == SameMemoryMapping) 
+  short vt = default_vector_type;
+  if (mm == SameMemoryMapping) {
     mm = ((a.marowi_ == 1) ? CMemoryMapping : FortranMemoryMapping);
+    vt = (a.marowi_ == a.veceli_) ? ColumnVector : RowVector;
+  }
+  else if (mm == AutoMemoryMapping)   mm = default_memory_mapping;
+
   if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) mm = default_memory_mapping;
   if (mm == CMemoryMapping) {
-    marowi_ = veceli_ = 1;  macoli_ = 0;
-  }
-  else {
-    marowi_ = veceli_ = 0;  macoli_ = 1;
-  }  
-}
-
+    marowi_  = 1;  macoli_ = 0;
+  }
+  else {
+    marowi_ = 0;  macoli_ = 1;
+  }
+  if ( (ndim_ == 2) && ((size_[0] == 1) || (size_[1] == 1)) ) {
+    // Choix automatique Vecteur ligne ou colonne
+    if ( size_[macoli_] == 1)  veceli_ = marowi_;
+    else veceli_ = marowi_;
+  }
+  else veceli_ = (vt ==  ColumnVector ) ?  marowi_ : macoli_;
+  ck_memo_vt_ = true;   // Check MemMapping and VectorType for CompareSize  
+}
+
+void BaseArray::SetMemoryMapping(short mm)
+{
+  if (mm == SameMemoryMapping) return;
+  if (mm == AutoMemoryMapping)  mm = default_memory_mapping;
+  if ( (mm != CMemoryMapping) && (mm != FortranMemoryMapping) ) return;
+  short vt = (marowi_ == veceli_) ? ColumnVector : RowVector;
+  if (mm == CMemoryMapping) {
+    marowi_ =  1;  macoli_ = 0;
+  }
+  else {
+    marowi_ =  0;  macoli_ = 1;
+  }
+  if ( (ndim_ == 2) && ((size_[0] == 1) || (size_[1] == 1)) ) {
+    // Choix automatique Vecteur ligne ou colonne
+    if ( size_[macoli_] == 1)  veceli_ = marowi_;
+    else veceli_ = macoli_;
+  }
+  else   veceli_ = (vt ==  ColumnVector ) ?  marowi_ : macoli_;
+  ck_memo_vt_ = true;   // Check MemMapping and VectorType for CompareSize  
+}
+
+void BaseArray::SetVectorType(short vt)
+{
+  if (vt == SameVectorType) return;
+  if (vt == AutoVectorType) vt =  default_vector_type;
+  if ( (ndim_ == 2) && ((size_[0] == 1) || (size_[1] == 1)) ) {
+    // Choix automatique Vecteur ligne ou colonne
+    if ( size_[macoli_] == 1)  veceli_ = marowi_;
+    else veceli_ = macoli_;
+  }
+  else  veceli_ = (vt ==  ColumnVector ) ?  marowi_ : macoli_;
+  ck_memo_vt_ = true;   // Check MemMapping and VectorType for CompareSize  
+}
 
 // -------------------------------------------------------
@@ -87,7 +161,13 @@
   moystep_ = 0;
   offset_ = 0;
-  // Default for matrices : Lines = Y , Columns = X, Default Vectore= ColumnVector
-  macoli_ = 0;
-  veceli_ = marowi_ = 1;
+  // Default for matrices : Memory organisation and Vector type 
+  if (default_memory_mapping == CMemoryMapping) {
+    marowi_ =  1;  macoli_ = 0;
+  }
+  else {
+    marowi_ =  0;  macoli_ = 1;
+  }
+  veceli_ = (default_vector_type ==  ColumnVector ) ?  marowi_ : macoli_;
+  ck_memo_vt_ = false;   // Default : Don't Check MemMapping and VectorType for CompareSize  
 }
 
@@ -103,6 +183,8 @@
   for(int k=0; k<ndim_; k++) 
     if (size_[k] != a.size_[k])  return(false);
-  if ( (macoli_ != a.macoli_) || (marowi_ != a.marowi_) ||
-       (veceli_ != a.veceli_) )  return(false);
+  //  $CHECK$   Reza doit-on verifier ca 
+  if (ck_memo_vt_ && a.ck_memo_vt_)
+    if ( (macoli_ != a.macoli_) || (marowi_ != a.marowi_) ||
+         (veceli_ != a.veceli_) )  return(false);
   return(true);
 }
@@ -166,15 +248,55 @@
 
 //  Acces lineaire aux elements ....  Calcul d'offset
+// --------------------------------------------------
+// Position de l'element 0 du vecteur i selon l'axe ka
+// --------------------------------------------------
+uint_8 BaseArray::Offset(uint_4 ka, uint_8 i) const
+{
+
+  if ( (ndim_ < 1) || (i == 0) )  return(offset_);
+  //#ifdef SO_BOUNDCHECKING
+  if (ka >= ndim_) 
+    throw RangeCheckError("BaseArray::Offset(uint_4 ka, uint_8 i) Axe KA Error");
+  if ( i*size_[ka] >= totsize_ )  
+    throw RangeCheckError("BaseArray::Offset(uint_4 ka, uint_8 i) Index Error");
+  //#endif
+  uint_4 idx[BASEARRAY_MAXNDIMS];
+  int k;
+  uint_8 rest = i;
+  idx[ka] = 0;
+  for(k=0; k<ndim_; k++) {
+    if (k == ka) continue;
+    idx[k] = rest%size_[k];   rest /= size_[k];
+  }
+  uint_8 off = offset_;
+  for(k=0; k<ndim_; k++)  off += idx[k]*step_[k];
+  return (off);
+}
 
 uint_8 BaseArray::Offset(uint_8 ip) const
 {
-if (ip == 0)  return(offset_);
-uint_4 idx[BASEARRAY_MAXNDIMS];
-int k;
-uint_8 rest = ip;
-for(k=0; k<ndim_; k++)   { idx[k] = rest%size_[k];   rest /= size_[k];  }   
-uint_8 off = offset_;
-for(k=0; k<ndim_; k++)  off += idx[k]*step_[k];
-return (off);
+  if ( (ndim_ < 1) || (ip == 0) )  return(offset_);
+  //#ifdef SO_BOUNDCHECKING
+  if (ip >= totsize_)
+    throw RangeCheckError("BaseArray::Offset(uint_8 ip) Out of range index ip");
+  //#endif
+
+  uint_4 idx[BASEARRAY_MAXNDIMS];
+  int k;
+  uint_8 rest = ip;
+  for(k=0; k<ndim_; k++) {
+    idx[k] = rest%size_[k];   rest /= size_[k];
+  }
+  //#ifdef SO_BOUNDCHECKING
+  if (rest != 0) 
+    throw PError("BaseArray::Offset(uint_8 ip) GUG !!! rest != 0");
+  //#endif
+//   if (rest != 0) cerr << " BUG ---- BaseArray::Offset( " << ip << " )" << rest << endl;
+//   cerr << " DBG-Offset( " << ip << ")" ;
+//   for(k=0; k<ndim_; k++) cerr << idx[k] << "," ;
+//   cerr << " ZZZZ " << endl;
+  uint_8 off = offset_;
+  for(k=0; k<ndim_; k++)  off += idx[k]*step_[k];
+  return (off);
 }
 
@@ -186,19 +308,32 @@
 void BaseArray::Show(ostream& os, bool si) const
 {
-  os << " TArray< " << DataType() << " >  NDim= " << ndim_
-     << "(" << typeid(*this).name() << " )" << endl;
-  os << "TotSize=" << totsize_ << " Size(X*Y*...)= " ;
+  os << "\n--- " << InfoString() ; 
+  os << " ND=" << ndim_ << " SizeX*Y*...= " ;
   for(int k=0; k<ndim_; k++) { 
     os << size_[k];
-    if (k<ndim_-1)  os << " x ";
-  }
-  os << endl;
-  os <<  " Step(X Y ...)= " ;
-  for(int k=0; k<ndim_; k++)     os << step_[k] << "  " ;
-  os << " Offset= " << offset_  << "\n " << endl;
-  if (si && (mInfo != NULL)) os << (*mInfo) << endl;
+    if (k<ndim_-1)  os << "x";
+  }
+  os << " ---" << endl;
+  if (prt_lev_ > 0) {
+    os <<  " TotSize= " << totsize_ << " Step(X Y ...)="  ;
+    for(int k=0; k<ndim_; k++)     os << step_[k] << "  " ;
+    os << " Offset= " << offset_  << endl;
+  }
+  if (prt_lev_ > 1) {
+    os << " MemoryMapping=" << GetMemoryMapping() << " VecType= " << GetVectorType()
+       << " RowsKA= " << RowsKA() << " ColsKA= " << ColsKA() 
+       << " VectKA=" << VectKA() << endl;
+  }
+  if (!si && (prt_lev_ < 2)) return;
+  if (mInfo != NULL) os << (*mInfo) << endl;
  
 }
 
+string BaseArray::InfoString() const
+{
+  string rs = "BaseArray Type= ";
+  rs +=  typeid(*this).name() ;
+  return rs;
+}
 
 DVList& BaseArray::Info()
@@ -238,7 +373,13 @@
   }
   offset_ = offset;
-  // Default for matrices : Lines = Y , Columns = X
-  macoli_ = 0;
-  marowi_ = veceli_ = 1;
+  // Default for matrices : Memory organisation and Vector type 
+  if (default_memory_mapping == CMemoryMapping) {
+    marowi_ =  1;  macoli_ = 0;
+  }
+  else {
+    marowi_ =  0;  macoli_ = 1;
+  }
+  veceli_ = (default_vector_type ==  ColumnVector ) ?  marowi_ : macoli_;
+  ck_memo_vt_ = false;   // Default : Don't Check MemMapping and VectorType for CompareSize  
   // Update OK 
   ndim_ = ndim;
@@ -280,7 +421,13 @@
   minstep_ = minstep;
   offset_ = offset;
-  // Default for matrices : Lines = Y , Columns = X
-  macoli_ = 0;
-  marowi_ = veceli_ = 1;
+  // Default for matrices : Memory organisation and Vector type 
+  if (default_memory_mapping == CMemoryMapping) {
+    marowi_ =  1;  macoli_ = 0;
+  }
+  else {
+    marowi_ =  0;  macoli_ = 1;
+  }
+  veceli_ = (default_vector_type ==  ColumnVector ) ?  marowi_ : macoli_;
+  ck_memo_vt_ = false;   // Default : Don't Check MemMapping and VectorType for CompareSize  
   // Update OK 
   ndim_ = ndim;
@@ -323,4 +470,5 @@
   marowi_ = a.marowi_;
   veceli_ = a.veceli_;
+  ck_memo_vt_ = a.ck_memo_vt_;
   // Update OK 
   ndim_ = a.ndim_;
