Index: trunk/SophyaLib/TArray/utilarr.cc
===================================================================
--- trunk/SophyaLib/TArray/utilarr.cc	(revision 1550)
+++ trunk/SophyaLib/TArray/utilarr.cc	(revision 1558)
@@ -112,9 +112,22 @@
   for(int k=0; k<8; k++) 
     cout << " k= " << k << " es(k)= " << es(k) << endl; 
+
+  // Decoding a sequence from a string
+  EnumeratedSequence ess;
+  int nbad;
+  ess.Append("56.5 (1.,-1.) 4 8 16", nbad);
+  cout << ess;
   \endcode
 */
 
+//! Default constructor
 EnumeratedSequence::EnumeratedSequence()
 {
+}
+
+//! Copy constructor
+EnumeratedSequence::EnumeratedSequence(EnumeratedSequence const & es)
+{
+  Append(es);
 }
 
@@ -131,4 +144,5 @@
 }
 
+//! Appends a new value to the sequence
 EnumeratedSequence & EnumeratedSequence::operator , (MuTyV const & v)
 {
@@ -137,4 +151,5 @@
 }
 
+//! Initialize the sequence with a single value \b v
 EnumeratedSequence & EnumeratedSequence::operator = (MuTyV const & v)
 {
@@ -144,11 +159,14 @@
 }
 
-EnumeratedSequence & EnumeratedSequence::Merge(EnumeratedSequence const & seq)
-{
-  for(int k=0; k<seq.vecv_.size(); k++) 
-    vecv_.push_back(seq.vecv_[k]);
-  return(*this);
-}
-
+//! Copy operator
+EnumeratedSequence & EnumeratedSequence::operator = (EnumeratedSequence const & seq)
+{
+  Clear();
+  Append(seq);
+  return(*this);  
+}
+
+
+//! Prints the list to the output stream \b os
 void EnumeratedSequence::Print(ostream& os) const 
 {
@@ -159,18 +177,127 @@
     else os << " " ;
   }
+  os << endl;
   return;
 }
 
-sa_size_t EnumeratedSequence::FillFromString(string const & str)
-{
-  cerr << " EnumeratedSequence::FillFromString() pas implemente !" << endl;
-  return (0);
-}
-
+//! Append the \b seq to the end of the sequence.
+/*!
+  \return the number of added elements.
+*/ 
+sa_size_t EnumeratedSequence::Append(EnumeratedSequence const & seq)
+{
+  for(int k=0; k<seq.vecv_.size(); k++) 
+    vecv_.push_back(seq.vecv_[k]);
+  return(seq.vecv_.size());
+}
+
+//! Decodes the string, appending values to the end of the sequence.
+/*!
+  \param str : string to be decoded
+  \param nbad : number of unmatched quotes or parenthesis
+  \return the number of added elements.
+*/ 
+sa_size_t EnumeratedSequence::Append(string const & str, int& nbad)
+{
+  nbad = 0;
+  sa_size_t n = 0;
+  size_t l = str.length();
+  if (l < 1) return(0);
+  if ((str[0] == '#') || (str[0] == '*')) return(0);
+  size_t q = 0;
+  size_t p = str.find_first_not_of(" \t");
+  if ((str[p] == '+') || (str[p] == '-')) {
+    if (p == l-1)  return(0);
+    if (!isdigit(str[p+1])) return(0);
+  }
+  else if (!isdigit(str[p]) && (str[p] != '\'') && (str[p] != '(') ) return(0);
+
+  while(q < l) {
+    p = str.find_first_not_of(" \t",q);
+    if (p >= l)  break;
+    if (str[p] == '\'')    {  // Decodage d'un string
+      q = str.find('\'',p+1);
+      if (q < l) {
+	vecv_.push_back(MuTyV(str.substr(p+1,q-p-1)));
+	n++;	q++;
+      }
+      else nbad++;
+    }
+    else if (str[p] == '(')    {  // Decodage d'un complex
+      q = str.find(')',p);
+      if (q < l) {
+	q++;
+	MuTyV mtv(str.substr(p,q-p));
+	complex<double> z = mtv;
+	vecv_.push_back(MuTyV(z));
+	n++;
+      }
+      else nbad++;      
+    }
+    else { 
+      q = str.find_first_of(" \t",p);
+      if (!isdigit(str[p]) && !(str[p] == '+') && !(str[p] == '-') ) { // une chaine
+	continue;
+      }
+      else {  // C'est un nombre 
+	if (str.find('.',p) < q)   { // c'est un flottant
+	  r_8 x = atof(str.substr(p,q-p).c_str());
+	  vecv_.push_back(MuTyV(x));
+	}
+	else {   // un entier
+	  int_8 l = atol(str.substr(p,q-p).c_str());
+	  vecv_.push_back(MuTyV(l));
+	}
+	n++;
+      }
+    }
+  }
+  return (n);
+}
+
+//! Decodes the input ASCII stream, creating a sequence of values
+/*! \param is : Input ASCII stream
+    \param nr : Number of non empty (or comment) lines in stream (return value)
+    \param nc : Number of columns (= ntot/nlines) (return value)
+    \return Number of decoded elements
+*/
 sa_size_t EnumeratedSequence::FillFromFile(istream& is, 
 					   sa_size_t& nr, sa_size_t& nc)
 {
-  cerr << " EnumeratedSequence::FillFromFile() pas implemente !" << endl;
-  return (0);
+  nr = 0;
+  nc = 0;
+  sa_size_t n = 0;
+  char buff[256];
+  string line;
+  int nbad, nbadtot, nel;
+  nbadtot = nbad = 0;
+  while (!is.eof()) {
+    is.clear(); 
+    is.getline(buff, 256);
+    line += buff;
+    if (is.good()) {
+      nel = Append(line, nbad);
+      cout << " Decoding line = " << line << " Nel= " << nel << endl;
+      if (nel > 0)  { 
+	nr++;  n += nel;
+      }
+      nbadtot += nbad;
+      line = "";
+    }
+  }
+  if (line.length() > 0) {
+    nel = Append(line, nbad);
+    cout << " Decoding Eline = " << line << " Nel= " << nel << endl;
+    if (nel > 0)  { 
+      nr++;  n += nel;
+    }
+    nbadtot += nbad;
+    line = ""; 
+  }
+  if (nbadtot > 0) 
+    cout << "EnumeratedSequence::FillFromFile()/Warning " << nbadtot 
+	 << " bad match (quotes or parenthesis) in stream " << endl;
+  nc = n/nr;
+  return (n);
 }
 
