close all
clear all

addpath(genpath('/Users/Mau/Documents/MATLABhelp_new/'));

% path_data='/Users/Mau/Documents/MBARIprojects/MR/TurbulenceData/ParagonTests/20211008/';
% cd(path_data)
% fname='DAT_014';
% pid=[4,18,28,35]; % 4; 18; 28; 35 % for file /TurbulenceData/ParagonTests/20211008/'; 
                  % NOTE: profile numbering/split up of data not working
                  % well but have identified those as the profiles with
                  % upward profiling data

% path_data='/Users/Mau/Documents/MBARIprojects/MR/TurbulenceData/ParagonTests/20211015/';
% cd(path_data)
% fname='DAT_017';
% pid=[4,9,14]; % total of 9 "profiles". 3,6,9 are upward profiles all the way to the top
% 
% path_data='/Users/Mau/Documents/MBARIprojects/MR/TurbulenceData/ParagonTests/20211019/';
% cd(path_data)
% fname='DAT_019';
% pid=[5,7,8,9,11,13,15,17]; % total of 9 profiles. 3,6,9 are upward profiles all the way to the top


path_data='/Users/Mau/Documents/MBARIprojects/MR/TurbulenceData/ParagonTests/2021-11-18/';
cd(path_data)
fname='DAT_032';
pid=[1]; % total of 9 profiles. 3,6,9 are upward profiles all the way to the top

% extract_setupstr(fname,'setup_new.cfg'); % setup_new.cfg is empty?
% patch_setupstr(fname,'/Users/Mau/Documents/MBARIprojects/MR/TurbulenceData/TankTests/20211004/from_Evan/setupMBARI_CPF.cfg'); % to Embed the configuration string in the file


% [P records]=show_P(fname);
% plot(record,P);


%% Load setting for post-processing
% form Evan:
load('/Users/Mau/Documents/MBARIprojects/MR/TurbulenceData/TankTests/20211004/from_Evan/ql_info.mat'); % load ql_info structure from Evan to reproduce his plots.


% ql_info from Rolf Lueck:
ql_info.HP_cut= 0.2000
LP_cut= 10
YD_0= 0
despike_A= [Inf 0.5000 0.0400]
despike_C= [10 1 0.0400]
despike_sh= [8 0.5000 0.0400]
diss_length= 20
f_AA= 98
f_limit= Inf
fft_length= 5
fit_2_isr= 1.5000e-05
fit_order= 3
goodman= 1
make_figures= 1
op_area= 'open_ocean'
overlap= 10
plot_battery= 0
plot_dissipation= 1
plot_kinematics= 1
plot_rawaccel= 0
plot_sensors= 1
plot_spectra= 1
plot_spectrograms= 0
profile_min_P= 0
profile_min_W= 0.1000
profile_min_duration= 30
profile_num= 1
MF_extra_points= 0
MF_k= 4
MF_k_mag= 1.7000
MF_len= 256
MF_st_dev= 'st_dev'
MF_threshold= []
aoa= []
constant_speed= []
constant_temp= []
gradC_method= 'high_pass'
gradT_method= 'high_pass'
hotel_file= []
speed_cutout= 0.0500
speed_tau= []
time_offset= 0
vehicle= ''

%% Quick Look of data for all profiles
                 
nP=length(pid);

D=cell(nP,1);

for p=1; %:nP

Pn=pid(p); 

q=quick_look(fname, 2 , 9, ql_info, 'profile_num', Pn);

%% save Figures

fig=figure(1);
print_setup(60,30)
print(fig,['Pressure_vs_Time_p',num2str(p),'.jpg'],'-djpeg');

%%
fig=figure(2);
print_setup(30,50)
print(fig,['Incl_and_PlatformVelocity_p',num2str(p),'.jpg'],'-djpeg');

%%
fig=figure(3);
print_setup(30,50)
print(fig,['vibrations_p',num2str(p),'.jpg'],'-djpeg');

%%
fig=figure(4);
print_setup(50,30)
print(fig,['all_channels_p',num2str(p),'.jpg'],'-djpeg');

%%
fig=figure(5);
print_setup(50,30)
print(fig,['Spectra_full_profile_p',num2str(p),'.jpg'],'-djpeg');

%%
fig=figure(6);
print_setup(30,50)
print(fig,['epsilon_p',num2str(p),'.jpg'],'-djpeg');


close all

D{p}=q;
MR=D{p};

save(['CPF003.00',num2str(p),'.MR.mat'],'MR')

end



%% Other quick ways to visualize data

show_ch(fname,'P')

show_ch(fname,'Ax')

%% Plot microstructure epsilon profiles (all profiles in 1 plot)

close all

plot(rand(100,50));
ColOrd = get(gca,'ColorOrder');
close all

cbar=cbrewer('seq','YlOrRd',21);

pp=1;

for p=1:nP
    
    subplot(1,nP,pp)

    semilogx(D{p}.e(1,:),D{p}.P,'color',ColOrd(p,:))
    axis ij
    
    grid on
    
    xlim([10^-12 10^(-6)])
    xlabel(['\epsilon_{1}'])
    
    pp=pp+1;
end

% % To omit space between subplots
% ha=get(gcf,'children');
% set(ha(1),'position',[0.1 0.8 0.1 0.5])
% set(ha(2),'position',[0.1 0.8 0.3 0.5])
% set(ha(3),'position',[0.1 0.8 0.6 0.5])
% set(ha(4),'position',[0.1 0.8 0.9 0.5])
% 

print_setup(80,30)
print(['epsilon1_p_1-4.jpg'],'-djpeg');
