%    RMSERR - function that plots the mean and rms of the difference between
%    two inputs
%
%    B. A. Moran, 07-Jan-1998

%    Copyright (C) 1998
%    Massachussetts Institute of Technology
%    Sea Grant AUV Laboratory
%    $Id: rmserr.m,v 1.1 2000/01/10 19:08:30 rob Exp $

function [m,s] = rmserr( run_names, var1, var2 )

M = size( run_names, 1 );

mm = zeros( M, 1 )*NaN;                 % preallocate mean & std
ss = zeros( M, 1 )*NaN;

review = 0;

label = run_names(1,:);

for ii = 1:M
    if ( ii > 1 )
        label = strcat( label, '|', run_names(ii,:) );
    end
    this = lower(run_names(ii,:));
    if exist( this ) == 2
        eval( this )
        eval( ['yy = data(:,' var1 ') - data(:,' var2 ');'] )

        ind = find( finite(yy) );
        mm(ii) = mean(yy(ind));
        ss(ii) = std(yy(ind));
    end
end

if nargout > 0
    m = mm;
    if nargout > 1
        s = ss;
    end
else
    subplot( 1, 2, 1 )
    barh( mm );
    title( 'Mean' )
    xlabel( [var1 ' - ' var2], 'Interpreter', 'none' )
    set( gca, 'YTickLabel', label );

    subplot( 1, 2, 2 )
    barh( ss );
    title( 'Standard Deviation' )
    xlabel( [var1 ' - ' var2], 'Interpreter', 'none' )
end

