close all
clear all

clear all
close all

addpath /home/stephdut/matlab/m_map

 logvolexp=[-141300:.513:-0.6900+25*.513];
 logvol=(10*ones(size(logvolexp))).^logvolexp;
 logdm=2*((3/4*logvol/pi).^(1/3));

 nphyt=31; nzoo=16; nbac=3; nplank=nphyt+nzoo+nbac;

 tsize=[2 4 4:5  6:10  6:10 6:14 7:15 7:22 1];
 ptype=[1 2 3 3 4 4 4 4 4 5 5  5 5 5 6 6 6 6 6  6 6 6 6 6 6 7 7 7  7 7 7 7 7 7 88 8];

 load grid_ecco.mat

 nx=length(X); ny=length(Y); nz=length(Z);
 for k=1:nz,
   volc(k,:,:)=rA(:,:)*drF(k);
 end
% iland1=find(squeeze(HFacC(:,:,1))==0);


for irun=1:2,
 if (irun==1), 
     load /nfs/micklab001/stephdut/DAR4_MAT/run29_51_holl2_y12_car_nut_gr.mat
 end %
 if (irun==2), 
     load /nfs/micklab001/stephdut/DAR4_MAT/run29_51_holl2_mixo_y12_car_nut_gr.mat
 end %


 cars(irun,:,:,:)=squeeze(car(:,:,:,1))*12;

 typ(irun,1,:,:)=squeeze(sum(car  (1:2,:,:,1),1))*12;
 typ(irun,2,:,:)=squeeze(sum(car  (3:4,:,:,1),1))*12;
 typ(irun,3,:,:)=squeeze(sum(car  (5:9,:,:,1),1))*12;
 typ(irun,4,:,:)=squeeze(sum(car  (10:14,:,:,1),1))*12;
 typ(irun,5,:,:)=squeeze(sum(car  (15:22,:,:,1),1))*12;
 typ(irun,6,:,:)=squeeze(sum(car  (23:31,:,:,1),1))*12;
 typ(irun,7,:,:)=squeeze(sum(car  (31:47,:,:,1),1))*12;
 typ(irun,8,:,:)=squeeze(sum(car  (48:50,:,:,1),1))*12;

 figure(1)
 xwide = 0.14; yhigh = 0.2;
 colormap(fake_parula())
 cmin1=-2; cmax1=2;
 
 for ityp=1:7,
    tmp=squeeze(typ(irun,ityp,:,:));
    fi=find(tmp<0); tmp(fi)=1e-9;
    tmp=log10(tmp); %tmp(filand1)=NaN;
%%
    ybottom=0.95-(irun*(yhigh-.08));
    xleft=0.0+(ityp-1)*(xwide);

   h=axes('position',[(xleft+0.002) (ybottom) (xwide-0.01) (yhigh-0.01)]);
   projec=['miller'];
   m_proj(projec,'longitude',[0 360],'latitude',[-79 79]);
   m_pcolor(X,Y,tmp'), caxis([cmin1 cmax1]);
   shading flat,
   hold on
   m_coast('patch','k');
   m_grid('fontsize',6,'xticklabels',[],'xtick',[],...
       'ytick',[],'yticklabels',[],'linest','-','color',[0 0 0]);
   bolder
   bolder

 end % ityp

%
 if (irun>1),
  figure(2)
  cmap = cmocean('balance'); colormap(cmap);
  for ityp=1:7,
    tmp=squeeze(typ(irun,ityp,:,:))-squeeze(typ(1,ityp,:,:));
%   tmp(filand1)=NaN;
%%
    ybottom=0.95-(irun*(yhigh-.08));
    xleft=0.0+(ityp-1)*(xwide);

   h=axes('position',[(xleft+0.002) (ybottom) (xwide-0.01) (yhigh-0.01)]);
   projec=['miller'];
   m_proj(projec,'longitude',[0 360],'latitude',[-79 79]);
   m_pcolor(X,Y,tmp'), caxis([-6 6]);
   shading flat,
   hold on
   m_coast('patch','k');
   m_grid('fontsize',6,'xticklabels',[],'xtick',[],...
       'ytick',[],'yticklabels',[],'linest','-','color',[0 0 0]);
   bolder
   bolder
  end % ityp

 end % if  irun


figure(3)
colormap(fake_parula())
cmin1=0; cmax1=2000;
xwide=0.35; yhigh=0.3;

for ip=1:3,
   if (ip==1), tmp=squeeze(sum(car([1:23],:,:,:),1)); tstr='Phyto'; end
   if (ip==2), tmp=squeeze(sum(car([24:31],:,:,:),1)); tstr='Mixo'; end
   if (ip==3), tmp=squeeze(sum(car([32:47],:,:,:),1)); tstr='Zoo'; end
   tmp2=zeros(nx,ny);
   for k=1:nz
    tmp2=tmp2+squeeze(tmp(:,:,k))*drF(k);
   end % for 
   clear tmp
   tmp=tmp2*12; 

   carts(irun,ip,:,:)=tmp;
    
    ybottom=0.95-(ip*(yhigh-.08));
    xleft=0.01+(irun-1)*(xwide);

   h=axes('position',[(xleft+0.002) (ybottom) (xwide-0.01) (yhigh-0.01)]);
   projec=['miller'];
   m_proj(projec,'longitude',[0 360],'latitude',[-79 79]);
   m_pcolor(X,Y,tmp'), caxis([cmin1 cmax1]);
   shading flat,
   colorbar
   hold on
   m_coast('patch','k');
   m_grid('fontsize',6,'xticklabels',[],'xtick',[],...
       'ytick',[],'yticklabels',[],'linest','-','color',[0 0 0]);
   bolder
end % for ip   

 if (irun>1),
  figure(6)
  cmap = cmocean('balance'); colormap(cmap);
cmin1=-1000; cmax1=1000;
xwide=0.35; yhigh=0.3;
  for ityp=1:3,
    tmp=squeeze(carts(irun,ityp,:,:))-squeeze(carts(1,ityp,:,:));
%   tmp(filand1)=NaN;
%%
    ybottom=0.95-(ityp*(yhigh-.08));
    xleft=0.01+(irun-1)*(xwide);


   h=axes('position',[(xleft+0.002) (ybottom) (xwide-0.01) (yhigh-0.01)]);
   projec=['miller'];
   m_proj(projec,'longitude',[0 360],'latitude',[-79 79]);
   m_pcolor(X,Y,tmp'), caxis([cmin1 cmax1]);
   shading flat,
   colorbar
   hold on
   m_coast('patch','k');
   m_grid('fontsize',6,'xticklabels',[],'xtick',[],...
       'ytick',[],'yticklabels',[],'linest','-','color',[0 0 0]);
   bolder
   bolder
  end % ityp
end % for irun


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for (ip=1:2),
 if (ip==1), tmp=squeeze(sum(pp([1:23],:,:,:),1)); end
 if (ip==2), tmp=squeeze(sum(pp([24:31],:,:,:),1)); end
 tmp2=zeros(nx,ny);
 for (k=1:nz),
   tmp2=tmp2+tmp(:,:,k)*drF(k);
 end
 pps(irun,ip,:,:)=tmp2;
end 
pps(irun,3,:,:)=0;
for (ip=1:3),
 if (ip==1), tmp=squeeze(sum(grgn([1:23],:,:,:),1)); end
 if (ip==2), tmp=squeeze(sum(grgn([24:31],:,:,:),1)); end
 if (ip==3), tmp=squeeze(sum(grgn([32:47],:,:,:),1)); end
 tmp2=zeros(nx,ny);
 for (k=1:nz),
   tmp2=tmp2+tmp(:,:,k)*drF(k);
 end
 grgns(irun,ip,:,:)=tmp2;
end



figure(3+irun)
colormap hot, cmap=colormap; colormap(cmap([62:-3:13],:));
cmin1=0; cmax1=100;
xwide=0.35; yhigh=0.3;

itt=1; 
for ip=1:9,
   if (ip==4 | ip==7), itt=itt+1; end
   if (ip==1 | ip==4 | ip==7), ipp=0; end
   ipp=ipp+1;

   if (ip<4), tmp=squeeze(pps(irun,ip,:,:)); end
   if (ip>3&ip<7), tmp=squeeze(grgns(irun,ip-3,:,:)); end
   if (ip>6), tmp=squeeze(pps(irun,ip-6,:,:))+squeeze(grgns(irun,ip-6,:,:)); end
   tmp=tmp*12*365*24*60*60/1000;

    ybottom=0.95-(ipp*(yhigh-.08));
    xleft=0.01+(itt-1)*(xwide);

   h=axes('position',[(xleft+0.002) (ybottom) (xwide-0.01) (yhigh-0.01)]);
   projec=['miller'];
   m_proj(projec,'longitude',[0 360],'latitude',[-79 79]);
   m_pcolor(X,Y,tmp'), caxis([cmin1 cmax1]);
   shading flat,
   colorbar;
   hold on
   m_coast('patch','k');
   m_grid('fontsize',6,'xticklabels',[],'xtick',[],...
       'ytick',[],'yticklabels',[],'linest','-','color',[0 0 0]);
   bolder

end % for ip

figure(7)
cmap = cmocean('thermal'); colormap(cmap);
cmin1=0; cmax1=1;
xwide=0.35; yhigh=0.3;
itt=1;
   tmp=squeeze(grgns(irun,2,:,:));
   tmp=tmp./squeeze(pps(irun,2,:,:))+squeeze(grgns(irun,2,:,:));

   rats(irun,:,:)=tmp;

    ybottom=0.95-(2*(yhigh-.08));
    xleft=0.01+(irun-1)*(xwide);

   h=axes('position',[(xleft+0.002) (ybottom) (xwide-0.01) (yhigh-0.01)]);
   projec=['miller'];
   m_proj(projec,'longitude',[0 360],'latitude',[-79 79]);
   m_pcolor(X,Y,tmp'), caxis([cmin1 cmax1]);
   shading flat,
   colorbar;
   hold on
   m_coast('patch','k');
   m_grid('fontsize',6,'xticklabels',[],'xtick',[],...
       'ytick',[],'yticklabels',[],'linest','-','color',[0 0 0]);
   bolder

if (irun>1),
figure(9)
cmap = cmocean('balance'); colormap(cmap);
cmin1=-.50; cmax1=.50;
xwide=0.35; yhigh=0.3;
    tmp=squeeze(rats(irun,:,:)-rats(1,:,:));

    ybottom=0.95-(2*(yhigh-.08));
    xleft=0.01+(irun-1)*(xwide);

   h=axes('position',[(xleft+0.002) (ybottom) (xwide-0.01) (yhigh-0.01)]);
   projec=['miller'];
   m_proj(projec,'longitude',[0 360],'latitude',[-79 79]);
   m_pcolor(X,Y,tmp'), caxis([cmin1 cmax1]);
   shading flat,
   colorbar;
   hold on
   m_coast('patch','k');
   m_grid('fontsize',6,'xticklabels',[],'xtick',[],...
       'ytick',[],'yticklabels',[],'linest','-','color',[0 0 0]);
   bolder
end % irun



if (irun>1),
figure(6+irun)
cmap = cmocean('balance'); colormap(cmap);
cmin1=-30; cmax1=30;
xwide=0.35; yhigh=0.3;
itt=1;
for ip=1:9,
   if (ip==4 | ip==7), itt=itt+1; end
   if (ip==1 | ip==4 | ip==7), ipp=0; end
   ipp=ipp+1;

   if (ip<4), tmp=squeeze(pps(irun,ip,:,:))-squeeze(pps(1,ip,:,:)); end
   if (ip>3&ip<7), tmp=squeeze(grgns(irun,ip-3,:,:))-squeeze(grgns(1,ip-3,:,:)); end
   if (ip>6), tmp=squeeze(pps(irun,ip-6,:,:))+squeeze(grgns(irun,ip-6,:,:)) ...
                   -squeeze(pps(1,ip-6,:,:))-squeeze(grgns(1,ip-6,:,:)); end
   tmp=tmp*12*365*24*60*60/1000;

    ybottom=0.95-(ipp*(yhigh-.08));
    xleft=0.01+(itt-1)*(xwide);

   h=axes('position',[(xleft+0.002) (ybottom) (xwide-0.01) (yhigh-0.01)]);
   projec=['miller'];
   m_proj(projec,'longitude',[0 360],'latitude',[-79 79]);
   m_pcolor(X,Y,tmp'), caxis([cmin1 cmax1]);
   shading flat,
   colorbar;
   hold on
   m_coast('patch','k');
   m_grid('fontsize',6,'xticklabels',[],'xtick',[],...
       'ytick',[],'yticklabels',[],'linest','-','color',[0 0 0]);
   bolder

end % for ip
end % for irun


end % for irun

