Index: trunk/SophyaPI/PIext/basexecut.cc
===================================================================
--- trunk/SophyaPI/PIext/basexecut.cc	(revision 341)
+++ trunk/SophyaPI/PIext/basexecut.cc	(revision 344)
@@ -155,6 +155,8 @@
 // Gestion des repertoires
 else if (kw == "mkdir" ) {
-  if (tokens.size() < 1) { cout << "Usage: mkdir dirname " << endl; return(0); }
-  mObjMgr->CreateDir(tokens[0]);  
+  if (tokens.size() < 1) { cout << "Usage: mkdir dirname [true]" << endl; return(0); }
+  bool crd = mObjMgr->CreateDir(tokens[0]);  
+  if ( crd && (tokens.size() > 1) && (tokens[1] == "true") )
+    mObjMgr->SetKeepOldDirAtt(tokens[0], true);
   }
 else if (kw == "rmdir" ) {
@@ -460,9 +462,16 @@
 else if (kw == "ntloop" ) {
   if (tokens.size() < 3) { 
-    cout << "Usage: ntloop nameobj fname funcname [ntname]" << endl;
+    cout << "Usage: ntloop nameobj fname funcname [ntname [N1 N2] ]" << endl;
     return(0);
     }
   if (tokens.size() < 4)  tokens.push_back("");
-  srvo->FillNTFrCFile(tokens[0],tokens[1], tokens[2], tokens[3]);
+  if (tokens[3] == "!") tokens[3] = "";
+  int nl1 = -1;
+  int nl2 = -1;
+  if (tokens.size() > 5) { 
+    nl1 = atoi(tokens[4].c_str()); 
+    nl2 = atoi(tokens[5].c_str());
+    }
+  srvo->FillNTFrCFile(tokens[0],tokens[1], tokens[2], tokens[3], nl1, nl2);
   }
 
@@ -626,5 +635,6 @@
 kw = "mkdir";
 usage = "Create a directory";
-usage += "\n Usage: mkdir dirname";
+usage += "\n Usage: mkdir dirname [true]";
+usage += "\n if second argument==true, the directory's KeepOld attribute is set to true";
 mpiac->RegisterCommand(kw, usage, this, "Object Managment");
 kw = "rmdir";
@@ -796,5 +806,6 @@
 usage = "Loops over an Object NTupleInterface calling a function from a C-file \n";
 usage += "and optionaly fills an NTuple(x,y,z,t) with (X=f(Object),Y=g(...),Z=h(...),T=k(...))";
-usage += "\n Usage: ntloop nameobj CFileName FuncName [NtupleName]";
+usage += "\n Usage: ntloop nameobj CFileName FuncName [NtupleName [N1 N2] ]";
+usage += "\n Or:    ntloop nameobj CFileName FuncName ! N1 N2 ";
 usage += "\n  Related commands: ntexpcfile fillnt";
 mpiac->RegisterCommand(kw, usage, this, "Expr. Plotting");
Index: trunk/SophyaPI/PIext/nobjmgr.cc
===================================================================
--- trunk/SophyaPI/PIext/nobjmgr.cc	(revision 341)
+++ trunk/SophyaPI/PIext/nobjmgr.cc	(revision 344)
@@ -42,5 +42,5 @@
 // include	nobjmgr.h
 //
-//	Cette classe fournit les services nécéssaire àla gestion des objets
+//	Cette classe fournit les services nécéssaires à la gestion des objets
 //	(l'ensemble des objets PPersist de PEIDA++) au sein du programme
 //	d'analyse interactive *piapp* . Elle constitue en outre l'interface
@@ -58,6 +58,8 @@
 // ......  Gestion des objets nommes, variables globales ............
 struct nobj_diritem {
-  int id;
-  int nobj;
+  int id;                 // Directory Id
+  int nobj;               // Number of objects in directory
+  bool lock;              // True -> directory locked, No Add, del or rename
+  bool keepold;           // True -> When duplicate object name, old object moved to /old
 };
 
@@ -65,9 +67,10 @@
 
 struct nobj_item {
-  AnyDataObj* obj;
-  NObjMgrAdapter* obja;
-  int oid;
-  int dirid;
-  list<int> wrsid;
+  AnyDataObj* obj;             // Object pointer
+  NObjMgrAdapter* obja;        // Object adapter pointer
+  int oid;                     // object Id
+  int dirid;                   // Directory Id
+  list<int> wrsid;             // List of Window Resource Id (Drawer, PIBaseWdg, ...) 
+                               // (for PIStdImgApp)
   bool operator==(nobj_item const& b) const
     { return (this->obj ==  b.obj); }
@@ -116,8 +119,11 @@
   string dirn = "home";
   CreateDir(dirn);
+  SetKeepOldDirAtt(dirn, true);
   dirn = "tmp";
   CreateDir(dirn);
+  SetKeepOldDirAtt(dirn, false);
   dirn = "old";
   CreateDir(dirn);
+  SetKeepOldDirAtt(dirn, false);
   dirn = "home";
   SetCurrentDir(dirn);
@@ -179,14 +185,14 @@
 
 /* --Methode-- */
-void NamedObjMgr::CreateDir(string & dirname)
+bool NamedObjMgr::CreateDir(string & dirname)
 {
 if ( !CheckDirName(dirname) ) {
   cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl;
-  return; 
+  return(false); 
   }
 NObjDirList::iterator it = myDirs->find(dirname);
 if (it != myDirs->end()) {
   cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl;
-  return;
+  return(false);
   }
 myDirId++;
@@ -194,4 +200,6 @@
 di.id = myDirId;
 di.nobj = 0;
+di.lock = false;
+di.keepold = false;
 (*myDirs)[dirname] = di;
 if (myImgApp)  { 
@@ -200,25 +208,30 @@
   }
 cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl;
-}
-
-/* --Methode-- */
-void NamedObjMgr::DeleteDir(string & dirname)
+return(true);
+}
+
+/* --Methode-- */
+bool NamedObjMgr::DeleteDir(string & dirname)
 {
 if ( !CheckDirName(dirname) ) {
   cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl;
-  return; 
+  return(false); 
   }
 NObjDirList::iterator it = myDirs->find(dirname);
 if (it == myDirs->end()) {
   cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl;
-  return;
+  return(false);
   }
 if ((*it).second.nobj > 0) {
   cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl;
-  return;
+  return(false);
+  }
+if ((*it).second.lock ) {
+  cout << "NamedObjMgr::DeleteDir() " << dirname << " locked ! " << endl;
+  return(false);
   }
 if ((*it).second.id < 50) {
   cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl;
-  return;
+  return(false);
   }
 
@@ -227,20 +240,58 @@
 myDirs->erase(it);
 cout << "amedObjMgr::DeleteDir() " << dirname << " deleted " << endl;  
-}
-
-/* --Methode-- */
-void NamedObjMgr::SetCurrentDir(string & dirname)
+return(true);
+}
+
+/* --Methode-- */
+void NamedObjMgr::LockDir(string & dirname)
+{
+if ( !CheckDirName(dirname) ) return;
+NObjDirList::iterator it = myDirs->find(dirname);
+if (it == myDirs->end()) return;
+(*it).second.lock = true;
+cout << "NamedObjMgr::LockDir() " << dirname << " Locked " << endl;
+return;
+}
+
+/* --Methode-- */
+void NamedObjMgr::UnlockDir(string & dirname)
+{
+if ( !CheckDirName(dirname) ) return;
+NObjDirList::iterator it = myDirs->find(dirname);
+if (it == myDirs->end()) return;
+(*it).second.lock = true;
+cout << "NamedObjMgr::UnlockDir() " << dirname << " Unlocked " << endl;
+return;
+}
+
+/* --Methode-- */
+void NamedObjMgr::SetKeepOldDirAtt(string & dirname, bool keepold)
+{
+if ( !CheckDirName(dirname) ) return;
+NObjDirList::iterator it = myDirs->find(dirname);
+if (it == myDirs->end()) return;
+(*it).second.keepold = keepold;
+cout << "NamedObjMgr::SetKeepOldDirAtt() " << dirname << "  ->  ";
+if ( keepold ) cout << " True " << endl;
+else cout << " False " << endl;
+return;
+}
+
+
+/* --Methode-- */
+bool NamedObjMgr::SetCurrentDir(string & dirname)
 {
 if ( !CheckDirName(dirname) ) {
   cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl;
-  return; 
+  return(false); 
   }
 NObjDirList::iterator it = myDirs->find(dirname);
 if (it == myDirs->end()) {
   cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl;
-  return;
+  return(false);
   }
 *currDir = dirname;
 cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl;
+return(true);
 }
 
@@ -262,5 +313,9 @@
   if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
   k++;
-  cout << k << "- " << (*it).first << "  (NbObj= " << (*it).second.nobj << ")" << endl; 
+  cout << k << "- " << (*it).first;
+  if ( (*it).second.lock )  cout << "  Locked " ;
+  if ( (*it).second.keepold )   cout << "  KeepOld " ;
+  cout << "  (Id= " << (*it).second.id << " NbObj= " << (*it).second.nobj << ")" << endl;
+   
   }
 }
@@ -311,8 +366,8 @@
 
 /* --Methode-- */
-void NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
-{
-
-if (obj == NULL)  return;
+bool NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
+{
+
+if (obj == NULL)  return(false);
 // On verifie si l'objet est deja dans la liste 
 NObjList::iterator it;
@@ -320,5 +375,5 @@
   if ((*it).second.obj == obj) {
     cout << "NamedObjMgr::AddObj() Object already present with name " << (*it).first << endl;
-    return;
+    return(false);
     }
   }
@@ -330,5 +385,5 @@
   if (!crd) {
     cout << "NamedObjMgr::AddObj() No " << nrep << " Directory " << endl;
-    return;
+    return(false);
     }
   else { CreateDir(nrep);  did =  myDirId; }
@@ -342,11 +397,12 @@
 
 nom = '/' + nrep + '/' + nobj;  
+NObjDirList::iterator itr = myDirs->find(nrep);
+if ((*itr).second.lock) {
+  cout << "NamedObjMgr::AddObj() " << nrep << " Locked Directory " << endl;
+  return(false);
+  }
 it = myObjs->find(nom);
 if (it != myObjs->end()) { // l'objet existe deja
-  if (nrep == "tmp") {  // Les objets de /tmp sont jetes
-    cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
-    DelObj(nom);
-    }
-  else {  // On met l'ancien objet dans /old
+  if ( (*itr).second.keepold ) { // On met l'ancien objet dans /old
     string on,od;
 //    ParseObjectName((*it).first, od, on); 
@@ -355,4 +411,8 @@
     RenameObj(nom, nomnew);
     }
+  else {  // Sinon, on remplace l'objet
+    cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
+    DelObj(nom);
+    }
   }
 
@@ -364,21 +424,23 @@
 (*myObjs)[nom] = no;
 
-NObjDirList::iterator itr = myDirs->find(nrep);
 (*itr).second.nobj++;
 
 cout << "NamedObjMgr::AddObj()  Object " << nom << " ( "  
      << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl;  
-return;
-}
-
-/* --Methode-- */
-void NamedObjMgr::RenameObj(string & nom, string& nomnew)
+return(true);
+}
+
+/* --Methode-- */
+bool NamedObjMgr::RenameObj(string & nom, string& nomnew)
 {
 string n1,r1,n2,r2;
-ParseObjectName(nom, r1, n1);
+int dids = ParseObjectName(nom, r1, n1);
+NObjDirList::iterator itr1 = myDirs->find(r1);
 int did = ParseObjectName(nomnew, r2, n2);
+NObjDirList::iterator itr2 = myDirs->find(r2);
+
 if (did == 0) {
   cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
-  return;
+  return(false);
   }
 nom = '/' + r1 + '/' + n1;
@@ -387,11 +449,18 @@
 if (it1 == myObjs->end()) {
   cout << "NamedObjMgr::RenameObj() Error -  No " << nom << " object !" << endl;
-  return;
+  return(false);
   }
 NObjList::iterator it2 = myObjs->find(nomnew);
 if (it2 != myObjs->end()) {
   cout << "NamedObjMgr::RenameObj() Error -  Object " << nomnew << " exist !" << endl;
-  return;
-  }
+  return(false);
+  }
+
+if ( (*itr1).second.lock || (*itr2).second.lock ) {
+  cout << "NamedObjMgr::RenameObj() Error - Source or destination directory locked !" 
+       << endl;
+  return(false);  
+  }
+
 
 nobj_item no = (*it1).second;
@@ -404,9 +473,9 @@
 (*itr).second.nobj++;
 cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl;
-return;
-}
-
-/* --Methode-- */
-void NamedObjMgr::DelObj(string & nom, bool fgd)
+return(true);
+}
+
+/* --Methode-- */
+bool NamedObjMgr::DelObj(string & nom, bool fgd)
 {
 string n1,r1;
@@ -414,5 +483,10 @@
 nom = '/' + r1 + '/' + n1;
 NObjList::iterator it = myObjs->find(nom);
-if (it == myObjs->end()) return; 
+if (it == myObjs->end()) return(false); 
+NObjDirList::iterator itr = myDirs->find(r1);
+if ( (*itr).second.lock  ) {
+  cout << "NamedObjMgr::DelObj() Error - Locked directory " << r1 << endl;
+  return(false);
+  }
 list<int>::iterator ii;
 if (myImgApp) {
@@ -425,14 +499,13 @@
 
 myObjs->erase(it);
-NObjDirList::iterator itr = myDirs->find(r1);
 (*itr).second.nobj--;
 
 if (fgd) cout << "NamedObjMgr::DelObj()  Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
 else  cout << "NamedObjMgr::DelObj()  Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
-return;  
-}
-
-/* --Methode-- */
-void NamedObjMgr::DelObj_Id(int oid)
+return(true);  
+}
+
+/* --Methode-- */
+bool NamedObjMgr::DelObj_Id(int oid)
 {
 NObjList::iterator it;
@@ -444,5 +517,6 @@
     break;
   }
-if (of) DelObj(nom, true);
+if (of) return(DelObj(nom, true));
+else return(false);
 }
 
@@ -786,10 +860,13 @@
 int opt = servnobjm->DecodeDispOption(dopt, fgsr);
 
+string n1,r1;
+ParseObjectName(nom, r1, n1);
+
 if (dr) { 
   PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
-  if(dr3)  wrsid = myImgApp->Disp3DDrawer(dr3, nom, opt);
-  else wrsid = myImgApp->DispScDrawer( dr, nom, opt); 
-  }
-else if (arr) wrsid = myImgApp->DispImage(arr, nom, opt);
+  if(dr3)  wrsid = myImgApp->Disp3DDrawer(dr3, n1, opt);
+  else wrsid = myImgApp->DispScDrawer( dr, n1, opt); 
+  }
+else if (arr) wrsid = myImgApp->DispImage(arr, n1, opt);
 
 if(wrsid != 0) {
@@ -821,8 +898,11 @@
   }
 
+string n1,r1;
+ParseObjectName(nom, r1, n1);
+
 int wrsid = 0;
 bool fgsr = true;
 int opt = servnobjm->DecodeDispOption(dopt, fgsr);
-wrsid = myImgApp->DispImage(arr, nom, opt);
+wrsid = myImgApp->DispImage(arr, n1, opt);
 
 if(wrsid != 0) {
@@ -860,9 +940,12 @@
   }
 
+string n1,r1;
+ParseObjectName(nom, r1, n1);
+
 int wrsid = 0;
 bool fgsr = true;
 int opt = servnobjm->DecodeDispOption(dopt, fgsr);
 PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
-wrsid = myImgApp->Disp3DDrawer(sdr, nom, opt);
+wrsid = myImgApp->Disp3DDrawer(sdr, n1, opt);
 if(wrsid >= 0) {
   NObjList::iterator it = myObjs->find(nom);
@@ -899,4 +982,7 @@
 int opt = servnobjm->DecodeDispOption(dopt, fgsr);
 
+string n1,r1;
+ParseObjectName(nom, r1, n1);
+
 if ( fg3d && (nmz.length()>0) )  { // Display 3D
   PINTuple3D* pin = new PINTuple3D(nt, false);
@@ -904,5 +990,5 @@
   pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
   string titre = nmz + "%" + nmy + "%" + nmz;
-  wrsid = myImgApp->Disp3DDrawer(pin, nom, opt, titre);  
+  wrsid = myImgApp->Disp3DDrawer(pin, n1, opt, titre);  
 }
 else {
@@ -912,5 +998,5 @@
   if ( nmz.length()>0 ) pin->SelectWt(nmz.c_str());
   string titre = nmy + "%" + nmx;
-  wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, nom, opt, titre);
+  wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, opt, titre);
   }
 
@@ -965,4 +1051,7 @@
  if(numvary.length()>0) numvy = atoi(numvary.c_str());
  
+ string n1,r1;
+ ParseObjectName(nom, r1, n1);
+
  int wrsid = 0;
  if(numvy>=0) {              // display 3D
@@ -970,10 +1059,10 @@
   pigfd->SelectXY(numvx,numvy);
   pigfd->SelectErrBar(errx,erry,errz);
-  wrsid = myImgApp->Disp3DDrawer(pigfd,nom,opt);  
+  wrsid = myImgApp->Disp3DDrawer(pigfd,n1,opt);  
 } else {                   // display 2D
   PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
   pigfd->SelectX(numvx);
   pigfd->SelectErrBar(errx,erry);
-  wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,nom,opt);
+  wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,opt);
 }
 
Index: trunk/SophyaPI/PIext/nobjmgr.h
===================================================================
--- trunk/SophyaPI/PIext/nobjmgr.h	(revision 341)
+++ trunk/SophyaPI/PIext/nobjmgr.h	(revision 344)
@@ -32,7 +32,10 @@
 
 // Gestion des repertoires
-  virtual void		CreateDir(string & dirname);
-  virtual void		DeleteDir(string & dirname);
-  virtual void		SetCurrentDir(string & dirname);
+  virtual bool		CreateDir(string & dirname);
+  virtual bool		DeleteDir(string & dirname);
+  virtual void		LockDir(string & dirname); 
+  virtual void		UnlockDir(string & dirname);
+  virtual void		SetKeepOldDirAtt(string & dirname, bool keepold=false); 
+  virtual bool		SetCurrentDir(string & dirname);
   virtual void		GetCurrentDir(string & dirname);
   virtual void		ListDirs(string & patt);
@@ -42,9 +45,9 @@
 
 //  Pour ajouter, supprimer et acceder aux objets 
-  virtual void		AddObj(AnyDataObj* obj, string & nom, bool crd=false);
-  virtual void		RenameObj(string & nom, string& nomnew);
-  virtual void          DelObj(string & nom, bool fgd=true);
+  virtual bool		AddObj(AnyDataObj* obj, string & nom, bool crd=false);
+  virtual bool		RenameObj(string & nom, string& nomnew);
+  virtual bool          DelObj(string & nom, bool fgd=true);
   virtual void		DelObjects(string & patt, bool fgd=true); 
-  virtual void          DelObj_Id(int oid);
+  virtual bool          DelObj_Id(int oid);
   virtual AnyDataObj*	GetObj(string & nom);
   virtual void          ListObjs(string & patt);  		
Index: trunk/SophyaPI/PIext/nomgadapter.cc
===================================================================
--- trunk/SophyaPI/PIext/nomgadapter.cc	(revision 341)
+++ trunk/SophyaPI/PIext/nomgadapter.cc	(revision 344)
@@ -70,8 +70,9 @@
 
 /* --Methode-- */
-NTupleInterface* NObjMgrAdapter::GetNTupleInterface()
+NTupleInterface* NObjMgrAdapter::GetNTupleInterface(bool& adel)
 {
 string s = typeid(*mObj).name();
 cout << "NObjMgrAdapter::GetNTupleInterface() - Error : Not supported for " << s << endl;
+adel = false;
 return(NULL);
 }
Index: trunk/SophyaPI/PIext/nomgadapter.h
===================================================================
--- trunk/SophyaPI/PIext/nomgadapter.h	(revision 341)
+++ trunk/SophyaPI/PIext/nomgadapter.h	(revision 344)
@@ -34,5 +34,9 @@
   virtual PIDrawer*		GetDrawer(string& dopt);
   virtual P2DArrayAdapter*	Get2DArray(string& dopt);
-  virtual NTupleInterface*	GetNTupleInterface();
+
+// NTupleInterface* nti = GetNTupleInterface(adel)
+// Retourne un objet de type NTupleInterface (nti), ainsi que adel
+// si adel == true, le programme appelant doit faire delete de nti 
+  virtual NTupleInterface*	GetNTupleInterface(bool& adel);
 protected:
   AnyDataObj* mObj;
Index: trunk/SophyaPI/PIext/nomgfdadapter.cc
===================================================================
--- trunk/SophyaPI/PIext/nomgfdadapter.cc	(revision 341)
+++ trunk/SophyaPI/PIext/nomgfdadapter.cc	(revision 344)
@@ -52,43 +52,8 @@
 
 /* --Methode-- */
-NTupleInterface* NOMAdapter_GeneralFitData::GetNTupleInterface()
+NTupleInterface* NOMAdapter_GeneralFitData::GetNTupleInterface(bool& adel)
 {
-return( new NTupInt_GeneralFitData(mG) );
+adel = false;
+return(mG);
 }
 
-// -------------------------------------------------------------
-
-/* --Methode-- */
-NTupInt_GeneralFitData::NTupInt_GeneralFitData(GeneralFitData* g)
-{
-mG = g;
-}
-
-/* --Methode-- */
-NTupInt_GeneralFitData::~NTupInt_GeneralFitData()
-{
-}
-
-/* --Methode-- */
-uint_4 NTupInt_GeneralFitData::NbLines() const 
-{
-return(mG->NbLines());
-}
-
-/* --Methode-- */
-uint_4 NTupInt_GeneralFitData::NbColumns() const 
-{
-return(mG->NbColumns());
-}
-
-/* --Methode-- */
-r_8* NTupInt_GeneralFitData::GetLineD(int n) const 
-{
-return(mG->GetLineD(n));
-}
-
-/* --Methode-- */
-string NTupInt_GeneralFitData::VarList_C(const char* nx) const 
-{
-return(mG->VarList_C(nx));
-}
Index: trunk/SophyaPI/PIext/nomgfdadapter.h
===================================================================
--- trunk/SophyaPI/PIext/nomgfdadapter.h	(revision 341)
+++ trunk/SophyaPI/PIext/nomgfdadapter.h	(revision 344)
@@ -24,5 +24,5 @@
 
   virtual void		   Print(ostream& os);
-  virtual NTupleInterface* GetNTupleInterface();
+  virtual NTupleInterface* GetNTupleInterface(bool& adel);
 
 protected:
@@ -30,16 +30,4 @@
 };
 
-// Class Interface GeneralFitData pour GeneralFitData 
-class NTupInt_GeneralFitData : public NTupleInterface {
-public:
-		  NTupInt_GeneralFitData(GeneralFitData* g);
-  virtual	  ~NTupInt_GeneralFitData();
-  virtual uint_4  NbLines() const ;
-  virtual uint_4  NbColumns() const ;
-  virtual r_8 *   GetLineD(int n) const ;
-  virtual string  VarList_C(const char* nomx=NULL) const ;
-protected:
-  GeneralFitData* mG;
-};
 
 #endif
Index: trunk/SophyaPI/PIext/nomhistadapter.cc
===================================================================
--- trunk/SophyaPI/PIext/nomhistadapter.cc	(revision 341)
+++ trunk/SophyaPI/PIext/nomhistadapter.cc	(revision 344)
@@ -63,6 +63,7 @@
 
 /* --Methode-- */
-NTupleInterface* NOMAdapter_Histo::GetNTupleInterface()
-{
+NTupleInterface* NOMAdapter_Histo::GetNTupleInterface(bool& adel)
+{
+adel = true;
 return( new NTupInt_Histo(mHis) );
 }
@@ -178,6 +179,7 @@
 
 /* --Methode-- */
-NTupleInterface* NOMAdapter_Histo2D::GetNTupleInterface()
-{
+NTupleInterface* NOMAdapter_Histo2D::GetNTupleInterface(bool& adel)
+{
+adel = true;
 return( new NTupInt_Histo2D(mHis) );
 }
@@ -289,44 +291,10 @@
 
 /* --Methode-- */
-NTupleInterface* NOMAdapter_NTuple::GetNTupleInterface()
-{
-return( new NTupInt_NTuple(mNt) );
-}
-
-
-// -------------------------------------------------------------
-
-/* --Methode-- */
-NTupInt_NTuple::NTupInt_NTuple(NTuple* nt)
-{
-mNt = nt;
-}
-
-/* --Methode-- */
-NTupInt_NTuple::~NTupInt_NTuple()
-{
-}
-
-/* --Methode-- */
-uint_4 NTupInt_NTuple::NbLines() const 
-{
-return(mNt->NEntry());
-}
-
-/* --Methode-- */
-uint_4 NTupInt_NTuple::NbColumns() const 
-{
-return(mNt->NVar());
-}
-
-/* --Methode-- */
-r_8* NTupInt_NTuple::GetLineD(int n) const 
-{
-return(mNt->GetVecD(n));
-}
-
-/* --Methode-- */
-string NTupInt_NTuple::VarList_C(const char* nx) const 
-{
-return(mNt->VarList_C(nx));
-}
+NTupleInterface* NOMAdapter_NTuple::GetNTupleInterface(bool& adel)
+{
+adel = false;
+return(mNt);
+// return( new NTupInt_NTuple(mNt) );
+}
+
+
Index: trunk/SophyaPI/PIext/nomhistadapter.h
===================================================================
--- trunk/SophyaPI/PIext/nomhistadapter.h	(revision 341)
+++ trunk/SophyaPI/PIext/nomhistadapter.h	(revision 344)
@@ -30,5 +30,5 @@
   virtual void			Print(ostream& os);
   virtual PIDrawer*		GetDrawer(string& dopt);
-  virtual NTupleInterface*	GetNTupleInterface();
+  virtual NTupleInterface*	GetNTupleInterface(bool& adel);
 
 protected:
@@ -68,5 +68,5 @@
   virtual PIDrawer*		GetDrawer(string& dopt);
   virtual P2DArrayAdapter*      Get2DArray(string& dopt);
-  virtual NTupleInterface*	GetNTupleInterface();
+  virtual NTupleInterface*	GetNTupleInterface(bool& adel);
 
 protected:
@@ -105,5 +105,5 @@
 
   virtual void			Print(ostream& os);
-  virtual NTupleInterface*	GetNTupleInterface();
+  virtual NTupleInterface*	GetNTupleInterface(bool& adel);
 
 protected:
@@ -111,16 +111,4 @@
 };
 
-// Class Interface NTuple pour NTuple 
-class NTupInt_NTuple : public NTupleInterface {
-public:
-			NTupInt_NTuple(NTuple* nt);
-  virtual		~NTupInt_NTuple();
-  virtual uint_4        NbLines() const ;
-  virtual uint_4        NbColumns() const ;
-  virtual r_8 *         GetLineD(int n) const ;
-  virtual string        VarList_C(const char* nomx=NULL) const ;
-protected:
-  NTuple* mNt;
-};
 
 
Index: trunk/SophyaPI/PIext/nomimagadapter.cc
===================================================================
--- trunk/SophyaPI/PIext/nomimagadapter.cc	(revision 341)
+++ trunk/SophyaPI/PIext/nomimagadapter.cc	(revision 344)
@@ -69,5 +69,5 @@
 void NOMAdapter_Image<T>::Print(ostream& os)
 {
-os << (*mImg);
+mImg->Print(os);
 }
 
@@ -82,6 +82,7 @@
 /* --Methode-- */
 template <class T>
-NTupleInterface* NOMAdapter_Image<T>::GetNTupleInterface()
+NTupleInterface* NOMAdapter_Image<T>::GetNTupleInterface(bool& adel)
 {
+adel = true;
 return( new NTupInt_Image<T>(mImg) );
 }
Index: trunk/SophyaPI/PIext/nomimagadapter.h
===================================================================
--- trunk/SophyaPI/PIext/nomimagadapter.h	(revision 341)
+++ trunk/SophyaPI/PIext/nomimagadapter.h	(revision 344)
@@ -30,5 +30,5 @@
   virtual void			Print(ostream& os);
   virtual P2DArrayAdapter*	Get2DArray(string& dopt);
-  virtual NTupleInterface*	GetNTupleInterface();
+  virtual NTupleInterface*	GetNTupleInterface(bool& adel);
 
 protected:
Index: trunk/SophyaPI/PIext/nommatvecadapter.cc
===================================================================
--- trunk/SophyaPI/PIext/nommatvecadapter.cc	(revision 341)
+++ trunk/SophyaPI/PIext/nommatvecadapter.cc	(revision 344)
@@ -61,6 +61,7 @@
 
 /* --Methode-- */
-NTupleInterface* NOMAdapter_Vector::GetNTupleInterface()
-{
+NTupleInterface* NOMAdapter_Vector::GetNTupleInterface(bool& adel)
+{
+adel = true;
 return( new NTupInt_Vector(mVec) );
 }
@@ -169,6 +170,7 @@
 
 /* --Methode-- */
-NTupleInterface* NOMAdapter_Matrix::GetNTupleInterface()
-{
+NTupleInterface* NOMAdapter_Matrix::GetNTupleInterface(bool& adel)
+{
+adel = true;
 return( new NTupInt_Matrix(mMtx) );
 }
Index: trunk/SophyaPI/PIext/nommatvecadapter.h
===================================================================
--- trunk/SophyaPI/PIext/nommatvecadapter.h	(revision 341)
+++ trunk/SophyaPI/PIext/nommatvecadapter.h	(revision 344)
@@ -28,5 +28,5 @@
   virtual void			Print(ostream& os);
   virtual PIDrawer*		GetDrawer(string& dopt);
-  virtual NTupleInterface*	GetNTupleInterface();
+  virtual NTupleInterface*	GetNTupleInterface(bool& adel);
 
 protected:
@@ -67,5 +67,5 @@
   virtual void			Print(ostream& os);
   virtual P2DArrayAdapter*	Get2DArray(string& dopt);
-  virtual NTupleInterface*	GetNTupleInterface();
+  virtual NTupleInterface*	GetNTupleInterface(bool& adel);
 
 protected:
Index: trunk/SophyaPI/PIext/nomstladapter.cc
===================================================================
--- trunk/SophyaPI/PIext/nomstladapter.cc	(revision 341)
+++ trunk/SophyaPI/PIext/nomstladapter.cc	(revision 344)
@@ -64,6 +64,7 @@
 
 /* --Methode-- */
-NTupleInterface* NOMAdapter_StarList::GetNTupleInterface()
+NTupleInterface* NOMAdapter_StarList::GetNTupleInterface(bool& adel)
 {
+adel = true;
 return( new NTupInt_StarList(mStl) );
 }
Index: trunk/SophyaPI/PIext/nomstladapter.h
===================================================================
--- trunk/SophyaPI/PIext/nomstladapter.h	(revision 341)
+++ trunk/SophyaPI/PIext/nomstladapter.h	(revision 344)
@@ -28,5 +28,5 @@
   virtual void			Print(ostream& os);
   virtual PIDrawer*		GetDrawer(string& dopt);
-  virtual NTupleInterface*	GetNTupleInterface();
+  virtual NTupleInterface*	GetNTupleInterface(bool& adel);
 
 protected:
Index: trunk/SophyaPI/PIext/pintuple.cc
===================================================================
--- trunk/SophyaPI/PIext/pintuple.cc	(revision 341)
+++ trunk/SophyaPI/PIext/pintuple.cc	(revision 344)
@@ -97,5 +97,5 @@
 msz = mMSz;
 if (msz < 1) msz = 1;
-g->SelMarker(sz, mrk);
+g->SelMarker(msz, mrk);
 
 nok = 0;  
@@ -136,2 +136,28 @@
 }
 
+/* --Methode-- */
+void PINTuple::AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax)
+{
+if (!mNT) return;
+if ( (xK < 0) || (yK < 0) )  return;
+
+int ncnt = 0;
+double xp,yp;
+char buff[128];
+sprintf(buff,"PINTuple: NLines= %d  NCol= %d \n", mNT->NbLines(),  mNT->NbColumns());
+info += buff;
+info += mNT->LineHeaderToString();
+for (int i=0; i<mNT->NbLines(); i++) {
+  xp = mNT->GetCell(i, xK);
+  yp = mNT->GetCell(i, yK);
+  if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) )  continue;
+  ncnt++;
+  if (ncnt > 101) continue;
+  info += mNT->LineToString(i);
+  }
+if (ncnt >= 101) info += " .... \n";
+sprintf(buff," %d points inside selected region \n", ncnt);
+info += buff;
+// printf("PINTuple::AppendTextInfo()-DBG %g %g %g %g - %d\n", xmin, ymin, xmax, ymax, ncnt); 
+return;
+}
Index: trunk/SophyaPI/PIext/pintuple.h
===================================================================
--- trunk/SophyaPI/PIext/pintuple.h	(revision 341)
+++ trunk/SophyaPI/PIext/pintuple.h	(revision 344)
@@ -1,2 +1,6 @@
+// This may look like C code, but it is really -*- C++ -*-
+// Module PI : Peida Interactive  PINTuple et PINTupleWdg
+// Traceur d objet de type NTupleInterface
+
 #ifndef PINTUPLE_H
 #define PINTUPLE_H
@@ -13,8 +17,9 @@
   virtual void       UpdateLimits();
   
-          void       SelectXY(const char* px, const char* py);
-          void       SelectWt(const char* pw=NULL, int nbins=10);
-          void       SelectErrBar(const char* erbx=NULL, const char* erby=NULL);
+  virtual void       SelectXY(const char* px, const char* py);
+  virtual void       SelectWt(const char* pw=NULL, int nbins=10);
+  virtual void       SelectErrBar(const char* erbx=NULL, const char* erby=NULL);
 
+  virtual void       AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax);
        
 protected:
Index: trunk/SophyaPI/PIext/pistdimgapp.cc
===================================================================
--- trunk/SophyaPI/PIext/pistdimgapp.cc	(revision 341)
+++ trunk/SophyaPI/PIext/pistdimgapp.cc	(revision 344)
@@ -655,10 +655,14 @@
 if (w == NULL)  return;
 w->Hide();
+bool ownwindow=false;  // To Check if this is one of our windows
 WindMList::iterator it;
 for(it = mWList.begin(); it != mWList.end(); it++) 
-  if ((*it).second == w)  { mWList.erase(it);  break; }
+  if ((*it).second == w)  { mWList.erase(it);  ownwindow = true; break; }
 if (w == mGrW) { mGrW = NULL;  mGrIdx = -1; }
 if (w == mStW) { mStW = NULL;  mStIdx = -1; m[2]->SetSensitivity("StackTools", false); }
 if (w == mCurWin) mCurWin = NULL;
+
+if (!ownwindow) return; // We do nothing if this is not a window we have created ...
+
 int k;
 PIWdg* cwd;
Index: trunk/SophyaPI/PIext/pistlist.cc
===================================================================
--- trunk/SophyaPI/PIext/pistlist.cc	(revision 341)
+++ trunk/SophyaPI/PIext/pistlist.cc	(revision 344)
@@ -101,2 +101,31 @@
 }
 
+/* --Methode-- */
+void PIStarList::AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax)
+{
+BStar *sti;
+double xp,yp;
+double flx,fnd;
+char buff[128];
+int ncnt = 0;
+sprintf(buff,"PIStarList: NStars \n", mStL->NbStars() );
+info += buff;
+info += "  Num:   XPos       YPos     Flux      Fond \n";
+for (int i=0; i<mStL->NbStars(); i++) {
+  sti = mStL->Star(i);
+  if ( !(sti->Nice(BStar::flagOK)) )  continue;
+  flx = sti->Flux();
+  if ( (flx < mFmin) || (flx > mFmax) )  continue;
+  xp = sti->PosX();   yp = sti->PosY();
+  if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) )  continue;
+  ncnt++;
+  if (ncnt > 101) continue;
+  fnd = sti->Fond();
+  sprintf(buff,"%6d: %8.3g %8.3g %8.3g %8.3g \n", i, xp, yp, flx, fnd); 
+  info += buff;
+  }
+if (ncnt >= 101) info += " .... \n";
+sprintf(buff," %d stars inside selected region \n", ncnt);
+info += buff;
+return;
+}
Index: trunk/SophyaPI/PIext/pistlist.h
===================================================================
--- trunk/SophyaPI/PIext/pistlist.h	(revision 341)
+++ trunk/SophyaPI/PIext/pistlist.h	(revision 344)
@@ -13,4 +13,6 @@
   virtual void       UpdateLimits();
   
+  virtual void       AppendTextInfo(string& info, double xmin, double ymin, double xmax, double ymax);
+
   void               SetFluxLimits(float min=1., float max=-1., int nl=5, bool dispflx=false, bool refr=false);
 
Index: trunk/SophyaPI/PIext/servnobjm.cc
===================================================================
--- trunk/SophyaPI/PIext/servnobjm.cc	(revision 341)
+++ trunk/SophyaPI/PIext/servnobjm.cc	(revision 344)
@@ -200,6 +200,12 @@
 
 if (vpy) {
-  string titre = (nom.length() < 1) ? "Function f(x)" : nom;
-  P1DArrayAdapter* vya = new POVectorAdapter(vpy, true);
+  string titre;
+  if (nom.length() < 1) {
+     titre = "Function f(x)";
+     nom = "/tmp/func";
+    }
+  else titre = nom;
+  
+  P1DArrayAdapter* vya = new POVectorAdapter(vpy, false);
   vya->DefineXCoordinate(xmin, (xmax-xmin)/np);
   PIYfXDrawer* dr = new   PIYfXDrawer(vya, NULL, true) ; 
@@ -256,8 +262,13 @@
 
 if (mtx) {
-  string titre = (nom.length() < 1) ? "Function f(x,y)" : nom;  
+  string titre;
+  if (nom.length() < 1) {
+     titre = "Function f(x,y)";
+     nom = "/tmp/func2d";
+    }
+  else titre = nom;
   bool fgsr = true;
   int opt = DecodeDispOption(dopt, fgsr);
-  P2DArrayAdapter* arr = new POMatrixAdapter(mtx, true);
+  P2DArrayAdapter* arr = new POMatrixAdapter(mtx, false);
   arr->DefineXYCoordinates(xmin, ymin, dx, dy);
   PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
@@ -636,5 +647,6 @@
 /* --Methode-- */
 void Services2NObjMgr::FillNTFrCFile(string & nom, string const & fname, 
-                                     string const & funcname, string & nomnt)
+                                     string const & funcname, string & nomnt,
+                                     int nl1, int nl2)
 {
 if (!mImgapp)  return; 
@@ -646,5 +658,6 @@
   return;
   }
-NTupleInterface* objnt = obja->GetNTupleInterface();
+bool adel = true;
+NTupleInterface* objnt = obja->GetNTupleInterface(adel);
 if (objnt == NULL)  {
   cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No NTupleInterface !" <<endl;
@@ -655,4 +668,5 @@
 if (!f) { 
   cerr << "Services2NObjMgr::FillNTFrCFile Error Creation  NTLoopExprFunc" <<  endl; 
+  if (adel) delete objnt;   // Delete de l'objet NTupleInterface si necessaire
   return;
   }
@@ -691,6 +705,9 @@
 TRY  {
   double* xn;
-  int kmax = objnt->NbLines();
-  for(k=0; k<kmax; k++)    {
+  if (nl1 < 0) nl1 = 0;
+  if (nl2 < 0) nl2 = objnt->NbLines();
+  if (nl2 > objnt->NbLines()) nl2 = objnt->NbLines();
+  int kmax = nl2;
+  for(k=nl1; k<kmax; k++)    {
     xn = objnt->GetLineD(k);
     if (f(xn, xnt, xnt+1, xnt+2, xnt+3, k, kmax) != 0) {
@@ -709,5 +726,6 @@
   cerr << "Services2NObjMgr::FillNTFrCFile()  Exception :" << merr << es;
   } ENDTRY;
- 
+
+if (adel) delete objnt;   // Delete de l'objet NTupleInterface si necessaire
 CloseDLL();
 
@@ -729,5 +747,6 @@
   return;
   }
-NTupleInterface* objnt = obja->GetNTupleInterface();
+bool adel = true;
+NTupleInterface* objnt = obja->GetNTupleInterface(adel);
 if (objnt == NULL)  {
   cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom 
@@ -740,10 +759,28 @@
 if ((fip = fopen(fname.c_str(), "w")) == NULL)   { 
   cout << "Services2NObjMgr::PrepareNTExpressionCFile()_Error: fopen " << fname << endl; 
+  if (adel) delete objnt;   // Delete de l'objet NTupleInterface si necessaire
   return; 
   }
+
 // constitution du fichier des decalarations des variables de l'interface NTuple
 fputs("#include <stdlib.h> \n", fip);
 fputs("#include <stdio.h> \n", fip);
 fputs("#include <math.h> \n\n", fip);
+
+fputs("/* ------ Some random number generators --------- */ \n", fip);
+fputs("#define frand01() ( (float) drand48() ) \n", fip);
+fputs("#define drand01() drand48()  \n", fip);
+fputs("#define rand01()  drand48()  \n", fip);
+fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
+fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
+fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
+fputs("double NorRand(void) \n", fip);
+fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
+fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
+fputs(" x = sqrt(-2.*log(A))*cos(M_2PI*B); \n", fip);
+fputs(" return(x); \n } \n", fip);
+fputs("#define GauRand() NorRand() \n", fip);
+fputs("#define gaurand() NorRand() \n\n", fip);
+
 fputs("/* NTupleInterface Variable declaration - Generated by piapp  \n", fip);
 fputs("      -- Services2NObjMgr::PrepareNTExpressionCFile()  --     */ \n\n", fip);
@@ -759,4 +796,6 @@
 
 fclose(fip);
+
+if (adel) delete objnt;   // Delete de l'objet NTupleInterface si necessaire
 return;
 }
@@ -1304,5 +1343,6 @@
 {
 if (obja == NULL) return;
-NTupleInterface* objnt = obja->GetNTupleInterface();
+bool adel = true;
+NTupleInterface* objnt = obja->GetNTupleInterface(adel);
 if (objnt == NULL)  return;
 string  vardec = objnt->VarList_C("_zz6qi_");
@@ -1311,4 +1351,5 @@
 if (!f) { 
   cerr << "Services2NObjMgr::::ComputeExpressions() Error Creation PlotExprFunc " <<  endl; 
+  if (adel) delete objnt;  // Delete de l'objet NTupleInterface si necessaire
   return;
   }
@@ -1344,4 +1385,5 @@
  
 
+if (adel) delete objnt;  // Delete de l'objet NTupleInterface si necessaire
 // Fermeture du fichier .so 
 CloseDLL();
@@ -1372,4 +1414,20 @@
 fputs("#include <stdlib.h> \n", fip);
 fputs("#include <math.h> \n", fip);
+
+fputs("/* ------ Some random number generators --------- */ \n", fip);
+fputs("#define frand01() ( (float) drand48() ) \n", fip);
+fputs("#define drand01() drand48()  \n", fip);
+fputs("#define rand01()  drand48()  \n", fip);
+fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
+fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
+fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
+fputs("double NorRand(void) \n", fip);
+fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
+fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
+fputs(" x = sqrt(-2.*log(A))*cos(M_2PI*B); \n", fip);
+fputs(" return(x); \n } \n", fip);
+fputs("#define GauRand() NorRand() \n", fip);
+fputs("#define gaurand() NorRand() \n\n", fip);
+
 fputs("int expf_pia_dl_func(double* _zz6qi_, double* _rx_6q_, double* _ry_6q_, double* _rz_6q_, double* _rt_6q_) \n{\n", fip);
 fprintf(fip,"%s \n", vardec.c_str());
Index: trunk/SophyaPI/PIext/servnobjm.h
===================================================================
--- trunk/SophyaPI/PIext/servnobjm.h	(revision 341)
+++ trunk/SophyaPI/PIext/servnobjm.h	(revision 344)
@@ -79,5 +79,6 @@
                                string& experr, string& expcut, string& nomgfd);
   virtual void          FillNTFrCFile(string & nom, string const & fname, 
-                                      string const & funcname, string & nomnt);
+                                      string const & funcname, string & nomnt,
+                                      int nl1=-1, int nl2=-1);
   virtual void		PrepareNTExpressionCFile(string & nomobj, string const & fname, 
                                                  string const & funcname);
