Index: trunk/SophyaLib/NTools/Makefile
===================================================================
--- trunk/SophyaLib/NTools/Makefile	(revision 2639)
+++ trunk/SophyaLib/NTools/Makefile	(revision 2650)
@@ -3,7 +3,7 @@
 all: $(LIB)libNTools.a
 clean:
-	rm -f $(OBJ)FSAppIrrSmpl.o $(OBJ)cimage.o $(OBJ)cspline.o $(OBJ)datatypes.o $(OBJ)dates.o $(OBJ)difeq.o $(OBJ)dynccd.o $(OBJ)fct1dfit.o $(OBJ)fct2dfit.o $(OBJ)fftmserver.o $(OBJ)fftpserver.o $(OBJ)fftservintf.o $(OBJ)functab.o $(OBJ)generaldata.o $(OBJ)generalfit.o $(OBJ)imageop.o $(OBJ)integ.o $(OBJ)median.o $(OBJ)ntoolsinit.o $(OBJ)objfitter.o $(OBJ)perandom.o $(OBJ)poly.o $(OBJ)rk4cdifeq.o $(OBJ)simplesort.o $(OBJ)tabmath.o $(OBJ)datime.o $(OBJ)fftmayer_r4.o $(OBJ)fftmayer_r8.o $(OBJ)fftpackc.o $(OBJ)matxop.o $(OBJ)nbmath.o $(OBJ)nbtri.o
+	rm -f $(OBJ)FSAppIrrSmpl.o $(OBJ)cimage.o $(OBJ)cspline.o $(OBJ)datatypes.o $(OBJ)dates.o $(OBJ)difeq.o $(OBJ)dynccd.o $(OBJ)fct1dfit.o $(OBJ)fct2dfit.o $(OBJ)fftmserver.o $(OBJ)fftpserver.o $(OBJ)fftservintf.o $(OBJ)functab.o $(OBJ)generaldata.o $(OBJ)generalfit.o $(OBJ)imageop.o $(OBJ)integ.o $(OBJ)median.o $(OBJ)ntoolsinit.o $(OBJ)objfitter.o $(OBJ)perandom.o $(OBJ)poly.o $(OBJ)rk4cdifeq.o $(OBJ)simplesort.o $(OBJ)simplex.o $(OBJ)tabmath.o $(OBJ)datime.o $(OBJ)fftmayer_r4.o $(OBJ)fftmayer_r8.o $(OBJ)fftpackc.o $(OBJ)matxop.o $(OBJ)nbmath.o $(OBJ)nbtri.o
 	rm -f $(LIB)libNTools.a
-$(LIB)libNTools.a : $(OBJ)FSAppIrrSmpl.o $(OBJ)cimage.o $(OBJ)cspline.o $(OBJ)datatypes.o $(OBJ)dates.o $(OBJ)datime.o $(OBJ)difeq.o $(OBJ)dynccd.o $(OBJ)fct1dfit.o $(OBJ)fct2dfit.o $(OBJ)fftmayer_r4.o $(OBJ)fftmayer_r8.o $(OBJ)fftmserver.o $(OBJ)fftpackc.o $(OBJ)fftpserver.o $(OBJ)fftservintf.o $(OBJ)functab.o $(OBJ)generaldata.o $(OBJ)generalfit.o $(OBJ)integ.o $(OBJ)matxop.o $(OBJ)median.o $(OBJ)nbmath.o $(OBJ)nbtri.o $(OBJ)ntoolsinit.o $(OBJ)objfitter.o $(OBJ)perandom.o $(OBJ)poly.o $(OBJ)rk4cdifeq.o $(OBJ)simplesort.o $(OBJ)tabmath.o
+$(LIB)libNTools.a : $(OBJ)FSAppIrrSmpl.o $(OBJ)cimage.o $(OBJ)cspline.o $(OBJ)datatypes.o $(OBJ)dates.o $(OBJ)datime.o $(OBJ)difeq.o $(OBJ)dynccd.o $(OBJ)fct1dfit.o $(OBJ)fct2dfit.o $(OBJ)fftmayer_r4.o $(OBJ)fftmayer_r8.o $(OBJ)fftmserver.o $(OBJ)fftpackc.o $(OBJ)fftpserver.o $(OBJ)fftservintf.o $(OBJ)functab.o $(OBJ)generaldata.o $(OBJ)generalfit.o $(OBJ)integ.o $(OBJ)matxop.o $(OBJ)median.o $(OBJ)nbmath.o $(OBJ)nbtri.o $(OBJ)ntoolsinit.o $(OBJ)objfitter.o $(OBJ)perandom.o $(OBJ)poly.o $(OBJ)rk4cdifeq.o $(OBJ)simplesort.o $(OBJ)simplex.o $(OBJ)tabmath.o
 	$(ARCXX) $(ARCXXFLAGS) $@ $($(ARARGS))
 ifeq ($(CXX),cxx)
@@ -11,429 +11,448 @@
 endif 
  
-$(OBJ)FSAppIrrSmpl.o: FSAppIrrSmpl.cc \
- $(INC)sopnamsp.h FSAppIrrSmpl.h \
- $(INC)machdefs.h nbmath.h \
- $(INC)smathconst.h \
- $(INC)timing.h \
- $(INC)array.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)pexceptions.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h \
- $(INC)tmatrix.h \
- $(INC)tvector.h \
- $(INC)matharr.h \
- $(INC)fioarr.h \
- $(INC)sopemtx.h fftservintf.h fftpserver.h \
- $(INC)toeplitzMatrix.h \
- $(INC)nbmath.h \
- $(INC)fftservintf.h \
- $(INC)fftpserver.h
+$(OBJ)FSAppIrrSmpl.o: FSAppIrrSmpl.cc $(INC)sopnamsp.h \
+  FSAppIrrSmpl.h $(INC)machdefs.h nbmath.h \
+  $(INC)smathconst.h \
+  $(INC)timing.h \
+  $(INC)array.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)pexceptions.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h \
+  $(INC)tmatrix.h \
+  $(INC)tvector.h \
+  $(INC)matharr.h \
+  $(INC)fioarr.h \
+  $(INC)sopemtx.h fftservintf.h fftpserver.h \
+  $(INC)toeplitzMatrix.h \
+  $(INC)nbmath.h \
+  $(INC)fftservintf.h \
+  $(INC)fftpserver.h
 $(OBJ)cimage.o: cimage.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h \
- $(INC)pexceptions.h cimage.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h \
- $(INC)fioarr.h \
- $(INC)tvector.h \
- $(INC)datatype.h
+  $(INC)machdefs.h \
+  $(INC)pexceptions.h cimage.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h \
+  $(INC)fioarr.h \
+  $(INC)tvector.h \
+  $(INC)datatype.h
 $(OBJ)cspline.o: cspline.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h nbtri.h cspline.h \
- $(INC)pexceptions.h
+  $(INC)machdefs.h nbtri.h cspline.h \
+  $(INC)pexceptions.h
 $(OBJ)datatypes.o: datatypes.cc $(INC)sopnamsp.h \
- datatypes.h $(INC)machdefs.h
+  datatypes.h $(INC)machdefs.h
 $(OBJ)dates.o: dates.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h \
- $(INC)perrors.h \
- $(INC)pexceptions.h dates.h
+  $(INC)machdefs.h \
+  $(INC)perrors.h \
+  $(INC)pexceptions.h dates.h
 $(OBJ)difeq.o: difeq.cc $(INC)sopnamsp.h difeq.h \
- $(INC)machdefs.h \
- $(INC)pexceptions.h \
- $(INC)tvector.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h \
- $(INC)ctimer.h
+  $(INC)machdefs.h \
+  $(INC)pexceptions.h \
+  $(INC)tvector.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h \
+  $(INC)ctimer.h
 $(OBJ)dynccd.o: dynccd.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h fmath.h perandom.h \
- $(INC)histos.h \
- $(INC)objfio.h \
- $(INC)anydataobj.h \
- $(INC)ppersist.h \
- $(INC)pexceptions.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)peida.h \
- $(INC)utils.h \
- $(INC)perrors.h \
- $(INC)fmath.h \
- $(INC)tvector.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h nbrandom.h \
- $(INC)srandgen.h cimage.h \
- $(INC)fioarr.h dynccd.h
+  $(INC)machdefs.h fmath.h perandom.h \
+  $(INC)histos.h \
+  $(INC)objfio.h \
+  $(INC)anydataobj.h \
+  $(INC)ppersist.h \
+  $(INC)pexceptions.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)peida.h \
+  $(INC)utils.h \
+  $(INC)perrors.h \
+  $(INC)fmath.h \
+  $(INC)tvector.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h nbrandom.h \
+  $(INC)srandgen.h cimage.h \
+  $(INC)fioarr.h dynccd.h
 $(OBJ)fct1dfit.o: fct1dfit.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h fct1dfit.h generalfit.h \
- $(INC)pexceptions.h \
- $(INC)tvector.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h generaldata.h \
- $(INC)ntupintf.h poly.h peida.h \
- $(INC)utils.h \
- $(INC)perrors.h fmath.h nbconst.h tabmath.h
+  $(INC)machdefs.h fct1dfit.h generalfit.h \
+  $(INC)pexceptions.h \
+  $(INC)tvector.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h generaldata.h \
+  $(INC)ntupintf.h poly.h peida.h \
+  $(INC)utils.h \
+  $(INC)perrors.h fmath.h nbconst.h tabmath.h
 $(OBJ)fct2dfit.o: fct2dfit.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h fct2dfit.h generalfit.h \
- $(INC)pexceptions.h \
- $(INC)tvector.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h generaldata.h \
- $(INC)ntupintf.h poly.h peida.h \
- $(INC)utils.h \
- $(INC)perrors.h fmath.h nbconst.h tabmath.h \
- simps2d.h
+  $(INC)machdefs.h fct2dfit.h generalfit.h \
+  $(INC)pexceptions.h \
+  $(INC)tvector.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h generaldata.h \
+  $(INC)ntupintf.h poly.h peida.h \
+  $(INC)utils.h \
+  $(INC)perrors.h fmath.h nbconst.h tabmath.h \
+  simps2d.h
 $(OBJ)fftmserver.o: fftmserver.cc $(INC)sopnamsp.h \
- fftmserver.h fftservintf.h $(INC)machdefs.h \
- $(INC)pexceptions.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h \
- $(INC)tvector.h fftmayer.h
+  fftmserver.h fftservintf.h $(INC)machdefs.h \
+  $(INC)pexceptions.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h \
+  $(INC)tvector.h fftmayer.h
 $(OBJ)fftpserver.o: fftpserver.cc $(INC)sopnamsp.h \
- fftpserver.h fftservintf.h $(INC)machdefs.h \
- $(INC)pexceptions.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h \
- $(INC)tvector.h fftpackc.h
-$(OBJ)fftservintf.o: fftservintf.cc \
- $(INC)sopnamsp.h fftservintf.h \
- $(INC)machdefs.h \
- $(INC)pexceptions.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h \
- $(INC)tvector.h
+  fftpserver.h fftservintf.h $(INC)machdefs.h \
+  $(INC)pexceptions.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h \
+  $(INC)tvector.h fftpackc.h
+$(OBJ)fftservintf.o: fftservintf.cc $(INC)sopnamsp.h \
+  fftservintf.h $(INC)machdefs.h \
+  $(INC)pexceptions.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h \
+  $(INC)tvector.h
 $(OBJ)functab.o: functab.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h \
- $(INC)pexceptions.h functab.h \
- $(INC)tvector.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h
-$(OBJ)generaldata.o: generaldata.cc \
- $(INC)sopnamsp.h \
- $(INC)machdefs.h \
- $(INC)strutil.h nbtri.h generalfit.h \
- $(INC)pexceptions.h \
- $(INC)tvector.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h generaldata.h \
- $(INC)ntupintf.h poly.h peida.h \
- $(INC)utils.h \
- $(INC)perrors.h fmath.h
+  $(INC)machdefs.h \
+  $(INC)pexceptions.h functab.h \
+  $(INC)tvector.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h
+$(OBJ)generaldata.o: generaldata.cc $(INC)sopnamsp.h \
+  $(INC)machdefs.h \
+  $(INC)strutil.h nbtri.h generalfit.h \
+  $(INC)pexceptions.h \
+  $(INC)tvector.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h generaldata.h \
+  $(INC)ntupintf.h poly.h peida.h \
+  $(INC)utils.h \
+  $(INC)perrors.h fmath.h
 $(OBJ)generalfit.o: generalfit.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h \
- $(INC)pexceptions.h generalfit.h \
- $(INC)tvector.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h generaldata.h \
- $(INC)ntupintf.h poly.h peida.h \
- $(INC)utils.h \
- $(INC)perrors.h fmath.h \
- $(INC)sopemtx.h
+  $(INC)machdefs.h \
+  $(INC)pexceptions.h generalfit.h \
+  $(INC)tvector.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h generaldata.h \
+  $(INC)ntupintf.h poly.h peida.h \
+  $(INC)utils.h \
+  $(INC)perrors.h fmath.h \
+  $(INC)sopemtx.h
 $(OBJ)integ.o: integ.cc $(INC)sopnamsp.h integ.h \
- $(INC)machdefs.h \
- $(INC)pexceptions.h classfunc.h generalfit.h \
- $(INC)tvector.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h generaldata.h \
- $(INC)ntupintf.h poly.h peida.h \
- $(INC)utils.h \
- $(INC)perrors.h fmath.h
+  $(INC)machdefs.h \
+  $(INC)pexceptions.h classfunc.h generalfit.h \
+  $(INC)tvector.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h generaldata.h \
+  $(INC)ntupintf.h poly.h peida.h \
+  $(INC)utils.h \
+  $(INC)perrors.h fmath.h
 $(OBJ)median.o: median.cc
 $(OBJ)ntoolsinit.o: ntoolsinit.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h ntoolsinit.h \
- $(INC)tarrinit.h \
- $(INC)sophyainit.h poly.h \
- $(INC)objfio.h \
- $(INC)anydataobj.h \
- $(INC)ppersist.h \
- $(INC)pexceptions.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h peida.h \
- $(INC)utils.h \
- $(INC)perrors.h fmath.h \
- $(INC)tvector.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h generaldata.h \
- $(INC)ntupintf.h cimage.h \
- $(INC)fioarr.h tabmath.h nbconst.h dates.h \
- datime.h
+  $(INC)machdefs.h ntoolsinit.h \
+  $(INC)tarrinit.h \
+  $(INC)sophyainit.h poly.h \
+  $(INC)objfio.h \
+  $(INC)anydataobj.h \
+  $(INC)ppersist.h \
+  $(INC)pexceptions.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h peida.h \
+  $(INC)utils.h \
+  $(INC)perrors.h fmath.h \
+  $(INC)tvector.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h generaldata.h \
+  $(INC)ntupintf.h cimage.h \
+  $(INC)fioarr.h tabmath.h nbconst.h dates.h \
+  datime.h
 $(OBJ)objfitter.o: objfitter.cc $(INC)sopnamsp.h \
- objfitter.h $(INC)machdefs.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)pexceptions.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h cimage.h \
- $(INC)fioarr.h \
- $(INC)tvector.h \
- $(INC)histos.h \
- $(INC)peida.h \
- $(INC)utils.h \
- $(INC)perrors.h \
- $(INC)fmath.h \
- $(INC)histos2.h \
- $(INC)hisprof.h generalfit.h generaldata.h \
- $(INC)ntupintf.h poly.h peida.h
+  objfitter.h $(INC)machdefs.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)pexceptions.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h cimage.h \
+  $(INC)fioarr.h \
+  $(INC)tvector.h \
+  $(INC)histos.h \
+  $(INC)peida.h \
+  $(INC)utils.h \
+  $(INC)perrors.h \
+  $(INC)fmath.h \
+  $(INC)histos2.h \
+  $(INC)hisprof.h generalfit.h generaldata.h \
+  $(INC)ntupintf.h poly.h peida.h
 $(OBJ)perandom.o: perandom.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h \
- $(INC)pexceptions.h perandom.h \
- $(INC)histos.h \
- $(INC)objfio.h \
- $(INC)anydataobj.h \
- $(INC)ppersist.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)peida.h \
- $(INC)utils.h \
- $(INC)perrors.h \
- $(INC)fmath.h \
- $(INC)tvector.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h nbrandom.h \
- $(INC)srandgen.h pemath.h
+  $(INC)machdefs.h \
+  $(INC)pexceptions.h perandom.h \
+  $(INC)histos.h \
+  $(INC)objfio.h \
+  $(INC)anydataobj.h \
+  $(INC)ppersist.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)peida.h \
+  $(INC)utils.h \
+  $(INC)perrors.h \
+  $(INC)fmath.h \
+  $(INC)tvector.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h nbrandom.h \
+  $(INC)srandgen.h pemath.h
 $(OBJ)poly.o: poly.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h poly.h \
- $(INC)objfio.h \
- $(INC)anydataobj.h \
- $(INC)ppersist.h \
- $(INC)pexceptions.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h peida.h \
- $(INC)utils.h \
- $(INC)perrors.h fmath.h \
- $(INC)tvector.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h linfit.h \
- $(INC)sopemtx.h \
- $(INC)fioarr.h
+  $(INC)machdefs.h poly.h \
+  $(INC)objfio.h \
+  $(INC)anydataobj.h \
+  $(INC)ppersist.h \
+  $(INC)pexceptions.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h peida.h \
+  $(INC)utils.h \
+  $(INC)perrors.h fmath.h \
+  $(INC)tvector.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h linfit.h \
+  $(INC)sopemtx.h \
+  $(INC)fioarr.h
 $(OBJ)rk4cdifeq.o: rk4cdifeq.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h rk4cdifeq.h difeq.h \
- $(INC)pexceptions.h \
- $(INC)tvector.h \
- $(INC)tmatrix.h \
- $(INC)tarray.h \
- $(INC)basarr.h \
- $(INC)anydataobj.h \
- $(INC)mutyv.h \
- $(INC)dvlist.h \
- $(INC)objfio.h \
- $(INC)ppersist.h \
- $(INC)gnumd5.h \
- $(INC)ppfbinstream.h \
- $(INC)rawstream.h \
- $(INC)ppfnametag.h \
- $(INC)ndatablock.h \
- $(INC)utilarr.h \
- $(INC)ctimer.h
+  $(INC)machdefs.h rk4cdifeq.h difeq.h \
+  $(INC)pexceptions.h \
+  $(INC)tvector.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h \
+  $(INC)ctimer.h
 $(OBJ)simplesort.o: simplesort.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h simplesort.h peida.h \
- $(INC)utils.h \
- $(INC)perrors.h \
- $(INC)pexceptions.h fmath.h
+  $(INC)machdefs.h simplesort.h peida.h \
+  $(INC)utils.h \
+  $(INC)perrors.h \
+  $(INC)pexceptions.h fmath.h
+$(OBJ)simplex.o: simplex.cc $(INC)sopnamsp.h simplex.h \
+  $(INC)machdefs.h \
+  $(INC)tvector.h \
+  $(INC)tmatrix.h \
+  $(INC)tarray.h \
+  $(INC)basarr.h \
+  $(INC)anydataobj.h \
+  $(INC)mutyv.h \
+  $(INC)dvlist.h \
+  $(INC)objfio.h \
+  $(INC)ppersist.h \
+  $(INC)pexceptions.h \
+  $(INC)gnumd5.h \
+  $(INC)ppfbinstream.h \
+  $(INC)rawstream.h \
+  $(INC)ppfnametag.h \
+  $(INC)ndatablock.h \
+  $(INC)utilarr.h generalfit.h generaldata.h \
+  $(INC)ntupintf.h poly.h peida.h \
+  $(INC)utils.h \
+  $(INC)perrors.h fmath.h \
+  $(INC)ntuple.h \
+  $(INC)timing.h
 $(OBJ)tabmath.o: tabmath.cc $(INC)sopnamsp.h \
- $(INC)machdefs.h tabmath.h peida.h \
- $(INC)utils.h \
- $(INC)perrors.h \
- $(INC)pexceptions.h fmath.h nbconst.h
+  $(INC)machdefs.h tabmath.h peida.h \
+  $(INC)utils.h \
+  $(INC)perrors.h \
+  $(INC)pexceptions.h fmath.h nbconst.h
 $(OBJ)datime.o: datime.c $(INC)machdefs.h \
- $(INC)strutil.h nbconst.h datime.h
+  $(INC)strutil.h nbconst.h datime.h
 $(OBJ)fftmayer_r4.o: fftmayer_r4.c fftmayer.h \
- $(INC)machdefs.h trigtbl.h
+  $(INC)machdefs.h trigtbl.h
 $(OBJ)fftmayer_r8.o: fftmayer_r8.c fftmayer.h \
- $(INC)machdefs.h trigtbl.h
+  $(INC)machdefs.h trigtbl.h
 $(OBJ)fftpackc.o: fftpackc.c fftpackc.h \
- $(INC)machdefs.h
+  $(INC)machdefs.h
 $(OBJ)matxop.o: matxop.c matxop.h nbmath.h \
- $(INC)machdefs.h \
- $(INC)smathconst.h
+  $(INC)machdefs.h \
+  $(INC)smathconst.h
 $(OBJ)nbmath.o: nbmath.c nbmath.h $(INC)machdefs.h \
- $(INC)smathconst.h matxop.h nbinteg.h \
- nbtri.h
+  $(INC)smathconst.h matxop.h nbinteg.h nbtri.h
 $(OBJ)nbtri.o: nbtri.c nbtri.h $(INC)machdefs.h
Index: trunk/SophyaLib/NTools/objlist.list
===================================================================
--- trunk/SophyaLib/NTools/objlist.list	(revision 2639)
+++ trunk/SophyaLib/NTools/objlist.list	(revision 2650)
@@ -29,3 +29,4 @@
 rk4cdifeq.o
 simplesort.o
+simplex.o
 tabmath.o
Index: trunk/SophyaLib/NTools/simplex.cc
===================================================================
--- trunk/SophyaLib/NTools/simplex.cc	(revision 2650)
+++ trunk/SophyaLib/NTools/simplex.cc	(revision 2650)
@@ -0,0 +1,440 @@
+#include "sopnamsp.h"
+#include "simplex.h"
+#include "ntuple.h"
+#include <math.h>
+
+#include "timing.h"
+
+//---------------------------------------------------------------
+//-------------------  Classe   MinZFunction  -------------------
+//---------------------------------------------------------------
+// Interface de classe de function multivariable pour le SimplexMinmizer
+
+MinZFunction::MinZFunction(unsigned int nvar)
+  : mNVar(nvar)
+{
+}
+
+MinZFunction::~MinZFunction()
+{
+}
+
+//---------------------------------------------------------------
+//-------------------  Classe   MinZFuncXi2  --------------------
+//---------------------------------------------------------------
+MinZFuncXi2::MinZFuncXi2(GeneralXi2* gxi2, GeneralFitData* gd)
+  : mGXi2(gxi2) , mGData(gd), MinZFunction(gxi2->NPar())
+{
+}
+
+MinZFuncXi2::~MinZFuncXi2()
+{
+}
+
+double MinZFuncXi2::Value(double const xp[])
+{
+  int ndataused;
+  return mGXi2->Value(*mGData, const_cast<double *>(xp), ndataused);
+}
+
+//---------------------------------------------------------------
+//-------------------  Classe  MinZTestFunc   -------------------
+//---------------------------------------------------------------
+class MinZTestFunc : public  MinZFunction {
+public:
+  MinZTestFunc(int sel);
+  virtual double Value(double const xp[]);
+  string  ToString();
+  Vector  OptParms();
+protected:
+  static int ISelToNvar(int isel);
+  int mSel;
+};
+
+int MinZTestFunc::ISelToNvar(int isel)
+{
+  if (isel == 0) return 1;
+  if (isel == 1) return 1;
+  else if (isel == 2) return 1;
+  else if (isel == 3) return 2;
+  else if (isel == 4) return 3;
+  else return 1;
+}
+
+MinZTestFunc::MinZTestFunc(int sel)
+  : MinZFunction(ISelToNvar(sel)) 
+{
+  if ((sel < 0) || (sel > 4)) sel = 0;
+  mSel = sel;
+}
+
+string MinZTestFunc::ToString()
+{
+  string rs;
+  if (mSel == 0) {
+    rs = "-x+(x-2)^2"; 
+  }
+  else if (mSel == 1) {
+    rs = "0.1*x^2-3exp(-(x-2)^2)-5*exp(-0.5*(x+3)^2)";
+  }
+  else if (mSel == 2) {
+    rs = "0.1*x^2-3exp(-(x-2)^2)+5*exp(-0.5*(x+3)^2)";
+  }
+  else if (mSel == 3) {
+    rs = "1.3*(x-50.35)^2+25*(y+3.14)^2";
+  }
+  else if (mSel == 4) {
+    rs = "(x-2.2)^2+2.*(y+3.6)^2+3.*(z-1.1)^2";
+  }
+  else rs = "????";
+  return  rs;
+}
+
+Vector MinZTestFunc::OptParms()
+{
+  Vector xx;
+  if (mSel == 0) {
+    Vector rv(1);
+    rv = 2.5;
+    return rv;
+  }
+  else if (mSel == 1) {
+    Vector rv(1);
+    rv = -2.883;
+    return rv;
+  }
+  else if (mSel == 2) {
+    Vector rv(1);
+    rv = 1.812;
+    return rv;
+  }
+  else if (mSel == 3) {
+    Vector rv(2);
+    rv(0) = 50.35;
+    rv(1) = -3.14;
+    return rv;
+  }
+  else if (mSel == 4) {
+    Vector rv(3);
+    rv(0) = 2.2;
+    rv(1) = -3.6;
+    rv(2) = 1.1;
+    return rv;
+  }
+  else xx = 0.;
+  return xx ;
+}
+
+
+double MinZTestFunc::Value(double const xp[])
+{
+  double retval = 0;
+  if (mSel == 0) {
+    double x = xp[0];
+    retval = -x+(x-2.)*(x-2.);
+  }
+  else if ((mSel == 1) || (mSel == 2)) {
+    double x = xp[0];
+    retval = 0.1*x*x;
+    x = xp[0]-2.;
+    x = x*x;
+    retval -= 3*exp(-x);
+    x = xp[0]+3.;
+    x = 0.5*x*x;
+    if (mSel == 1) retval -= 5*exp(-x);
+    else retval += 5*exp(-x);
+  }
+  else if (mSel == 3) {
+    double x = xp[0]-50.35;
+    double y = xp[1]+3.14;
+    retval = 1.3*x*x+25.*y*y;
+  }
+  else if (mSel == 4) {
+    double x = xp[0]-2.2;
+    double y = xp[1]+3.6;
+    double z = xp[2]-1.1;
+    retval = x*x+2.*y*y+3.*z*z;
+  }
+  else retval = 0.;
+  return retval;
+}
+
+//---------------------------------------------------------------
+//-------------------  Classe   MinZSimplex  --------------------
+//---------------------------------------------------------------
+string __Vec2Str4MinZ_AutoTest(Vector& xx) 
+{
+  string rs;
+  char buff[32];
+  for(int i=0; i<xx.Size(); i++) {
+    sprintf(buff," %g " , xx(i));
+    rs += buff;
+  }
+  return rs;
+}
+
+int MinZSimplex::AutoTest(int tsel, int prtlev)
+{
+  int rc = 0;
+  cout << " --- MinZSimplex::AutoTest() --- TSel= " << tsel << " PrtLev=" << prtlev << endl;
+  for(int i=0; i<5; i++) {
+    if ((tsel >= 0) && (tsel != i))  continue; 
+    cout << " ======= Test avec ISel= " << i;
+    Vector xx;
+    MinZTestFunc mzf(i);
+    cout << " - Func= " << mzf.ToString() << endl;
+    Vector rv = mzf.OptParms();
+    xx = rv;
+    for(int j=0; j<2; j++) {
+      double vi = 50.*(j-0.5);
+      for(int k=0; k<2; k++) {
+	double vs = (k == 0) ? 1. : 10. ;
+	cout << "--[" << j << "," << k 
+	     << "] Initialisation avec IniPoint= " << vi << " IniStep= " << vs << endl;
+	MinZSimplex simplex(&mzf);
+	xx = vi;
+	simplex.SetInitialPoint(xx);
+	xx = vs;
+	simplex.SetInitialStep(xx);
+	simplex.SetPrtLevel(prtlev);
+	int rcs = simplex.Minimize(xx);
+	Vector diff = rv-xx;
+	double d2 = diff.Norm2();
+	cout << " Rc(simplex.Minimize() = " << rc << " NIter= " 
+	     << simplex.NbIter() << " ===> Distance^2= " << d2
+	     << "\nConverged to " <<  __Vec2Str4MinZ_AutoTest(xx) 
+	     << "  Best Value= " << __Vec2Str4MinZ_AutoTest(rv) 
+	     << "  Diff = " << __Vec2Str4MinZ_AutoTest(diff) << endl;
+	if ((rcs > 5) || (d2 > 0.5))  rc ++;
+      }
+    }
+  }
+  cout << " --- MinZSimplex::AutoTest() --- Rc=" << rc << " -- END ----- " << endl;
+  return rc;
+}
+
+MinZSimplex::MinZSimplex(MinZFunction *mzf)
+  : mZF(mzf) , mPoint0(mZF->NVar()) , mStep0(mZF->NVar())
+{
+  SetMaxIter();
+  SetControls();
+  Vector xx(NDim());
+  xx = 0.;
+  SetInitialPoint(xx);
+  xx = 1.0;
+  SetInitialStep(xx);
+  SetStopTolerance();
+  mIter = -1;
+  mStop = -1;
+  SetPrtLevel();
+}
+
+MinZSimplex::~MinZSimplex()
+{
+}
+
+int MinZSimplex::Minimize(Vector& fpoint)
+{
+  // vector< TVector<r_8> > splx;
+  Vector splx[100];
+  Vector Y(NDim()+1);
+  // On calcule le simplex initial
+  // N = NDim, N+1 points (pp) ds l'espace a N dimensions
+  // Point0, Point0 + Step0(i) e_i  
+  Vector pp,ppc;
+  pp = mPoint0;
+  //ppc = pp;
+  //splx.push_back(ppc);
+  splx[0] = pp;
+  int i,j,k;
+  for(i=0; i<NDim(); i++) {
+    Vector pps;
+    pps = mPoint0;
+    pps(i) += mStep0(i);
+    //splx.push_back(pps);    
+    splx[i+1] = pps;
+  }
+  int mpts = NDim()+1;
+  // calcul des valeurs de la fonction sur les sommets
+  for(i=0; i<mpts; i++) 
+    Y(i) = Value(splx[i]); 
+
+  int iter = 0;
+  mIter = iter;
+  mStop = 0;
+
+  int nbugrtol2 = 0;
+  bool stop = false, stop0=false;      
+  int rc = 0;
+  int ilo, ihi, inhi;
+  int move = 0;
+  char* smov[6] = { "None", "Reflection", "ReflecExpand", "ContractHigh", "ContractLow", "ExpandHigh" };
+  int movcnt[6] = {0,0,0,0,0,0};
+
+  int nrep1=0, nrep2=0;
+  FindMinMax12(Y, ilo, ihi, inhi);
+  double yhilast = Y(ihi);
+  yhilast += fabs(yhilast); 
+
+  while (!stop) {  // 
+    FindMinMax12(Y, ilo, ihi, inhi);
+    double ymean = (fabs(Y(ihi))+fabs(Y(ilo)));
+    if (ymean < mTol0) { stop0 = true; ymean = mTol0; }
+    double rtol1 = 2.*fabs(Y(ihi)-Y(ilo))/ymean;
+    double ym2 = (fabs(yhilast)+fabs(Y(ihi)));
+    if (ym2 < mTol0) ym2 = mTol0; 
+    double rtol2 = 2.*(yhilast-Y(ihi))/ym2;
+    yhilast = Y(ihi);
+    if (rtol2 < 0.) {
+      if (move != 40) { 
+	cout << " !!!! MinZSimplex::Minimize() BUG RTol2< 0. --> Chs " << endl;
+	nbugrtol2++;
+      }
+      else nrep2 = 0;
+      rtol2 = -rtol2;
+    }
+    if (PrtLevel() > 1)  
+      cout << "--MinZSimplex::Minimize() - Iter=" << iter
+	   << " Move= " << move << " (" <<  smov[move/10] << ")" << endl;
+    if (PrtLevel() > 2)  
+      cout << "..ILO=" << ilo << " IHI=" << ihi << " INHI=" << inhi
+	   << " Y(ILO)=" << Y(ilo) << " Y(IHI)=" << Y(ihi) << "\n"
+	   << "...YMean_Abs=" << ymean <<  " RTOL1=" << rtol1 << " RTOL2=" << rtol2 <<  endl;
+    if (PrtLevel() > 3) {
+      for(i=0; i<mpts; i++) {
+	cout << "....Simplex[" << i << "]= "; 
+	for(j=0; j<NDim(); j++) cout << splx[i](j) << " , ";
+	cout << " Y=Value= " << Y(i) << endl;
+      }
+    }
+    if (rtol1 < mTol1) nrep1++;
+    else nrep1 = 0;
+    if (rtol2 < mTol2) nrep2++;
+    else nrep2 = 0;
+    
+    if (stop0) { mStop = 1; rc = 0; stop = true; break; }
+    if (nrep1 > mRep1) { mStop = 2; rc = 0; stop = true; break; }
+    if (nrep2 > mRep2) { mStop = 3; rc = 0; stop = true; break; }
+    if (iter > MaxIter() ) { mStop = 0, rc = iter;  break; }
+    iter++;
+    if (iter > 0)  movcnt[move/10]++;  
+
+    // Next iteration, on modifie le simplex
+    // Calcul du centre de gravite su simplex, hors le point le + haut
+    Vector pbar(NDim());
+    pbar = 0.;
+    for(i=0; i<mpts; i++) {
+      if (i == ihi)  continue;
+      pbar += splx[i];
+    }
+    pbar /= (double)NDim();
+    // On calcule le sommet oppose a point IHI (le + haut)
+    Vector pr, prr;
+    double YPR, YPRR;
+    pr = (1.+Alpha())*pbar-Alpha()*splx[ihi];
+    YPR = Value(pr);
+    if (YPR < Y(ilo)) {   // Amelioaration par rapport au meilleur point,
+      // on va plus loin d'un facteur gamma
+      prr = Gamma()*pr+(1.-Gamma())*pbar;
+      YPRR = Value(prr);
+      if (YPRR < Y(ilo)) {  // On remplace le IHI par YPRR 
+	splx[ihi] = prr;
+	Y(ihi) = YPRR;
+	move = 20;
+      }
+      else {  // sinon, on remplace par YPR
+	splx[ihi] = pr;
+	Y(ihi) = YPR;
+	move = 10;
+      }
+    }
+    else {  // Moins bon que le meilleur point .. 
+      if (YPR > Y(inhi)) {  // Plus mauvais que le second plus haut (INHI)
+	if (YPR < Y(ihi)) {   // Mais meilleur que le plus haut (IHI)
+	  splx[ihi] = pr;     // On remplace donc le plus haut
+	  Y(ihi) = YPR;		
+	  move = 11;
+	}
+	else { // Plus mauvais que le plus mauvais IHI 
+	  // on tente avec un point intermediaire 
+	  prr = Beta()*splx[ihi]+(1.-Beta())*pbar;
+	  YPRR = Value(prr);
+	  if (YPRR < Y(ihi)) {   // Le point intermediaire ameliore les choses
+	    splx[ihi] = prr;     // On remplace donc le point le + haut
+	    Y(ihi) = YPRR;
+	    move = 30;
+	  }
+	  else {  
+	    // On tente aussi de rester du meme cote, mais aller plus loin 
+	    prr = Gamma2()*splx[ihi]+(1.-Gamma2())*pbar;
+	    YPRR = Value(prr);
+	    if (YPRR < Y(ihi)) {   // Le point intermediaire ameliore les choses
+	      splx[ihi] = prr;     // On remplace donc le point le + haut
+	      Y(ihi) = YPRR;
+	      move = 50;
+	    }
+	    else { 
+	    // Rien n'y fait, on contracte autour du meilleur point 
+	      for(i=0; i<mpts; i++) {
+		if (i == ilo)  continue;
+		splx[i] = Beta2()*splx[i]+(1.-Beta())*splx[ilo];
+		Y(i) = Value(splx[i]);
+		move = 40;
+	      } 
+	    }
+	  }
+	}
+      }
+      else {  // Meilleur que le IHI et le INHI
+	splx[ihi] = pr;     // On remplace le plus haut
+	Y(ihi) = YPR;	
+	move = 12;
+      }
+    }			 
+  }   // Fin de la boucle while principale
+
+  fpoint = splx[ilo];
+  mIter = iter;
+
+  if (PrtLevel() > 0) {
+    string sr;
+    StopReason(sr);
+    cout << "-----MinZSimplex::Minimize()/Ended - NIter=" << iter 
+	 << " Moves[0..5]= " << movcnt[0] << "," << movcnt[1] << "," 
+	 << movcnt[2] << "," << movcnt[3] << "," 
+	 << movcnt[4] << "," << movcnt[5] 
+	 << "\n..MinZSimplex Stop=" << StopReason() << " -> " << sr << endl;
+    
+    if (nbugrtol2 > 0)  cout << "MinZSimplex::Minimize()/Warning - nbugrtol2= " << nbugrtol2 << endl;
+  }
+  return rc;
+}
+
+int MinZSimplex::StopReason(string& s)
+{
+  char* sr[5] = { "NoConverg, MaxIterReached", "OK, fm<Tol0", "OK, Df/f<Tol1", 
+		  "OK, [Df/f max]Iter<Tol2" "Error - Wrong StopReason" };
+  int stop = mStop;
+  if ((stop < 0) || (stop > 3)) stop = 4;
+  s = sr[stop];
+  return mStop;
+}
+
+int MinZSimplex::FindMinMax12(Vector& fval, int& ilo, int& ihi, int& inhi)
+{
+  ilo = 0;
+  if (fval(0) > fval(1)) { ihi = 0;  inhi = 1; }
+  else { ihi = 1;  inhi = 0; }
+  
+  for(int k=0; k<fval.Size(); k++) {
+    if (fval(k) < fval(ilo))  ilo = k;
+    if (fval(k) > fval(ihi)) {
+      inhi = ihi;
+      ihi = k;
+    }
+    else if (fval(k) > fval(inhi)) {
+      if (k != ihi)  inhi = k;  // ce test n'est peut-etre pas necessaire ???
+    }
+  }
+  return ilo;
+}
Index: trunk/SophyaLib/NTools/simplex.h
===================================================================
--- trunk/SophyaLib/NTools/simplex.h	(revision 2650)
+++ trunk/SophyaLib/NTools/simplex.h	(revision 2650)
@@ -0,0 +1,133 @@
+#ifndef SIMPLEX_SEEN
+#define SIMPLEX_SEEN
+
+#include "machdefs.h"
+#include "tvector.h"
+#include "generalfit.h"
+#include <string>
+#include <vector>
+
+// ---------------------------------------------------------------
+//             (C) UPS-LAL  R. Ansari , Aout 2004 
+// ---------------------------------------------------------------
+// Classe de minimisation (optimisation) non lineaire dans
+// un espace multidimensionnel suivant la methode des simplex.
+// Simplex : Figure geometrique formee de N+1 sommets (points) 
+//  (points) dans un espace a N dimension 
+// La methode d'optimisation codee ici dans la classe MinZSimplex 
+// est basee sur celle decrite dans Numerical Recipes ,
+// Chapitre X, Minimization or Maximization of Functions 
+// L'algorithme est ameliore sur deux aspects :
+//  - Test d'arret plus complexe 
+//  - Ajout d'une transformation du simplex  (ExpandHigh)
+//    Reflection,ReflecExpand,ContractHigh,ContractLow+ExpandHigh 
+// ----------------------------------------------------------------
+
+using namespace std;
+
+namespace SOPHYA {
+
+//! Interface definition for multivaruable function (used by SimplexMinmizer)
+class MinZFunction {
+public:
+  //! Constructor with nVar defining the number of variables
+  MinZFunction(unsigned int nVar); 
+  virtual ~MinZFunction();
+  //! Returns the value of the function for the point defined by xp[]
+  virtual double Value(double const xp[])=0;
+  //! Returns the number of variables (dimension of xp[]) in method Value()
+  inline int     NVar() const {return mNVar;}  
+protected:
+  const int mNVar;  //!< nombre de variables f(x,y,z,...)  
+};
+
+//!  Classe implementing MinZFunction for a GeneralXi2 associated with a GeneralFitData
+class MinZFuncXi2 : public MinZFunction {
+public: 
+  MinZFuncXi2(GeneralXi2* gxi2, GeneralFitData* gd);
+  virtual ~MinZFuncXi2(); 
+  virtual double Value(double const xp[]);
+protected:
+  GeneralXi2 *mGXi2;
+  GeneralFitData *mGData;
+};
+
+//! Class implementing the Simplex minimisation method 
+class MinZSimplex {
+public:
+  static int     AutoTest(int tsel=-1, int prtlev=0);
+
+                 MinZSimplex(MinZFunction *mzf);
+  virtual        ~MinZSimplex();
+
+  inline int     NDim() { return mZF->NVar(); }
+  // Simplex initial 
+  inline void    SetInitialPoint(Vector& point) { mPoint0 = point; }
+  inline void    SetInitialStep(Vector& step) { mStep0 = step; }
+
+  inline void    SetPrtLevel(int lev=0) { mPrt = lev; }
+  inline int     PrtLevel() { return mPrt; }
+
+  inline void    SetMaxIter(int max = 100000) { mMaxIter = max; }
+  inline int     MaxIter() { return mMaxIter; }
+  inline int     NbIter() { return mIter; }
+  inline int     StopReason() { return mStop; }
+         int     StopReason(string& s);
+
+  // On minimise f(x) f=mZF->Value() , 
+  //             f_max = max(f) sur simplex , f_min = min(f) sur simplex 
+  //             fm = (abs(f_max)+abs(f_min))
+  //             [Delta f] = abs(f_max-f_min)
+  //             [Delta f/f]simplex = 2.*Delta f / fm
+  //             fm2 = (abs(f_max)+abs(f_max(iter-1)))
+  //             [Delta f_max/f_max]iter = [f_max(iter-1)-f_max]/fm2 
+  // Test d'arret :  
+  //  fm < mTol0                                                       OU 
+  //  [Delta f/f]simplex              < mTol1   mRep1 fois de suite    OU 
+  //  [Delta f_max/f_max]iter         < mTol2   mRep2 fois de suite 
+  // 
+  inline void    SetStopTolerance(double tol0=1.e-39, double tol1 = 1.e-3, int rep1=5, 
+				  double tol2=1.e-4, int rep2=5)   
+                 { mTol0 = tol0; mTol1 = tol1; mRep1 = rep1; mTol2 = tol2, mRep2 = rep2; }
+
+  // Controle des facteurs de deformation du simplex:
+  // Alpha  = Facteur d'homothetie pour la reflexion simple (Reflection)
+  // Gamma  = Facteur d'homothetie pour la reflexion+expansion (ReflecExpand)
+  // Beta   = Facteur d'homothetie pour la contraction pour le sommet haut f_max (ContractHigh)
+  // Beta2  = Facteur d'homothetie pour la contraction vers le sommet bas f_min (ContractLow)
+  // Gamma2 = Facteur d'homothetie pour la l'extension pour le sommet haut ExpandHigh
+  inline void    SetControls(double alpha=1., double beta=0.5, double beta2=0.5, 
+			     double gamma=2.0, double gamma2=2.0)
+                 { mAlpha = alpha; mBeta = beta; mBeta2 = beta2;  mGamma = gamma; mGamma2 = gamma2;}  
+
+  inline double  Alpha() { return mAlpha; }
+  inline double  Beta() { return mBeta; }
+  inline double  Beta2() { return mBeta2; }
+  inline double  Gamma() { return mGamma; }
+  inline double  Gamma2() { return mGamma2; }
+
+  // Fonction de minimisation - Rc=0, OK, convergence , Rc>0, Non convergence 
+  // Voir StopReason(string& s)
+  virtual int    Minimize(Vector& fpoint);
+  
+protected:
+  int            FindMinMax12(Vector& fval, int& ilo, int& ihi, int& inhi);
+  inline double  Value(Vector& point) { return mZF->Value(point.Data()); }
+  
+  MinZFunction* mZF;
+  int mMaxIter, mIter;
+  int mStop;
+  int mPrt;
+
+  Vector mPoint0;
+  Vector mStep0;
+  //  vector< Vector > simplex0;
+  //  vector< Vector > simplex_cur;
+  double mAlpha, mBeta, mBeta2, mGamma, mGamma2;
+  double mTol0, mTol1, mTol2;
+  int mRep1,mRep2;
+};
+
+} // namespace SOPHYA
+
+#endif
