allsettings = add_cruise_info;

% met_156_1_settings.m
% settings for CTD calibration
allsettings.release = 2;
allsettings.quality_control_indicator = '5';
allsettings.quality_index = '0';

allsettings.uncertainty.t = 0.002;
allsettings.uncertainty.s = 0.003;
allsettings.uncertainty.p = 2;
allsettings.uncertainty.o = 1.0;

allsettings.loopedit = 0.20;
allsettings.use_dens1_loopedit = 1;
allsettings.use_dens2_loopedit = 1;

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.sbepre_filename = 'msm_089_1_';
allsettings.crsid_long = 'Maria S. Merian 89/1';
allsettings.crsid = 'msm_089_1';
allsettings.cruise_leg = '1';
allsettings.aligndepthrange = [550,1100];
allsettings.alignsigns = [1,-1];		% for C and for O
allsettings.sbepre_addname = '';
allsettings.print_format = 'jpg';

allsettings.autosal_deviation_range = [-0.05,0.05];


allsettings.bsh_ref = '';    %%% ????
allsettings.author = '';
allsettings.contact = '';

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

allsettings.yoyo=[];
allsettings.do_not_write_down_data_write_up_in_down_file_instead = [];
allsettings.do_not_write_up_file = [];
allsettings.lonlat = [];
allsettings.lonlat = [-40,20,-13,18];
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,allsettings.sbepre_addname);
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.33;               
  pri_settings(pri(n)).o_meth = 'f'; 
  pri_settings(pri(n)).o_exps = [2,1,0,1,0,0,0];   
  pri_settings(pri(n)).c_std = 0.33;               
  pri_settings(pri(n)).c_meth = 'f'; 
  pri_settings(pri(n)).c_exps = [2,1,1,0,0,0];   
  pri_settings(pri(n)).corr_hyst = 'off';   
end
% uncomment this to do salinity calibration for the whole cruise
%sensor.sec_setup = ones(1,999);
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.33;               
  sec_settings(sec(n)).o_meth = 'f'; 
  sec_settings(sec(n)).o_exps = [2,1,0,1,0,0,0];   
  sec_settings(sec(n)).c_std = 0.33;               
  sec_settings(sec(n)).c_meth = 'f'; 
  sec_settings(sec(n)).c_exps = [2,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 = 0;               
  ctd_settings(ctd(n)).chl_offset = 0;               
end
% $$$ 
% $$$ %set_cal(1).chl_down_pri_str = 'a';
% $$$ set_cal(1).c_up_pri_str = '-0.008044+5.4652e-07*p-0.00022251*t+0.002428*c';
% $$$ set_cal(1).c_down_pri_str = '-0.019029-3.3721e-07*p-0.00071771*t+0.0067227*c';
% $$$ set_cal(1).o_up_pri_str = '2.7838-7.6517e-06*p-0.13764*t+0.066036*o';
% $$$ set_cal(1).o_down_pri_str = '3.8649-0.00079005*p-0.21236*t+0.068315*o';
%set_cal(1).c_up_sec_str = '0.010387+1.3172e-07*p+0.00035683*t-0.0036848*c';
%set_cal(1).c_down_sec_str = '0.016185+2.7698e-07*p+0.00056018*t-0.0057773*c';
%set_cal(2).c_up_sec_str = '0.010387+1.3172e-07*p+0.00035683*t-0.0036848*c';
%set_cal(2).c_down_sec_str = '0.016185+2.7698e-07*p+0.00056018*t-0.0057773*c';
% $$$ set_cal(1).o_up_sec_str = '1.4885+0.0004909*p-0.051796*t+0.048072*o';
% $$$ set_cal(1).o_down_sec_str = '4.1019-0.00058408*p-0.48891*t+0.061793*o';

%set_delays.o_pri(1) = 3.2;
%set_delays.o_sec(1) = 3.2;
%% set_delays.o_pri(3) = 3.68;
% set_delays.o_pri(4) = 3.68;


% insert 'median' from final plot in step 1
% this will remove deck pressure
%
% <---------- Hier anpassen  p_offset
ctd_settings(1).p_offset = 0.49;
ctd_settings(1).chl_offset = 0;

% <---------- Hier anpassen  [1:bis Dein letztes Profil]
use_settings(1).apply2prof = [1:86];
use_settings(1).use_sensor = [1,1,1]; % ????
% use_settings(2).apply2prof = [2:4];
% use_settings(2).use_sensor = [1,1,1]; % ????



% ctd_settings(2).p_offset = 0.99;
% ctd_settings(2).chl_offset = 0.035;
% 
% use_settings(2).apply2prof = [1:13];
% use_settings(2).apply2prof = [1:13];
% use_settings(2).use_sensor = [1,1,1];



% 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
% okg  oxygen in umol/kg
% chl  chlorophyl in ug/l
% c    conductivity
% sig  in situ density
% ss   sound speed
% sth  sigma theta
% tim  time in Matlab datenum units
allsettings.write_prof_vars = {'tim','lon','lat','p','z','t','s','o','ss','sth','chl2_raw','turb_raw','nox','cdom_raw','par','spar'};
% allsettings.write_prof_vars = {'tim','lon','lat','p','z','t','s','o','ss','sth','chl_raw','turb_raw','nox'};
allsettings.write_time_vars = {'tim','p','t','s','c','o','lat','lon'};

% 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 = 2; 
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

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

% mark bad scans
allsettings.bad_c_1_scans = [[32,61450,77000]];
allsettings.bad_c_2_scans = [[32,44042,108980];[66,7090,7105];[67,16590,16620]];
allsettings.bad_c_1_scans = [[4,29440,30900];[5,15160,15210];[8,13450,13540];[32,61450,77000]];
allsettings.bad_c_2_scans = [[4,29440,30900];[32,40400,108900]];
%allsettings.bad_t_1_scans = [];
%allsettings.bad_t_2_scans = [[47,12570,12700];[47,12740,12900];[47,13060,13060];[47,14005,14010];[47,15048,15048]];
%allsettings.bad_c_1_scans = [[4,68000,122000]];
allsettings.bad_o_1_scans = [[4,108100,108500];[4,29400,31200]];
allsettings.bad_o_2_scans = [[4,29400,31200];...
  [86,48100,48600];[86,50900,51200];[86,55600,55800];[86,68250,68450];...
  [86,68550,68750];[86,69400,69500];[48,15550,15700];[45,103500,105000];[43,82600,82900];...
  [43,85500,85650];[43,88400,88800];[43,93600,94700];[43,95900,96200];[43,98800,99000];...
  [43,101400,101600];[43,104700,104850];[43,111500,111500];[43,135900,136200];...
  [43,142600,142800];[43,148550,148650];[11,20920,21000];[11,27410,27470];[42,61500,64000];...
  [42,79800,80000];[42,80600,80800];[42,86700,87100];[42,102050,102250];[43,111200,111400]];

allsettings.area = '';

%allsettings.tsal.s1_time_chunks = [-1000,1000];
%allsettings.tsal.s2_time_chunks = [-1000,1000];
allsettings.tsal.s1_time_dep = [0];
allsettings.tsal.s2_time_dep = [0];
allsettings.tsal.s1_bad_times = [];
allsettings.tsal.s2_bad_times = [];
allsettings.tsal.comment = ''; 
allsettings.tsal.write_time_range = [0,1000];

