%% class demo
%           amsc 460
%           11.02.15

%% intro
%   help always helps
%   short cut
%   directory set up
%               matlab code files
%               data files
%   how to run

%% initialization
clear all
close all

%% input
Npts=100;
xrange=[0 10];
Nwave=3;
Awave=[1 3 5];
kwave=[2 1 4];
pwave=[sqrt(3) 1.2*pi  2.3^7];
fnm='../mdata/wave.dat';

%% generate data
x=linspace(xrange(1),xrange(end),Npts)';
ywave=zeros(Npts,Nwave);
for n=1:Nwave;
    ywave(:,n)=Awave(n)*cos(kwave(n)*x+pwave(n));
end

%%  save & load data
save(fnm,'-mat','Nwave','Npts','Awave','kwave','pwave','x','ywave');
% load saved data
clear all
fnm='../mdata/wave.dat';
load(fnm,'-mat')

%% plot: can be in a separate file (any portion of the file is)
% plot parameters
ln_clr='rbg';
ln_styl='-.+';
ln_wdth=[2 1 2];
fntsz_x=12; fntsz_y=fntsz_x;
Awave_mx=6;
pname=[int2str(Nwave) ' Waves'];

% plot 1
hwave1=figure('Name',pname);

for n=1:Nwave
    % subplot(Nwave,1,n)
    plot(x,ywave(:,n),[ln_clr(n) ln_styl(n)],'linewidth',ln_wdth(n))
    if(ishold~=1); hold on; end
    axis([x(1) x(end)*2 -Awave_mx Awave_mx]);
    ylabel('wave','fontsize',fntsz_y)
end
xlabel('x','fontsize',fntsz_x)
legend('wave 1','wave 2','wave 3','Location','southwest')
title(pname)

% plot 2
scrnsz = get(0,'ScreenSize');
hwave2=figure('Name',[pname 'in subplot'],...
    'Position',[1 scrnsz(4)/2 scrnsz(3)/2 scrnsz(4)/2]);
for n=1:Nwave
    subplot(Nwave,2,n)
    plot(x,ywave(:,n),[ln_clr(n) ln_styl(n)],'linewidth',ln_wdth(n))
    axis([x(1) x(end) -Awave_mx Awave_mx]);    
    ylabel(['wave' int2str(n)],'fontsize',fntsz_y)
    if(n==1); title(pname); end
end
xlabel('x','fontsize',fntsz_x)



