clear;

load data/midterm_isabel_dat;
load data/xland_isabel;


s_pres=squeeze(pres(1,:,:));
s_pres(XLAND<2)=NaN;

[a1, ny]=min(min(s_pres,[],2));
[a1, nx]=min(min(s_pres,[],1));

xlat1=XLAT;
xlong1=XLONG;


[d3 d2 d1]=size(Hydrometer);

lat_center1=xlat1(ny,nx);
lon_center1=xlong1(ny,nx);

for k=1:d3
u1=squeeze(u(k,:,:));
v1=squeeze(v(k,:,:));
wind1=sqrt(u1.^2+v1.^2);
for i=1:d1
for j=1:d2
x1=xlong1(j,i)-lon_center1;
y1=xlat1(j,i)-lat_center1;
cour(j,i)=course(x1,y1);
dist=sqrt((i-nx)^2+(j-ny)^2);
if dist > 1.0
 alpha=atan(v1(j,i)/u1(j,i))*180/pi;
 if cour(j,i)<=180
  if alpha > 0
  phi1(k,j,i)=alpha+cour(j,i)-180;
   if phi1(k,j,i) < -90
   phi1(k,j,i)=phi1(k,j,i)+180;
   end
  else
  phi1(k,j,i)=cour(j,i)+alpha;
   if phi1(k,j,i) > 90
   phi1(k,j,i)=phi1(k,j,i)-180;
   end
  end
 else
  if alpha >0
  phi1(k,j,i)=alpha+cour(j,i)-360;
   if phi1(k,j,i) < -90
   phi1(k,j,i)=phi1(k,j,i)+180;
   end
  else
  phi1(k,j,i)=alpha+cour(j,i)-180;
   if phi1(k,j,i) > 90
   phi1(k,j,i)=phi1(k,j,i)-180;
   end
  end
 end
else
 phi1(k,j,i)=0;
end
end
end
spd_t(k,:,:)=wind1.*cos(squeeze(phi1(k,:,:))*pi/180);
spd_r(k,:,:)=wind1.*sin(squeeze(phi1(k,:,:))*pi/180);
end

x0=xlong1-lon_center1;
y0=xlat1-lat_center1;

%contourf(x0,y0,squeeze(spd_r(1,:,:)),'edgecolor','none');

contourf(x0,y0,squeeze(w(10,:,:)),'edgecolor','none');

%contourf(squeeze(w(:,ny,:)),'edgecolor','none');

contourf(squeeze(spd_r(:,ny,:)),'edgecolor','none');

xz=x0(ny,:);
zz=z(1:65,ny,nx)/1000;

[Xz,Zz]=meshgrid(xz,zz);

%contourf(Xz,Zz,squeeze(spd_r(:,ny,:)),'edgecolor','none');

uz=squeeze(spd_r(:,ny,:));
for i=1:d1
    if i<nx
        uz1(:,i)=uz(:,i);
    else
        uz1(:,i)=-uz(:,i);
    end
end
wz=squeeze(w(:,ny,:));

quiver(Xz(1:2:40,230:2:end-100),Zz(1:2:40,230:2:end-100),uz1(1:2:40,230:2:end-100)/50,wz(1:2:40,230:2:end-100)/5,0);

%contourf(Xz(1:1:30,200:1:end-70),Zz(1:1:30,200:1:end-70),wz(1:1:30,200:1:end-70),'edgecolor','none');
contourf(Xz(1:1:30,200:1:end-70),Zz(1:1:30,200:1:end-70),uz1(1:1:30,200:1:end-70),'edgecolor','none');


