Index: /inundation/ga/storm_surge/pyvolution/data_manager.py
===================================================================
--- /inundation/ga/storm_surge/pyvolution/data_manager.py	(revision 1065)
+++ /inundation/ga/storm_surge/pyvolution/data_manager.py	(revision 1066)
@@ -208,9 +208,11 @@
 
 
-    def __init__(self, domain, mode = 'w'):
+    def __init__(self, domain, mode = 'w', filename_ext = ''):
         from Scientific.IO.NetCDF import NetCDFFile
         from Numeric import Int, Float, Float32
 
         self.precision = Float32 #Use single precision
+        self.max_size = 2000000000#file size max is 2Gig
+        self.mode = mode
 
         Data_format.__init__(self, domain, 'sww', mode)
@@ -333,4 +335,5 @@
         import types
 	from time import sleep
+        from os import stat
 
 
@@ -358,43 +361,87 @@
 
 
-        domain = self.domain
-
-        # Get the variables
+
+        #Check to see if the file is already too big:
         time = fid.variables['time']
-        stage = fid.variables['stage']
-        xmomentum = fid.variables['xmomentum']
-        ymomentum = fid.variables['ymomentum']
-        i = len(time)
-
-        #Store time
-        time[i] = self.domain.time
-
-
-        if type(names) not in [types.ListType, types.TupleType]:
-            names = [names]
-
-        for name in names:
-            # Get quantity
-            Q = domain.quantities[name]
-            A,V = Q.get_vertex_values(xy=False,
+        i = len(time)+1
+        file_size = stat(self.filename)[6]
+        file_size_increase =  file_size/i
+        if file_size + file_size_increase > self.max_size:
+            #in order to get the file name and start time correct,
+            #I change the domian.filename and domain.starttime.
+            #This is the only way to do this without changing
+            #other modules (I think).
+
+            #write a filename addon that won't bread swollen
+            filename_ext = '_time_%s'%self.domain.time            
+            filename_ext = filename_ext.replace('.', '_')
+            #remember the old filename, then give domain a 
+            #name with the extension
+            old_domain_filename = self.domain.filename
+            self.domain.filename = self.domain.filename+filename_ext
+
+            #change the domain starttime to the current time
+            old_domain_starttime = self.domain.starttime
+            self.domain.starttime = self.domain.time
+
+            #build a new data_structure.
+            next_data_structure=\
+                Data_format_sww(self.domain, mode=self.mode\
+                                ,filename_ext=filename_ext)
+            print '    file_size = %s'%file_size
+            print '    saving file to %s'%self.next_data_structure.filename
+
+            #set up the new data_structure
+            self.domain.writer = next_data_structure
+
+            #FIXME - could be cleaner to use domain.store_timestep etc.
+            next_data_structure.store_connectivity()
+            next_data_structure.store_timestep(names)
+            fid.sync()
+            fid.close()
+
+            #restore the old starttime and filename
+            self.domain.starttime = old_domain_starttime
+            self.domain.filename = old_domain_filename
+        else:
+            domain = self.domain
+
+            # Get the variables
+            time = fid.variables['time']
+            stage = fid.variables['stage']
+            xmomentum = fid.variables['xmomentum']
+            ymomentum = fid.variables['ymomentum']
+            i = len(time)
+
+            #Store time
+            time[i] = self.domain.time
+
+
+            if type(names) not in [types.ListType, types.TupleType]:
+                names = [names]
+
+            for name in names:
+                # Get quantity
+                Q = domain.quantities[name]
+                A,V = Q.get_vertex_values(xy=False,
                                       precision = self.precision)
 
-            #FIXME: Make this general (see below)
-            if name == 'stage':
-                stage[i,:] = A.astype(self.precision)
-            elif name == 'xmomentum':
-                xmomentum[i,:] = A.astype(self.precision)
-            elif name == 'ymomentum':
-                ymomentum[i,:] = A.astype(self.precision)
-
-            #As in....
-	    #eval( name + '[i,:] = A.astype(self.precision)' )
-	    #FIXME: But we need a UNIT test for that before refactoring
-
-
-
-        #Flush and close
-        fid.sync()
-        fid.close()
+                #FIXME: Make this general (see below)
+                if name == 'stage':
+                    stage[i,:] = A.astype(self.precision)
+                elif name == 'xmomentum':
+                    xmomentum[i,:] = A.astype(self.precision)
+                elif name == 'ymomentum':
+                    ymomentum[i,:] = A.astype(self.precision)
+
+                #As in....
+	        #eval( name + '[i,:] = A.astype(self.precision)' )
+	        #FIXME: But we need a UNIT test for that before refactoring
+
+
+
+            #Flush and close
+            fid.sync()
+            fid.close()
 
 
