Index: trunk/Poubelle/archTOI.old/archtoi.cc
===================================================================
--- trunk/Poubelle/archTOI.old/archtoi.cc	(revision 436)
+++ trunk/Poubelle/archTOI.old/archtoi.cc	(revision 534)
@@ -9,5 +9,6 @@
 
 #include "archeopsfile.h"
-#include "toisvr.h"
+#include "toiiter.h"
+#include "toimanager.h"
 #include "archtoi.h"
 #include "archparam.h"
@@ -39,5 +40,5 @@
 {
   init();
-  svr.readReq(str);
+  iter.readReq(str);
 }
 
@@ -47,5 +48,5 @@
   init();
   ifstream str(filename.c_str());
-  svr.readReq(str);
+  iter.readReq(str);
 }
 
@@ -59,22 +60,14 @@
   ostr = NULL;
   requestVersion = "";
-  svr.registerReqHandler(this);
-}
-
-
-bool ArchTOI::processTOIReq(string line, string toiname, TOIKind /*kind*/, int index, 
-                            bool interp, bool repet, bool flag, bool /*notrig*/)
+  iter.registerReqHandler(this);
+  
+  TOIManager::registerDefaultProducers();
+}
+
+
+bool ArchTOI::processTOIReq(TOI const& toi, string line)
 {
   headertoi.push_back(line);
-  if (index>=0) {
-    char idx[10]; 
-    sprintf(idx,"_%d",index);
-    toiname += idx;
-  }
-  if (flag) {
-    toinames.push_back("flg_"+toiname);
-  }
-  toinames.push_back(toiname);
-  toiflags.push_back(flg((flag?hasflag:0)+((!repet&&!interp)?useNA:0)));
+  tois.push_back(toi);
   return true;
 } 
@@ -130,11 +123,11 @@
   
   cout << "starting query" << endl;
-  TOIIter iter = svr.doQuery();
+  iter.init();
   (this->*openFile)(outfilename);
   (this->*outHeader)(iter);
   
   cout << "processing" << endl;
-  while (iter.Next()) {
-    int nn = iter.getSampleIndex() / iter.getUnderSampling(); // Only for tick mark...
+  while (iter.next()) {
+    int nn = iter.getSampleNum() / iter.getUnderSample(); // Only for tick mark...
     #ifdef __MWERKS__
     yield();
@@ -145,21 +138,23 @@
      if (nn%(200*80) == 0) cout << endl;
     // Si rien de dispo parmi les triggering, alors on passe au suivant
-    bool hasValue = false;
-    for (int i=0; i<toiflags.size(); i++) {
-       if (!iter.isTrig(i)) continue;
-       if (iter.canGetValue(i)) {hasValue=true; break;}
-    }
-    if (!hasValue) continue;
+    // normalement, c'est gere par le toiiter...
+    //bool hasValue = false;
+    //for (int i=0; i<toiflags.size(); i++) {
+    //   if (!iter.isTrig(i)) continue;
+    //   if (iter.canGetValue(i)) {hasValue=true; break;}
+    //}
+    //if (!hasValue) continue;
     int icol=0;
-    for (int i=0; i<toiflags.size(); i++) {
+    for (int i=0; i<tois.size(); i++) {
       double value = iter.getValue(i);
       bool   ok    = iter.canGetValue(i);
-      bool   isnew = iter.newValue(i);
-      flg    flag  = toiflags[i];
-      if (flag & hasflag) {
-        (this->*outValue)(icol,  (ok && isnew ? 1 : 0));
-        icol++;
-      }
-      if (((flag & useNA)!=0 && !isnew) || !ok) 
+     // bool   isnew = iter.newValue(i);
+     // flg    flag  = toiflags[i];
+     // if (flag & hasflag) {
+     //   (this->*outValue)(icol,  (ok && isnew ? 1 : 0));
+     //   icol++;
+     // }
+     //if (((flag & useNA)!=0 && !isnew) || !ok) 
+      if (!ok) 
         (this->*outValue)(icol,  0, true);
       else
@@ -184,5 +179,5 @@
   for (list<string>::iterator i = headeropt.begin(); i != headeropt.end(); i++)
     *ostr << (*i) << '\n';;
-  block_type_param* blk = iter.lastParam();
+  block_type_param* blk = iter.getFSet().lastParam();
   if (blk) {
     int nb = blk->param.n_max_bolo;
@@ -227,4 +222,29 @@
 }
 
+list<string> ArchTOI::buildNames() {
+  list<string> toinames;
+  map<string,int> namecount;
+  
+  for (list<TOI>::iterator i = tois.begin(); i != tois.end(); i++) {
+    namecount[(*i).name]++;
+  }
+  
+  map<string,int> curcount;
+  for (list<TOI>::iterator i = tois.begin(); i != tois.end(); i++) {
+    string toiname = (*i).name;
+    if (namecount[(*i).name]>1) {
+      char s[10];
+      sprintf(s,"_%d",curcount[(*i).name]++);
+      toiname += s;
+    }
+    if ((*i).index != TOI::unspec) {
+      char s[10];
+      sprintf(s,"_%d",(*i).index);
+      toiname += s;
+    }
+    toinames.push_back(toiname);
+  }
+  return toinames;
+}
 
 void ArchTOI::openFile_F(string const& filename) {
@@ -237,5 +257,8 @@
 }
 
+
 void ArchTOI::outHeader_F(TOIIter& iter) {  
+  list<string> toinames = buildNames();
+
   int ncols=toinames.size();
   
@@ -244,8 +267,10 @@
   char** colunits = new (char*[ncols]);
   int j=0;
-  for (list<string>::iterator i = toinames.begin(); i != toinames.end(); i++,j++) {
+  list<TOI>::iterator kk = tois.begin();
+  for (list<string>::iterator i = toinames.begin(); i != toinames.end(); i++,j++,kk++) {
     colnames[j] = const_cast<char*>((*i).c_str()); // should work for most STL implementations... Check...
     coltypes[j] = "1D";
-    colunits[j] = " ";
+    colunits[j] = const_cast<char*>((*kk).unit.c_str());
+    cout << (*i).c_str() << " " << ((*kk).unit.c_str()) << endl;
   }
   
@@ -261,9 +286,11 @@
   int ntoireq = headertoi.size();
   fits_write_key(fptr, TINT, "TOIREQ", &ntoireq, NULL, &fitsStatus);
-  for (list<string>::iterator i = headertoi.begin(); i != headertoi.end(); i++,j++) {
+  list<string>::iterator kkk = toinames.begin();
+  for (list<string>::iterator i = headertoi.begin(); i != headertoi.end(); i++,j++,kkk++) {
     char line[80];
     strcpy(line, (*i).c_str());
     char* pline = line;
-    fits_write_keys_str(fptr, "TOIREQ", j, 1, &pline, (char**) NULL, &fitsStatus);
+    char* cmt   = const_cast<char*>((*kkk).c_str());
+    fits_write_keys_str(fptr, "TOIREQ", j, 1, &pline, &cmt, &fitsStatus);
   }
   j=1;
@@ -278,5 +305,5 @@
 
   // Noms des bolos
-  block_type_param* blk = iter.lastParam();
+  block_type_param* blk = iter.getFSet().lastParam();
   if (blk) {
     int nb = blk->param.n_max_bolo;
@@ -338,2 +365,4 @@
   fits_report_error(stderr, fitsStatus);  /* print out any error messages */
 }
+
+
