%srf_dck_prs_report.m - Read in markscan file and print table and figures

%filepath='/Users/jhooper/Documents/Work_data/WBTS/ab1202/Documents/surface_prs.txt'
filepath=[pwd,'/Documents/markscans.xlsx']


%read in surface pressure variables
%[stt mark dckpsrt dckpend spstrt spend notes] = ...
%    textscan(filepath,'%f%f%f%f%f%f%s','headerlines',1);
[num]=xlsread(filepath)
stt=num(:,1)
mark=num(:,2)
dckpsrt=num(:,3)
dckpend=num(:,4)
spstrt=num(:,5)
spend=num(:,6)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                CREATES A THE surface/on deck pressure TABLE             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    fid=fopen(['tables/sfc_dck_prs_diff.txt'],'w');
    fprintf(fid,'%s','\begin{longtable}{cccccc}');
    fprintf(fid,'\n');    
    fprintf(fid,'%s','\caption{Near surface Pressure values and scan number used to remove surface soak and on-deck values.\label{long} }');
    fprintf(fid,'\n');
    fprintf(fid,'%s','\hline');
    fprintf(fid,'\n');
    bp=[sprintf('%s\t','Station &','Markscan &','Deck Prs Start &','Deck Prs End &','Sfc Prs Start &','Sfc Prs End \\')];
    fprintf(fid,bp);
    fprintf(fid,'\n');    
    fprintf(fid,'%s','\hline');
    fprintf(fid,'\n');   
    for ii=1:length(stt)
    fprintf(fid,'%2i\t%s%i\t%s%1.4f\t%s%1.4f\t%s%1.4f\t%s%1.4f%s\n',stt(ii), '&',...
        mark(ii),'&',dckpsrt(ii), '&', dckpend(ii), '&', spstrt(ii), '&', spend(ii),'\\');
    end;
    fprintf(fid,'\n');    
    fprintf(fid,'%s','\hline');
    fprintf(fid,'\n');          
    fprintf(fid,'%s','\end{longtable}');
    fclose(fid);   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                CREATES A THE surface/on deck pressure FIGURES           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%on deck start
disp('on deck start')
median_dckpsrt=nanmedian(dckpsrt)
stddev_dckpsrt=nanstd(dckpsrt)

%on deck end
disp('on deck end')
median_dckpend=nanmedian(dckpend)
stddev_dckpend=nanstd(dckpend)

%surface start
disp('surface start')
median_spstrt=nanmedian(spstrt)
stddev_spstrt=nanstd(spstrt)

%surface end
disp('surface end')
median_spend=nanmedian(spend)
stddev_spend=nanstd(spend)


%%%%%%%%%%%%%%%%%%%%%%%% Plot deck pressure %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


f1
clf
font(16)
subplot(2,1,1)
plot(stt,dckpsrt,'b')
hold on;
plot(stt,dckpend,'r')
hold on;
plot(stt,(dckpsrt-dckpend),'g')
title('On Deck Pressure','fonts',16)
ylabel('Pressure (db)','fonts',16)
%xlabel('Station','fonts',16)
legend('Start','End','Difference')


%%%%%%%%%%%%%%%%%%%%%%%% Plot surface pressure %%%%%%%%%%%%%%%%%%%%%%%%%%%%

subplot(2,1,2)
plot(stt,spstrt,'b')
hold on;
plot(stt,spend,'r')
hold on;
plot(stt,(spstrt-spend),'g')
title('Surface Pressure','fonts',16)
ylabel('Pressure (db)','fonts',16)
xlabel('Station Number','fonts',16)
legend('Start','End','Difference')
print -depsc figures/srf_dck_prs_diff
%%%%%%%%%%%%%%%%%%%%%%%%%%%% get end btl prs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear num stt mark dckpsrt dckpend spstrt spend median_dckpsrt stddev_dckpsrt
clear median_dckpend stddev_dckpend median_spstrt stddev_spstrt median_spend
clear stddev_spend fid ans filepath ii bp