clear all;format compact

% coast
load coastlines;
lon2=coastlon;
lat2=coastlat;

lon1=coastlon;
lat1=coastlat;
for i=1:length(lon1)
  if(lon1(i)<0)
    lon1(i)=lon1(i)+360;
  end
  if((lon1(i)<=1)||(lon1(i)>=359))
    lon1(i)=NaN;
  end
end
clear coastlon coastlat lon2 lat2
% coast


file1 = '../seeding_masks/mask_0375_025-200_SSP245.nc';

f0 = '../seeding_masks/b.e21.BSSP245cmip6.f09_g17.CMIP6-MCB-cntl.000.SWCF.nc';
lon = ncread(f0,'lon');
lat = ncread(f0,'lat');

   
tmp=ncread(file1,'mask');
ii = [1:5:36];
for i=1:length(ii);
    mask(i,:,:,:) = squeeze(tmp(:,:,:,ii(i)));
end
clear tmp


for n=1:12
    sum_mask(:,:,n) = squeeze(sum(mask(:,:,:,n),1));
end


sum_mask1 = sum_mask;

for i=1:length(lon)
for j=1:length(lat)
for n=1:12
if(sum_mask(i,j,n)==1)
   sum_mask1(i,j,n) = 8;
end
if(sum_mask(i,j,n)==2)
   sum_mask1(i,j,n) = 7;
end
if(sum_mask(i,j,n)==3)
   sum_mask1(i,j,n) = 6;
end
if(sum_mask(i,j,n)==4)
   sum_mask1(i,j,n) = 5;
end
if(sum_mask(i,j,n)==5)
   sum_mask1(i,j,n) = 4;
end
if(sum_mask(i,j,n)==6)
   sum_mask1(i,j,n) = 3;
end
if(sum_mask(i,j,n)==7)
   sum_mask1(i,j,n) = 2;
end
if(sum_mask(i,j,n)==8)
   sum_mask1(i,j,n) = 1;
end
end
end
end	

%sum_mask1 = sum_mask1+.1;

pp = [.1 .68 .2 .24;.32 .68 .2 .24;.54 .68 .2 .24;.76 .68 .2 .24;...
      .1 .39 .2 .24;.32 .39 .2 .24;.54 .39 .2 .24;.76 .39 .2 .24;...
      .1 .1 .2 .24;.32 .1 .2 .24;.54 .1 .2 .24;.76 .1 .2 .24];

ctb = [1 1 1;...
	 .7 0 0;...
	 1 0 1;...
	 1 .7 0;...
	 1 1 0;...
	 0 1 0;...
	 0 1 1;...
	 0 .7 1;...
         0 .2 1];


v=[0:1:9];

tt = {'JAN';'FEB';'MAR';'APR';'MAY';'JUN';'JUL';'AUG';'SEP';'OCT';'NOV';'DEC'};

figure(1);orient tall;orient landscape;colormap(ctb)
for i=1:12
    subplot('position',pp(i,:))
    [c,h]=contourf(lon,lat,squeeze(sum_mask1(:,:,i))',v);
    set(gca,'clim',[0 9]);
    set(h,'edgecolor','none')
    hold on;plot(lon1,lat1,'k-')
    axis([0 360 -90 90])
    set(gca,'xtick',[0:60:360],'xminortick','on','xticklabel',[])
    set(gca,'ytick',[-90:30:90],'yminortick','on','yticklabel',[])
    set(title(char(tt(i))),'fontsize',8)      
end

h=colorbar('horiz');
set(h,'position',[0.2  0.07 0.6  0.01])
set(h,'TickLabels',{'   0';' 2.5';' 5.0';' 7.5';'10.0';'12.5';'15.0';'17.5';'20.0';'    '})
set(h,'Ticks',[0.5 1.5 2.5 3.5 4.5 5.5 6.5 7.5 8.5 9.5])
 set(h,'TickLength',0)
