Index: trunk/SophyaPI/PIext/basexecut.cc
===================================================================
--- trunk/SophyaPI/PIext/basexecut.cc	(revision 381)
+++ trunk/SophyaPI/PIext/basexecut.cc	(revision 384)
@@ -51,5 +51,5 @@
 // >>>>>>>>>>> Fenetre graphique , changement d'attributs graphiques 
 else if (kw == "zone") {
-  if (tokens.size() < 2) { cout << "Usage: zone nx ny" << endl;  return(0); }
+  while (tokens.size() < 2) tokens.push_back("1");
   int nx, ny;
   nx = ny = 1;
@@ -596,5 +596,5 @@
 
 kw = "zone";
-usage = "To Divide the Graphic window \n  Usage: zone nx ny";
+usage = "To Divide the Graphic window \n  Usage: zone [nx=1 ny=1]";
 mpiac->RegisterCommand(kw, usage, this, "Graphics");
 kw = "newwin";
Index: trunk/SophyaPI/PIext/dlftypes.h
===================================================================
--- trunk/SophyaPI/PIext/dlftypes.h	(revision 381)
+++ trunk/SophyaPI/PIext/dlftypes.h	(revision 384)
@@ -14,9 +14,17 @@
 #endif
 
+// ------------ Fonctions pour trace de fonctions --------------
 typedef double (* DlFunctionOfX) (double x);
 typedef double (* DlFunctionOfXY) (double x, double y);
+// ---- Fonctions pour trace d'expressions d'objets ------------
 typedef int (* PlotExprFunc) (double* x, double* rx, double* ry, double* rz, double* rt);
 typedef int (* NTLoopExprFunc) (double* x, double* rx, double* ry, double* rz, 
                                 double* rt, int n, int nmax);
+
+// ---------- Fonctions UserFit ----------------
+typedef double (* DlUserFitFunc)(double const*, double const*);
+typedef double (* DlUserFitFuncDer)(double const*, double const*, double*);
+
+// ---------- Fonctions User et gestion de modules chargeables ----
 typedef void (* DlUserProcFunction) (vector<string>& args);
 typedef void (* DlFunction) ();
Index: trunk/SophyaPI/PIext/piacmd.cc
===================================================================
--- trunk/SophyaPI/PIext/piacmd.cc	(revision 381)
+++ trunk/SophyaPI/PIext/piacmd.cc	(revision 384)
@@ -809,4 +809,13 @@
 
 if ( (fip = fopen(file.c_str(),"r")) == NULL ) {
+  if (file.find('.') >= file.length()) {
+    cout << "PIACmd::Exec(): Error opening file " << file << endl;
+    file += ".pic";
+    cout << "                Trying file " << file << endl;
+    fip = fopen(file.c_str(),"r");
+    }
+  }
+
+if(fip == NULL) {
   cerr << "PIACmd::Exec() Error opening file " << file << endl;
   hist << "##! PIACmd::Exec() Error opening file " << file << endl;
Index: trunk/SophyaPI/PIext/piafitting.cc
===================================================================
--- trunk/SophyaPI/PIext/piafitting.cc	(revision 381)
+++ trunk/SophyaPI/PIext/piafitting.cc	(revision 384)
@@ -150,4 +150,6 @@
 , mFit(NULL)
 , mV(NULL), mH(NULL), mM(NULL), mH2(NULL), mIm(NULL), mG(NULL)
+, mDlUFunc(NULL), mNameFitFunc(""), mFitFunc(NULL), mFitFuncDer(NULL)
+, mUFNVar(0), mUFNPar(0)
 {
 // Init et Set des options
@@ -176,4 +178,9 @@
 usage += "\n Usage: fitlin nomobj func [o:... o:...]";
 piac->RegisterCommand(kw,usage,this,"Fitting");
+
+kw = "crfitfun";
+usage = "Creation de user function ";
+usage += "\n Usage: crfitfun file func nvar npar";
+piac->RegisterCommand(kw,usage,this,"Fitting");
 }
 
@@ -185,4 +192,5 @@
 if(mGData != NULL) {delete mGData; mGData=NULL;}
 if(FWindFit != NULL) {delete FWindFit; FWindFit=NULL;}
+if (mDlUFunc != NULL) delete mDlUFunc;
 }
 
@@ -658,6 +666,6 @@
 if(mFunc && (mOpt.okres||mOpt.okfun)) {
   NamedObjMgr omg;
-  string nomres = mNObj + "res";
-  string nomfun = mNObj + "fun";
+  string nomres = mNObj + "_res";
+  string nomfun = mNObj + "_fun";
   if(mV) {
     if(mOpt.okres) {Vector* ob = mV->FitResidus(*mFit);  if(ob) omg.AddObj(ob,nomres);}
@@ -673,6 +681,12 @@
     if(mOpt.okfun) {Histo2D* ob = mH2->FitFunction(*mFit); if(ob) omg.AddObj(ob,nomfun);}
   } else if(mIm) {
-    if(mOpt.okres) {RzImage* ob = mIm->FitResidus(*mFit);  if(ob) omg.AddObj(ob,nomres);}
-    if(mOpt.okfun) {RzImage* ob = mIm->FitFunction(*mFit); if(ob) omg.AddObj(ob,nomfun);}
+    if(mOpt.okres) {
+      RzImage* ob = mIm->FitResidus(*mFit);  
+      if(ob) {ImageR4* rob = new ImageR4(*ob); omg.AddObj(rob,nomres); delete ob;}
+    }
+    if(mOpt.okfun) {
+      RzImage* ob = mIm->FitFunction(*mFit);
+      if(ob) {ImageR4* rob = new ImageR4(*ob); omg.AddObj(rob,nomfun); delete ob;}
+    }
   } else if(mG) {
     if(mOpt.okres) {GeneralFitData* ob = mG->FitResidus(*mFit);  if(ob) omg.AddObj(ob,nomres);}
@@ -713,4 +727,55 @@
 
 return;
+}
+
+/* --Methode-- */
+void PIAFitter::LinkFitFunc(string const & fname, string const & funcname, int nvar, int npar)
+{
+
+if ((nvar < 1) || (npar < 1)) return;
+
+if (mDlUFunc != NULL) delete mDlUFunc;  // Nous en avons deja un, on nettoie
+
+mDlUFunc = NULL;
+mFitFunc = NULL; 
+mFitFuncDer = NULL; 
+mUFNVar= mUFNPar = 0;
+mNameFitFunc = "";
+
+// On compile le fichier C, on fabrique un .so et on l'ouvre
+mDlUFunc = PDynLinkMgr::BuildFromCFile(fname);
+if (mDlUFunc == NULL) {
+  cerr << "PIAFitter::LinkFitFunc() Erreur building .so " << endl;
+  return;
+  }
+
+// On recupere la fonction de fit
+mFitFunc = (DlUserFitFunc) mDlUFunc->GetFunction(funcname);
+if (mFitFunc == NULL) { // Probleme, on n'a pas trouve etc ... 
+  cerr << "PIAFitter::LinkFitFunc() Erreur linking function " << funcname << endl;
+  delete mDlUFunc;
+  mDlUFunc = NULL;
+  return;
+  }
+
+// On recupere la fonction de derives
+string fnameder = funcname+"_der";
+mFitFuncDer = (DlUserFitFuncDer) mDlUFunc->GetFunction(fnameder);
+if (mFitFunc == NULL) { 
+  cout << "PIAFitter::LinkFitFunc() No derive for " << fnameder << endl;
+  }
+
+mNameFitFunc = funcname;
+mUFNVar = nvar;
+mUFNPar = npar;
+
+cout << "PIAFitter::LinkFitFunc() UserFitFunc" << funcname
+     << " NVar=" << nvar << " NPar=" << npar << endl;
+
+}
+/* --Methode-- */
+void PIAFitter::PrepareFitFuncCFile(string const & fname, string const & funcname, int nvar, int npar)
+{
+// A Faire 
 }
 
@@ -760,5 +825,13 @@
   FWindFit = new PIAFitterWind(mApp,this);
   FWindFit->Show();
-}
+} else if (kw == "crfitfun") {
+  if (tokens.size() < 4) { 
+    cout <<"Usage:crfitfun ... " << endl; return(0); }
+    LinkFitFunc(tokens[0], tokens[1], 1, 7);
+    double par[7]={1000,0.,0.,1.,1.,0.1,100.};
+    double x[2]={1.,1.};
+    cout<<"Salut:"<<mFitFunc(x,par)<<endl;
+}
+
 
 return(0);
Index: trunk/SophyaPI/PIext/piafitting.h
===================================================================
--- trunk/SophyaPI/PIext/piafitting.h	(revision 381)
+++ trunk/SophyaPI/PIext/piafitting.h	(revision 384)
@@ -35,4 +35,6 @@
   virtual ~PIAFitter();
   virtual int Execute(string& keyw, vector<string>& args);
+  virtual void  LinkFitFunc(string const & fname, string const & funcname, int nvar, int npar);
+  virtual void  PrepareFitFuncCFile(string const & fname, string const & funcname, int nvar, int npar);
 
 friend class PIAFitterWind;
@@ -82,4 +84,10 @@
 GeneralFitData* mG; // Do not delete
 
+// Gestion de fonction de fit user
+PDynLinkMgr* mDlUFunc;
+string mNameFitFunc;
+DlUserFitFunc mFitFunc;
+DlUserFitFuncDer mFitFuncDer;
+int mUFNVar, mUFNPar; 
 };
 
Index: trunk/SophyaPI/PIext/pistdimgapp.cc
===================================================================
--- trunk/SophyaPI/PIext/pistdimgapp.cc	(revision 381)
+++ trunk/SophyaPI/PIext/pistdimgapp.cc	(revision 384)
@@ -1181,5 +1181,5 @@
     sprintf(strg,"Image: %s -  Pave %d %d \n",  curpimg->Nom().c_str(), 
             curpimg->XPave(),  curpimg->YPave());     
-    mps->DrawString(10., 25., strg, PI_Black, PI_BoldFont, 20);
+    mps->DrawString(10., 25., strg, PI_Black, PI_DefaultFont, PI_BoldFont, 20);
     mps->EndBloc();
 
