Index: /inundation/pyvolution/util.py
===================================================================
--- /inundation/pyvolution/util.py	(revision 2980)
+++ /inundation/pyvolution/util.py	(revision 2981)
@@ -717,9 +717,10 @@
 
     return generate_figures(plot_quantity, file_loc, report,
-                            f, gauges, locations,
+                            f, gauges, locations, 
                             time_min, time_max, title_on, label_id, verbose)
                          
 
 def get_gauges_from_file(filename):
+    from os import sep, getcwd, access, F_OK, mkdir
     fid = open(filename)
     lines = fid.readlines()
@@ -740,5 +741,5 @@
         loc = fields[name_index]
         gaugelocation.append(loc.strip('\n'))
-    
+
     return gauges, gaugelocation
 
@@ -778,10 +779,11 @@
 
     from math import sqrt, atan, degrees
-    from Numeric import ones, allclose
+    from Numeric import ones, allclose, zeros, Float
     from os import sep, altsep, getcwd, mkdir, access, F_OK, environ
-    from pylab import ion, hold, plot, axis, figure, legend, savefig, xlabel, ylabel, title, close
+    from pylab import ion, hold, plot, axis, figure, legend, savefig, \
+         xlabel, ylabel, title, close, subplot
 
     filename = file_loc.split(sep)
-        
+
     if report == True:
         label_id1 = label_id.replace(sep,'')
@@ -794,49 +796,46 @@
         texfilename = texfile + '.tex' 
         if verbose: print '\n Latex output printed to %s \n' %texfilename
-
         fid = open(texfilename, 'w')
-        s = '\\begin{center} \n \\begin{tabular}{|l|l|l|}\hline \n \\bf{Gauge Name} & \\bf{Easting} & \\bf{Northing} \\\\ \hline \n'
-        fid.write(s)
-        gauges1 = gauges
-        for name, gauges1 in zip(locations, gauges1):
-            east = gauges1[0]
-            north = gauges1[1]
-            s = '%s & %.2f & %.2f \\\\ \hline \n' %(name.replace('_',' '), east, north)
-            fid.write(s)
-
-        s = '\\end{tabular} \n \\end{center} \n \n'
-        fid.write(s)
     else:
         texfile = ''
 
+    n = len(f.get_time())
+    m = len(locations)
+    model_time = zeros((n,m), Float) # this is actually T, but need to think about
+                                     # how to change this for tmin to tmax range
+    stages = zeros((n,m), Float)
+    elevations = zeros((n,m), Float) # same as model_time
+    momenta = zeros((n,m), Float)
+    xmom = zeros((n,m), Float)
+    ymom = zeros((n,m), Float)
+    velocity = zeros((n,m), Float)
+    bearings = zeros((n,m), Float)
+    depths = zeros((n,m), Float)
+    min_stages = []
+    max_stages = []
+    max_momentums = []
+    max_velocitys = []
     c = 0
     ##### loop over each gauge #####
     for k, g in enumerate(gauges):
         if verbose: print 'Gauge %d of %d' %(k, len(gauges))
-        model_time = []
-        stages = []
-        elevations = []
-        momenta = []
-        xmom = []
-        ymom = []
-        velocity = []
-        bearings = []
-        depths = []
-        max_depth = 0
+        min_stage = 10
+        max_stage = 0
         max_momentum = 0
-        max_velocity = 0      
-        
+        max_velocity = 0   
+        gaugeloc = locations[k]
+        thisfile = file_loc+sep+'gauges_time_series'+'_'+gaugeloc+'.csv'
+        fid_out = open(thisfile, 'w')
+        s = 'Time, Stage, Momentum, Velocity \n'
+        fid_out.write(s)
         #### generate quantities #######
+        
         for i, t in enumerate(f.get_time()): 
-
             if time_min <= t <= time_max:
-
                 w = f(t, point_id = k)[0]
                 z = f(t, point_id = k)[1]
                 uh = f(t, point_id = k)[2]
-                vh = f(t, point_id = k)[3]
-                gaugeloc = locations[k]
-                depth = w-z
-                
+                vh = f(t, point_id = k)[3]     
+                depth = w-z      
                 m = sqrt(uh*uh + vh*vh)   
                 if m < 0.001:
@@ -845,48 +844,70 @@
                     vel = m / (depth + 1.e-30) 
                 bearing = calc_bearing(uh, vh)
-
-                model_time.append(t)        
-                stages.append(w)
-                elevations.append(z)
-                xmom.append(uh)
-                ymom.append(vh)
-                momenta.append(m)
-                velocity.append(vel)
-                bearings.append(bearing)
-                depths.append(depth)
-
-                if depth > max_depth: max_depth = w-z
+                model_time[i,k] = t         
+                stages[i,k] = w 
+                elevations[i,k] = z 
+                xmom[i,k] = uh 
+                ymom[i,k] = vh 
+                momenta[i,k] = m 
+                velocity[i,k] = vel 
+                bearings[i,k] = bearing 
+                depths[i,k] = depth 
+                s = '%.2f, %.2f, %.2f, %.2f\n' %(t, w, m, vel)
+                fid_out.write(s)
+                if w > max_stage: max_stage = w
+                if w < min_stage: min_stage = w
                 if m > max_momentum: max_momentum = m
                 if vel > max_velocity: max_velocity = vel
 
+        max_stages.append(max_stage)
+        min_stages.append(min_stage)
+        max_momentums.append(max_momentum)
+        max_velocitys.append(max_velocity)        
+        
         #### finished generating quantities #####
-                
+
+    stage_axis = axis([time_min, time_max, min(min_stages), max(max_stages)*1.1])
+    vel_axis = axis([time_min, time_max, min(max_velocitys), max(max_velocitys)*1.1])
+    mom_axis = axis([time_min, time_max, min(max_momentums), max(max_momentums)*1.1])
+    
+    nn = len(plot_quantity)
+    no_cols = 2
+    for k, g in enumerate(gauges):                
         #### generate figures ###
         ion()
         hold(False)
-
-        for i in range(len(plot_quantity)):
-            which_quantity = plot_quantity[i]
-            figure(i+1, frameon = False)
+        count = 0
+        where = 0
+        word_quantity = ''
+        if report == True:
+            s = '\\begin{figure}[hbt] \n \\centering \n \\begin{tabular}{cc} \n'
+            fid.write(s)
+            
+        for which_quantity in plot_quantity:
+            count += 1
+            where += 1
+            figure(count, frameon = False)
             if which_quantity == 'depth':
-                plot(model_time, depths, '-')
+                plot(model_time[:,k], depths[:,k], '-')
                 units = 'm'
             if which_quantity == 'stage':
-                if elevations[0] < -10:
-                    plot(model_time, stages, '-')
-                else:
-                    plot(model_time, stages, '-', model_time, elevations, '-')
+                plot(model_time[:,k], stages[:,k], '-')
+                axis(stage_axis)
                 units = 'm'
             if which_quantity == 'momentum':
-                plot(model_time, momenta, '-')
+                plot(model_time[:,k], momenta[:,k], '-')
+                axis(mom_axis)
                 units = 'm^2 / sec'
             if which_quantity == 'xmomentum':
-                plot(model_time, xmom, '-')
+                plot(model_time[:,k], xmom[:,k], '-')
+                axis(mom_axis)
                 units = 'm^2 / sec'
             if which_quantity == 'ymomentum':
-                plot(model_time, ymom, '-')
+                plot(model_time[:,k], ymom[:,k], '-')
+                axis(mom_axis)
                 units = 'm^2 / sec'
             if which_quantity == 'velocity':
-                plot(model_time, velocity, '-')
+                plot(model_time[:,k], velocity[:,k], '-')
+                axis(vel_axis)
                 units = 'm / sec'
             if which_quantity == 'bearing':
@@ -903,5 +924,6 @@
 
             gaugeloc1 = gaugeloc.replace(' ','')
-            gaugeloc2 = gaugeloc1.replace('_','')
+            #gaugeloc2 = gaugeloc1.replace('_','')
+            gaugeloc2 = locations[k].replace(' ','')
             graphname = '%sgauge%s_%s' %(file_loc, gaugeloc2, which_quantity)
 
@@ -915,15 +937,25 @@
                 # storing files in production directory
                 graphname_latex = '%sgauge%s%s%s' %(latex_file_loc, gaugeloc2, which_quantity, label_id2)
+
                 # giving location in latex output file
                 graphname_report = '%sgauge%s%s%s' %('..'+altsep+'report_figures'+altsep, gaugeloc2, which_quantity, label_id2)
-                        
-                label = '%s%sgauge%s' %(label_id2, which_quantity, gaugeloc2) 
-                caption = 'Time series for %s at %s gauge location' %(which_quantity, gaugeloc.replace('_',' '))
-                s = '\\begin{figure}[hbt] \n \\centerline{\includegraphics[width=100mm, height=75mm]{%s%s}} \n' %(graphname_report, '.png')
+                
+                s = '\includegraphics[width=0.49\linewidth, height=50mm]{%s%s}' %(graphname_report, '.png')
                 fid.write(s)
-                s = '\\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
+                if where % 2 == 0:
+                    s = '\\\\ \n'
+                    where = 0
+                else:
+                    s = '& \n'
                 fid.write(s)
-                c += 1
-                if c % 10 == 0: fid.write('\\clearpage \n')
+                
+                #label = '%s%sgauge%s' %(label_id2, which_quantity, gaugeloc2) 
+                #caption = 'Time series for %s at %s gauge location' %(which_quantity, gaugeloc.replace('_',' '))
+                #s = '\\begin{figure}[hbt] \n \\centerline{\includegraphics[width=100mm, height=75mm]{%s%s}} \n' %(graphname_report, '.png')
+                #fid.write(s)
+                #s = '\\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
+                #fid.write(s)
+                #c += 1
+                #if c % 10 == 0: fid.write('\\clearpage \n')
                 savefig(graphname_latex) # save figures in production directory for report generation
             
@@ -933,12 +965,19 @@
             savefig(graphname) # save figures with sww file
 
-    
-        thisfile = file_loc+sep+'gauges_time_series'+'_'+gaugeloc+'.csv'
-        fid_out = open(thisfile, 'w')
-        s = 'Time, Depth, Momentum, Velocity \n'
-        fid_out.write(s)
-        for i_t, i_d, i_m, i_vel in zip(model_time, depths, momenta, velocity):
-            s = '%.2f, %.2f, %.2f, %.2f\n' %(i_t, i_d, i_m, i_vel)
-            fid_out.write(s)
+        if report == True:
+            for i in range(nn-1):
+                if nn > 2:
+                    word_quantity += plot_quantity[i] + ', '
+                else:
+                    word_quantity += plot_quantity[i]
+                
+            word_quantity += ' and ' + plot_quantity[nn-1]                
+            caption = 'Time series for %s at %s gauge location' %(word_quantity, locations[k]) #gaugeloc.replace('_',' '))
+            label = '%sgauge%s' %(label_id2, gaugeloc2)
+            s = '\end{tabular} \n \\caption{%s} \n \label{fig:%s} \n \end{figure} \n \n' %(caption, label)
+            fid.write(s)
+            c += 1
+            if c % 10 == 0: fid.write('\\clearpage \n')
+
             
         #### finished generating figures ###
