%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% For visualization of the "rolls"%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

load avg3.mat

for i=1:61
    VELavg(:,:,i)= VELavg(:,:,i)';
end

%resize to focus on upper right-hand corner
VELavgNew = VELavg(170:300,170:300,:);
% VELavgNew = VELavg(195:215,185:205,:);

xmin = min(xc(170:300)); 
ymin = min(yc(170:300)); 
% xmin = min(xc(195:215));
% ymin = min(yc(185:205));
zmin = min(zc(:));

xmax = max(xc(170:300)); 
ymax = max(yc(170:300));
% xmax = max(xc(195:215));
% ymax = max(yc(185:205));
zmax = max(zc(:));

xc = xc(170:300);
yc = yc(170:300);
xc2 = xc;
yc2 = yc;
zc2 = zc;
% xc = xc(195:215);
% yc = yc(185:205);
zc = zc(:);
% for i = -xmin-700:200:xmax
% u=figure;
% j=num2str(i);
% hslice = surf(linspace(xmin,xmax,100),linspace(ymin,ymax,100),zeros(100));
% rotate(hslice,[0 1 0],90);
% rotate(hslice,[0 0 1],45);
% 
% xd = get(hslice,'XData');
% xd = xd+i;
% yd = get(hslice,'YData');
% yd = yd+i;
% zd = get(hslice,'ZData');
% delete(hslice)
% 
% h = slice(xc,yc,zc,VELavgNew,xd,yd,zd);
% hold on
% hx = slice(xc,yc,zc,VELavgNew,xmax,[],[]);
% set(hx,'FaceColor','interp','EdgeColor','none')
% 
% hy = slice(xc,yc,zc,VELavgNew,[],ymax,[]);
% set(hy,'FaceColor','interp','EdgeColor','none')
% 
% hz = slice(xc,yc,zc,VELavgNew,[],[],zmin);
% set(hz,'FaceColor','interp','EdgeColor','none')
% 
% daspect([1,1,1])
% axis tight
% box on
% 
% shading interp;
% 
% v = [-5 5];
% caxis(v);
% axis([0 8000 0 8000 0 1500]);
% daspect([3 3 1])
% xlabel('x (m)');
% ylabel('y (m)');
% zlabel('z (m)');
% colormap(rollsbar);
% h = colorbar;
% set(get(h,'ylabel'),'string','radial velocity perturbation');
% title('Radial Velocity Perturbation (m/s)');
% lightangle(-45,20);
% saveas(u,['C:\Documents and Settings\Jeff\Desktop\rolls\windloop',j,'.jpg']);
% close all;
% end


%Radial velocity colormap
%colormap(vector);
% v = [-5 5];
% caxis(v);
% colormap(rad);
% 
% clear;
% clc;
% for i=1:19
%     u = figure;
%     open('C:\Documents and Settings\Jeff\Desktop\rolls\windloop',j,'.fig');
%     saveas(u,['C:\Documents and Settings\Jeff\Desktop\rolls\windloop',j,'.jpg']);
%     close all;
% end

%%%%%%%%%%%%%%%
% Isosurfaces %
%%%%%%%%%%%%%%%

p = patch(isosurface(xc,yc,zc,VELavgNew,1.75));
isonormals(xc,yc,zc,VELavgNew,p)
set(p,'FaceColor','red','EdgeColor','none');
daspect([1 1 1])
view(3); axis tight
camlight 
lighting gouraud
xlabel('x (m)');
ylabel('y (m)');
zlabel('z (m)');

% hold on
% 
% p = patch(isosurface(xc,yc,zc,VELavgNew,-1));
% isonormals(xc,yc,zc,VELavgNew,p)
% set(p,'FaceColor','blue','EdgeColor','none');
% daspect([1 1 1])
% view(3); axis tight
% camlight 
% lighting gouraud
% xlabel('x (m)');
% ylabel('y (m)');
% zlabel('z (m)');

% yc = yc(72:131);
% xc = xc(23:82);
% VELavgNew = VELavgNew(23:82,72:131,:);
