Index: branches/numpy_anuga_validation/automated_validation_tests/patong_beach_validation/cmpsww.py
===================================================================
--- branches/numpy_anuga_validation/automated_validation_tests/patong_beach_validation/cmpsww.py	(revision 6974)
+++ branches/numpy_anuga_validation/automated_validation_tests/patong_beach_validation/cmpsww.py	(revision 7141)
@@ -21,6 +21,10 @@
 #####
 
-# allowable 'slop' when testing two float values
-epsilon = 1.0e-9
+# Global for the '-q' quiet flag
+quiet = None
+
+# default tolerances - same as numpy defaults
+default_abs_tolerance = 1.0e-08
+default_rel_tolerance = 1.0000000000000001e-05
 
 # Global attributes that should exist and be same in both files
@@ -69,5 +73,7 @@
 # @param variables A list of variable names to compare.
 # @return Returns if files 'equal', else raises RuntimeError.
-def files_are_the_same(files, globals=None, timesteps=None, variables=None):
+def files_are_the_same(files, globals=None, timesteps=None, variables=None,
+                       rel_tolerance=default_rel_tolerance,
+                       abs_tolerance=default_abs_tolerance):
     # split out the filenames and check they exist
     (file1, file2) = files
@@ -232,4 +238,6 @@
 
     # check data variables, be clever with time series data
+    max_difference = -1
+    diff_count = 0
     for var_name in variables:
         var_dims = expected_variables[var_name]
@@ -239,35 +247,46 @@
                 var1 = num.array(fid1.variables[var_name][t,:])
                 var2 = num.array(fid2.variables[var_name][t,:])
-                if var1 != var2:
+                if not num.allclose(var1, var2,
+                                    rtol=rel_tolerance, atol=abs_tolerance):
+                    error = True
                     for i in xrange(len(var1)):
-                        if var1[i] != var2[i]:
-                            error_msg += ('\nFiles differ in variable '
-                                              '%s[%d,%d]:\n'
-                                          '%s: %f\n'
-                                          '%s: %f\n'
-                                          'difference=%f\n'
-                                          % (var_name, t, i,
-                                             filename1, var1[i],
-                                             filename2, var2[i],
-                                             var1[i]-var2[i]))
-                            break
-                    error = True
+                        if not num.allclose(var1[i], var2[i],
+                                            rtol=rel_tolerance,
+                                            atol=abs_tolerance):
+                            if not quiet:
+                                error_msg += ('\nFiles differ in variable '
+                                                  '%s[%d,%d]:\n'
+                                              '%s: %f\n'
+                                              '%s: %f\n'
+                                              'difference=%e\n'
+                                              % (var_name, t, i,
+                                                 filename1, var1[i],
+                                                 filename2, var2[i],
+                                                 num.abs(var1[i]-var2[i])))
+                            max_difference = max(max_difference,
+                                                 num.abs(var1[i]-var2[i]))
+                            diff_count += 1
         else:
             # simple data, check whole thing at once
             var1 = num.array(fid1.variables[var_name][:])
             var2 = num.array(fid2.variables[var_name][:])
-            if not num.allclose(var1, var2):
+            if not num.allclose(var1, var2,
+                                rtol=rel_tolerance, atol=abs_tolerance):
                 for j in xrange(len(var1)):
-                    if abs(var1[j] - var2[j]) > epsilon:
-                        error_msg += ('\nFiles differ in variable '
-                                      '%s[%d]:\n'
-                                      '%s: %f\n'
-                                      '%s: %f\n'
-                                      'difference=%f\n'
-                                       % (var_name, j,  
-                                          filename1, var1[j],
-                                          filename2, var2[j],
-                                          var1[j]-var2[j]))
-                        break
+                    if not num.allclose(var1[j], var2[j],
+                                          rtol=rel_tolerance, atol=abs_tolerance):
+                        if not quiet:
+                            error_msg += ('\nFiles differ in variable '
+                                          '%s[%d]:\n'
+                                          '%s: %f\n'
+                                          '%s: %f\n'
+                                          'difference=%e\n'
+                                           % (var_name, j,  
+                                              filename1, var1[j],
+                                              filename2, var2[j],
+                                              num.abs(var1[j]-var2[j])))
+                        max_difference = max(max_difference,
+                                             num.abs(var1[i]-var2[i]))
+                        diff_count += 1
                 error = True
 
@@ -280,4 +299,7 @@
 
     if error:
+        error_msg += ('\nNumber of data differences=%d\n'
+                      'Maximum data difference=%e\n'
+                      % (diff_count, max_difference))
         raise RuntimeError, error_msg
 
@@ -293,4 +315,5 @@
     a('where <options> is zero or more of:\n')
     a('                   -h        print this help\n')
+    a('                   -q        be quiet, print only summary of differences\n')
     a("                   -a <val>  set absolute threshold of 'equivalent'\n")
     a("                   -r <val>  set relative threshold of 'equivalent'\n")
@@ -319,4 +342,6 @@
 # @return The status code the program will exit with.
 def main(argv=None):
+    global quiet
+
     if argv is None:
         argv = sys.argv
@@ -324,5 +349,5 @@
     try:
         try:
-            opts, args = getopt.getopt(argv[1:], 'hg:t:v:',
+            opts, args = getopt.getopt(argv[1:], 'hqa:g:r:t:v:',
                                        ['help', 'globals',
                                         'variables', 'timesteps'])
@@ -338,8 +363,17 @@
     timesteps = None
     variables = None
+    quiet = False
+    rel_tolerance = default_rel_tolerance
+    abs_tolerance = default_abs_tolerance
     for opt, arg in opts:
         if opt in ('-h', '--help'):
             print usage()
             sys.exit(0)
+        elif opt in ('-q', '--quiet'):
+            quiet = True
+        elif opt in ('-a', '--absolute'):
+            abs_tolerance = float(arg)
+        elif opt in ('-r', '--relative'):
+            rel_tolerance = float(arg)
         elif opt in ('-g', '--globals'):
             globals = arg.split(',')
@@ -357,5 +391,7 @@
     try:
         files_are_the_same(args, globals=globals,
-                           timesteps=timesteps, variables=variables)
+                           timesteps=timesteps, variables=variables,
+                           rel_tolerance=rel_tolerance,
+                           abs_tolerance=abs_tolerance)
     except RuntimeError, msg:
          print msg
