%make a movie of sea-ice thickness southern ocean

%define input
 ifil='../../data/processed/zoneTr_refer.nc'

%plotting details
 xlims=[0 360];
 ylims=[-78.15 -20];
 in=[-100:5:10];
 cla=[1:2:length(in)];

%get grid once
 x=ncread(ifil,'XU_OCEAN');
 y=ncread(ifil,'YU_OCEAN');
 [X,Y]=meshgrid(x,y); 
 t=ncread(ifil,'TIME1');
 timeStr=datevec(daynoleap2datenum(t,1900));

%some ini
 n=0;
 D=ncread(ifil,'ZONETR_REF'); 
 I=find(D<=-1000); D(I)=NaN; 
 D=double(D);

 for k=1:length(t)
    n=n+1;
    figure; drawnow
        % m_proj('Mercator','long',xlims,'lat', ylims);
          m_proj('stereographic','lat',-90,'long',0,'radius',60);
          hold on
          [xxtt,yytt]=m_ll2xy(X,Y);
          flat_pcolor(xxtt,yytt,squee(D(:,:,k))'), shading flat;
          amcolormap(jet,in); amcaxis(in);

          [cc]=amcolorbar('horiz',in);
          set(cc,'linewidth',2,'tickdir','out','fontweight','bold', ...
                  'xtick',in(cla),'xticklabel',in(cla),'position', ...
                  [0.130+0.15 0.1100+0.1 0.7750-0.3 0.0611/4], ...
                  'fontsize',10)
          m_grid('xtick',12,'tickdir','out','ytick',[-70:30:20],'linest','-', ...
                 'color','k','xticklabels',[],'yticklabels',[]);

          m_coast('patch',[0.7 0.7 0.7])
          title(['Year ' num2str(timeStr(1))],'fontsize',14)
          legend('off')
  brighten(0.2)
  eval(['print -dtiff ../tmp/hi_' num2str(n+1000) '.tiff'])
  close
 end

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

