%climatological winds

idir=['/Volumes/work/mom4p1_pubrel_18dec2009/baltic_preprocess/forcing/forcing_200612_remade2_rca_era40_25km_northsea/nc/UV/UV_a_19'];


  ncload([idir num2str(87) '.nc']);
  yu_ocean=YAXIS; xu_ocean=XAXIS;
  UU=zeros(length(yu_ocean),length(xu_ocean), 12);
  VV=UU;
  Uab=UU;
  PE=UU;
  EE=UU;

for k=1:12
 Utmp=zeros(length(yu_ocean), length(xu_ocean), 1);
 Vtmp=zeros(length(yu_ocean), length(xu_ocean), 1);
 n=0;
 for i=87:93 
  ncload([idir num2str(i) '.nc']); 
  u=squee(U); v=squee(V);
  I=round(linspace(1,length(TAXIS),13));
  for l=I(k):I(k+1)
   n=n+1;
   Utmp(:,:,n)=squee(u(l,:,:));
   Vtmp(:,:,n)=squee(v(l,:,:));
  end
 end
   UU(:,:,k)=mean(Utmp,3);
   VV(:,:,k)=mean(Vtmp,3);
   Uab(:,:,k)=mean(0.5.*(Utmp.^2+Vtmp.^2).^0.5,3);
   PE(:,:,k)=(UU(:,:,k).^2+VV(:,:,k).^2).^0.5 ./ mean((Utmp.^2+Vtmp.^2).^0.5,3);
   for i=1:length(xu_ocean)
    for j=1:length(yu_ocean);
     EE(j,i,k)=0.5.*mean( (squee(Utmp(j,i,:))-squee(UU(j,i,k))).^2 + (squee(Vtmp(j,i,:))-squee(VV(j,i,k))).^2  );
    end
   end
end

I=find(UU<-1e10); UU(I)=NaN; EE(I)=NaN; VV(I)=NaN; PE(I)=NaN; Uab(I)=NaN;
x=xu_ocean;
y=yu_ocean;

save(['../data/processed/both/surfwinds.mat'],'x','y','UU','VV','EE','PE','Uab')
