Index: pcyl_Gauss.py
===================================================================
--- Capcyl_Gauss.py	(revision 2de9a5e5fa221a201e0d071bc49f8bf651f6f679)
+++ 	(revision )
@@ -1,98 +1,0 @@
-Gauss76Z = {.999505948362153*(-1.0),.997397786355355*(-1.0),.993608772723527*(-1.0),.988144453359837*(-1.0),
-               .981013938975656*(-1.0),.972229228520377*(-1.0),.961805126758768*(-1.0),.949759207710896*(-1.0),
-               .936111781934811*(-1.0),.92088586125215*(-1.0),.904107119545567*(-1.0),.885803849292083*(-1.0),
-               .866006913771982*(-1.0),.844749694983342*(-1.0),.822068037328975*(-1.0),.7980001871612*(-1.0),
-               .77258672828181*(-1.0),.74587051350361*(-1.0),.717896592387704*(-1.0),.688712135277641*(-1.0),
-               .658366353758143*(-1.0),.626910417672267*(-1.0),.594397368836793*(-1.0),.560882031601237*(-1.0),
-               .526420920401243*(-1.0),.491072144462194*(-1.0),.454895309813726*(-1.0),.417951418780327*(-1.0),
-               .380302767117504*(-1.0),.342012838966962*(-1.0),.303146199807908*(-1.0),.263768387584994*(-1.0),
-               .223945802196474*(-1.0),.183745593528914*(-1.0),.143235548227268*(-1.0),.102483975391227*(-1.0),
-               .0615595913906112*(-1.0),.0205314039939986*(-1.0),-.0205314039939986*(-1.0),-.0615595913906112*(-1.0),
-               -.102483975391227*(-1.0),-.143235548227268*(-1.0),-.183745593528914*(-1.0),-.223945802196474*(-1.0),
-               -.263768387584994*(-1.0),-.303146199807908*(-1.0),-.342012838966962*(-1.0),-.380302767117504*(-1.0),
-               -.417951418780327*(-1.0),-.454895309813726*(-1.0),-.491072144462194*(-1.0),-.526420920401243*(-1.0),
-               -.560882031601237*(-1.0),-.594397368836793*(-1.0),-.626910417672267*(-1.0),-.658366353758143*(-1.0),
-               -.688712135277641*(-1.0),-.717896592387704*(-1.0),-.74587051350361*(-1.0),-.77258672828181*(-1.0),
-               -.7980001871612*(-1.0),	-.822068037328975*(-1.0),-.844749694983342*(-1.0),-.866006913771982*(-1.0),
-               -.885803849292083*(-1.0),-.904107119545567*(-1.0),-.92088586125215*(-1.0),-.936111781934811*(-1.0),
-               -.949759207710896*(-1.0),-.961805126758768*(-1.0),-.972229228520377*(-1.0),-.981013938975656*(-1.0),
-               -.988144453359837*(-1.0),-.993608772723527*(-1.0),-.997397786355355*(-1.0),-.999505948362153*(-1.0) }
-
-Gauss76Wt= {
-.00126779163408536,
-.00294910295364247,
-.00462793522803742,
-.00629918049732845,
-.00795984747723973,
-.00960710541471375,
-.0112381685696677,
-.0128502838475101,
-.0144407317482767,
-.0160068299122486,
-.0175459372914742,
-.0190554584671906,
-.020532847967908,
-.0219756145344162,
-.0233813253070112,
-.0247476099206597,
-.026072164497986,
-.0273527555318275,
-.028587223650054,
-.029773487255905,
-.0309095460374916,
-.0319934843404216,
-.0330234743977917,
-.0339977794120564,
-.0349147564835508,
-.0357728593807139,
-.0365706411473296,
-.0373067565423816,
-.0379799643084053,
-.0385891292645067,
-.0391332242205184,
-.0396113317090621,
-.0400226455325968,
-.040366472122844,
-.0406422317102947,
-.0408494593018285,
-.040987805464794,
-.0410570369162294,
-.0410570369162294,
-.040987805464794,
-.0408494593018285,
-.0406422317102947,
-.040366472122844,
-.0400226455325968,
-.0396113317090621,
-.0391332242205184,
-.0385891292645067,
-.0379799643084053,
-.0373067565423816,
-.0365706411473296,
-.0357728593807139,
-.0349147564835508,
-.0339977794120564,
-.0330234743977917,
-.0319934843404216,
-.0309095460374916,
-.029773487255905,
-.028587223650054,
-.0273527555318275,
-.026072164497986,
-.0247476099206597,
-.0233813253070112,
-.0219756145344162,
-.020532847967908,
-.0190554584671906,
-.0175459372914742,
-.0160068299122486,
-.0144407317482767,
-.0128502838475101,
-.0112381685696677,
-.00960710541471375,
-.00795984747723973,
-.00629918049732845,
-.00462793522803742,
-.00294910295364247,
-.00126779163408536
-}
Index: Capcyl_Kfun.cpp
===================================================================
--- Capcyl_Kfun.cpp	(revision 2de9a5e5fa221a201e0d071bc49f8bf651f6f679)
+++ Capcyl_Kfun.cpp	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -14,160 +14,2 @@
 	return(val);
 }
-/*
-real Gauss76Z[76]={
-	 .999505948362153*(-1.0),		//0
-	 .997397786355355*(-1.0),
-	 .993608772723527*(-1.0),
-	 .988144453359837*(-1.0),
-	 .981013938975656*(-1.0),
-	 .972229228520377*(-1.0),
-	 .961805126758768*(-1.0),
-	 .949759207710896*(-1.0),
-	 .936111781934811*(-1.0),
-	 .92088586125215*(-1.0),
-	 .904107119545567*(-1.0),		//10
-	 .885803849292083*(-1.0),
-	 .866006913771982*(-1.0),
-	 .844749694983342*(-1.0),
-	 .822068037328975*(-1.0),
-	 .7980001871612*(-1.0),
-	 .77258672828181*(-1.0),
-	 .74587051350361*(-1.0),
-	 .717896592387704*(-1.0),
-	 .688712135277641*(-1.0),
-	 .658366353758143*(-1.0),		//20
-	 .626910417672267*(-1.0),
-	 .594397368836793*(-1.0),
-	 .560882031601237*(-1.0),
-	 .526420920401243*(-1.0),
-	 .491072144462194*(-1.0),
-	 .454895309813726*(-1.0),
-	 .417951418780327*(-1.0),
-	 .380302767117504*(-1.0),
-	 .342012838966962*(-1.0),
-	 .303146199807908*(-1.0),		//30
-	 .263768387584994*(-1.0),
-	 .223945802196474*(-1.0),
-	 .183745593528914*(-1.0),
-	 .143235548227268*(-1.0),
-	 .102483975391227*(-1.0),
-	 .0615595913906112*(-1.0),
-	 .0205314039939986*(-1.0),
-	-.0205314039939986*(-1.0),
-	-.0615595913906112*(-1.0),
-	-.102483975391227*(-1.0),			//40
-	-.143235548227268*(-1.0),
-	-.183745593528914*(-1.0),
-	-.223945802196474*(-1.0),
-	-.263768387584994*(-1.0),
-	-.303146199807908*(-1.0),
-	-.342012838966962*(-1.0),
-	-.380302767117504*(-1.0),
-	-.417951418780327*(-1.0),
-	-.454895309813726*(-1.0),
-	-.491072144462194*(-1.0),		//50
-	-.526420920401243*(-1.0),
-	-.560882031601237*(-1.0),
-	-.594397368836793*(-1.0),
-	-.626910417672267*(-1.0),
-	-.658366353758143*(-1.0),
-	-.688712135277641*(-1.0),
-	-.717896592387704*(-1.0),
-	-.74587051350361*(-1.0),
-	-.77258672828181*(-1.0),
-	-.7980001871612*(-1.0),	//60
-	-.822068037328975*(-1.0),
-	-.844749694983342*(-1.0),
-	-.866006913771982*(-1.0),
-	-.885803849292083*(-1.0),
-	-.904107119545567*(-1.0),
-	-.92088586125215*(-1.0),
-	-.936111781934811*(-1.0),
-	-.949759207710896*(-1.0),
-	-.961805126758768*(-1.0),
-	-.972229228520377*(-1.0),		//70
-	-.981013938975656*(-1.0),
-	-.988144453359837*(-1.0),
-	-.993608772723527*(-1.0),
-	-.997397786355355*(-1.0),
-	-.999505948362153*(-1.0)		//75
-};
-real Gauss76Wt[76]={
-	.00126779163408536,		//0
-	.00294910295364247,
-	.00462793522803742,
-	.00629918049732845,
-	.00795984747723973,
-	.00960710541471375,
-	.0112381685696677,
-	.0128502838475101,
-	.0144407317482767,
-	.0160068299122486,
-	.0175459372914742,		//10
-	.0190554584671906,
-	.020532847967908,
-	.0219756145344162,
-	.0233813253070112,
-	.0247476099206597,
-	.026072164497986,
-	.0273527555318275,
-	.028587223650054,
-	.029773487255905,
-	.0309095460374916,		//20
-	.0319934843404216,
-	.0330234743977917,
-	.0339977794120564,
-	.0349147564835508,
-	.0357728593807139,
-	.0365706411473296,
-	.0373067565423816,
-	.0379799643084053,
-	.0385891292645067,
-	.0391332242205184,		//30
-	.0396113317090621,
-	.0400226455325968,
-	.040366472122844,
-	.0406422317102947,
-	.0408494593018285,
-	.040987805464794,
-	.0410570369162294,
-	.0410570369162294,
-	.040987805464794,
-	.0408494593018285,		//40
-	.0406422317102947,
-	.040366472122844,
-	.0400226455325968,
-	.0396113317090621,
-	.0391332242205184,
-	.0385891292645067,
-	.0379799643084053,
-	.0373067565423816,
-	.0365706411473296,
-	.0357728593807139,		//50
-	.0349147564835508,
-	.0339977794120564,
-	.0330234743977917,
-	.0319934843404216,
-	.0309095460374916,
-	.029773487255905,
-	.028587223650054,
-	.0273527555318275,
-	.026072164497986,
-	.0247476099206597,		//60
-	.0233813253070112,
-	.0219756145344162,
-	.020532847967908,
-	.0190554584671906,
-	.0175459372914742,
-	.0160068299122486,
-	.0144407317482767,
-	.0128502838475101,
-	.0112381685696677,
-	.00960710541471375,		//70
-	.00795984747723973,
-	.00629918049732845,
-	.00462793522803742,
-	.00294910295364247,
-	.00126779163408536		//75 (indexed from 0)
-};
-*/
Index: Kernel-CapCyl.cpp
===================================================================
--- Kernel-CapCyl.cpp	(revision 09e15be6501267fc2d7d3d325f9db88aa762c63c)
+++ Kernel-CapCyl.cpp	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -16,5 +16,5 @@
         real cos_val = cyl_x*qx[i]/q + cyl_y*qy[i]/q;
         real alpha = acos(cos_val);
-        real yyy=0; real ans1=0; real ans2=0; real y=0; real xx=0; real ans=0; real zij=0; real be=0; real summj=0;
+        real ans1=0; real ans2=0; real y=0; real xx=0; real ans=0; real zij=0; real be=0; real summj=0;
 
         real hDist = -1.0*sqrt(fabs(rad_cap*rad_cap-rad_cyl*rad_cyl));
@@ -25,11 +25,9 @@
         {
             zij = (Gauss76Z[j]*(1.0-vaj)+vaj+1.0)/2.0;
-            yyy = Gauss76Wt[j]*ConvLens_kernel(length,rad_cyl,rad_cap,q,zij,alpha);
-            summj += yyy;
+            summj += Gauss76Wt[j]*ConvLens_kernel(length,rad_cyl,rad_cap,q,zij,alpha);
         }
-        real inner = (1.0-vaj)/2.0*summj*4.0*pi*rad_cap*rad_cap*rad_cap;
+        real yyy = (1.0-vaj)/2.0*summj*4.0*pi*rad_cap*rad_cap*rad_cap;
         real arg1 = q*length/2.0*cos(alpha);
         real arg2 = q*rad_cyl*sin(alpha);
-        yyy = inner;
 
         if(arg2 == 0) {be = 0.5;}
Index: Kernel-OneDCylinder.cpp
===================================================================
--- Kernel-OneDCylinder.cpp	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
+++ Kernel-OneDCylinder.cpp	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -0,0 +1,25 @@
+__kernel void OneDCylKernel(__global const real *q, __global real *answer, const real sub, const real length,
+const real radius, const real scale, const real size, const real uplim, const real lolim)
+{
+    int k = get_global_id(0);
+    if(k < size)
+    {
+        real Pi = 4.0*atan(1.0);
+        real up = uplim*Pi/180;
+        real low = lolim*Pi/180;
+
+        real summ = 0.0; real zi = 0;
+        real halfheight = length/2.0;
+
+        for(int i=0; i<76; i++)
+        {
+            zi = (Gauss76Z(i)*(up-low) + up + low )/2.0;
+            summ += Gauss76Wt(i)*CylKernel(q[k], radius, halfheight, zi);
+        }
+
+        answer[k] = (up-low)/2.0*summ*sub*sub*1.0e8*scale*Pi*radius*radius*length;
+
+    }
+}
+
+
Index: OneDCyl_Kfun.cpp
===================================================================
--- OneDCyl_Kfun.cpp	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
+++ OneDCyl_Kfun.cpp	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -0,0 +1,73 @@
+real CylKernel(real qq, real rr, real h, real theta)
+{
+    // qq is the q-value for the calculation (1/A)
+    // rr is the radius of the cylinder (A)
+    // h is the HALF-LENGTH of the cylinder = L/2 (A)
+    real be=0; real si=0;
+    real besarg = qq*rr*sin(theta);
+    real siarg = qq*h*cos(theta);
+    real bj = NR_BessJ1(besarg);
+
+    real d1 = qq*rr*sin(theta);
+
+    if (besarg == 0.0){
+        be = sin(theta);
+    }else{
+        be = bj*bj*4.0*sin(theta) / (d1*d1);
+    }
+
+    if (siarg == 0.0){
+        si = 1.0;
+    }else{
+        si = sin(siarg)*sin(siarg)/(siarg*siarg);
+    }
+    return be*si;
+}
+real Gauss76Z(int i)
+{
+real array[76] = {.999505948362153*(-1.0),.997397786355355*(-1.0),.993608772723527*(-1.0),.988144453359837*(-1.0),
+.981013938975656*(-1.0),.972229228520377*(-1.0),.961805126758768*(-1.0),.949759207710896*(-1.0),
+.936111781934811*(-1.0),.92088586125215*(-1.0),.904107119545567*(-1.0),.885803849292083*(-1.0),
+.866006913771982*(-1.0),.844749694983342*(-1.0),.822068037328975*(-1.0),.7980001871612*(-1.0),
+.77258672828181*(-1.0),.74587051350361*(-1.0),.717896592387704*(-1.0),.688712135277641*(-1.0),
+.658366353758143*(-1.0),.626910417672267*(-1.0),.594397368836793*(-1.0),.560882031601237*(-1.0),
+.526420920401243*(-1.0),.491072144462194*(-1.0),.454895309813726*(-1.0),.417951418780327*(-1.0),
+.380302767117504*(-1.0),.342012838966962*(-1.0),.303146199807908*(-1.0),.263768387584994*(-1.0),
+.223945802196474*(-1.0),.183745593528914*(-1.0),.143235548227268*(-1.0),.102483975391227*(-1.0),
+.0615595913906112*(-1.0),.0205314039939986*(-1.0),-.0205314039939986*(-1.0),-.0615595913906112*(-1.0),
+-.102483975391227*(-1.0),-.143235548227268*(-1.0),-.183745593528914*(-1.0),-.223945802196474*(-1.0),
+-.263768387584994*(-1.0),-.303146199807908*(-1.0),-.342012838966962*(-1.0),-.380302767117504*(-1.0),
+-.417951418780327*(-1.0),-.454895309813726*(-1.0),-.491072144462194*(-1.0),-.526420920401243*(-1.0),
+-.560882031601237*(-1.0),-.594397368836793*(-1.0),-.626910417672267*(-1.0),-.658366353758143*(-1.0),
+-.688712135277641*(-1.0),-.717896592387704*(-1.0),-.74587051350361*(-1.0),-.77258672828181*(-1.0),
+-.7980001871612*(-1.0),	-.822068037328975*(-1.0),-.844749694983342*(-1.0),-.866006913771982*(-1.0),
+-.885803849292083*(-1.0),-.904107119545567*(-1.0),-.92088586125215*(-1.0),-.936111781934811*(-1.0),
+-.949759207710896*(-1.0),-.961805126758768*(-1.0),-.972229228520377*(-1.0),-.981013938975656*(-1.0),
+-.988144453359837*(-1.0),-.993608772723527*(-1.0),-.997397786355355*(-1.0),-.999505948362153*(-1.0) };
+
+return array[i];
+}
+real Gauss76Wt(int i)
+{
+real array[76] = {.00126779163408536,.00294910295364247,.00462793522803742,.00629918049732845,
+.00795984747723973,.00960710541471375,.0112381685696677,.0128502838475101,
+.0144407317482767,.0160068299122486,.0175459372914742,.0190554584671906,
+.020532847967908,.0219756145344162,.0233813253070112,.0247476099206597,
+.026072164497986,.0273527555318275,.028587223650054,.029773487255905,
+.0309095460374916,.0319934843404216,.0330234743977917,.0339977794120564,
+.0349147564835508,.0357728593807139,.0365706411473296,.0373067565423816,
+.0379799643084053,.0385891292645067,.0391332242205184,.0396113317090621,
+.0400226455325968,.040366472122844,.0406422317102947,.0408494593018285,
+.040987805464794,.0410570369162294,.0410570369162294,.040987805464794,
+.0408494593018285,.0406422317102947,.040366472122844,.0400226455325968,
+.0396113317090621,.0391332242205184,.0385891292645067,.0379799643084053,
+.0373067565423816,.0365706411473296,.0357728593807139,.0349147564835508,
+.0339977794120564,.0330234743977917,.0319934843404216,.0309095460374916,
+.029773487255905,.028587223650054,.0273527555318275,.026072164497986,
+.0247476099206597,.0233813253070112,.0219756145344162,.020532847967908,
+.0190554584671906,.0175459372914742,.0160068299122486,.0144407317482767,
+.0128502838475101,.0112381685696677,.00960710541471375,.00795984747723973,
+.00629918049732845,.00462793522803742,.00294910295364247,.00126779163408536 };
+
+return array[i];
+}
Index: code_capcyl.py
===================================================================
--- code_capcyl.py	(revision 8a21ba344fbafe9f71ac47f2c8925dc03b57e096)
+++ code_capcyl.py	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -7,5 +7,5 @@
 from weights import GaussianDispersion
 from sasmodel import card
-from Capcyl_Gauss import Gauss76Wt, Gauss76Z
+from Gauss import Gauss76Wt, Gauss76Z
 
 def set_precision(src, qx, qy, dtype):
@@ -43,5 +43,6 @@
         self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx)
         self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy)
-        G, Z = Gauss76Wt, Gauss76Z
+        G = np.ascontiguousarray(Gauss76Wt, dtype=dtype)
+        Z = np.ascontiguousarray(Gauss76Z, dtype=dtype)
         self.Gauss76W_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=G)
         self.Gauss76Z_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=Z)
Index: code_coreshellcyl.py
===================================================================
--- code_coreshellcyl.py	(revision 09e15be6501267fc2d7d3d325f9db88aa762c63c)
+++ code_coreshellcyl.py	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -48,11 +48,18 @@
                                      for base in GpuCoreShellCylinder.PD_PARS]
 
-        radius.value, radius.weight = radius.get_weights(pars['radius'], 0, 1000, True)
-        length.value, length.weight = length.get_weights(pars['length'], 0, 1000, True)
-        thickness.value, thickness.weight = thickness.get_weights(pars['thickness'], 0, 1000, True)
+        radius.value, radius.weight = radius.get_weights(pars['radius'], 0, 10000, True)
+        length.value, length.weight = length.get_weights(pars['length'], 0, 10000, True)
+        thickness.value, thickness.weight = thickness.get_weights(pars['thickness'], 0, 10000, True)
         axis_phi.value, axis_phi.weight = axis_phi.get_weights(pars['axis_phi'], -90, 180, False)
         axis_theta.value, axis_theta.weight = axis_theta.get_weights(pars['axis_theta'], -90, 180, False)
 
         sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0
+
+        print radius.value
+        print thickness.weight
+        print axis_phi.weight
+        print axis_theta.weight
+        print length.value
+
         size = len(axis_theta.weight)
 
@@ -80,6 +87,6 @@
                                     *axis_phi.weight[p]
 
-        if size>1:
-            norm /= math.asin(1.0)
+        #if size>1:
+         #   norm /= math.asin(1.0)
         if vol != 0.0 and norm_vol != 0.0:
             sum *= norm_vol/vol
Index: code_cylinder.py
===================================================================
--- code_cylinder.py	(revision 09e15be6501267fc2d7d3d325f9db88aa762c63c)
+++ code_cylinder.py	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -3,5 +3,4 @@
 
 import numpy as np
-import math
 import pyopencl as cl
 from weights import GaussianDispersion
@@ -21,4 +20,17 @@
 """
     return header+src, qx, qy
+
+def set_precision_1d(src, q, dtype):
+    q = np.ascontiguousarray(q, dtype=dtype)
+    if np.dtype(dtype) == np.dtype('float32'):
+        header = """\
+#define real float
+"""
+    else:
+        header = """\
+#pragma OPENCL EXTENSION cl_khr_fp64: enable
+#define real double
+"""
+    return header+src, q
 
 class GpuCylinder(object):
@@ -52,6 +64,6 @@
 
         #Get the weights for each
-        radius.value, radius.weight = radius.get_weights(pars['radius'], 0, 1000, True)
-        length.value, length.weight = length.get_weights(pars['length'], 0, 1000, True)
+        radius.value, radius.weight = radius.get_weights(pars['radius'], 0, 10000, True)
+        length.value, length.weight = length.get_weights(pars['length'], 0, 10000, True)
         cyl_theta.value, cyl_theta.weight = cyl_theta.get_weights(pars['cyl_theta'], -90, 180, False)
         cyl_phi.value, cyl_phi.weight = cyl_phi.get_weights(pars['cyl_phi'], -90, 180, False)
@@ -86,36 +98,60 @@
         return sum/norm+pars['background']
 
-def demo():
-    from time import time
-    import matplotlib.pyplot as plt
+class OneDGpuCylinder(object):
+    PARS = {
+        'scale':1,'radius':1,'length':1,'sldCyl':1e-6,'sldSolv':0,'background':0,
+        'bolim':0, 'uplim':90
+    }
+    PD_PARS = ['radius', 'length']
 
-    #create qx and qy evenly spaces
-    qx = np.linspace(-.02, .02, 128)
-    qy = np.linspace(-.02, .02, 128)
-    qx, qy = np.meshgrid(qx, qy)
+    def __init__(self, q, dtype='float32'):
 
-    #saved shape of qx
-    r_shape = qx.shape
+        #create context, queue, and build program
+        ctx,_queue = card()
+        trala = open('NR_BessJ1.cpp').read()+"\n"+open('OneDCyl_Kfun.cpp').read()+"\n"+open('Kernel-OneDCylinder.cpp').read()
+        src, self.q = set_precision_1d(trala, q, dtype=dtype)
+        self.prg = cl.Program(ctx, src).build()
 
-    #reshape for calculation; resize as float32
-    qx = qx.flatten()
-    qy = qy.flatten()
+        #buffers
+        mf = cl.mem_flags
+        self.q_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.q)
+        self.res_b = cl.Buffer(ctx, mf.WRITE_ONLY, q.nbytes)
+        self.res = np.empty_like(self.q)
 
-    pars = CylinderParameters(scale=1, radius=64.1, length=266.96, sldCyl=.291e-6, sldSolv=5.77e-6, background=0,
-                              cyl_theta=0, cyl_phi=0)
-    t = time()
-    result = GpuCylinder(qx, qy)
-    result.x = result.cylinder_fit(pars, r_n=10, t_n=10, l_n=10, p_n=10, r_w=.1, t_w=.1, l_w=.1, p_w=.1, sigma=3)
-    result.x = np.reshape(result.x, r_shape)
-    tt = time()
+    def eval(self, pars):
 
-    print("Time taken: %f" % (tt - t))
+        _ctx,queue = card()
+        radius, length = \
+            [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma'])
+             for base in OneDGpuCylinder.PD_PARS]
 
-    plt.pcolormesh(result.x)
-    plt.show()
+        #Get the weights for each
+        radius.value, radius.weight = radius.get_weights(pars['radius'], 0, 10000, True)
+        length.value, length.weight = length.get_weights(pars['length'], 0, 10000, True)
 
+        #Perform the computation, with all weight points
+        sum, norm, vol = 0.0, 0.0, 0.0,
+        sub = pars['sldCyl'] - pars['sldSolv']
 
-if __name__=="__main__":
-    demo()
+        real = np.float32 if self.q.dtype == np.dtype('float32') else np.float64
+        #Loop over radius, length, theta, phi weight points
+        for r in xrange(len(radius.weight)):
+            for l in xrange(len(length.weight)):
+                        self.prg.OneDCylKernel(queue, self.q.shape, None, self.q_b, self.res_b, real(sub),
+                                           real(length.value[l]), real(radius.value[r]), real(pars['scale']),
+                                           np.uint32(self.q.size), real(pars['uplim']), real(pars['bolim']))
+                        cl.enqueue_copy(queue, self.res, self.res_b)
+                        sum += radius.weight[r]*length.weight[l]*self.res*pow(radius.value[r],2)*length.value[l]
+                        vol += radius.weight[r]*length.weight[l] *pow(radius.value[r],2)*length.value[l]
+                        norm += radius.weight[r]*length.weight[l]
+
+        if vol != 0.0 and norm != 0.0:
+            sum *= norm/vol
+
+        return sum/norm + pars['background']
+
+       
+
+        
 
 
@@ -145,2 +181,3 @@
 
 
+
Index: code_ellipse.py
===================================================================
--- code_ellipse.py	(revision 09e15be6501267fc2d7d3d325f9db88aa762c63c)
+++ code_ellipse.py	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -49,6 +49,6 @@
              for base in GpuEllipse.PD_PARS]
 
-        radius_a.value, radius_a.weight = radius_a.get_weights(pars['radius_a'], 0, 1000, True)
-        radius_b.value, radius_b.weight = radius_b.get_weights(pars['radius_b'], 0, 1000, True)
+        radius_a.value, radius_a.weight = radius_a.get_weights(pars['radius_a'], 0, 10000, True)
+        radius_b.value, radius_b.weight = radius_b.get_weights(pars['radius_b'], 0, 10000, True)
         axis_theta.value, axis_theta.weight = axis_theta.get_weights(pars['axis_theta'], -90, 180, False)
         axis_phi.value, axis_phi.weight = axis_phi.get_weights(pars['axis_phi'], -90, 180, False)
Index: code_lamellar.py
===================================================================
--- code_lamellar.py	(revision 2de9a5e5fa221a201e0d071bc49f8bf651f6f679)
+++ code_lamellar.py	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -45,5 +45,5 @@
 
         bi_thick = GaussianDispersion(int(pars['bi_thick_pd_n']), pars['bi_thick_pd'], pars['bi_thick_pd_nsigma'])
-        bi_thick.value, bi_thick.weight = bi_thick.get_weights(pars['bi_thick'], 0, 1000, True)
+        bi_thick.value, bi_thick.weight = bi_thick.get_weights(pars['bi_thick'], 0, 10000, True)
 
         sum, norm = 0.0, 0.0
Index: code_triaxialellipse.py
===================================================================
--- code_triaxialellipse.py	(revision 09e15be6501267fc2d7d3d325f9db88aa762c63c)
+++ code_triaxialellipse.py	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -48,7 +48,7 @@
              for base in GpuTriEllipse.PD_PARS]
 
-        axisA.value, axisA.weight = axisA.get_weights(pars['axisA'], 0, 1000, True)
-        axisB.value, axisB.weight = axisB.get_weights(pars['axisB'], 0, 1000, True)
-        axisC.value, axisC.weight = axisC.get_weights(pars['axisC'], 0, 1000, True)
+        axisA.value, axisA.weight = axisA.get_weights(pars['axisA'], 0, 10000, True)
+        axisB.value, axisB.weight = axisB.get_weights(pars['axisB'], 0, 10000, True)
+        axisC.value, axisC.weight = axisC.get_weights(pars['axisC'], 0, 10000, True)
         theta.value, theta.weight = theta.get_weights(pars['theta'], -90, 180, False)
         phi.value, phi.weight = phi.get_weights(pars['phi'], -90, 180, False)
Index: fit.py
===================================================================
--- fit.py	(revision 79fcc4062b8d89e414a4ff08dded369f28b31be4)
+++ fit.py	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -3,5 +3,5 @@
 
 from bumps.names import *
-from code_cylinder import GpuCylinder
+from code_cylinder import GpuCylinder, OneDGpuCylinder
 from code_lamellar import GpuLamellar
 from code_ellipse import GpuEllipse
@@ -10,43 +10,61 @@
 from code_triaxialellipse import GpuTriEllipse
 from sasmodel import SasModel, load_data, set_beam_stop, set_half
+import numpy as np
+
+""" IMPORT THE DATA USED """
+
+data = load_data('December/Tangential/Sector0/DEC07133.ABS')
+#data = load_data('December/DEC07133.DAT')
+
+""" SET INNER BEAM STOP, OUTER RING, AND MASK HALF OF THE DATA """
+set_beam_stop(data, 0.0052)#, outer=0.025)
+#set_half(data, 'left')
 
 
-data = load_data('DEC07282.DAT')
-set_beam_stop(data, 0.0048)#, outer=0.025)
-#set_half(data, 'right')
-"""
-model = SasModel(data, GpuCylinder, scale=0.09402, radius=106, length=442.298,
-                                    sldCyl=.291e-6, sldSolv=5.77e-6, background=0,
-                                    cyl_theta=0, cyl_phi=0,
-                                    radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=0,
-                                    length_pd=0.1, length_pd_n=5, length_pd_nsigma=0,
-                                    cyl_theta_pd=0.1, cyl_theta_pd_n=10, cyl_theta_pd_nsigma=3,
-                                    cyl_phi_pd=0.1, cyl_phi_pd_n=4, cyl_phi_pd_nsigma=3,
-                                    dtype='float')
-model.radius.range(0, 1000)
-model.length.range(0, 1000)
-#model.cyl_theta.range(0,90)
-#model.cyl_phi.range(0,90)
-model.scale.range(0, 1)
-"""
+
+model = SasModel(data, OneDGpuCylinder,
+scale=0.0013,
+radius=105,
+length=1000,
+background=21,
+sldCyl=.291e-6,sldSolv=5.77e-6,
+radius_pd=0.1,radius_pd_n=10,radius_pd_nsigma=0,
+length_pd=0.1,length_pd_n=5,length_pd_nsigma=0,
+bolim=0.0,
+uplim=90) #bottom limit, upper limit of angle integral
+
+
 """
 model = SasModel(data, GpuEllipse,
-                 scale=0.0007, radius_a=42.8251, radius_b=700, sldEll=.291e-6, sldSolv=7.105e-6,
-                 background=10, axis_theta=0, axis_phi=0,
-                 radius_a_pd=0.222296, radius_a_pd_n=1, radius_a_pd_nsigma=0,
-                 radius_b_pd=.000128, radius_b_pd_n=1, radius_b_pd_nsigma=0,
-                 axis_theta_pd=24.8059, axis_theta_pd_n=40, axis_theta_pd_nsigma=3,
-                 axis_phi_pd=2.63698e-05, axis_phi_pd_n=20, axis_phi_pd_nsigma=3,
-                 dtype='float')
+scale=0.0011,
+radius_a=100, radius_b=800.8,
+sldEll=.291e-6, sldSolv=7.105e-6,
+background=8.30161,
+axis_theta=0, axis_phi=0,
+axis_theta_pd=20, axis_theta_pd_n=40, axis_theta_pd_nsigma=3,
+radius_a_pd=0.222296, radius_a_pd_n=1, radius_a_pd_nsigma=0,
+radius_b_pd=.000128, radius_b_pd_n=1, radius_b_pd_nsigma=0,
+axis_phi_pd=2.63698e-05, axis_phi_pd_n=20, axis_phi_pd_nsigma=0,
+dtype='float')
 
+
+# SET THE FITTING PARAMETERS
 model.radius_a.range(15, 1000)
-#model.radius_b.range(15, 1000)
+model.radius_b.range(15, 1000)
 #model.axis_theta_pd.range(0, 360)
 #model.background.range(0,1000)
 model.scale.range(0, 1)
 """
+
 """
-model = SasModel(data, GpuLamellar, scale=0.0128, bi_thick=35.1, sld_bi=.291e-6, sld_sol=5.77e-6, background=17.3,
-                 bi_thick_pd= 0.000009, bi_thick_pd_n=35, bi_thick_pd_nsigma=3, dtype='float')
+model = SasModel(data, GpuLamellar,
+scale=0.70,
+bi_thick=5,
+sld_bi=.291e-6,sld_sol=5.77e-6,
+background=85.23,
+bi_thick_pd= 0.0013, bi_thick_pd_n=5, bi_thick_pd_nsigma=3,
+dtype='float')
+
+# SET THE FITTING PARAMETERS
 model.bi_thick.range(0, 1000)
 model.scale.range(0, 1)
@@ -54,18 +72,40 @@
 #model.background.range(0, 1000)
 """
+
+
+
+"""
+model = SasModel(data, GpuCylinder,
+scale=0.0013, radius=105, length=1000,
+sldCyl=.291e-6, sldSolv=5.77e-6, background=21,
+cyl_theta=90, cyl_phi=0,
+cyl_theta_pd=534, cyl_theta_pd_n=40, cyl_theta_pd_nsigma=3,
+
+# SET THE FITTING PARAMETERS
+radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=0,
+length_pd=0.1, length_pd_n=5, length_pd_nsigma=0,
+cyl_phi_pd=0.1, cyl_phi_pd_n=4, cyl_phi_pd_nsigma=0,
+dtype='float')
+#model.radius.range(0, 1000)
+#model.length.range(0, 1000)
+#model.cyl_theta_pd.range(0,90)
+model.scale.range(0, 1)
+model.background.range(0, 1000)
+"""
+
 """
 model = SasModel(data, GpuCoreShellCylinder,
-                 scale= 1.77881e-06, radius=325, thickness=25, length=34.2709,
-                 core_sld=1e-6, shell_sld=.291e-6, solvent_sld=7.105e-6,
-                 background=223.827, axis_theta=90, axis_phi=0,
-                 axis_theta_pd=15.8,
+                 scale= 0.08, radius=200, thickness=30, length=2000,
+                 core_sld=7e-6, shell_sld=.291e-6, solvent_sld=7.105e-6,
+                 background=0, axis_theta=0, axis_phi=0,
 
-                 radius_pd=0.1, radius_pd_n=1, radius_pd_nsigma=0,
-                 length_pd=0.1, length_pd_n=1, length_pd_nsigma=0,
+                 radius_pd=0.38, radius_pd_n=10, radius_pd_nsigma=3,
+                 length_pd=.9, length_pd_n=10, length_pd_nsigma=3,
                  thickness_pd=0.1, thickness_pd_n=1, thickness_pd_nsigma=0,
-                 axis_theta_pd_n=10, axis_theta_pd_nsigma=3,
-                 axis_phi_pd=0.0008748, axis_phi_pd_n=10, axis_phi_pd_nsigma=3,
+                 axis_theta_pd=10, axis_theta_pd_n=40, axis_theta_pd_nsigma=3,
+                 axis_phi_pd=0.1, axis_phi_pd_n=1, axis_phi_pd_nsigma=0,
                  dtype='float')
 
+# SET THE FITTING PARAMETERS
 model.radius.range(15, 1000)
 #model.length.range(0, 1000)
@@ -80,6 +120,6 @@
 """
 
+"""
 
-"""
 model = SasModel(data, GpuCapCylinder, scale=1, rad_cyl=20, rad_cap=40, length=400, sld_capcyl=1e-6, sld_solv=6.3e-6,
                  background=0, theta=0, phi=0, rad_cyl_pd=.1, rad_cyl_pd_n=10, rad_cyl_nsigma=3, rad_cap_pd=.1, rad_cap_pd_n=1,
@@ -87,5 +127,5 @@
                  theta_pd_nsigma=3, phi_pd=.1, phi_pd_n=4, phi_pd_nsigma=3, dtype='float')
 """
-
+"""
 
 model = SasModel(data, GpuTriEllipse,
@@ -100,6 +140,7 @@
                  axisC_pd=.1, axisC_pd_n=1, axisC_pd_nsigma=0, dtype='float')
 
-#model.axisA.range(15, 1000)
-#model.axisB.range(15, 1000)
+# SET THE FITTING PARAMETERS
+model.axisA.range(15, 1000)
+model.axisB.range(15, 1000)
 #model.axisC.range(15, 1000)
 #model.background.range(0,1000)
@@ -110,8 +151,6 @@
 
 
-
-
+"""
 
 problem = FitProblem(model)
 
-
Index: multi-fit.py
===================================================================
--- multi-fit.py	(revision 9a9f5b5060cd754295dd53d9583f6d410496af99)
+++ multi-fit.py	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -5,13 +5,13 @@
 from code_lamellar import GpuLamellar
 from code_ellipse import GpuEllipse
-from sasmodel import SasModel, load_data, set_beam_stop, set_half
+from multisasmodels import SasModel, load_data, set_beam_stop, set_half
 import numpy as np
 
-data = load_data('DEC07269.DAT')
+data = load_data('DEC07282.DAT')
 set_beam_stop(data, 0.0052)#, outer=0.025)
 #set_half(data, 'left')
 
 truth = SasModel(data, GpuEllipse,
-                scale=.5, radius_a=45.265, radius_b=600.8, sldEll=.291e-6, sldSolv=7.105e-6,
+                scale=.0011, radius_a=45.265, radius_b=600.8, sldEll=.291e-6, sldSolv=7.105e-6,
                  background=8.30161, axis_theta=0, axis_phi=0,
                  radius_a_pd=0.222296, radius_a_pd_n=1, radius_a_pd_nsigma=0,
Index: multisasmodels.py
===================================================================
--- multisasmodels.py	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
+++ multisasmodels.py	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -0,0 +1,157 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+import numpy as np
+import pyopencl as cl
+from bumps.names import Parameter
+from sans.dataloader.loader import Loader
+from sans.dataloader.manipulations import Ringcut, Boxcut
+
+
+def load_data(filename):
+    loader = Loader()
+    data = loader.load(filename)
+    if data is None:
+        raise IOError("Data %r could not be loaded"%filename)
+    return data
+
+
+def set_beam_stop(data, radius, outer=None):
+    data.mask = Ringcut(0, radius)(data)
+    if outer is not None:
+        data.mask += Ringcut(outer,np.inf)(data)
+
+def set_half(data, half):
+    if half == 'left':
+        data.mask += Boxcut(x_min=-np.inf, x_max=0.0, y_min=-np.inf, y_max=np.inf)(data)
+    if half == 'right':
+        data.mask += Boxcut(x_min=0.0, x_max=np.inf, y_min=-np.inf, y_max=np.inf)(data)
+
+
+
+def plot_data(data, iq, vmin=None, vmax=None):
+    from numpy.ma import masked_array
+    import matplotlib.pyplot as plt
+    img = masked_array(iq, data.mask)
+    xmin, xmax = min(data.qx_data), max(data.qx_data)
+    ymin, ymax = min(data.qy_data), max(data.qy_data)
+    plt.imshow(img.reshape(128,128),
+               interpolation='nearest', aspect=1, origin='upper',
+               extent=[xmin, xmax, ymin, ymax], vmin=vmin, vmax=vmax)
+
+def plot_result(data, theory, view='linear'):
+    import matplotlib.pyplot as plt
+    from numpy.ma import masked_array, masked
+    plt.subplot(1, 3, 1)
+    #print "not a number",sum(np.isnan(data.data))
+    #data.data[data.data<0.05] = 0.5
+    mdata = masked_array(data.data, data.mask)
+    mdata[np.isnan(mdata)] = masked
+    if view is 'log':
+        mdata[mdata <= 0] = masked
+        mdata = np.log10(mdata)
+        mtheory = masked_array(np.log10(theory), mdata.mask)
+    else:
+        mtheory = masked_array(theory, mdata.mask)
+    mresid = masked_array((theory-data.data)/data.err_data, data.mask)
+    vmin = min(mdata.min(), mtheory.min())
+    vmax = max(mdata.max(), mtheory.max())
+
+    plot_data(data, mdata, vmin=vmin, vmax=vmax)
+    plt.colorbar()
+    plt.subplot(1, 3, 2)
+    plot_data(data, mtheory, vmin=vmin, vmax=vmax)
+    plt.colorbar()
+    plt.subplot(1, 3, 3)
+    plot_data(data, mresid)
+    plt.colorbar()
+
+
+def demo():
+    data = load_data('JUN03289.DAT')
+    set_beam_stop(data, 0.004)
+    plot_data(data)
+    import matplotlib.pyplot as plt; plt.show()
+
+
+GPU_CONTEXT = None
+GPU_QUEUE = None
+def card():
+    global GPU_CONTEXT, GPU_QUEUE
+    if GPU_CONTEXT is None:
+        GPU_CONTEXT = cl.create_some_context()
+        GPU_QUEUE = cl.CommandQueue(GPU_CONTEXT)
+    return GPU_CONTEXT, GPU_QUEUE
+
+
+class SasModel(object):
+    def __init__(self, data, model, dtype='float32', **kw):
+        self.__dict__['_parameters'] = {}
+        self.index = (data.mask==0) & (~np.isnan(data.data))
+        self.iq = data.data[self.index]
+        self.diq = data.err_data[self.index]
+        self.data = data
+        self.qx = data.qx_data
+        self.qy = data.qy_data
+        self.gpu = model(self.qx, self.qy, dtype=dtype)
+        pd_pars = set(base+attr for base in model.PD_PARS for attr in ('_pd','_pd_n','_pd_nsigma'))
+        total_pars = set(model.PARS.keys()) | pd_pars
+        extra_pars = set(kw.keys()) - total_pars
+        if extra_pars:
+            raise TypeError("unexpected parameters %s"%(str(extra_pars,)))
+        pars = model.PARS.copy()
+        pars.update((base+'_pd', 0) for base in model.PD_PARS)
+        pars.update((base+'_pd_n', 35) for base in model.PD_PARS)
+        pars.update((base+'_pd_nsigma', 3) for base in model.PD_PARS)
+        pars.update(kw)
+        self._parameters = dict((k, Parameter.default(v, name=k)) for k, v in pars.items())
+
+    def set_result(self, result):
+        self.result = result
+        return self.result
+
+    def get_result(self):
+        return self.result
+
+    def numpoints(self):
+        return len(self.iq)
+
+    def parameters(self):
+        return self._parameters
+
+    def __getattr__(self, par):
+        return self._parameters[par]
+
+    def __setattr__(self, par, val):
+        if par in self._parameters:
+            self._parameters[par] = val
+        else:
+            self.__dict__[par] = val
+
+    def theory(self):
+        pars = dict((k,v.value) for k,v in self._parameters.items())
+        result = self.gpu.eval(pars)
+        return result
+
+    def residuals(self):
+        #if np.any(self.err ==0): print "zeros in err"
+        return (self.get_result()[self.index]-self.iq)/self.diq
+
+    def nllf(self):
+        R = self.residuals()
+        #if np.any(np.isnan(R)): print "NaN in residuals"
+        return 0.5*np.sum(R**2)
+
+    def __call__(self):
+        return 2*self.nllf()/self.dof
+
+    def plot(self, view='log'):
+        plot_result(self.data, self.get_result(), view=view)
+
+    def save(self, basename):
+        pass
+
+    def update(self):
+        pass
+
Index: sasmodel.py
===================================================================
--- sasmodel.py	(revision 9a9f5b5060cd754295dd53d9583f6d410496af99)
+++ sasmodel.py	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
@@ -19,7 +19,12 @@
 
 def set_beam_stop(data, radius, outer=None):
-    data.mask = Ringcut(0, radius)(data)
-    if outer is not None:
-        data.mask += Ringcut(outer,np.inf)(data)
+    if hasattr(data, 'qx_data'):
+        data.mask = Ringcut(0, radius)(data)
+        if outer is not None:
+            data.mask += Ringcut(outer,np.inf)(data)
+    else:
+        data.mask = (data.x>=radius)
+        if outer is not None:
+            data.mask &= (data.x<outer)
 
 def set_half(data, half):
@@ -41,8 +46,7 @@
                extent=[xmin, xmax, ymin, ymax], vmin=vmin, vmax=vmax)
 
-def plot_result(data, theory, view='linear'):
+def plot_result2D(data, theory, view='linear'):
     import matplotlib.pyplot as plt
     from numpy.ma import masked_array, masked
-    plt.subplot(1, 3, 1)
     #print "not a number",sum(np.isnan(data.data))
     #data.data[data.data<0.05] = 0.5
@@ -59,4 +63,5 @@
     vmax = max(mdata.max(), mtheory.max())
 
+    plt.subplot(1, 3, 1)
     plot_data(data, mdata, vmin=vmin, vmax=vmax)
     plt.colorbar()
@@ -69,9 +74,26 @@
 
 
-def demo():
-    data = load_data('JUN03289.DAT')
-    set_beam_stop(data, 0.004)
-    plot_data(data)
-    import matplotlib.pyplot as plt; plt.show()
+def plot_result1D(data, theory, view='linear'):
+    import matplotlib.pyplot as plt
+    from numpy.ma import masked_array, masked
+    #print "not a number",sum(np.isnan(data.y))
+    #data.y[data.y<0.05] = 0.5
+    mdata = masked_array(data.y, data.mask)
+    mdata[np.isnan(mdata)] = masked
+    if view is 'log':
+        mdata[mdata <= 0] = masked
+    mtheory = masked_array(theory, mdata.mask)
+    mresid = masked_array((theory-data.y)/data.dy, mdata.mask)
+
+    plt.subplot(1,2,1)
+    plt.errorbar(data.x, mdata, yerr=data.dy)
+    plt.plot(data.x, mtheory, '-', hold=True)
+    plt.yscale(view)
+    plt.subplot(1, 2, 2)
+    plt.plot(data.x, mresid, 'x')
+    #plt.axhline(1, color='black', ls='--',lw=1, hold=True)
+    #plt.axhline(0, color='black', lw=1, hold=True)
+    #plt.axhline(-1, color='black', ls='--',lw=1, hold=True)
+
 
 
@@ -89,11 +111,19 @@
     def __init__(self, data, model, dtype='float32', **kw):
         self.__dict__['_parameters'] = {}
-        self.index = (data.mask==0) & (~np.isnan(data.data))
-        self.iq = data.data[self.index]
-        self.diq = data.err_data[self.index]
+        self.is2D = hasattr(data,'qx_data')
         self.data = data
-        self.qx = data.qx_data
-        self.qy = data.qy_data
-        self.gpu = model(self.qx, self.qy, dtype=dtype)
+        if self.is2D:
+            self.index = (data.mask==0) & (~np.isnan(data.data))
+            self.iq = data.data[self.index]
+            self.diq = data.err_data[self.index]
+            self.qx = data.qx_data
+            self.qy = data.qy_data
+            self.gpu = model(self.qx, self.qy, dtype=dtype)
+        else:
+            self.index = (data.mask==0) & (~np.isnan(data.y))
+            self.iq = data.y[self.index]
+            self.diq = data.dy[self.index]
+            self.q = data.x
+            self.gpu = model(self.q, dtype=dtype)
         pd_pars = set(base+attr for base in model.PD_PARS for attr in ('_pd','_pd_n','_pd_nsigma'))
         total_pars = set(model.PARS.keys()) | pd_pars
@@ -107,11 +137,4 @@
         pars.update(kw)
         self._parameters = dict((k, Parameter.default(v, name=k)) for k, v in pars.items())
-
-    def set_result(self, result):
-        self.result = result
-        return self.result
-
-    def get_result(self):
-        return self.result
 
     def numpoints(self):
@@ -137,5 +160,5 @@
     def residuals(self):
         #if np.any(self.err ==0): print "zeros in err"
-        return (self.get_result()[self.index]-self.iq)/self.diq
+        return (self.theory()[self.index]-self.iq)/self.diq
 
     def nllf(self):
@@ -148,5 +171,8 @@
 
     def plot(self, view='log'):
-        plot_result(self.data, self.get_result(), view=view)
+        if self.is2D:
+            plot_result2D(self.data, self.theory(), view=view)
+        else:
+            plot_result1D(self.data, self.theory(), view=view)
 
     def save(self, basename):
@@ -155,2 +181,12 @@
     def update(self):
         pass
+
+
+def demo():
+    data = load_data('DEC07086.DAT')
+    set_beam_stop(data, 0.004)
+    plot_data(data)
+    import matplotlib.pyplot as plt; plt.show()
+
+if __name__ == "__main__":
+    demo()
