Index: /anuga_validation/automated_validation_tests/pixel_registration/README.txt
===================================================================
--- /anuga_validation/automated_validation_tests/pixel_registration/README.txt	(revision 4810)
+++ /anuga_validation/automated_validation_tests/pixel_registration/README.txt	(revision 4810)
@@ -0,0 +1,12 @@
+This test verifies that ascii grids are imported correctly.
+Joaquim Luis discovered that ANUGA misinterpreted the xllcorner and yllcorner 
+parameters and devised this test to reveal the problem. See sourceforge mailing thread: http://sourceforge.net/mailarchive/forum.php?thread_name=4727D555.7010208%40ualg.pt&forum_name=anuga-user
+
+For testing purposes, the script was modified with use_cache=False.
+
+The error manifests itself when the dem (sub_region.asc, sub_region.prj) and the polygons (shallow.csv, out_rect.csv) in turned into a domain and the boundary condition defined in br_swan.sww is applied. With wrong pixel registration, the domain will be out by 0.5*cellsize and therefor outside the area covered by 
+the boundary condition.
+
+After Joaquim's fix (November 2007), this passed.
+
+The file layer01.png shows the polygons constituting this example. 
Index: /anuga_validation/automated_validation_tests/pixel_registration/out_rect.csv
===================================================================
--- /anuga_validation/automated_validation_tests/pixel_registration/out_rect.csv	(revision 4810)
+++ /anuga_validation/automated_validation_tests/pixel_registration/out_rect.csv	(revision 4810)
@@ -0,0 +1,4 @@
+514460.,4098600.
+514460.,4103597.
+519470.,4103597.
+519470.,4098600.
Index: /anuga_validation/automated_validation_tests/pixel_registration/run_pixel_registration.py
===================================================================
--- /anuga_validation/automated_validation_tests/pixel_registration/run_pixel_registration.py	(revision 4810)
+++ /anuga_validation/automated_validation_tests/pixel_registration/run_pixel_registration.py	(revision 4810)
@@ -0,0 +1,157 @@
+"""Script for running a tsunami inundation scenario for Boca do Rio.
+Adopted from cairns files
+
+Joaquim Luis, 2007
+"""
+
+#------------------------------------------------------------------------------
+# Import necessary modules
+#------------------------------------------------------------------------------
+
+# Standard modules
+import os
+import time
+import sys
+
+# Related major packages
+from anuga.shallow_water import Domain
+from anuga.shallow_water import Transmissive_boundary
+from anuga.shallow_water import Reflective_boundary
+from anuga.shallow_water import Dirichlet_boundary
+from anuga.shallow_water import Time_boundary
+from anuga.shallow_water import File_boundary
+from anuga.shallow_water import Field_boundary
+
+from anuga.pmesh.mesh_interface import create_mesh_from_regions
+from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf
+from anuga.shallow_water.data_manager import dem2pts
+from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary
+from anuga.abstract_2d_finite_volumes.util import file_function
+
+
+#------------------------------------------------------------------------------
+# Define scenario as either ...
+#------------------------------------------------------------------------------
+scenario = 'br'
+basename = scenario + 'source'
+
+#------------------------------------------------------------------------------
+# Preparation of topographic data
+# Convert ASC 2 DEM 2 PTS using source data and store result in source data
+#------------------------------------------------------------------------------
+
+# Filenames
+dem_name = 'sub_region_bat' 
+meshname = 'sub_region.msh'
+
+# Create DEM from asc data
+convert_dem_from_ascii2netcdf(dem_name, use_cache=False, verbose=True)
+
+# Create pts file for onshore DEM
+dem2pts(dem_name, use_cache=False, verbose=True)
+
+from anuga.utilities.polygon import read_polygon, plot_polygons, \
+                                    polygon_area, is_inside_polygon
+
+###############################
+# Domain definitions
+###############################
+
+# bounding polygon for study area
+bounding_polygon = read_polygon('out_rect.csv')
+
+print 'Area of bounding polygon in km?', polygon_area(bounding_polygon)/1000000.0
+
+###############################
+# Interior region definitions
+###############################
+
+# interior polygons
+poly_shallow = read_polygon('shallow.csv')
+
+#------------------------------------------------------------------------------
+# Create the triangular mesh based on overall clipping polygon with a tagged
+# boundary and interior regions defined in project.py along with
+# resolutions (maximal area of per triangle) for each polygon
+#------------------------------------------------------------------------------
+
+remainder_res = 2500
+shallow_res = 250
+interior_regions = [[bounding_polygon, remainder_res], [poly_shallow, shallow_res]]
+
+create_mesh_from_regions(bounding_polygon, 
+                         boundary_tags={'west': [0],
+                                        'south': [1],
+                                        'east': [2],
+                                        'north': [3]},
+                         maximum_triangle_area=remainder_res,
+                         filename=meshname,
+                         interior_regions=interior_regions,
+                         use_cache=False,
+                         verbose=True)
+
+#------------------------------------------------------------------------------
+# Setup computational domain
+#------------------------------------------------------------------------------
+
+domain = Domain(meshname, use_cache=False, verbose=True)
+
+print 'Number of triangles = ', len(domain)
+print 'The extent is ', domain.get_extent()
+print domain.statistics()
+
+domain.set_name(basename) 
+domain.set_quantities_to_be_stored(['stage', 'xmomentum', 'ymomentum'])
+domain.set_minimum_storable_height(0.01)
+
+#------------------------------------------------------------------------------
+# Setup initial conditions
+#------------------------------------------------------------------------------
+
+tide = 0.0
+domain.set_quantity('stage', tide)
+domain.set_quantity('friction', 0.025) 
+domain.set_quantity('elevation', 
+                    filename=dem_name + '.pts',
+                    use_cache=False,
+                    verbose=True,
+                    alpha=0.1)
+
+#------------------------------------------------------------------------------
+# Setup boundary conditions
+#------------------------------------------------------------------------------
+
+# Create boundary function from timeseries provided in file
+#function1 = file_function('mareg.tms', domain, verbose=True)
+
+# Create and assign boundary objects
+#Bts1 = Transmissive_Momentum_Set_Stage_boundary(domain, function1) 
+
+print 'Available boundary tags', domain.get_boundary_tags()
+#Bt = Transmissive_boundary(domain)    # Continue all values on boundary 
+Br = Reflective_boundary(domain)
+Bd = Dirichlet_boundary([tide,0,0])
+Bf = Field_boundary('br_swan.sww',
+                    domain, time_thinning=1, mean_stage=tide, 
+                    use_cache=False, verbose=True)
+   
+#Boundary condition for sww feed at the east boundary
+domain.set_boundary({'west': Br,'south':Bf,'east': Br,'north': Br})
+    
+#------------------------------------------------------------------------------
+# Evolve system through time
+#------------------------------------------------------------------------------
+
+import time
+t0 = time.time()
+
+from Numeric import allclose
+from anuga.abstract_2d_finite_volumes.quantity import Quantity
+
+
+    # save every 1sec leading up to wave approaching land
+for t in domain.evolve(yieldstep = 1, finaltime = 960): 
+        domain.write_time()
+        domain.write_boundary_statistics(tags = 'east')
+           
+print 'That took %.2f seconds' %(time.time()-t0)
Index: /anuga_validation/automated_validation_tests/pixel_registration/shallow.csv
===================================================================
--- /anuga_validation/automated_validation_tests/pixel_registration/shallow.csv	(revision 4810)
+++ /anuga_validation/automated_validation_tests/pixel_registration/shallow.csv	(revision 4810)
@@ -0,0 +1,46 @@
+518448.119794,4102167.438977
+518476.459662,4101931.273405
+518674.838743,4100325.347514
+515425.200469,4100211.988039
+515302.394371,4102091.865994
+515406.307223,4102328.031567
+515406.307223,4102498.070779
+515255.161257,4102800.362711
+515104.015291,4102913.722186
+515179.588274,4103074.314775
+515538.559944,4102705.896482
+515595.239681,4102346.924812
+515859.745122,4102413.051173
+515973.104597,4102328.031567
+516483.222233,4102394.157927
+516624.921576,4102365.818058
+516521.008724,4102668.109991
+516303.736398,4102696.449859
+516502.115478,4102951.508677
+516407.649250,4103102.654644
+516209.270169,4103319.926970
+516020.337711,4103386.053330
+516048.677580,4103595.131754
+515916.424859,4103595.937852
+516322.629644,4103595.491229
+516606.028330,4103329.373593
+516700.494559,4103423.839822
+516719.387805,4103595.937852
+517059.466229,4103595.937852
+516955.553377,4103433.286445
+517550.690619,4103556.092542
+517909.662289,4103546.645919
+518108.041370,4103595.345263
+518230.847467,4103414.393199
+518013.575141,4103178.227627
+517796.302814,4103045.974906
+517484.564259,4103027.081660
+517068.912852,4102639.770122
+517021.679737,4102450.837664
+517238.952064,4102318.584944
+518060.808255,4102261.905206
+517881.322420,4102507.517402
+518013.575141,4102809.809334
+518287.527205,4102904.275563
+518637.052251,4102620.876876
+518259.187336,4102413.051173
Index: /anuga_validation/automated_validation_tests/pixel_registration/sub_region_bat.asc
===================================================================
--- /anuga_validation/automated_validation_tests/pixel_registration/sub_region_bat.asc	(revision 4810)
+++ /anuga_validation/automated_validation_tests/pixel_registration/sub_region_bat.asc	(revision 4810)
@@ -0,0 +1,14 @@
+ncols 7
+nrows 8
+xllcorner 514000
+yllcorner 4098000
+cellsize 800
+nodata_value -9999
+55 57 44 31 22 13 32
+61 55 56 12 59 32 52
+42 38 -3 -7 -3 23 -9
+19 9 -12 -18 -15 -4 -18
+-12 -11 -17 -24 -20 -19 -23
+-21 -24 -31 -39 -36 -34 -35
+-36 -40 -43 -48 -49 -48 -48
+-47 -48 -51 -55 -54 -53 -51
Index: /anuga_validation/automated_validation_tests/pixel_registration/sub_region_bat.prj
===================================================================
--- /anuga_validation/automated_validation_tests/pixel_registration/sub_region_bat.prj	(revision 4810)
+++ /anuga_validation/automated_validation_tests/pixel_registration/sub_region_bat.prj	(revision 4810)
@@ -0,0 +1,9 @@
+Projection    UTM
+Zone          26
+Datum         WGS84
+Zunits        NO
+Units         METERS
+Spheroid      WGS84
+Xshift        500000
+Yshift        0
+Parameters
Index: /anuga_validation/automated_validation_tests/pixel_registration/validate_pixel_registration.py
===================================================================
--- /anuga_validation/automated_validation_tests/pixel_registration/validate_pixel_registration.py	(revision 4810)
+++ /anuga_validation/automated_validation_tests/pixel_registration/validate_pixel_registration.py	(revision 4810)
@@ -0,0 +1,41 @@
+"""Automatic verification that the ANUGA code validates against the example
+   devised by Joquim Luis. See README.txt for more details.
+"""
+
+import unittest
+import os
+
+class Test_Pixel(unittest.TestCase):
+    def setUp(self):
+        
+        # Remove garbage
+        for file in os.listdir('.'):
+
+            # Don't remove br_swan.sww            
+            if file == 'br_swan.sww': continue
+            
+            if file.endswith('.stdout') or\
+               file.endswith('.dem') or\
+               file.endswith('.pts') or\
+               file.endswith('.sww') or\
+               file.endswith('.msh') or\
+               file.endswith('~'):
+                os.remove(file)
+                
+        
+    def tearDown(self):
+        pass
+
+    def test_that_script_can_run_without_errors(self):
+
+        s = 'run_pixel_registration.py'
+        res = os.system('python %s > run_pixel_registration.stdout' %s)
+        assert res == 0
+
+
+
+#-------------------------------------------------------------
+if __name__ == "__main__":
+    suite = unittest.makeSuite(Test_Pixel, 'test')
+    runner = unittest.TextTestRunner(verbosity=2)
+    runner.run(suite)
Index: /anuga_validation/automated_validation_tests/validate_all.py
===================================================================
--- /anuga_validation/automated_validation_tests/validate_all.py	(revision 4809)
+++ /anuga_validation/automated_validation_tests/validate_all.py	(revision 4810)
@@ -30,5 +30,5 @@
 
 for path, filename in validation_dirs_and_files:
-    print 'filename path',path, filename
+    print 'filename path', path, filename
 
     os.chdir(path)
@@ -37,5 +37,5 @@
     print 'current dir', os.getcwd() 
     
-    #back to parent directory
+    # Back to parent directory
     os.chdir(os.pardir)
 
