%  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
%

% >>>>>>>>>>>>>>>>>>>> user must edit the following lines >>>>>>>>>>>>>>>>>>>>
% DOC[PARAMETERS]{

tem_file   = '[[BLK]:LST_CTD:ASC:00:OUT]';
sal_file   = '[[BLK]:LST_CTD:ASC:01:OUT]';
trt_file   = '[[BLK]:LST_TEMP:ASC:00:OUT]';
plot_title = '[PROJECT]-[AREA]-ADCP-[DBNAME]-[BLK]: Transducer TS from CTD and ADCP';
year_base  = [YEAR_BASE];

% }DOC[PARAMETERS]
% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< end editing <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
orient tall;
clf;

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

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

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

% Choose the time axis:
if tem,
	t = t_t;
elseif sal,
	t = t_s;
elseif 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 tem,
	plot(t, tem, '-')
end
if 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 sal,
	plot(t, sal, '-')
end
xlabel(xaxis_label)
ylabel('ppm ([-]: CTD)')
grid

%title(plot_title)

print plotctd.ps

