Index: park_integration/AbstractFitEngine.py
===================================================================
--- park_integration/AbstractFitEngine.py	(revision 985c88b87a5cf7319bfda1d8af0737566479cd84)
+++ park_integration/AbstractFitEngine.py	(revision 48882d14c03b61d8a22b600abadcccba552c8697)
@@ -1,3 +1,143 @@
 
+import park,numpy
+
+class SansParameter(park.Parameter):
+    """
+        SANS model parameters for use in the PARK fitting service.
+        The parameter attribute value is redirected to the underlying
+        parameter value in the SANS model.
+    """
+    def __init__(self, name, model):
+         self._model, self._name = model,name
+         self.set(model.getParam(name))
+         
+    def _getvalue(self): return self._model.getParam(self.name)
+    
+    def _setvalue(self,value): 
+        self._model.setParam(self.name, value)
+        
+    value = property(_getvalue,_setvalue)
+    
+    def _getrange(self):
+        lo,hi = self._model.details[self.name][1:]
+        if lo is None: lo = -numpy.inf
+        if hi is None: hi = numpy.inf
+        return lo,hi
+    
+    def _setrange(self,r):
+        self._model.details[self.name][1:] = r
+    range = property(_getrange,_setrange)
+
+
+class Model(object):
+    """
+        PARK wrapper for SANS models.
+    """
+    def __init__(self, sans_model):
+        self.model = sans_model
+        #print "ParkFitting:sans model",self.model
+        self.sansp = sans_model.getParamList()
+        #print "ParkFitting: sans model parameter list",sansp
+        self.parkp = [SansParameter(p,sans_model) for p in self.sansp]
+        #print "ParkFitting: park model parameter ",self.parkp
+        self.parameterset = park.ParameterSet(sans_model.name,pars=self.parkp)
+        self.pars=[]
+        
+    def getParams(self,fitparams):
+        list=[]
+        self.pars=[]
+        self.pars=fitparams
+        for item in fitparams:
+            for element in self.parkp:
+                 if element.name ==str(item):
+                     list.append(element.value)
+        #print "abstractfitengine: getparams",list
+        return list
+    
+    def setParams(self, params):
+        list=[]
+        for item in self.parkp:
+            list.append(item.name)
+        list.sort()
+        for i in range(len(params)):
+            #self.parkp[i].value = params[i]
+            #print "abstractfitengine: set-params",list[i],params[i]
+            
+            self.model.setParam(list[i],params[i])
+  
+    def eval(self,x):
+        #print "eval",self.parameterset[0].value,self.parameterset[1].value
+        return self.model.runXY(x)
+       
+
+class Data(object):
+    """ Wrapper class  for SANS data """
+    def __init__(self,x=None,y=None,dy=None,dx=None,sans_data=None):
+        
+        if  sans_data !=None:
+            self.x= sans_data.x
+            self.y= sans_data.y
+            self.dx= sans_data.dx
+            self.dy= sans_data.dy
+           
+        elif (x!=None and y!=None and dy!=None):
+                self.x=x
+                self.y=y
+                self.dx=dx
+                self.dy=dy
+        else:
+            raise ValueError,\
+            "Data is missing x, y or dy, impossible to compute residuals later on"
+        self.qmin=None
+        self.qmax=None
+       
+    def setFitRange(self,mini=None,maxi=None):
+        """ to set the fit range"""
+        self.qmin=mini
+        self.qmax=maxi
+    def getFitRange(self):
+         return self.qmin, self.qmax
+    def residuals(self, fn):
+        """ @param fn: function that return model value
+            @return residuals
+        """
+        x,y,dy = [numpy.asarray(v) for v in (self.x,self.y,self.dy)]
+        if self.qmin==None and self.qmax==None: 
+            fx =[fn(v) for v in x]
+            return (y - fx)/dy
+        else:
+            idx = (x>=self.qmin) & (x <= self.qmax)
+            fx = [fn(item)for item in x[idx ]]
+            return (y[idx] - fx)/dy[idx]
+          
+            
+         
+    def residuals_deriv(self, model, pars=[]):
+        """ 
+            @return residuals derivatives .
+            @note: in this case just return empty array
+        """
+        return []
+    
+class sansAssembly:
+    def __init__(self,Model=None , Data=None):
+       self.model = Model
+       self.data  = Data
+       self.res=[]
+    def chisq(self, params):
+        """
+            Calculates chi^2
+            @param params: list of parameter values
+            @return: chi^2
+        """
+        sum = 0
+        for item in self.res:
+            sum += item*item
+        return sum
+    def __call__(self,params):
+        self.model.setParams(params)
+        self.res= self.data.residuals(self.model.eval)
+        return self.res
+    
 class FitEngine:
     def __init__(self):
@@ -8,7 +148,5 @@
             @param listdata: list of data 
             
-            @return xtemp, ytemp,dytemp:  x,y,dy respectively of data all combined
-                if xi,yi,dyi of two or more data are the same the second appearance of xi,yi,
-                dyi is ignored in the concatenation.
+            @return Data:
                 
             @raise: if listdata is empty  will return None
@@ -22,6 +160,19 @@
             ytemp=[]
             dytemp=[]
+            self.mini=None
+            self.maxi=None
                
             for data in listdata:
+                mini,maxi=data.getFitRange()
+                if self.mini==None and self.maxi==None:
+                    self.mini=mini
+                    self.maxi=maxi
+                else:
+                    if mini < self.mini:
+                        self.mini=mini
+                    if self.maxi < maxi:
+                        self.maxi=maxi
+                        
+                    
                 for i in range(len(data.x)):
                     xtemp.append(data.x[i])
@@ -31,37 +182,16 @@
                     else:
                         raise RuntimeError, "Fit._concatenateData: y-errors missing"
-            return xtemp, ytemp,dytemp
-    
+            #return xtemp, ytemp,dytemp
+            data= Data(x=xtemp,y=ytemp,dy=dytemp)
+            data.setFitRange(self.mini, self.maxi)
+            return data
     def set_model(self,model,name,Uid,pars=[]):
-        """ 
-      
-            Receive a dictionary of parameter and save it Parameter list
-            For scipy.fit use.
-            Set model in a FitArrange object and add that object in a dictionary
-            with key Uid.
-            @param model: model on with parameter values are set
-            @param name: model name
-            @param Uid: unique key corresponding to a fitArrange object with model
-            @param pars: dictionary of paramaters name and value
-            pars={parameter's name: parameter's value}
-            
-        """
-        print "AbstractFitEngine:  fitting parmater",pars
-       
         if len(pars) >0:
-            self.parameters=[]
+            self.paramList = []
             if model==None:
                 raise ValueError, "AbstractFitEngine: Specify parameters to fit"
             else:
-                model.name=name
-                for param_name in pars:
-                    value=model.getParam(param_name)
-                    if value==None:
-                        raise ValueError ,"%s has not value set"%param_name
-                    param = Parameter(model,param_name,value)
-                    self.parameters.append(param)
-                   
-                    self.paramList.append(param_name)
-            print "AbstractFitEngine: self.paramList2", self.paramList
+                model.name = name
+                self.paramList=pars
             #A fitArrange is already created but contains dList only at Uid
             if self.fitArrangeList.has_key(Uid):
@@ -69,12 +199,11 @@
             else:
             #no fitArrange object has been create with this Uid
-                fitproblem= FitArrange()
+                fitproblem = FitArrange()
                 fitproblem.set_model(model)
-                self.fitArrangeList[Uid]=fitproblem
+                self.fitArrangeList[Uid] = fitproblem
         else:
             raise ValueError, "park_integration:missing parameters"
-        
-        
-    def set_data(self,data,Uid):
+    
+    def set_data(self,data,Uid,qmin=None,qmax=None):
         """ Receives plottable, creates a list of data to fit,set data
             in a FitArrange object and adds that object in a dictionary 
@@ -83,4 +212,6 @@
             @param Uid: unique key corresponding to a fitArrange object with data
             """
+        if qmin !=None and qmax !=None:
+            data.setFitRange(mini=qmin,maxi=qmax)
         #A fitArrange is already created but contains model only at Uid
         if self.fitArrangeList.has_key(Uid):
@@ -90,6 +221,6 @@
             fitproblem= FitArrange()
             fitproblem.add_data(data)
-            self.fitArrangeList[Uid]=fitproblem
-            
+            self.fitArrangeList[Uid]=fitproblem    
+   
     def get_model(self,Uid):
         """ 
@@ -107,29 +238,5 @@
         if self.fitArrangeList.has_key(Uid):
             del self.fitArrangeList[Uid]
-            
-      
-   
-   
-class Parameter:
-    """
-        Class to handle model parameters
-    """
-    def __init__(self, model, name, value=None):
-            self.model = model
-            self.name = name
-            if not value==None:
-                self.model.setParam(self.name, value)
-           
-    def set(self, value):
-        """
-            Set the value of the parameter
-        """
-        self.model.setParam(self.name, value)
-
-    def __call__(self):
-        """ 
-            Return the current value of the parameter
-        """
-        return self.model.getParam(self.name)
+
     
 class FitArrange:
Index: park_integration/Fitting.py
===================================================================
--- park_integration/Fitting.py	(revision 9855699d89d104257e027f73eeed1c6216999681)
+++ park_integration/Fitting.py	(revision 48882d14c03b61d8a22b600abadcccba552c8697)
@@ -53,10 +53,9 @@
         """Perform the fit """
         return self._engine.fit(qmin,qmax)
-    def set_model(self,model,name,Uid,pars={}):
-        """ Set model """
-        self._engine.set_model(model,name,Uid, pars)
-    def set_data(self,data,Uid):
-        """ Receive plottable and create a list of data to fit"""
-        self._engine.set_data(data,Uid)
+    def set_model(self,model,name,Uid,pars=[]):
+         self._engine.set_model(model,name,Uid,pars)
+   
+    def set_data(self,data,Uid,qmin=None, qmax=None):
+        self._engine.set_data(data,Uid,qmin,qmax)
     def get_model(self,Uid):
         """ return list of data"""
Index: park_integration/ParkFitting.py
===================================================================
--- park_integration/ParkFitting.py	(revision ee5b04cc7ceddf34bee2bdd5b33cb63f2d5c8152)
+++ park_integration/ParkFitting.py	(revision 48882d14c03b61d8a22b600abadcccba552c8697)
@@ -6,107 +6,12 @@
 import time
 import numpy
-
 import park
 from park import fit,fitresult
 from park import assembly
 from park.fitmc import FitSimplex, FitMC
-
 from sans.guitools.plottables import Data1D
 from Loader import Load
-from AbstractFitEngine import FitEngine, Parameter, FitArrange
-class SansParameter(park.Parameter):
-    """
-        SANS model parameters for use in the PARK fitting service.
-        The parameter attribute value is redirected to the underlying
-        parameter value in the SANS model.
-    """
-    def __init__(self, name, model):
-         self._model, self._name = model,name
-         self.set(model.getParam(name))
-         
-    def _getvalue(self): return self._model.getParam(self.name)
-    
-    def _setvalue(self,value): 
-        self._model.setParam(self.name, value)
-        
-    value = property(_getvalue,_setvalue)
-    
-    def _getrange(self):
-        lo,hi = self._model.details[self.name][1:]
-        if lo is None: lo = -numpy.inf
-        if hi is None: hi = numpy.inf
-        return lo,hi
-    
-    def _setrange(self,r):
-        self._model.details[self.name][1:] = r
-    range = property(_getrange,_setrange)
+from AbstractFitEngine import FitEngine,FitArrange,Model
 
-
-class Model(object):
-    """
-        PARK wrapper for SANS models.
-    """
-    def __init__(self, sans_model):
-        self.model = sans_model
-        #print "ParkFitting:sans model",self.model
-        sansp = sans_model.getParamList()
-        #print "ParkFitting: sans model parameter list",sansp
-        parkp = [SansParameter(p,sans_model) for p in sansp]
-        #print "ParkFitting: park model parameter ",parkp
-        self.parameterset = park.ParameterSet(sans_model.name,pars=parkp)
-        
-    def eval(self,x):
-        #print "eval",self.parameterset[0].value,self.parameterset[1].value
-        #print "model run ",self.model.run(x)
-        return self.model.run(x)
-    
-class Data(object):
-    """ Wrapper class  for SANS data """
-    def __init__(self,x=None,y=None,dy=None,dx=None,sans_data=None):
-        if not sans_data==None:
-            self.x= sans_data.x
-            self.y= sans_data.y
-            self.dx= sans_data.dx
-            self.dy= sans_data.dy
-        else:
-            if x!=None and y!=None and dy!=None:
-                self.x=x
-                self.y=y
-                self.dx=dx
-                self.dy=dy
-            else:
-                raise ValueError,\
-                "Data is missing x, y or dy, impossible to compute residuals later on"
-        self.qmin=None
-        self.qmax=None
-       
-    def setFitRange(self,mini=None,maxi=None):
-        """ to set the fit range"""
-        self.qmin=mini
-        self.qmax=maxi
-        
-    def residuals(self, fn):
-        """ @param fn: function that return model value
-            @return residuals
-        """
-        x,y,dy = [numpy.asarray(v) for v in (self.x,self.y,self.dy)]
-        if self.qmin==None and self.qmax==None: 
-            self.fx = fn(x)
-            return (y - fn(x))/dy
-        
-        else:
-            self.fx = fn(x[idx])
-            idx = x>=self.qmin & x <= self.qmax
-            return (y[idx] - fn(x[idx]))/dy[idx]
-            
-         
-    def residuals_deriv(self, model, pars=[]):
-        """ 
-            @return residuals derivatives .
-            @note: in this case just return empty array
-        """
-        return []
-
-            
 class ParkFit(FitEngine):
     """ 
@@ -154,7 +59,8 @@
         i=0
         for k,value in self.fitArrangeList.iteritems():
-            sansmodel=value.get_model()
+            #sansmodel=value.get_model()
             #wrap sans model
-            parkmodel = Model(sansmodel)
+            #parkmodel = Model(sansmodel)
+            parkmodel = value.get_model()
             #print "ParkFitting: createproblem: just create a model",parkmodel.parameterset
             for p in parkmodel.parameterset:
@@ -162,12 +68,11 @@
                 #if p.isfixed():
                 #print 'parameters',p.name
-                #print "self.paramList",self.paramList
+                print "parkfitting: self.paramList",self.paramList
                 if p.isfixed() and p._getname()in self.paramList:
                     p.set([-numpy.inf,numpy.inf])
             i+=1    
             Ldata=value.get_data()
-            x,y,dy=self._concatenateData(Ldata)
-            #wrap sansdata
-            parkdata=Data(x,y,dy,None)
+            parkdata=self._concatenateData(Ldata)
+            
             couple=(parkmodel,parkdata)
             #print "Parkfitting: fitness",couple   
@@ -204,5 +109,5 @@
         localfit.ftol = 1e-8
         fitter = FitMC(localfit=localfit)
-        
+        print "ParkFitting: result1"
         result = fit.fit(self.problem,
                      fitter=fitter,
@@ -212,5 +117,6 @@
             #for p in result.parameters:
             #    print "fit in park fitting", p.name, p.value,p.stderr
-            return result.fitness,result.pvec,result.cov,result
+            #return result.fitness,result.pvec,result.cov,result
+            return result
         else:
             raise ValueError, "SVD did not converge"
Index: park_integration/ScipyFitting.py
===================================================================
--- park_integration/ScipyFitting.py	(revision ee5b04cc7ceddf34bee2bdd5b33cb63f2d5c8152)
+++ park_integration/ScipyFitting.py	(revision 48882d14c03b61d8a22b600abadcccba552c8697)
@@ -4,10 +4,27 @@
     simple fit with scipy optimizer.
 """
+#import scipy.linalg
+import numpy 
 from sans.guitools.plottables import Data1D
 from Loader import Load
 from scipy import optimize
-from AbstractFitEngine import FitEngine, Parameter
-from AbstractFitEngine import FitArrange
 
+from AbstractFitEngine import FitEngine, sansAssembly
+from AbstractFitEngine import FitArrange,Data
+class fitresult:
+    """
+        Storing fit result
+    """
+    calls     = None
+    fitness   = None
+    chisqr    = None
+    pvec      = None
+    cov       = None
+    info      = None
+    mesg      = None
+    success   = None
+    stderr    = None
+    parameters= None
+    
 class ScipyFit(FitEngine):
     """ 
@@ -42,19 +59,6 @@
         self.fitArrangeList={}
         self.paramList=[]
-        
     def fit(self,qmin=None, qmax=None):
-        """
-            Performs fit with scipy optimizer.It can only perform fit with one model
-            and a set of data.
-            @note: Cannot perform more than one fit at the time.
-            
-            @param pars: Dictionary of parameter names for the model and their values
-            @param qmin: The minimum value of data's range to be fit
-            @param qmax: The maximum value of data's range to be fit
-            @return chisqr: Value of the goodness of fit metric
-            @return out: list of parameter with the best value found during fitting
-            @return cov: Covariance matrix
-        """
-        # Protect against simultanous fitting attempts
+         # Protect against simultanous fitting attempts
         if len(self.fitArrangeList)>1: 
             raise RuntimeError, "Scipy can't fit more than a single fit problem at a time."
@@ -66,67 +70,37 @@
         listdata = fitproblem.get_data()
         # Concatenate dList set (contains one or more data)before fitting
-        xtemp,ytemp,dytemp=self._concatenateData( listdata)
+        data=self._concatenateData( listdata)
         #Assign a fit range is not boundaries were given
         if qmin==None:
-            qmin= min(xtemp)
+            qmin= min(data.x)
         if qmax==None:
-            qmax= max(xtemp) 
-        #perform the fit 
-        chisqr, out, cov = fitHelper(model,self.parameters, xtemp,ytemp, dytemp ,qmin,qmax)
-        return chisqr, out, cov
+            qmax= max(data.x) 
+        functor= sansAssembly(model,data)
+        print "scipyfitting:param list",model.getParams(self.paramList)
+        print "scipyfitting:functor",functor(model.getParams(self.paramList))
     
-
-def fitHelper(model, pars, x, y, err_y ,qmin=None, qmax=None):
-    """
-        Fit function
-        @param model: sans model object
-        @param pars: list of parameters
-        @param x: vector of x data
-        @param y: vector of y data
-        @param err_y: vector of y errors 
-        @return chisqr: Value of the goodness of fit metric
-        @return out: list of parameter with the best value found during fitting
-        @return cov: Covariance matrix
-    """
-    def f(params):
-        """
-            Calculates the vector of residuals for each point 
-            in y for a given set of input parameters.
-            @param params: list of parameter values
-            @return: vector of residuals
-        """
-        i = 0
-        for p in pars:
-            p.set(params[i])
-            i += 1
+        out, cov_x, info, mesg, success = optimize.leastsq(functor,model.getParams(self.paramList), full_output=1, warning=True)
+        chisqr = functor.chisq(out)
         
-        residuals = []
-        for j in range(len(x)):
-            if x[j] >= qmin and x[j] <= qmax:
-                residuals.append( ( y[j] - model.runXY(x[j]) ) / err_y[j] )
+        print "scipyfitting: info",mesg
+        print"scipyfitting : success",success
+        print "scipyfitting: out", out
+        print "scipyfitting: cov_x", cov_x
+        print "scipyfitting: chisqr", chisqr
+        
+        if not (numpy.isnan(out).any()):
+                result = fitresult()
+                result.fitness = chisqr
+                result.cov  = cov_x
+                
+                result.pvec = out
+                result.success =success
+               
+                return result
+        else:  
+            raise ValueError, "SVD did not converge"
+        
+       
+              
             
-        return residuals
-        
-    def chi2(params):
-        """
-            Calculates chi^2
-            @param params: list of parameter values
-            @return: chi^2
-        """
-        sum = 0
-        res = f(params)
-        for item in res:
-            sum += item*item
-        return sum
-        
-    p = [param() for param in pars]
-    out, cov_x, info, mesg, success = optimize.leastsq(f, p, full_output=1, warning=True)
-    #print info, mesg, success
-    # Calculate chi squared
-    if len(pars)>1:
-        chisqr = chi2(out)
-    elif len(pars)==1:
-        chisqr = chi2([out])
-        
-    return chisqr, out, cov_x    
-
+      
Index: park_integration/test/test_large_model.py
===================================================================
--- park_integration/test/test_large_model.py	(revision f44dbc7756cb2cf8e8d1959765cc44d35f8321b5)
+++ park_integration/test/test_large_model.py	(revision 48882d14c03b61d8a22b600abadcccba552c8697)
@@ -5,12 +5,10 @@
 from sans.guitools.plottables import Theory1D
 from sans.guitools.plottables import Data1D
-
+from sans.fit.AbstractFitEngine import Data,Model
 import math
 class testFitModule(unittest.TestCase):
     """ test fitting """
-    
-      
-    def testfit_11Data_1Model(self):
-        """ test fitting for one data and one model park vs scipy"""
+    def test_cylinder_park(self):
+        """ test fitting large model with park"""
         #load data
         from sans.fit.Loader import Load
@@ -18,11 +16,8 @@
         load.set_filename("cyl_testdata.txt")
         load.set_values()
-        data1 = Data1D(x=[], y=[],dx=None, dy=None)
-        load.load_data(data1)
+        data11 = Data1D(x=[], y=[],dx=None, dy=None)
+        load.load_data(data11)
+        data1=Data(sans_data=data11)
         
-        load.set_filename("testdata_line1.txt")
-        load.set_values()
-        data2 = Data1D(x=[], y=[],dx=None, dy=None)
-        load.load_data(data2)
         
         #Importing the Fit module
@@ -33,20 +28,55 @@
         from sans.models.CylinderModel import CylinderModel
         model1  = CylinderModel()
-        #model2  = CylinderModel()
+        model =Model(model1)
         
         #Do the fit SCIPY
         fitter.set_data(data1,1)
         import math
-        pars1={'background':0,'contrast':3*math.pow(10, -6),\
-                'cyl_phi':1,'cyl_theta':1,'length':400,'radius':20,'scale':1}
-        fitter.set_model(model1,"M1",1,pars1)
+        #pars1=['background','contrast', 'length']
+        pars1=['background','contrast',\
+                'cyl_phi','cyl_theta','length','radius','scale']
+        pars1.sort()
+        fitter.set_model(model,"M1",1,pars1)
+        fitter.set_data(data1,1)
+      
+        result=fitter.fit()
+        print "park",result.fitness,result.cov, result.pvec
+        self.assert_(result.fitness)
         
-        #fitter.set_data(data2,2)
-        #fitter.set_model(model1,"M1",2,pars1)
+     
+    def test_cylinder_scipy(self):
+        """ test fitting large model with scipy"""
+        #load data
+        from sans.fit.Loader import Load
+        load= Load()
+        load.set_filename("cyl_testdata.txt")
+        load.set_values()
+        data11 = Data1D(x=[], y=[],dx=None, dy=None)
+        load.load_data(data11)
+        data1=Data(sans_data=data11)
         
-        chisqr1, out1, cov1=fitter.fit()
-        print "park",chisqr1, out1, cov1
-        self.assert_(chisqr1)
         
-       
+        #Importing the Fit module
+        from sans.fit.Fitting import Fit
+        fitter= Fit('scipy')
+        
+        # Receives the type of model for the fitting
+        from sans.models.CylinderModel import CylinderModel
+        model1  = CylinderModel()
+        model =Model(model1)
+        
+        #Do the fit SCIPY
+        fitter.set_data(data1,1)
+        import math
+        #pars1=['background','contrast', 'length']
+        pars1=['background','contrast',\
+                'cyl_phi','cyl_theta','length','radius','scale']
+        pars1.sort()
+        fitter.set_model(model,"M1",1,pars1)
+        fitter.set_data(data1,1)
       
+        result=fitter.fit()
+        print "scipy",result.fitness,result.cov, result.pvec
+        self.assert_(result.fitness)
+        
+    
Index: park_integration/test/testfitting.py
===================================================================
--- park_integration/test/testfitting.py	(revision 985c88b87a5cf7319bfda1d8af0737566479cd84)
+++ park_integration/test/testfitting.py	(revision 48882d14c03b61d8a22b600abadcccba552c8697)
@@ -5,5 +5,5 @@
 from sans.guitools.plottables import Theory1D
 from sans.guitools.plottables import Data1D
-
+from sans.fit.AbstractFitEngine import Data, Model
 import math
 class testFitModule(unittest.TestCase):
@@ -15,5 +15,4 @@
         from sans.fit.Loader import Load
         load= Load()
-        
         load.set_filename("testdata_line.txt")
         self.assertEqual(load.get_filename(),"testdata_line.txt")
@@ -23,7 +22,5 @@
         dx=[]
         dy=[]
-        
         x,y,dx,dy = load.get_values()
-        
         # test that values have been loaded
         self.assertNotEqual(x, None)
@@ -59,6 +56,6 @@
         load.set_filename("testdata_line.txt")
         load.set_values()
-        data1 = Data1D(x=[], y=[],dx=None, dy=None)
-        load.load_data(data1)
+        data11 = Data1D(x=[], y=[],dx=None, dy=None)
+        load.load_data(data11)
         
         #Importing the Fit module
@@ -68,14 +65,22 @@
         # Receives the type of model for the fitting
         from sans.guitools.LineModel import LineModel
-        model1  = LineModel()
-        model2  = LineModel()
+        model11  = LineModel()
+        model22  = LineModel()
         
         #Do the fit SCIPY
-        model1.setParam( 'A', 2)
-        model1.setParam( 'B', 1)
+        model11.setParam( 'A', 2)
+        model11.setParam( 'B', 1)
+        data1=Data(sans_data=data11)
+        model1 =Model(model11)
+        model2 =Model(model22)
+      
         fitter.set_data(data1,1)
         fitter.set_model(model1,"M1",1,['A','B'])
         
-        chisqr1, out1, cov1=fitter.fit()
+        result= fitter.fit()
+        out1=result.pvec
+        chisqr1=result.fitness
+        cov1=result.cov
+        print "scipy",chisqr1, out1, cov1
         """ testing SCIPy results"""
         self.assert_(math.fabs(out1[1]-2.5)/math.sqrt(cov1[1][1]) < 2)
@@ -87,10 +92,12 @@
         #Do the fit
         fitter.set_data(data1,1)
-        model2.setParam( 'A', 2)
-        model2.setParam( 'B', 1)
+        model2.setParams( [2,1])
+    
         fitter.set_model(model2,"M1",1,['A','B'])
        
-        chisqr2, out2, cov2,result=fitter.fit(None,None)
-        
+        result2=fitter.fit(None,None)
+        out2=result2.pvec
+        chisqr2=result2.fitness
+        cov2=result2.cov
         self.assert_(math.fabs(out2[1]-2.5)/math.sqrt(cov2[1][1]) < 2)
         self.assert_(math.fabs(out2[0]-4.0)/math.sqrt(cov2[0][0]) < 2)
@@ -103,4 +110,38 @@
         self.assertAlmostEquals(cov1[1][1], cov2[1][1],1)
         self.assertAlmostEquals(chisqr1, chisqr2)
+         
+    def testfit_1Data_1Model(self):
+        """ test fitting for one data and one model cipy"""
+        #load data
+        from sans.fit.Loader import Load
+        load= Load()
+        load.set_filename("testdata_line.txt")
+        load.set_values()
+        data11 = Data1D(x=[], y=[],dx=None, dy=None)
+        load.load_data(data11)
+        data1=Data(sans_data=data11)
+    
+        #Importing the Fit module
+        from sans.fit.Fitting import Fit
+        fitter= Fit('scipy')
+        
+        # Receives the type of model for the fitting
+        from sans.guitools.LineModel import LineModel
+        model1  = LineModel()
+        model =Model(model1)
+        
+        #Do the fit SCIPY
+        fitter.set_data(data1,1)
+        import math
        
+        pars1=['A','B']
+        pars1.sort()
+        fitter.set_model(model,"M1",1,pars1)
+        result=fitter.fit()
+        print "scipy",result.fitness,result.cov, result.pvec
+    
+        self.assert_(result.fitness)
+        
+       
+    
       
Index: park_integration/test/testnewscipy.py
===================================================================
--- park_integration/test/testnewscipy.py	(revision 48882d14c03b61d8a22b600abadcccba552c8697)
+++ park_integration/test/testnewscipy.py	(revision 48882d14c03b61d8a22b600abadcccba552c8697)
@@ -0,0 +1,44 @@
+"""
+    Unit tests for fitting module 
+"""
+import unittest
+from sans.guitools.plottables import Theory1D
+from sans.guitools.plottables import Data1D
+from sans.fit.AbstractFitEngine import Data, Model
+import math
+class testFitModule(unittest.TestCase):
+    """ test fitting """
+    
+    def testfit_1Data_1Model(self):
+        """ test fitting for one data and one model park vs scipy"""
+        #load data
+        from sans.fit.Loader import Load
+        load= Load()
+        load.set_filename("testdata_line.txt")
+        load.set_values()
+        data11 = Data1D(x=[], y=[],dx=None, dy=None)
+        load.load_data(data11)
+        
+        #Importing the Fit module
+        from sans.fit.Fitting import Fit
+        fitter= Fit('scipy')
+        
+        # Receives the type of model for the fitting
+        from sans.guitools.LineModel import LineModel
+        model1  = LineModel()
+        data1=Data(sans_data=data11)
+        model =Model(model1)
+        #Do the fit SCIPY
+       
+        fitter.set_data_assembly(data1,1)
+        fitter.set_model_assembly(model,"M1",1,['A','B'])
+    
+        result=fitter.fit()
+        print "scipy",result.pvec,
+        chisqr1, out1, cov1=fitter.fit()
+        """ testing SCIPy results"""
+        self.assert_(math.fabs(out1[1]-2.5)/math.sqrt(cov1[1][1]) < 2)
+        self.assert_(math.fabs(out1[0]-4.0)/math.sqrt(cov1[0][0]) < 2)
+        self.assert_(chisqr1/len(data1.x) < 2)
+       
+      
Index: park_integration/test/testnewscipys.py
===================================================================
--- park_integration/test/testnewscipys.py	(revision 48882d14c03b61d8a22b600abadcccba552c8697)
+++ park_integration/test/testnewscipys.py	(revision 48882d14c03b61d8a22b600abadcccba552c8697)
@@ -0,0 +1,98 @@
+"""
+    Unit tests for fitting module 
+"""
+import unittest
+from sans.guitools.plottables import Theory1D
+from sans.guitools.plottables import Data1D
+from sans.fit.AbstractFitEngine import Data, Model
+from sans.fit.AbstractFitEngine import sansAssembly
+import math
+class testFitModule(unittest.TestCase):
+    """ test fitting """
+    
+    def test_Data(self):
+        """ test data"""
+        #load data
+        from sans.fit.Loader import Load
+        load= Load()
+        load.set_filename("cyl_testdata.txt")
+        load.set_values()
+        data11 = Data1D(x=[], y=[],dx=None, dy=None)
+        load.load_data(data11)
+        
+        #Importing the Fit module
+        from sans.fit.Fitting import Fit
+        fitter= Fit('scipy')
+        
+        # Receives the type of model for the fitting
+        from sans.guitools.LineModel import LineModel
+        model1  = LineModel()
+        data1=Data(sans_data=data11)
+        model =Model(model1)
+        #Do the fit SCIPY0.007778 1.78E+14 13335629 
+        v=[0.007778,0.023333,0.031111,0.038889,0.046667,0.054444]
+        for i in range(len(v)):
+            self.assertEquals(data1.x[i],v[i])
+        #fitter.set_data_assembly(data1,1)
+        #fitter.set_model_assembly(model,"M1",1,['A','B'])
+    def test_Model(self):
+        """ test model"""
+        #load data
+        from sans.fit.Loader import Load
+        load= Load()
+        load.set_filename("cyl_testdata.txt")
+        load.set_values()
+        data11 = Data1D(x=[], y=[],dx=None, dy=None)
+        load.load_data(data11)
+        
+        #Importing the Fit module
+        from sans.fit.Fitting import Fit
+        fitter= Fit('scipy')
+        
+        # Receives the type of model for the fitting
+        from sans.models.CylinderModel import CylinderModel
+        model1  = CylinderModel()
+        data1=Data(sans_data=data11)
+        model =Model(model1)
+        for item in data1.x:
+            self.assertEquals(model.eval(item),model.model.run(item))
+        p=[0.0, 3.0000000000000001e-006, 1.0, 1.0, 400.0, 20.0, 1.0]  
+        model.setParams(p)
+        res=[]
+        for i in range(len(data1.x)):
+            res.append((data1.y[i]-model.eval(data1.x[i]))/data1.dy[i])
+            self.assertEquals(model.eval(data1.x[i]),model.model.run(data1.x[i]))  
+        print res
+    def test_funtor(self):
+        """ test functor"""
+        #load data
+        from sans.fit.Loader import Load
+        load= Load()
+        load.set_filename("cyl_testdata.txt")
+        load.set_values()
+        data11 = Data1D(x=[], y=[],dx=None, dy=None)
+        load.load_data(data11)
+        
+        #Importing the Fit module
+        from sans.fit.Fitting import Fit
+        fitter= Fit('scipy')
+        
+        # Receives the type of model for the fitting
+        from sans.models.CylinderModel import CylinderModel
+        model1  = CylinderModel()
+        data1=Data(sans_data=data11)
+        model =Model(model1)
+        functor= sansAssembly(model,data1)
+        for item in data1.x:
+            self.assertEquals(model.eval(item),model.model.run(item))
+        p=[0.0, 3.0000000000000001e-006, 1.0, 1.0, 400.0, 20.0, 1.0]  
+        model.setParams(p)
+        res=[]
+        for i in range(len(data1.x)):
+            res.append((data1.y[i]-model.eval(data1.x[i]))/data1.dy[i])
+            self.assertEquals(model.eval(data1.x[i]),model.model.run(data1.x[i]))  
+        f=functor(p)
+
+        for i in range(len(res)):
+            self.assertEquals(res[i],f[i])    
+       
