%  1.  NAME
%
%  plotctd - Plots ADCP transducer T and S
%
%  2.  USAGE
%
%  plotctd
%
%  3.  DESCRIPTION
%
%  This Matlab script makes a plot of ADCP transducer temperaature and
%  salinity. The input files can be generated with tr_ctd(1) and
%  lst_temp. They must have the following columns:
%
%  1. Profile time in decimal days
%
%  2. Transducer temperature or CTD temperature at transducer depth or
%     CTD Salinity at transducer depth
%
%  4.  PARAMETERS
%
%  The following parameters must be edited:
%
%     tem_file
%        Name of file with transducer CTD temperatures (output of
%        tr_ctd(1)).
%
%     sal_file
%        Name of file with transducer CTD salinities (output of
%        tr_ctd(1)).
%
%     trt_file
%        Name of file with transducer temperatures (output of
%        _ref_lst_temp(1)).  )
%
%     plot_title
%        Title for plot.
%
%     year_base
%        Base year used in input files.
%
%  5.  FILES
%
%  o  plotctd.ps
%
%  6.  AUTHORS
%
%  Pierre Jaccard, Geophysical Institute, University of Bergen, 1999
%

%--------------------------------------------------------------------------
% 
% plotctd.m -- 
% 
% Author          : Jaccard Pierre
% Created On      : 2000/06/28 16:58:21
% Last Modified By: Jaccard Pierre
% Last Modified On: 2000/06/28 17:00:58
% Directory       : /dataOS/jaccard/codas/codas3c/gfi/matlab/matlab50/
% ----------------------------------------------------------------------- +
% VERSION CONTROL: 
% 
%   $Author$
%   $Date$
%   $Id$
%   $Name$
%   $Revision$
%   $State$
%   $Log$
% 
%--------------------------------------------------------------------------

% >>>>>>>>>>>>>>>>>>>> user must edit the following lines >>>>>>>>>>>>>>>>>>>>


tem_file   = 'ssr.T';
sal_file   = 'ssr.S';
trt_file   = 'adcp.T';
plot_title = 'VEINS-SVINOY-HM0015';
year_base  = 2000;

% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< end editing <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

orient tall;
clf;

tem = [];
sal = [];
trt = [];

if length(tem_file),
  [t_t, tem] = read_asc(tem_file);
end
if length(sal_file),
	[t_s, sal] = read_asc(sal_file);
end
if length(trt_file),
	[t_a, trt] = read_asc(trt_file);
end

% NaN-out missing values (coded as BADFLOAT = 1e38):
if length(tem),
	tem = tonan(tem);
end
if length(sal),
	sal = tonan(sal);
end
if length(trt),
	trt = tonan(trt);
end

% Choose the time axis:
if length(tem),
	t = t_t;
elseif length(sal),
	t = t_s;
elseif length(trt),
	t = t_a;
else
	error('\n\nNo time axis defined for plotting\n\n');
end

time1 = to_date(year_base, t(1), 'string');
time2 = to_date(year_base, t(length(t)), 'string');
xaxis_label = sprintf('(from %s to %s)', time1, time2);

subplot(2,1,1);
hold on;
if length(tem),
	plot(t, tem, '-')
end
if length(trt),
	plot(t, trt, '--')
end
xlabel(xaxis_label)
ylabel('deg C ([-]: CTD [--]: ADCP)')
grid
title(plot_title)

xaxis_label = sprintf('%4d decimal days', year_base);

t = t_s;
subplot(2,1,2);
if length(sal),
	plot(t, sal, '-')
end
xlabel(xaxis_label)
ylabel('ppm ([-]: CTD)')
grid

%title(plot_title)

print plotctd.ps

