Index: /trunk/anuga_core/source/anuga/structures/inlet.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/inlet.py	(revision 8091)
+++ /trunk/anuga_core/source/anuga/structures/inlet.py	(revision 8092)
@@ -235,5 +235,5 @@
         
         # find the number of cells which will be filled
-        index = num.nonzero(summed_volume<volume)[0][-1]
+        index = num.nonzero(summed_volume<=volume)[0][-1]
 
         # calculate stage needed to fill chosen cells with given volume of water
Index: /trunk/anuga_core/source/anuga/structures/inlet_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/inlet_operator.py	(revision 8091)
+++ /trunk/anuga_core/source/anuga/structures/inlet_operator.py	(revision 8092)
@@ -35,5 +35,4 @@
         self.Q = Q
 
-
         if description == None:
             self.description = ' '
@@ -50,11 +49,7 @@
         self.verbose = verbose
 
-        
         # Keep count of inlet operator
         Inlet_operator.counter += 1
 
-        import pdb
-        #pdb.set_trace()
-        
         self.enquiry_point = 0.5*(self.line[0] + self.line[1])
         self.outward_vector = self.line
@@ -66,12 +61,13 @@
 
         timestep = self.domain.get_timestep()
+
+        t = self.domain.get_time()
+        Q1 = self.update_Q(t)
+        Q2 = self.update_Q(t + timestep)
         
-        Q = self.Q
-
-        volume = Q*timestep
-
-        assert Q >= 0.0, 'Q < 0: Water to be removed from an inlet!'
-
-
+        volume = 0.5*(Q1+Q2)*timestep
+        
+        assert 0.5*(Q1+Q2) >= 0.0, 'Q < 0: Water to be removed from an inlet!'
+        
         # Distribute volume so as to obtain flat surface
         self.inlet.set_stages_evenly(volume)
@@ -79,6 +75,17 @@
         # Distribute volume evenly over all cells
         #self.inlet.set_depths_evenly(volume)
+        
+    def update_Q(self, t):
+        """Virtual method allowing local modifications by writing an
+        overriding version in descendant
+        """
+        
+        if callable(self.Q):
+            Q = self.Q(t)[0]
+        else:
+            Q = self.Q
+
+        return Q    
   
-
     def statistics(self):
 
Index: /trunk/anuga_core/source/anuga/structures/test_inlet_operator.py
===================================================================
--- /trunk/anuga_core/source/anuga/structures/test_inlet_operator.py	(revision 8091)
+++ /trunk/anuga_core/source/anuga/structures/test_inlet_operator.py	(revision 8092)
@@ -9,9 +9,7 @@
 import anuga
 
-from anuga.utilities.system_tools import get_pathname_from_package
-from anuga.structures.boyd_box_operator import Boyd_box_operator
 from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross
 from anuga.shallow_water.shallow_water_domain import Domain
-from anuga.shallow_water.forcing import Rainfall, Inflow
+from anuga.abstract_2d_finite_volumes.util import file_function
 
 from anuga.structures.inlet_operator import Inlet_operator
@@ -83,5 +81,5 @@
         return domain
 
-    def test_inlet_Q(self):
+    def test_inlet_constant_Q(self):
         """test_inlet_Q
         
@@ -129,5 +127,52 @@
         assert numpy.allclose((Q1+Q2)*finaltime, vol1-vol0, rtol=1.0e-8) 
         
+    def test_inlet_variable_Q(self):
+        """test_inlet_Q
         
+        This tests that the inlet operator adds the correct amount of water
+        """
+
+        stage_0 = 11.0
+        stage_1 = 10.0
+        elevation_0 = 10.0
+        elevation_1 = 10.0
+
+        domain_length = 200.0
+        domain_width = 200.0
+        
+
+        domain = self._create_domain(d_length=domain_length,
+                                     d_width=domain_width,
+                                     dx = 10.0,
+                                     dy = 10.0,
+                                     elevation_0 = elevation_0,
+                                     elevation_1 = elevation_1,
+                                     stage_0 = stage_0,
+                                     stage_1 = stage_1)
+
+        vol0 = domain.compute_total_volume()
+
+        finaltime = 3.0
+        line1 = [[95.0, 10.0], [105.0, 10.0]]
+        Q1 = file_function('inlet_operator_test1.tms', quantities=['hydrograph'])
+        
+        line2 = [[10.0, 90.0], [20.0, 90.0]]
+        Q2 = file_function('inlet_operator_test2.tms', quantities=['hydrograph'])
+        
+        Inlet_operator(domain, line1, Q1)
+        Inlet_operator(domain, line2, Q2)
+
+        for t in domain.evolve(yieldstep = 1.0, finaltime = finaltime):
+            #domain.write_time()
+            #print domain.volumetric_balance_statistics()
+            pass
+ 
+
+        vol1 = domain.compute_total_volume()
+        
+        print vol1 - vol0
+        
+        assert numpy.allclose(13.5, vol1-vol0, rtol=1.0e-8) 
+                
 
 
