Index: calculator/slit_length_calculator.py
===================================================================
--- calculator/slit_length_calculator.py	(revision 0bf2c6fdc738983d6c30d6d8affecb850e56884b)
+++ calculator/slit_length_calculator.py	(revision 0bf2c6fdc738983d6c30d6d8affecb850e56884b)
@@ -0,0 +1,110 @@
+"""
+This software was developed by the University of Tennessee as part of the
+Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
+project funded by the US National Science Foundation. 
+
+See the license text in license.txt
+
+copyright 2008, 2009, University of Tennessee
+"""
+from numpy import *
+
+class SlitlengthCalculator(object):
+    """
+        compute slit length from SAXSess beam profile (1st col. Q , 2nd col. I , and 3rd col. dI.: don't need the 3rd)
+        @object: data where are data.y and data.x
+    """
+    def __init__(self):
+        
+        # x data
+        self.x = None
+        # y data
+        self.y = None
+        #default slit length
+        self.slit_length = 0.0
+        
+        # The unit is unknown from SAXSess profile: 
+        # It seems 1/nm but it could be not fixed, 
+        # so users should be notified to determine the unit by themselves.
+        self.slit_length_unit = "unknown"
+    
+    def set_data(self, x=None, y=None):
+        """
+            set data
+            @ Param x, y: x array and y array
+        """
+        self.x = x
+        self.y = y
+        
+        
+    def calculate_slit_length(self):
+        """
+            Calculate slit length using 10 max point
+            ToDo: Near future, it should be re-factored in better method.
+        """
+        # None data do nothing
+        if self.y == None or self.x == None:
+            return
+        
+        # set local variable
+        y = self.y
+        x = self.x
+
+        # find max y
+        max_y = y.max()
+        
+        # initial values 
+        y_sum = 0.0
+        y_max = 0.0
+        ind = 0.0
+        
+        # sum 10 or more y values until getting max_y, 
+        while (True):
+            if ind >= 10 and y_max == max_y:
+                break
+            y_sum = y_sum + y[ind]
+            if y[ind] > y_max: y_max = y[ind]
+            ind += 1
+     
+        # find the average value/2 of the top values  
+        y_half = y_sum/(2.0*ind)
+        
+        # defaults
+        y_half_d = 0.0
+        ind = 0.0
+        # find indices where it crosses y = y_half.
+        while (True):
+            ind += 1                # no need to check when ind == 0
+            y_half_d = y[ind]       # y value and ind just after passed the spot of the half height 
+            if y[ind] < y_half: break
+   
+        y_half_u = y[ind-1]         # y value and ind just before passed the spot of the half height
+        
+        # get corresponding x values
+        x_half_d = x[ind]
+        x_half_u = x[ind-1] 
+        
+        # calculate x at y = y_half using linear interpolation
+        if y_half_u == y_half_d:
+            x_half = (x_half_d + x_half_u)/2.0
+        else:
+            x_half = (x_half_u * (y_half - y_half_d) + x_half_d*(y_half_u-y_half))/(y_half_u - y_half_d)
+        
+        # multiply by 2 due to the beam profile is for half beam
+        slit_length = 2.0 * x_half
+        
+        # set slit_length
+        self.slit_length = slit_length
+   
+    def get_slit_length(self): 
+        """
+            Calculate and return the slit length
+        """
+        self.calculate_slit_length()
+        return self.slit_length
+        
+    def get_slit_length_unit(self): 
+        """
+            return the slit length unit
+        """
+        return self.slit_length_unit
Index: calculator/test/beam profile.DAT
===================================================================
--- calculator/test/beam profile.DAT	(revision 0bf2c6fdc738983d6c30d6d8affecb850e56884b)
+++ calculator/test/beam profile.DAT	(revision 0bf2c6fdc738983d6c30d6d8affecb850e56884b)
@@ -0,0 +1,54 @@
+                                                                                
+SAXS BOX                                                                       
+       49        30         0         0         0         0         0         0
+  0.000000E+00   0.261200E+03   0.000000E+00   0.100000E+01   0.154200E+00
+  0.100000E+01   0.155999E+01   0.000000E+00   0.000000E+00   0.000000E+00
+  0.000000E+00   0.100000E+01   0.836825E+02
+  0.754396E-01   0.975440E+00   0.938981E+02
+  0.150879E+00   0.975745E+00   0.991879E+02
+  0.226319E+00   0.975473E+00   0.767819E+02
+  0.301758E+00   0.974517E+00   0.131319E+03
+  0.377198E+00   0.973001E+00   0.817830E+02
+  0.452637E+00   0.969088E+00   0.668273E+02
+  0.528077E+00   0.967890E+00   0.934950E+02
+  0.603517E+00   0.975536E+00   0.116805E+03
+  0.678956E+00   0.982809E+00   0.966191E+02
+  0.754396E+00   0.982538E+00   0.138675E+03
+  0.829835E+00   0.985082E+00  -0.100000E+01
+  0.905275E+00   0.991786E+00  -0.100000E+01
+  0.980715E+00   0.988353E+00  -0.100000E+01
+  0.105615E+01   0.977319E+00  -0.100000E+01
+  0.113159E+01   0.973398E+00  -0.100000E+01
+  0.120703E+01   0.975829E+00  -0.100000E+01
+  0.128247E+01   0.978032E+00  -0.100000E+01
+  0.135791E+01   0.977557E+00  -0.100000E+01
+  0.143335E+01   0.976422E+00  -0.100000E+01
+  0.150879E+01   0.982926E+00  -0.100000E+01
+  0.158423E+01   0.991207E+00  -0.100000E+01
+  0.165967E+01   0.982255E+00  -0.100000E+01
+  0.173511E+01   0.968295E+00  -0.100000E+01
+  0.181055E+01   0.973161E+00  -0.100000E+01
+  0.188599E+01   0.980441E+00  -0.100000E+01
+  0.196143E+01   0.973060E+00  -0.100000E+01
+  0.203687E+01   0.967479E+00  -0.100000E+01
+  0.211231E+01   0.968228E+00  -0.100000E+01
+  0.218775E+01   0.954858E+00  -0.100000E+01
+  0.226319E+01   0.920322E+00  -0.100000E+01
+  0.233863E+01   0.870665E+00  -0.100000E+01
+  0.241407E+01   0.814629E+00  -0.100000E+01
+  0.248951E+01   0.758434E+00  -0.100000E+01
+  0.256495E+01   0.694671E+00  -0.100000E+01
+  0.264039E+01   0.621470E+00  -0.100000E+01
+  0.271583E+01   0.554105E+00  -0.100000E+01
+  0.279126E+01   0.490278E+00  -0.100000E+01
+  0.286670E+01   0.408652E+00  -0.100000E+01
+  0.294214E+01   0.321530E+00  -0.100000E+01
+  0.301758E+01   0.255968E+00  -0.100000E+01
+  0.309302E+01   0.200420E+00  -0.100000E+01
+  0.316846E+01   0.140477E+00  -0.100000E+01
+  0.324390E+01   0.907699E-01  -0.100000E+01
+  0.331934E+01   0.593287E-01  -0.100000E+01
+  0.339478E+01   0.366914E-01  -0.100000E+01
+  0.347022E+01   0.198629E-01  -0.100000E+01
+  0.354566E+01   0.120037E-01  -0.100000E+01
+  0.362110E+01   0.110363E-01  -0.100000E+01
Index: calculator/test/utest_slit_length_calculator.py
===================================================================
--- calculator/test/utest_slit_length_calculator.py	(revision 0bf2c6fdc738983d6c30d6d8affecb850e56884b)
+++ calculator/test/utest_slit_length_calculator.py	(revision 0bf2c6fdc738983d6c30d6d8affecb850e56884b)
@@ -0,0 +1,32 @@
+"""
+    Unit tests for slit_length_calculator
+"""
+
+import unittest
+from DataLoader.readers.ascii_reader import Reader
+from  sans.calculator.slit_length_calculator import SlitlengthCalculator as calculator
+
+import os.path
+
+class slit_calculator(unittest.TestCase):
+    
+    def setUp(self):
+        
+        self.reader = Reader()
+        
+    def test_slitlength_calculation(self):
+        """
+            Test slit_length_calculator"
+        """
+        f = self.reader.read("beam profile.DAT")
+        cal = calculator()
+        cal.set_data(f.x,f.y)
+        slitlength = cal.get_slit_length()
+        
+        # The value "5.5858" was obtained by manual calculation.
+        self.assertAlmostEqual(slitlength,5.5858, 3)
+        
+        
+if __name__ == '__main__':
+    unittest.main()
+   
