%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                     GV1
%
% FIRST PROGRAM TO STUDY GROUP VELOCITY
%
% SIMPLE CASE: two waves with close wavenumbers.
%

XLEN = 40E6; XNUM = 1001; 
x=linspace(0,XLEN,XNUM);
TDAYS = 500;
TLEN=TDAYS*24*3600; TNUM = 251;
t=linspace(0,TLEN,TNUM);

UBAR = [ 0.0, 2.5 ];
for nubar=1:2

ubar = UBAR(nubar)

m1 = 24;
m2 = 26;
k1 = 2*pi*m1/XLEN;
k2 = 2*pi*m2/XLEN;

beta=1.6E-11;

sig1 = k1*ubar - beta/k1;
sig2 = k2*ubar - beta/k2;

c1 = sig1/k1;
c2 = sig2/k2;
fprintf(' Cphase: %g %g \n', c1, c2);

w10 = sin(k1*x);
w20 = sin(k2*x);
ws0 = (w10+w20);
XU = ubar*t(1);
axis('off')
subplot(3,1,1); plot(x,w10); title('WAVE 1');
hold on; plot(XU,0,'--r>','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','r',...
                'MarkerSize',16); hold off
subplot(3,1,2); plot(x,w20); title('WAVE 2');
hold on; plot(XU,0,'--r>','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','r',...
                'MarkerSize',16); hold off
subplot(3,1,3); plot(x,ws0); title(' SUM ');
hold on; plot(XU,0,'--r>','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','r',...
                'MarkerSize',16); hold off
pause
for nt=1:TNUM
   tt = t(nt);
   w1 = sin(k1*x-sig1*tt);
   w2 = sin(k2*x-sig2*tt);
   ws = (w1+w2);
   XU = ubar*tt; XU = rem(XU,XLEN);
   subplot(3,1,1); plot(x,w1,'LineWidth',1);
   title('WAVE 1');
   hold on; plot(XU,0,'--r>','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','r',...
                'MarkerSize',16); hold off
   subplot(3,1,2); plot(x,w2,'LineWidth',1);
   title('WAVE 2');
   hold on; plot(XU,0,'--r>','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','r',...
                'MarkerSize',16); hold off
   subplot(3,1,3); plot(x,ws,'LineWidth',1);
   title(' SUM '); 
   hold on; plot(XU,0,'--r>','LineWidth',2,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','r',...
                'MarkerSize',16); hold off
   drawnow
   %pause
end

pause
end

return   
