Index: /anuga_work/production/busselton/export_results_all.py
===================================================================
--- /anuga_work/production/busselton/export_results_all.py	(revision 5848)
+++ /anuga_work/production/busselton/export_results_all.py	(revision 5849)
@@ -1,5 +1,16 @@
+"""
+Generates ascii grids of nominated areas -
+Input: sww file from run_perth.py
+       boundaries for grids from project.py
+Outputs: ascii grids of specified variables
+Stored in the 'outputs_dir' folder for respective .sww file
+
+Note:
+If producing a grid for the enitre extent cellsize should be greater than 30m
+If producing grids for inundation area resolution should be greater than mesh (ie ~22m)
+"""
+
 import project, os
 import sys
-
 from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts
 from anuga.shallow_water.data_manager import sww2dem
@@ -7,84 +18,75 @@
 
 
-#time_dir = '20080815_103708_run_final_0.6_polyline_newExtent_kvanputt'
-time_dir = '20080910_154939_run_final_0.6_27255_alpha0.1_kvanputt'
+directory = project.output_dir
 
-is_parallel = False
-#is_parallel = True
-if is_parallel == True: nodes = 4
+time_dir1 = '20081002_111432_run_final_0_27283_250m_none_kvanputt'
+time_dir2 = '20081002_111258_run_final_0_27283_250m_all_kvanputt'
+time_dir3 = '20080815_103818_run_final_0_polyline_newExtent_kvanputt'
 
+time_dirs = [time_dir1, time_dir2, time_dir3]
 
-cellsize = 15
+#cellsize = 20
+cellsize = 250
+
+timestep = None    # None means no timestep!
 #timestep = 0
-directory = project.output_dir
-name1 = directory+time_dir+sep+project.scenario_name
-name2 = directory+time_dir+sep+'sww2'+sep+project.scenario_name+'_time_38460_0'
-name3 = directory+time_dir+sep+'sww3'+sep+project.scenario_name+'_time_76920_0'
 
-names= [name1, name2, name3]
-for name in names:
+######
+# Set the special areas of interest.  If none, do: area='All'
+######
+#area = ['Geordie', 'Sorrento', 'Fremantle', 'Rockingham']  # strings must match keys in var_equations below
+area = ['All']      # 'All' means no special areas - the whole thing
 
-    area = ['Busselton', 'Bunbury']
+######
+# Define allowed variable names and associated equations to generate values.
+# This would not normally change.
+######
+var_equations = {'stage':     'stage',
+                 'momentum':  '(xmomentum**2 + ymomentum**2)**0.5',
+                 'depth':     'stage-elevation',
+                 'speed':     '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6)',
+                 'elevation': 'elevation' }
 
-    for which_area in area:
-        if which_area == 'Busselton':
-            easting_min = project.xminBusselton
-            easting_max = project.xmaxBusselton
-            northing_min = project.yminBusselton
-            northing_max = project.ymaxBusselton
+# one or more key strings from var_equations above
+var = ['stage', 'elevation']
 
-        if which_area == 'Bunbury':
-            easting_min = project.xminBunbury
-            easting_max = project.xmaxBunbury
-            northing_min = project.yminBunbury
-            northing_max = project.ymaxBunbury
+######
+# Start running the various conversions we require.
+######
+for time_dir in time_dirs:
+    name1 = directory+time_dir+sep+project.scenario_name
+#    name2 = directory+time_dir+sep+'sww2'+sep+project.scenario_name+'_time_39900_0' #need to get assistance on how to make this into anything
+    names = [name1]
+    
+    for name in names:
+        for which_area in area:
+            if which_area == 'All':
+                easting_min = None
+                easting_max = None
+                northing_min = None
+                northing_max = None
+            else:
+                try:
+                    easting_min = eval('project.xmin%s' % which_area)
+                    easting_max = eval('project.xmax%s' % which_area)
+                    northing_min = eval('project.ymin%s' % which_area)
+                    northing_max = eval('project.ymax%s' % which_area)
+                except AttributeError:
+                    print 'Unrecognized area name: %s' % which_area
+                    break
+              
+            for which_var in var:
+                if which_var not in var_equations:
+                    print 'Unrecognized variable name: %s' % which_var
+                    break
 
-        var = [2] # momentum and depth
-        #var = [2] # depth
-        #var = [0,4]
+                outname = name + which_area + '_' + which_var
+                quantityname = var_equations[which_var]
 
-        for which_var in var:
-            if which_var == 0:  # Stage
-                outname = name + which_area + '_stage' 
-                quantityname = 'stage'
-
-            if which_var == 1:  # Absolute Momentum
-                outname = name + which_area + '_momentum' 
-                quantityname = '(xmomentum**2 + ymomentum**2)**0.5'  
-
-            if which_var == 2:  # Depth
-                outname = name + which_area + '_depth'
-                quantityname = 'stage-elevation'  
-
-            if which_var == 3:  # Speed
-                outname = name + which_area + '_speed'
-                quantityname = '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-6/(stage-elevation))'  #Speed
-
-            if which_var == 4:  # Elevation
-                outname = name + which_area + '_elevation'
-                quantityname = 'elevation'  #Elevation
-
-            if is_parallel == True:
-            #    print 'is_parallel',is_parallel
-                for i in range(0,nodes):
-                    namei = name + '_P%d_%d' %(i,nodes)
-                    outnamei = outname + '_P%d_%d' %(i,nodes)
-                    print 'start sww2dem for sww file %d' %(i)
-                    sww2dem(namei, basename_out = outnamei,
-                                quantity = quantityname,
-                                #timestep = timestep,
-                                cellsize = cellsize,      
-                                easting_min = project_grad.e_min_area,
-                                easting_max = project_grad.e_max_area,
-                                northing_min = project_grad.n_min_area,
-                                northing_max = project_grad.n_max_area,        
-                                reduction = max, 
-                                verbose = True,
-                                format = 'asc')
-            else:
-                print 'start sww2dem',which_area, easting_min,name,outname
+                print 'start sww2dem: time_dir=%s' % time_dir
+                
                 sww2dem(name, basename_out = outname,
                             quantity = quantityname,
-                            #timestep = timestep,
+                            timestep = timestep,
                             cellsize = cellsize,      
                             easting_min = easting_min,
@@ -95,3 +97,2 @@
                             verbose = True,
                             format = 'asc')
-
