% CTD_COMPLETE_PROCESS - script for doing complete CTD calibration process
%
% This matlab script is intended to do the complete calibration process to
% the CTD data
%
% Created by Rigo Garcia; March, 2007
%
% 
% VERSION: 
%	$Revision: 1.5 $
%	$Date: 2008/01/19 19:34:53 $
%	$Id: ctd_complete_process.m,v 1.5 2008/01/19 19:34:53 duncombe Exp duncombe $
%
% CHANGELOG:
%

% Note: You need to run this program from the "home directory" where you
% are planning to create the cruise process directory

clear all
close all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% STEP 1: Create cruise directories and obtain the needed 1db processed
%% data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%'Matlab script to do complete CTD calibration process...'
%
%
disp('                                                       ')
disp('Matlab script to do complete CTD calibration process...')
disp('                                                       ')

%% Ask if the user want to run a new cruise or continue doing the process
%% for one particular cruise (hacerlo despues...ToDo)
%
cruiseid=input('Please Enter the Cruise ID: ','s');

disp('                                                               ')

% Setup created by:
%
created_by=input('Name of the person doing this CTD cruise process: ','s');

% Start date and time
%
str_startdatetime=datestr(now);

% Current directory where you need to run the complete process...(the data
% and result of the preocess are saved in a different directory...
%
home_dir=pwd;

if home_dir(1)=='/'
    cruise_dir=[home_dir '/' cruiseid '/'];  % Unit or Linux version
    os=1;  % Operating System
else
    cruise_dir=[home_dir '\' cruiseid '\'];  % Microsoft Windows version
    os=0;
end

%%
disp('                                                            ')
disp('STEP 1: Creating cruise directories...                      ')
disp('                                                            ')

% Make the cruise's complete directory tree
% 
% Cruise directory
[success, message, messageid]=mkdir(home_dir,cruiseid); 
% Cruise subdirectories
[success, message, messageid]=mkdir(cruise_dir, 'mfiles');
[success, message, messageid]=mkdir(cruise_dir, 'bottle');
[success, message, messageid]=mkdir(cruise_dir, 'salts');
[success, message, messageid]=mkdir(cruise_dir, 'oxy');
[success, message, messageid]=mkdir(cruise_dir, 'proc_data');
[success, message, messageid]=mkdir(cruise_dir, 'raw_data');
[success, message, messageid]=mkdir(cruise_dir, 'calibrated');
[success, message, messageid]=mkdir(cruise_dir, 'log');
[success, message, messageid]=mkdir(cruise_dir, 'tmp');
[success, message, messageid]=mkdir(cruise_dir, 'figures');
[success, message, messageid]=mkdir(cruise_dir, 'report');     % Where we will save the processing report

%
% Incluir el ctdcalpath para el crucero que esta siendo analizado...
% Este ctdcalpath debe guardarse en el subdirectorio matlab para ese
% crucero y debe correrse cada vez que el este programa sea accesado, asi
% aseguramos que tenemos los caminos definidos cuando trabajamos con un
% crucero particular... 

% 
% VER COMO PONER AUTOMATICAMENTE LOS DATOS PROCESADOS EN EL 1db
% 
% b_data='bottle';
% p_data='proc_data';
% r_data='raw_data';
% 
% % Directories needed to save some 1db processed data:
% %
% if os==1
%     b_data_dir=[cruise_dir b_data '/'];
%     p_data_dir=[cruise_dir p_data '/'];
%     r_data_dir=[cruise_dir r_data '/'];
% elseif os==0
%     b_data_dir=[cruise_dir b_data '\'];
%     p_data_dir=[cruise_dir p_data '\'];
%     r_data_dir=[cruise_dir r_data '\'];
% end
% 
% % Where the 1db data are:
% %
% ctd_data_dir=['CTD_data/' cruiseid];
% e_dir='1bd';                % Data from the lectronic sensors in the CTD
% s_dir='sample_data';        % Data from samples
% 
% onedb_dir=[home_dir '/' ctd_data_dir];
% onedb_e_dir=[home_dir '/' ctd_data_dir '/' e_dir];
% onedb_s_dir=[home_dir '/' ctd_data_dir '/' s_dir];
% 
% % Copy the file
% [SUCCESS,MESSAGE,MESSAGEID] = copyfile([onedb_e_dir '/proc_data/d*.cnv'], cruise_dir)


%
% Crear el ctdcalpath y "Registrar" el crucero...Tremenda mierda
%

% Register the cruise
%
rg_register_cruise(cruiseid,cruiseid,2,cruise_dir);


% Crear el reporte que diga estos datos iniciales...

%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% STEP 2: Load in the 1db processed data in matlab format
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp('                                                               ')
disp('STEP 2: Load in the .bl, .btl, and .cnv from 1db CTD process...')
disp('                                                               ')

load_bl('cruiseid')
load_btl('cruiseid')
load_cnv('cruiseid')


%%
%% Compare CTD sensors
%%
compare_ctd_sensors('cruiseid')

%%
%% Compare T-S diagram 
%%
compare_tsplot('cruiseid')
