% load info from cruise_info
allsettings = add_cruise_info;

% die hier eintragen
allsettings.sbepre_filename = 'met_116_1_';
allsettings.lonlat = [-60 10 0 25];   %[lonmin,lonmax,latmin,latmax] for cruise map


% met_097_1_settings.m
% settings for CTD calibration
allsettings.release = 0;
allsettings.quality_control_indicator = '0';
allsettings.quality_index = '0';
allsettings.uncertainty.t = 0.002;
allsettings.uncertainty.s = 0.003;
allsettings.uncertainty.p = 2;
allsettings.uncertainty.o = 1.5;

allsettings.loopedit = 0.01;
allsettings.use_system_upload_time = 0;

allsettings.start_scan = [];
% override start_scan of profiles (determined in step 1)
% enter pairs [profile_number,first_good_scan]

allsettings.area = ''; 
allsettings.aligndepthrange = [200,600];
allsettings.alignsigns = [1,-1];		% for C and for O
allsettings.addname = 's1s2s3s4s5';
allsettings.print_format = 'jpg';

allsettings.author = 'Sunke Schmidtko';
allsettings.contact = 'sschmidtko@geomar.de';

allsettings.comment = '';
allsettings.references = '';

allsettings.do_not_write_down_data_write_up_in_down_file_instead = [];
allsettings.down_is_up = [];
allsettings.use_davis_nav = [];  % This should be empty and
                                      % is only used for station 54 and 55
                                      % of MSM182, where NMEA was
                                      % not recorded in .cnv file

% load sensor SNs and create settings
if ~exist(['mat/',allsettings.crsid,'_sensors.mat'])
  sensor = get_sensors(allsettings.crsid);
  load(['mat/',allsettings.crsid,'_sensors.mat'])
else
  load(['mat/',allsettings.crsid,'_sensors.mat'])
end

pri = unique(sensor.pri_setup);
pri = pri(find(~isnan(pri)));
sec = unique(sensor.sec_setup);
sec = sec(find(~isnan(sec)));
ctd = unique(sensor.ctd_setup);
ctd = ctd(find(~isnan(ctd)));

for n=1:length(pri)
  pri_settings(pri(n)).prof = sensor.prof(find(pri(n)==sensor.pri_setup));
  pri_settings(pri(n)).apply2prof = sensor.prof(find(pri(n)==sensor.pri_setup));
  pri_settings(pri(n)).o_std = 0.3333;               
  pri_settings(pri(n)).o_meth = 'f'; 
  pri_settings(pri(n)).o_exps = [1,1,0,1,0,0];   
  pri_settings(pri(n)).c_std = 0.3;               
  pri_settings(pri(n)).c_meth = 'f'; 
  pri_settings(pri(n)).c_exps = [1,1,1,0,0,0];   
  pri_settings(pri(n)).corr_hyst = 'off';   
end
for n=1:length(sec)
  sec_settings(sec(n)).prof = sensor.prof(find(sec(n)==sensor.sec_setup));
  sec_settings(sec(n)).apply2prof = sensor.prof(find(sec(n)==sensor.sec_setup));
  sec_settings(sec(n)).o_std = 0.3333;               
  sec_settings(sec(n)).o_meth = 'f'; 
  sec_settings(sec(n)).o_exps = [1,1,0,1,0,0];   
  sec_settings(sec(n)).c_std = 0.3;               
  sec_settings(sec(n)).c_meth = 'f'; 
  sec_settings(sec(n)).c_exps = [1,1,1,0,0,0];   
  sec_settings(sec(n)).corr_hyst = 'off';   
end
for n=1:length(ctd)
  ctd_settings(ctd(n)).prof = sensor.prof(find(ctd(n)==sensor.ctd_setup));
  ctd_settings(ctd(n)).apply2prof = sensor.prof(find(ctd(n)==sensor.ctd_setup));
  ctd_settings(ctd(n)).p_offset = -1.17;               
  ctd_settings(ctd(n)).chl_offset = 0;               
end


% insert 'median' from final plot in step 1
% this will remove deck pressure

%ctd_settings(2).p_offset = -0.46;
%ctd_settings(2).chl_offset = NaN;
%ctd_settings(2).turb_offset = 0.15;
%ctd_settings(2).chl2_offset = -0.044;
%ctd_settings(2).chl3_offset = 0;
%ctd_settings(2).cdom_offset = 0;
%ctd_settings(2).apply2prof = 4;
%use_settings(2).apply2prof = 4;
%use_settings(2).use_sensor = [2,2,2];

% ctd_settings(1).p_offset = -1.14;
%ctd_settings(1).chl_offset = NaN;
%ctd_settings(1).turb_offset = 0.15;
%ctd_settings(1).chl2_offset = -0.044;
%ctd_settings(1).chl3_offset = 0;
%ctd_settings(1).cdom_offset = 0;
%ctd_settings(1).apply2prof = [3:23];

sec_settings(3).prof = 3:4;
sec_settings(3).apply2prof = 3:4;

sec_settings(2).prof = 5:82;
sec_settings(2).apply2prof = 5:82;

use_settings(1).apply2prof = [1:82];
use_settings(1).use_sensor = [1,1,1];



allsettings.stick_voltage_number_into_haardtc = 0;

% what to set for sensor calibration
%  _f = 's' for outlier selection by std criterion (in _std)
%  _f = 'f' for outlier selection by fraction of data criterion (in _std)
%  _exps =   degree of polynom in [press, temp, cond, oxyf, time,chl]
 
% which variables to write into calibrated files
% choose from
% p          pressure
% z          depth
% t          in situ temperature
% s          salinity
% o          oxygen in umol/kg
% chl_raw    Dr. Haardt chlorophyl in raw uncorrected ug/l
% chl2_raw   Wetlabs chlorophyl in raw uncorrected ug/l
% turb_raw   Wetlabs turbidity in raw uncorrected NTU
% c          conductivity
% sig        in situ density
% ss         sound speed
% sth        sigma theta
% tim        time in Matlab datenum units
allsettings.write_prof_vars = {'tim','p','z','t','s','o','ss','sth','chl_raw','voltage6'};
allsettings.write_time_vars = {'tim','p','t','s','c','o','chl_raw'};

% btl_down 1: pressure only;(fastest) 2: pressure and closest temperature
%          3: best vertical shift of up temperature profile (slow but good)
allsettings.btl_down = 3; 
allsettings.btl_down_tshift = [1,50];   % delta p for shift, prange for shift
allsettings.btl_down_sensor = 1;  % use primary or secondary to pick
                                  % down bottle equivalents

% allsettings.bad_profiles=[1;2];                    
allsettings.bad_profiles=[];                    
                   
%
% define which calibrated rodbfiles are to be written
% give a vector of the types
%
% 1: regular 1 dbar file
% 2: upcast 1 dbar file
% 3: 1 second binned full cast file
% 4: full data rate full cast file
allsettings.which_file_types = [1,2,3];

allsettings.yoyo = [];


%% Comment NM:
%Startscan for Profile 118 was set manually to 15800, as program determined
%it wrong
%%


% mark bad scans


allsettings.bad_c_1_scans = [];
allsettings.bad_c_2_scans = [];
allsettings.bad_t_1_scans = [];
allsettings.bad_t_2_scans = [];
allsettings.bad_o_1_scans = [];
allsettings.bad_o_2_scans = [];
