close all
clear all

% -------------------------------------------------------------------------
% Run basic processing on extracted WAP data for Transect2 ACS files
% -------------------------------------------------------------------------
files = dir('Transect2\extracted\eqbox_06_???_21_ACS.*')
files = strcat('Transect2\extracted\', {files.name}')
for kf = 1:length(files)
    Make_ACS_Binned_from_WAP(files{kf}, ['Transect2\ACS_Binned\'], [], 'noplot','save')
end
copyfile('Transect2\ACS_Binned\', 'Transect2\ACS_Binned.BAK\')

% Plot Transect2 ACS data to determine ranges where additional QC is needed
close all
files_binned = dir('Transect2\ACS_Binned\eqbox_06_???_ACS_*.*');
files_binned = strcat('Transect2\ACS_Binned\', {files_binned.name}')
Plot_ACS_Binned(files_binned)

% Basic QC by removing minute bins with stdev of a555,c555 greater than
% threshold
files_binned = dir('Transect2\ACS_Binned\eqbox_06_???_ACS_*.*');
files_binned = strcat('Transect2\ACS_Binned\', {files_binned.name}')
QC_ACS_by_std(files_binned, 0.01, 0.01)

% Plot Transect2 ACS data to determine ranges where additional QC is needed
close all
files_binned = dir('Transect2\ACS_Binned\eqbox_06_???_ACS_*.*');
files_binned = strcat('Transect2\ACS_Binned\', {files_binned.name}')
Plot_ACS_Binned(files_binned)

% QC on specific sections of data
% 27 Aug (239)
Make_ACS_Binned_from_WAP('Transect2\extracted\eqbox_06_239_21_ACS.006', 'Transect2\ACS_Binned\', ...
        [datenum(2006,0,239,06,10,00),datenum(2006,0,239,09,08,00)], 'noplot','save')
Make_ACS_Binned_from_WAP('Transect2\extracted\eqbox_06_239_21_ACS.007', 'Transect2\ACS_Binned\', ...
        [datenum(2006,0,239,06,10,00),datenum(2006,0,239,09,08,00)], 'noplot','save')
Make_ACS_Binned_from_WAP('Transect2\extracted\eqbox_06_239_21_ACS.008', 'Transect2\ACS_Binned\', ...
        [datenum(2006,0,239,06,10,00),datenum(2006,0,239,09,08,00)], 'noplot','save')
Make_ACS_Binned_from_WAP('Transect2\extracted\eqbox_06_239_21_ACS.009', 'Transect2\ACS_Binned\', ...
        [datenum(2006,0,239,06,10,00),datenum(2006,0,239,09,08,00)], 'noplot','save')
% 02 Sep (245) - 03 Sep (246)  Removed acs data starting 245_ACS_014
% through 246_ACS_009, appeared heavily contaminated by bubbles
delete Transect2\ACS_Binned\eqbox_06_245_ACS_014.mat
delete Transect2\ACS_Binned\eqbox_06_245_ACS_015.mat
delete Transect2\ACS_Binned\eqbox_06_245_ACS_016.mat
delete Transect2\ACS_Binned\eqbox_06_245_ACS_017.mat
delete Transect2\ACS_Binned\eqbox_06_245_ACS_018.mat
delete Transect2\ACS_Binned\eqbox_06_245_ACS_019.mat
delete Transect2\ACS_Binned\eqbox_06_245_ACS_020.mat
delete Transect2\ACS_Binned\eqbox_06_245_ACS_021.mat
delete Transect2\ACS_Binned\eqbox_06_245_ACS_022.mat
delete Transect2\ACS_Binned\eqbox_06_245_ACS_023.mat
delete Transect2\ACS_Binned\eqbox_06_246_ACS_000.mat
delete Transect2\ACS_Binned\eqbox_06_246_ACS_001.mat
delete Transect2\ACS_Binned\eqbox_06_246_ACS_002.mat
delete Transect2\ACS_Binned\eqbox_06_246_ACS_003.mat
delete Transect2\ACS_Binned\eqbox_06_246_ACS_004.mat
delete Transect2\ACS_Binned\eqbox_06_246_ACS_005.mat
delete Transect2\ACS_Binned\eqbox_06_246_ACS_006.mat
delete Transect2\ACS_Binned\eqbox_06_246_ACS_007.mat
delete Transect2\ACS_Binned\eqbox_06_246_ACS_008.mat
delete Transect2\ACS_Binned\eqbox_06_246_ACS_009.mat
delete Transect2\ACS_Binned\eqbox_06_246_ACS_017.mat


% Load binned data for transect
[acs_a, acs_c] = Load_ACS_Binned(files_binned)
   
% Processing to subtract filtered measurement and do residual temperature
% and scattering correction
[acs_ap, acs_cp, acs_bp] = Calc_ACS_apcp(acs_a, acs_c, 0,10)

ACS_apcp_Transect2_version = datestr(now,30)
% save(['Transect2\ACS_apcp_Transect2_' ACS_apcp_Transect2_version '.mat'], 'ACS_apcp_Transect2_version', 'files_binned', ...
                                    'acs_ap', 'acs_cp', 'acs_bp') 
                                
    

figure, hold on
plot(acs_ap.time, acs_ap.mean(:,10), 'b.-')
datetick
xlabel('GMT Date (2006)')
ylabel('Particulate Absorption, ap(440) [1/m]')

figure, hold on
plot(acs_cp.time, acs_cp.mean(:,34), 'r.-')
datetick
xlabel('GMT Date (2006)')
ylabel('Particulate Attenuation, cp(555) [1/m]')

figure, hold on
plot(acs_ap.wavel, acs_ap.mean, 'b-')
xlabel('Wavelength, \lambda [nm]')
ylabel('Particulate Absorption, ap(\lambda) [1/m]')

figure, hold on
plot(acs_cp.wavel, acs_cp.mean, 'r-')    
xlabel('Wavelength, \lambda [nm]')
ylabel('Particulate Attenuation, cp(\lambda) [1/m]')



