
def plot_compare_csv(location, file_sim, file_exp, y_label,
                     save_as=None,
                     x_label='Time (s)',
                     legend_sim='ANUGA simulation',
                     legend_exp='Measured flume result',
                     is_interactive=False):
    """ 
    """
    from pylab import ion, plot, xlabel, ylabel, close, legend, \
         savefig
    from anuga.shallow_water.data_manager import csv2dict



    # Load in the csv files and convert info from strings to floats
    simulation, _ = csv2dict(file_sim)
    experiment, _ = csv2dict(file_exp)
    
    time_sim = [float(x) for x in simulation['time']]
    quantity_sim = [float(x) for x in simulation[location]]
    #print "quantity_sim", quantity_sim
    time_exp = [float(x) for x in experiment['time']]
    quantity_exp = [float(x) for x in experiment[location]]

    if is_interactive:
        ion()
    
    plot(time_sim, quantity_sim, time_exp, quantity_exp)

    # Add axis stuff and legend
    xlabel(x_label)
    ylabel(y_label)
    legend((legend_sim, legend_exp))
    
    if is_interactive:
        # Wait for enter pressed
        raw_input()

    if save_as is not None:
        savefig(save_as)
    
    #Need to close this plot
    close()
    


#-------------------------------------------------------------
if __name__ == "__main__":
    """ Plot the stage graph for the ANUGA validation papar
    """

    import project
    import shutil
    from os import sep, path

    depth_file = "uq-flume-not-sloped-depth.eps"
    velocity_file = "uq-flume-not-sloped-velocity.eps"
    # create Depth plot
    plot_compare_csv(location='0.4:0.2',
                     file_sim=project.depth_filename,
                     file_exp=project.experiment_depth_filename,
                     y_label='Water height (m)',
                     save_as=depth_file)

    # create Velocity plot
    plot_compare_csv(location='0.45:0.2',
                     file_sim=project.velocity_x_filename,
                     file_exp=project.experiment_vel_filename,
                     y_label='Velocity (m/s)',
                     save_as=velocity_file)
     
 
    # Move the files to the dir where the paper is being put together
    paper_dir = path.join('..','..','anuga_work','publications','anuga_2007')
    dest = path.join(paper_dir, depth_file)
    shutil.copyfile(depth_file,dest)
    dest = path.join(paper_dir, velocity_file)
    shutil.copyfile(velocity_file,dest)
