%make a movie of absolute velocity in the southern ocean

%define input
 idiru='../data/mod/ref/out/u/';
 filsu = dir([idiru '*.nc']);

 idirv='../data/mod/ref/out/v/';
 filsv = dir([idirv '*.nc']);

%plotting details
 %start lims
  xlimss=[10 30];
  ylimss=[53 66];
 %end lims
  xlimse=[13.7 17.5];
  ylimse=[54.8 56.7];

 %number of frames till halfway
  del=40 *1e10;

 %contour interval
  in=[0:0.025:0.3 0.4:0.1:0.7];

%get grid once
 ncload([idiru filsu(1).name]);
 y=yu_ocean; clear yu_ocean
 x=xu_ocean; clear xize(u)_ocean
 [X,Y]=meshgrid(x,y); 

%some ini
 n=0;
 
for i=37:48 %:length(filsu)
 ncload([idiru filsu(i).name]);
 ncload([idirv filsv(i).name]);

 u=squee(u(:,1,:,:)); u=permute(u,[3 2 1]); 
 v=squee(v(:,1,:,:)); v=permute(v,[3 2 1]);

 t=time; clear time; 
 t=get_calendar_date((t./24)  + get_julian_day(1987,1,1,0));
 
 I=find(u<-1e10); u(I)=NaN; v(I)=NaN;
 u=double((u.^2+v.^2).^0.5); clear v; 
 for k=1:length(t)
    n=n+1;
    figure; drawnow
         m=n-1+del;
         xlims=[(del*xlimss(1)+(n-1)*xlimse(1))./m  (del*xlimss(2)+(n-1)*xlimse(2))./m];
         ylims=[(del*ylimss(1)+(n-1)*ylimse(1))./m  (del*ylimss(2)+(n-1)*ylimse(2))./m];
         m_proj('Mercator','long',xlims,'lat', ylims);
        %  m_proj('stereographic','lat',-90,'long',0,'radius',28);
          hold on
          [xxtt,yytt]=m_ll2xy(X,Y);
          flat_pcolor(xxtt,yytt,squee(u(:,:,k))'), shading flat;
          amcolormap(jet,in); amcaxis(in);

          [cc]=amcolorbar('horiz',in);
          set(cc,'linewidth',2,'tickdir','out','fontweight','bold', ...
                  'xtick',in(1:4:end),'xticklabel',in(1:1:end),'position', ...
                  [0.130+0.15 0.1100+0.1 0.7750-0.3 0.0611/4], ...
                  'fontsize',10)

          %m_coast('patch',[0.7 0.7 0.7])
          m_gshhs_f('color','k')
          m_grid('xtick',[],'ytick',[],'color',[0.99 0.99 0.99])

  ye=num2str(t(k,1)); mo=t(k,2); da=t(k,3); 
   if mo<10; mo=['0' num2str(mo)]; else; mo=num2str(mo); end
   if da<10; da=['0' num2str(da)]; else; da=num2str(da); end
  title([da '.' mo '.' ye],'fontsize',14)
  eval(['print -dtiff ../ps/tmp/uabs_' num2str(n+1000) '.tiff'])
  close
 end
end

!rm -f filelist.asc
!ls ../ps/tmp/*.tiff > filelist.asc
!rm -f ../mov/uabs.flc
!ppm2fli -ftifftopnm -s50 -N -g1200x900 filelist.asc ../mov/uabsNoav.flc
!rm -f filelist.asc
!rm ../ps/tmp/*.tiff
