%DOITALL - all steps required to do a complete ctd calibration process
% 
%USAGE - doitall	
%
%EXPLANATION -	script to run all the ctdcnv functions
%
%SEE ALSO -	
%

%PROGRAM - 	MATLAB code by c.m.duncombe rae
%
%CREATED -	2008/02/05
% 
%VERSION - 
%	$Revision: 1.10 $
%	$Date: 2008/03/13 00:19:22 $
%	$Id: doitall.m,v 1.10 2008/03/13 00:19:22 duncombe Exp duncombe $
%
%CHANGE_LOG -
%
%DISCLAIMER -	No responsibility can be accepted for failure or 
%		incorrect operation of this code. No guarantee, express 
%		or implied, is given. 
%

% these are for a new cruise, and now half of them are run automatically
% anyway.
% 
% make_cruise_dir
% register_cruise
% ctdcalpath
% getpref

cruiseid=getcruiseid;

R=input('Do you want to create postscript files of the figures? Y/[N] ','s');
if strncmpi(R,'Y',1), print_figures=1; else print_figures=0; end;

R=input('Load the raw data? Y/[N] ','s');
if strncmpi(R,'Y',1), 
	bl=load_bl;
	btl=load_btl;
	[cnv,cnv_load]=load_cnv;
 	[raw,raw_load]=load_raw(cruiseid);
end;

R=input('fill_surface, despike and deloop? Y/[N] ','s');
if strncmpi(R,'Y',1), 
	cnv_fill=fill_surface(cruiseid,[],[]);
	cnv_ds1=despike1(cruiseid,[],[]);
	cnv_ds2=despike2(cruiseid,[],[]);
	cnv_dlp=deloop(cruiseid,[],[]);
end;

R=input('Sensors comparison? Y/[N] ','s');
if strncmpi(R,'Y',1), 
disp('Running compare_ctd_sensors');
fh=compare_ctd_sensors(cruiseid,[],[]);
	if print_figures,
		disp('Running print_compare_ctd_sensors');
		print_compare_ctd_sensors(cruiseid,fh); end;
end;

R=input('TS plot? Y/[N] ','s');
if strncmpi(R,'Y',1), 
disp('Running compare_tsplot');
fh=compare_tsplot(cruiseid,[],[]);
	if print_figures,
		disp('Running print_compare_tsplot');
		print_compare_tsplot(cruiseid,fh);
	end;
end;


R=input('Process salinities? Y/[N] ','s');
if strncmpi(R,'Y',1), 
salts=load_salts(cruiseid);
	cond_match=make_cond_sumfile(cruiseid);
	[sfh,fh]=compare_cond(cruiseid,[],[]);
	if print_figures,
		print_compare_cond('',sfh);
	end;
[cond_coeff,fh]=cond_cal(cruiseid,[],[]);
	if print_figures,
		print_cond_cal('',fh);
	end;
end;

R=input('Process oxygens? Y/[N] ','s');
if strncmpi(R,'Y',1), 
oxy=load_oxy(cruiseid);
	oxy_match=make_oxy_sumfile(cruiseid);
	[sfh,fh]=compare_oxy(cruiseid,[],[]);
	if print_figures,
		print_compare_oxy('',sfh);
	end;
[oxy_coeff,fh]=oxy_cal(cruiseid,[],[]);
	if print_figures,
		print_oxy_cal(cruiseid,fh);
	end;
end;

R=input('Apply calibrations? Y/[N] ','s');
if strncmpi(R,'Y',1), 
[cnv_cal,fh]=FS_apply_calibration(cruiseid, cond_coeff, oxy_coeff);
	if print_figures, print_cal_figures(cruiseid, fh); end;
end;

R=input('TS plot? Y/[N] ','s');
if strncmpi(R,'Y',1), 
fh=compare_tsplot([],[],[]);
	if print_figures,
		print_compare_tsplot(cruiseid,fh);
	end;
end;

% save_final_results.m	
save_final_results(cruiseid,[],[]);

write_s87(cruiseid);


