istart=1; 

clear all
close all

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

 nphyt=31; nzoo=17; nbac=2; nplank=nphyt+nzoo+nbac;
   
 tsize=[1 2 3:4  5:9  5:9 5:15 7:16 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 8];

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

 load amt15_extend.dat; amte=amt15_extend;
 [niamte njamte]=size(amt15_extend);

 load amt15.dat; amt=amt15;
 [niamt njamt]=size(amt);
 nzamt=14;

    xtrans=-158;
   GrX=180+(180+xtrans);
   GrY=[22:1:53]; GrY1=[22:1:54];

   Grj=find(Y>=GrY(1)-0.5 & Y<=GrY(length(GrY))+0.5);
   Gri=find(X>=GrX-0.5 & X<GrX+0.5);
   GrYT=Y(Grj);
 

 nrun=3;

 for irun=1:nrun,

%if (irun==1), load run21b2_5.mat; end
%if (irun==2), load run21b2_16_car.mat; end
%if (irun==2), load run21b2_22_car.mat; end
%if (irun==3), load run21b2_23_car.mat; end
%if (irun==4), load run21b2_24_car.mat; end
%if (irun==2), load run21b2_16_cat_april.mat; end
%if (irun==2), load run21b2_16_may_car.mat; end
%if (irun==3), load run21b2_16_cat_sept.mat; end
%if (irun==1), load run21b2_39_may_car.mat; end
%if (irun==2), load run21b2_39_jun_car.mat; end
%if (irun==3), load run21b2_39_sep_car.mat; end
if (irun==1), load /nfs/micklab001/stephdut/DAR3_MAT/run22_77_m4_car_nut.mat; mstr='Apr'; end
if (irun==2), load /nfs/micklab001/stephdut/DAR3_MAT/run22_77_m6_car_nut.mat; mstr='Apr'; end
if (irun==3), load /nfs/micklab001/stephdut/DAR3_MAT/run22_77_m9_car_nut.mat; mstr='Apr'; end
%if (irun==2), load run21b2_48_jun_car.mat; mstr='Jun'; end
%if (irun==3), load run21b2_48_sep_car.mat; mstr='Sep'; end
cars(irun,:,:,:,:)=car;

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

%%
%%% PLOT TRANSECT PROFILES %%%%%%%%%%%%%%%%%%
   figure
   colormap(fake_parula())
   xsize=0.45; ysize=0.14;
   xoff1=.10; xoff2=.46;

   cax1=-0.5; cax2=1.5;
   
  for ip=1:5
    if (ip==1), tmp=squeeze(car(1,:,:,:)); tstr='Pro'; end
    if (ip==2), tmp=squeeze(sum(car(2,:,:,:),1)); tstr='Syn'; end
    if (ip==3), tmp=squeeze(sum(car([3:5 15],:,:,:),1)); tstr='Pico Euk'; end
    if (ip==4), tmp=squeeze(sum(car(48:50,:,:,:),1));; tstr='Het Bact'; end
    if (ip==5), tmp=squeeze(sum(car(32:34,:,:,:),1)); tstr='Small Zoo'; end
    tmp=tmp*12;
 %%%   
   for il=1:2,
     clear tmp2
     if (il==1), 
      for iy=1:niamte
       tmp2(:,iy)=squeeze(tmp(amte(iy,4),amte(iy,2),1:nzamt));
       xax=amte(:,1);
      end % for iy
      xa1=-60; xa2=58;
      tx=-50;
     end % il 1
     if (il==2), 
       tmp2=squeeze(tmp(Gri,Grj,1:nzamt))';
       xax=GrY1;
       xa1=22; xa2=50;
       tx=23;
     end % il 1


     clear fi, fi=find(tmp2<0); tmp2(fi)=1e-20;
     tmp2=log10(tmp2);
     xoff=.08+(il-1)*.5;
     x2=.97-ip*ysize-ip*.02;
     h=axes('position',[xoff x2 xsize ysize]);
     pcolor(xax,Z(1:14),tmp2); caxis([cax1 cax2]); shading flat, 
         colorbar;
%        hp = gca ; hc = colorbar; axes(hc);
%        bolder, set(gca,'Ytick',[-2 -1 0 1.0] );
%        set(gca,'YTickLabel',['0.01';'0.1 ';'1.  ';'10. ']); axes(hp),
     hold on
     axis([xa1 xa2 -200 0])
     set(h,'Ytick',[-150 -50] ); set(h,'YTickLabel',['150';' 50'])
     if (il==1 ),
       set(h,'Xtick',[-50 0 50] ); set(h,'XTickLabel',['-50';' 0 ';' 50']);
     end
     if (il==2 ),
       set(h,'Xtick',[25 35 45] ); set(h,'XTickLabel',['25';'35';'45']);
     end
     bolder
%    text( tx, -160,[tstr])
%    if (ip==4), xlabel('latitude'); end
   end % il
  end % ip


figure
  for ip=1:5
    if (ip==1), tmp=squeeze(car(1,:,:,:)); tstr='Pro'; cstr=['g-']; end
    if (ip==2), tmp=squeeze(sum(car(2,:,:,:),1)); tstr='Syn'; cstr=['y']; end
    if (ip==3), tmp=squeeze(sum(car([3:5 15],:,:,:),1)); tstr='Pico Euk'; cstr=['m']; end
    if (ip==4), tmp=squeeze(sum(car(48:50,:,:,:),1));; tstr='Het Bact'; cstr=['b-']; end
    if (ip==5), tmp=squeeze(sum(car(32:34,:,:,:),1)); tstr='Small Zoo'; cstr=['k-']; end
    tmp=tmp*12;
 %%%   
   for il=1:2,
     clear tmp2
     if (il==1),
      for iy=1:niamte
       tmp2(iy)=squeeze(tmp(amte(iy,4),amte(iy,2),1));
       xax=amte(:,1);
      end % for iy
      xa1=-60; xa2=58;
      tx=-50;
     end % il 1
     if (il==2),
       tmp2=squeeze(tmp(Gri,Grj,1))';
       xax=GrY1;
       xa1=22; xa2=50;
       tx=23;
     end % il 1

     clear fi, fi=find(tmp2<0); tmp2(fi)=1e-20;
%    tmp2=log10(tmp2);
     subplot(2,1,il),
     plot(xax,tmp2,[cstr],'LineWidth',2);
     hold on
     c=axis;
     axis([xa1 xa2 0 20])
     if (il==1 ),
       set(h,'Xtick',[-50 0 50] ); set(h,'XTickLabel',['-50';' 0 ';' 50']);
     end
     if (il==2 ),
       set(h,'Xtick',[25 35 45] ); set(h,'XTickLabel',['25';'35';'45']);
     end
     bolder
     xlabel('latitude');
   end % il
  end % ip

figure
colormap(fake_parula())
cmin1=-0.5; cmax1=1.5; %log10(100);
for ip=1:4,
   if (ip==1), tmp=squeeze(car(1,:,:,1)); tstr='Pro'; end
   if (ip==2), tmp=squeeze(car(2,:,:,1)); tstr='Syn'; end
   if (ip==3), tmp=squeeze(sum(car([3:5 15],:,:,1),1)); tstr='PicoEuk'; end
   if (ip==4), tmp=squeeze(sum(car(48:50,:,:,1),1)); tstr='Het Bact'; end
   tmp=tmp*12; tmp=log10(tmp);
   subplot(2,2,ip),
   projec=['miller'];
   m_proj(projec,'longitude',[360-170 360-110],'latitude',[15 60]);
   m_pcolor(X,Y,tmp'), caxis([cmin1 cmax1]);
   shading flat,
%  colorbar
%  hp = gca ; hc = colorbar; axes(hc);
%  bolder, set(gca,'Ytick',[ -1 0 1 ] );
%  set(gca,'YTickLabel',['0.01','1.  ','10. ']); axes(hp),
   hold on
   m_text(360-135,20,tstr,'FontSize',14);
   m_plot([360-158 360-158],[25 45],'k-','LineWidth',2)
   m_plot([360-155 360-130],[25 52],'k-','LineWidth',2)
   m_coast('patch','k');
   m_grid('fontsize',6,'xticklabels',[],'xtick',[],...
       'ytick',[],'yticklabels',[],'linest','-','color',[0 0 0]);
lt1=15; lt2=60;
lg1=360-170; lg2=360-110;

  bolder
  for il=lg1+10:10:lg2-10;
m_plot([il il],[lt1 lt2],'k:');
  end
  for il=lg1+10:20:lg2-10;
m_text(il-5,lt1-4,num2str(il-360),'FontSize',10);
  end
  for lt=lt1+5:10:lt2-10;
m_plot([lg1 lg2],[lt lt],'k:');
  end % for 
  for lt=lt1+5:10:lt2-10;
m_text(lg1-7,lt,num2str(lt),'FontSize',10)
  end % for lt
  bolder


end % for ip



%   tmp2=squeeze(tmp(Gri,Grj,1));
% plot(GrYT,tmp2',cstr,'LineWidth',2); hold on
% bolder
% ylabel('biomass'), xlabel('latitude');

end % for irun

