%  1.  NAME
%
%  process - Plot results of NBR ADCP data processing
%
%  2.  USAGE
%
%  process
%
%  3.  DESCRIPTION
%
%  This script reads the log file output by process(1) and plots the
%  different logged parameters. This is usefull for checking the data
%  averging process, but also for visualizing transducer glitches.
%
%  4.  PARAMETERS
%
%  The fillowing parameters must be edited:
%
%     log_file
%        Log file name from process(1).
%
%     plot_title
%        Title for the plot.
%
%  5.  FILES
%
%  o  process.ps
%
%  6.  AUTHORS
%
%  Pierre Jaccard, Geophysical Institute, University of Bergen, 1999
%

log_file   = 'process.log';
plot_title = 'VEINS-SVINOY-9820-001';

% End editing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%------------------------------------------------------------------
% Initializations:
%------------------------------------------------------------------

lines = strvcat( '-', ':', '-.', '--');

%------------------------------------------------------------------
% Get the header with variable descriptions:
%------------------------------------------------------------------

hdr = get_hdr(log_file);
data = read_asc(log_file);

%------------------------------------------------------------------
% Average controls: graphical display
%------------------------------------------------------------------

figure;
orient tall;

% average status: centered about 1 (NORMAL_AVERAGE)
subplot(6,1,1);
x = 1;
y = 2;
bar(data(:,x), data(:,y)-1);
ylabel('AVG Status');
grid on;

% number of ensembles
subplot(6,1,2);
x = 1;
y = 3;
plot(data(:,x), data(:,y), '+', 'MarkerSize', 4);
ylabel('N Ensembles');
grid on;

% Average time:
subplot(6,1,3);
x = 1;
y = 4;
plot(data(:,x), data(:,y), '+', 'MarkerSize', 4);
ylabel('AVG Time (s)');
grid on;

% Last good beam solution
subplot(6,1,4);
x = 1;
y = 5;
plot(data(:,x), data(:,y), '+', 'MarkerSize', 4);
ylabel('Last good sol');
grid on;

% Velocity beam solutions:
subplot(6,1,5);
hold on;
x = 1;
y = 6;
for i=0:3,
	plot(data(:,x), data(:,y+i), lines(i+1,:));
end
ylabel('V beam sols');
grid on;

% BT beam solutions:
subplot(6,1,6);
hold on;
x = 1;
y = 10;
for i=0:3,
	plot(data(:,x), data(:,y+i), lines(i+1,:));
end
ylabel('BTV beam sols');
xlabel(hdr{x});
grid on;

%------------------------------------------------------------------
% Additionnal Stuff: legends, stamping, ...
%------------------------------------------------------------------

%--- Time stamp:
date_it([ '- LOG File: ' log_file ' - PS File: process.ps' ]);

old_axes = gca;
aa = axes('position', [0 0 1 1]);
axis('off');

%--- Title:
str = plot_title;
text(0.5, 0.99, str, 'units', 'normalized', ...
	'FontAngle', 'italic', 'HorizontalAlignment', 'center', ...
	'VerticalAlignment', 'top', 'FontSize', 12, 'FontWeight', 'bold');
str = 'Averaging Controls';
text(0.5, 0.96, str, 'units', 'normalized', ...
	'FontAngle', 'italic', 'HorizontalAlignment', 'center', ...
	'VerticalAlignment', 'top', 'FontSize', 10, 'FontWeight', 'bold');

% Since the plot has been centered about y=1, one has to be substracted
% to the true values defined in programme `process'.
str = 'Status:  [-2]=ABORT  [0]=NORMAL  [1]=FORCE  [2]=FORCE_LAST';
text(0.05, 0.03, str, 'units', 'normalized', ...
	'FontAngle', 'italic', 'HorizontalAlignment', 'left', ...
	'VerticalAlignment', 'bottom', 'FontSize', 8, 'Interpreter', 'none');

str = 'Sols:  [+]=BAD  [+]=2  [+]=3  [+]=4';
for i=1:4,
	j = findstr('+', str);
	str = [ str(1:j-1) lines(i,:) str(j+1:length(str)) ];
end
text(0.9, 0.03, str, 'units', 'normalized', ...
	'FontAngle', 'italic', 'HorizontalAlignment', 'right', ...
	'VerticalAlignment', 'bottom', 'FontSize', 8);

%------------------------------------------------------------------
% Print the file:
%------------------------------------------------------------------

print -dps process.ps




