%%
clear all;close all;
%-----------------------------------------------------------------------------
% this matlab script reads ascii-format files (in column format, possibly
% some header lines with first character "#" or "%"), then plots them. 
%
% requires the function "read_skiplines.m" to be located on the current matlab-path.
%
% a.g. kidanemariam & m. uhlmann, Nov. 2015
%-----------------------------------------------------------------------------
set(0,...
   'DefaultAxesFontSize',   12,...
   'DefaultAxesFontName',  'Helvetica',...
   'DefaultTextFontSize',   12,...
   'DefaultAxesVisible',   'on',...
   'DefaultLineLineWidth',  2,...
   'DefaultLineMarkerSize', 4,...
   'DefaultAxesBox',        'on',...
   'DefaultAxesTickDir',    'out'...
   );
%
%basedir = './'; %location of ascii data files
basedir = '../profiles/'; %location of ascii data files
%
iprint  = 0;  % save plots to file
odir    = './'; %directory for output of graphs
%
% read data:
%
ff10 = [basedir 'rough_bottom_channel_flow_F10_global_fluid_statistics.dat'];
pf50 = [basedir 'rough_bottom_channel_flow_F50_global_fluid_statistics.dat'];
%
F10 = read_skiplines(ff10,6);  
F50 = read_skiplines(pf50,6);
%
% column format in the files is as follows:
% 1:y 2:<u_f> 3:<u'_f*u'_f> 4:<v'_f*v'_f> 5:<w'_f*w'_f> 6:<u'_f*v'_f>
%
%
% NOTE: all dimensional quantities are made dimensionless with the 
% following reference scales:
% length:   effective flow depth "h"
% velocity: friction velocity "utau"
%-------------------------------------------------------------------------
Ubh_F10=15.2;
Ubh_F50=12.2;
retau_F10=188;
retau_F50=235;
%-------------------------------------------------------------------------
fig(1) = figure; ax(1) = axes; hold on
%
plot(F10(:,2)/Ubh_F10,F10(:,1),'k')
plot(F50(:,2)/Ubh_F50,F50(:,1),'k--')
%
set(ax(1),'xlim',[-.01 1.25],'ylim',[-0.2 1])
set(ax(1),'xtick',0:5:20,'ytick',-0.2:0.2:1)
%
title('figure 2(a) of Chan-Braun et al. (JFM 2011)');
xlabel('mean velocity');ylabel('(y-y_0)/h');
legend('F10','F50');
%
%-------------------------------------------------------------------------
fig(2) = figure; ax(2) = axes; hold on
%
plot(F10(:,1)*retau_F10,F10(:,2),'k')
plot(F50(:,1)*retau_F50,F50(:,2),'k--')
%
set(ax(2),'xlim',[5e-1 3e2],'ylim',[0 20])
%set(ax(1),'xtick',0:5:20,'ytick',-0.2:0.2:1)
set(ax(2),'XScale','log');
%
title('figure 2(b) of Chan-Braun et al. (JFM 2011)');
ylabel('<u>^+');xlabel('(y-y_0)/\delta_\nu');
legend('F10','F50');
%
%-------------------------------------------------
fig(3) = figure; ax(3) = axes; hold on
%
plot(sqrt(F10(:,3)),F10(:,1),'k')
plot(sqrt(F10(:,4)),F10(:,1),'r')
plot(sqrt(F10(:,5)),F10(:,1),'b')
%
plot(sqrt(F50(:,3)),F50(:,1),'k--')
plot(sqrt(F50(:,4)),F50(:,1),'r--')
plot(sqrt(F50(:,5)),F50(:,1),'b--')
%
set(ax(3),'xlim',[0 3],'ylim',[-0.2 1])
set(ax(3),'xtick',0:0.5:3,'ytick',-0.2:0.2:1)
%
title('figure 4(a) of Chan-Braun et al. (JFM 2011)');
xlabel('rms velocity fluctuations');ylabel('(y-y_0)/h');
legend('u_{rms} F10','v_{rms} F10','w_{rms} F10',...
       'u_{rms} F50','v_{rms} F50','w_{rms} F50');
%
%-------------------------------------------------
fig(4) = figure; ax(4) = axes; hold on
%
plot(F10(:,6),F10(:,1),'k')
plot(F50(:,6),F50(:,1),'k--')
%
set(ax(4),'xlim',[-1 0],'ylim',[-0.2 1])
set(ax(4),'xtick',-1:0.2:0,'ytick',-0.2:0.2:1)
%
title('figure 4(b) of Chan-Braun et al. (JFM 2011)');
xlabel('Reynolds shear stress');ylabel('(y-y_0)/h');
legend('<uv> F10','<uv> F50');
%
%-------------------------------------------------
if iprint==1
  figure(fig(1));
  nam = [odir 'mean_streamwise_velocity.eps']
  print(nam,'-depsc'); 
  %
  figure(fig(2));
  nam = [odir 'mean_streamwise_velocity_semilog.eps']
  print(nam,'-depsc'); 
  %
  figure(fig(3));
  nam = [odir 'rms_velocity_fluctuations.eps']
  print(nam,'-depsc'); 
  %
  figure(fig(4));
  nam = [odir 'Reynolds_shear_stress.eps']
  print(nam,'-depsc'); 
end
%-------------------------------------------------


