function preflyr1(file, psf, unit, year, cruise, note)
%%-------------------------------------------------------------------------
%% 
%% preflyr1.m -- 
%% 
%% Author          : Jaccard Pierre
%% Created On      : 1999/09/17 11:11:54
%% Last Modified By: Jaccard Pierre
%% Last Modified On: 1999/09/17 17:47:26
%% Update Count    : 24
%% Directory       : /dataOS/jaccard/codas/codas3c/gfi/matlab/matlab50/
%% Version         : 0.0
%% Status          : Unknown
%% --------------------------------------------------------------------- ++
%% DESCRIPTION: 
%% 
%%    Undocumented.
%% 
%% --------------------------------------------------------------------- ++
%% REVISIONS: 
%% --------------------------------------------------------------------- ++
%% CHANGES: 
%%-------------------------------------------------------------------------

%--- Read the data:
data = tonan(read_asc(file));

%--- Get index to good and bad data:
igood = ones(size(data(:,1)));
for i=1:size(data,2),
	igood = igood .* (~isnan(data(:,i)));
end
ibad  = find(igood == 0);
igood = find(igood ~= 0);
if isempty(igood),
	error([ 'Only bad data in file ' file ]);
end

%--- Calculate speed and direction:
data(:,4) = ones(size(data(:,1))) * NaN;
data(:,5) = ones(size(data(:,1))) * NaN;
data(igood,4) = to_speed(data(igood,2), data(igood,3));
data(igood,5) = to_dir(data(igood,2), data(igood,3));

%------------------------------------------------------------------
% Plot #1

figure
orient tall
for n=1:4,
	% Select subplot:
	subplot(4,1,n);
	% Plot good data:
	iy = n+1;
	plot(data(igood,1), data(igood,iy), '-');
	% Put label:
	switch(n)
		case 1,
			ylabel([ 'U ' unit ]);
		case 2,
			ylabel([ 'V ' unit ]);
		case 3,
			ylabel([ 'Speed ' unit ]);
		case 4,
			ylabel([ 'Direction (degree)' ]);
	end
	hold on;
	% Plot bad data:
	if ~isempty(ibad),
		ymin = min(get(gca, 'YLim'));
		ymax = max(get(gca, 'YLim'));
		dy = (ymax - ymin)/20;
		ybad = (ymin + dy) * ones(size(ibad));
		plot(data(ibad,1), ybad, 'x', 'MarkerSize', 5);
	end
	grid on;
end
xlabel([ 'Decimal Days (' int2str(year) ')' ]);

% Plot title:
old_axes = gca;
axes('position', [0 0 1 1]);
axis('off');
text(0.5, 0.95, [ cruise ' - Reference Layer Velocities' ], ...
		'HorizontalAlignment', 'center', ...
		'VerticalAlignment', 'bottom');
	
% Stamp:
date_it([ '-- ' file ' -- ' psf ' -- ' note ]);
eval([ 'print -dps -append ' psf ]); 

%------------------------------------------------------------------

function s = to_speed(u, v)

s = sqrt(u .* u + v .* v);

return;

%------------------------------------------------------------------

function d = to_dir(u, v)

d  = atan2(v, u) * 180.0/pi;
d = 90.0 - d;
d = mod(d, 360);

return;







