clear all

filename0 = 'Fig08' 

load('ehtable','whitejet','greyjet','redblue', 'color7');
set(groot,'defaultAxesColorOrder',color7)

A_Boundary_DIIID;

load('Lim_Boundary_in_lcfs_DIIID', 'rvec','zvec', 'in', 'in_lcfs');
[Rmesh,Zmesh] = meshgrid(rvec,zvec);

%%

den0 = [5 15 20 30 40];


%% DEN #1
ii = 1;
load Fig08_085_den05e17_total Err Epr Ezr JE cx 
Er1 = Err;
Ey1 = Epr;
Ez1 = Ezr;
JE1 = JE;
cx1 = cx;

%% DEN #1
ii = 1;
load Fig08_085_den15e17_total Err Epr Ezr JE cx 
Er2 = Err;
Ey2 = Epr;
Ez2 = Ezr;
JE2 = JE;
cx2 = cx;

%% DEN #3
ii = 3;
load Fig08_085_den20e17_total Err Epr Ezr JE cx 
Er3 = Err;
Ey3 = Epr;
Ez3 = Ezr;
JE3 = JE;
cx3 = cx;

%% DEN #4
ii = 4;
load Fig08_085_den30e17_total Err Epr Ezr JE cx 
Er4 = Err;
Ey4 = Epr;
Ez4 = Ezr;
JE4 = JE;
cx4 = cx; 

%% DEN #5
ii = 5;
load Fig08_085_den40e17_total Err Epr Ezr JE cx 
Er5 = Err;
Ey5 = Epr;
Ez5 = Ezr;
JE5 = JE;
cx5 = cx;


%%

xx  = [1.6, 2.4];
yy  = [-0.4 0.8];

xx2  = [2.17, 2.32];
yy2  = [0.2, 0.5];

xx3  = xx; 
yy3  = yy;

cc2 = [-20,20];

%%

minc = 1e-1;  
maxc = 1e2;  
maxc    = log10(maxc/minc);
logminc = log10(minc);
ytickn2  = -maxc:maxc; 

for ii=1:length(ytickn2)
    val = ytickn2(ii); 
    if(val>0)
        lbl2{ii} = ['10^{',num2str(val+logminc,'%3.0f'),'}'];
    elseif (val<0)
        lbl2{ii} = ['-10^{',num2str(val-logminc,'%3.0f'),'}'];
    else (val==0)
        lbl2{ii} = ['+- 10^{',num2str(log10(minc),'%3.0f'),'}'];
    end
end

xxlabel = 'r (m)';
yylabel = 'z (m)';
labelfont = 15;
axisfont  = 13;
titlefont = 15;
lcfscolor = 'k--';

%%

ynum = 4;
xnum = 5;

xw  = 0.155;
yw  = 0.21;
x0  = 0.1 + [0:xnum-1]*(xw+0.01);
y0  = 0.05 + [0:ynum-1]*(yw+0.024);
y0  = flip(y0);


%%

hh=figure(1);
hh.Position = [3 100 850 1000];
set(gcf,'color','w');


%%

cc1 = [-3,3];

%%

p = subplot(ynum,xnum,1);
imagesc(rvec,zvec, Er1)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx1(1,:), cx1(2,:), 'm')
 fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1) 
set(gca, 'position', [x0(1), y0(1), xw, yw])
ylabel(yylabel,'fontsize', labelfont)
title(['(a) n_{ant} = ' num2str(den0(1)) 'e17/m^3'],'fontsize', titlefont,'FontWeight','normal')
colormap(p, redblue)
text(1.2,  0.69, 'E_r', 'fontsize', 17, 'backgroundcolor',[0.8,0.8,0.8])
text(2, 0.7, 'FW cutoff', 'color','m', 'fontsize', 14)
text(2, -0.3, 'LCFS', 'color','k', 'fontsize', 14) 

p = subplot(ynum,xnum,2);  
imagesc(rvec,zvec, Er2)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx2(1,:), cx2(2,:), 'm')
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(2), y0(1), xw, yw])
title(['(b) n_{ant} = ' num2str(den0(2)) 'e17/m^3'],'fontsize', titlefont,'FontWeight','normal')
colormap(p, redblue)


p = subplot(ynum,xnum,3);  
imagesc(rvec,zvec, Er3)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx3(1,:), cx3(2,:), 'm')
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(3), y0(1), xw, yw])
title(['(c) n_{ant} = ' num2str(den0(3)) 'e17/m^3'],'fontsize', titlefont,'FontWeight','normal')
colormap(p, redblue)


p = subplot(ynum,xnum,4); 
imagesc(rvec,zvec, Er4)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx4(1,:), cx4(2,:), 'm')
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(4), y0(1), xw, yw])
title(['(d) n_{ant} = ' num2str(den0(4)) 'e17/m^3'],'fontsize', titlefont,'FontWeight','normal')
colormap(p, redblue)


p = subplot(ynum,xnum,5); 
imagesc(rvec,zvec, Er5);
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx5(1,:), cx5(2,:), 'm')
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
h=colorbar;
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(5), y0(1), xw, yw])
% set(h, 'ytick', ytickn, 'yticklabel', lbl1)
title(['(e) n_{ant} = ' num2str(den0(5)) 'e17/m^3'],'fontsize', titlefont,'FontWeight','normal')
ylabel(h,'keV/m')
colormap(p, redblue)


%%

cc1 = [-1,1];

%%

p = subplot(ynum,xnum,6);
imagesc(rvec,zvec, Ey1)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx1(1,:), cx1(2,:), 'm')
 fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1) 
set(gca, 'position', [x0(1), y0(2), xw, yw])
ylabel(yylabel,'fontsize', labelfont)
colormap(p, redblue)
text(1.2,  0.69, 'E_\phi', 'fontsize', 17, 'backgroundcolor',[0.8,0.8,0.8])
 

p = subplot(ynum,xnum,7);  
imagesc(rvec,zvec, Ey2)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx2(1,:), cx2(2,:), 'm')
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(2), y0(2), xw, yw])
colormap(p, redblue)


p = subplot(ynum,xnum,8);  
imagesc(rvec,zvec, Ey3)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx3(1,:), cx3(2,:), 'm')
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(3), y0(2), xw, yw])
colormap(p, redblue)


p = subplot(ynum,xnum,9); 
imagesc(rvec,zvec, Ey4)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx4(1,:), cx4(2,:), 'm')
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(4), y0(2), xw, yw])
colormap(p, redblue)


p = subplot(ynum,xnum,10); 
imagesc(rvec,zvec, Ey5);
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx5(1,:), cx5(2,:), 'm')
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
h=colorbar;
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(5), y0(2), xw, yw])
% set(h, 'ytick', ytickn, 'yticklabel', lbl1)
ylabel(h,'keV/m')
colormap(p, redblue)


%%

cc1 = [-3,3];

%%

p = subplot(ynum,xnum,11);
imagesc(rvec,zvec, Ez1)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx1(1,:), cx1(2,:), 'm')
 fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1) 
set(gca, 'position', [x0(1), y0(3), xw, yw])
ylabel(yylabel,'fontsize', labelfont)
colormap(p, redblue)
text(1.2,  0.69, 'E_z', 'fontsize', 17, 'backgroundcolor',[0.8,0.8,0.8])
% text(1.1, -1.95, ' J . E* ', 'fontsize', 17, 'backgroundcolor',[0.8,0.8,0.8], 'rotation', 90)
 

p = subplot(ynum,xnum,12);  
imagesc(rvec,zvec, Ez2)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx2(1,:), cx2(2,:), 'm')
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(2), y0(3), xw, yw])
colormap(p, redblue)


p = subplot(ynum,xnum,13);  
imagesc(rvec,zvec, Ez3)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx3(1,:), cx3(2,:), 'm')
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(3), y0(3), xw, yw])
colormap(p, redblue)


p = subplot(ynum,xnum,14); 
imagesc(rvec,zvec, Ez4)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx4(1,:), cx4(2,:), 'm')
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(4), y0(3), xw, yw])
colormap(p, redblue)


p = subplot(ynum,xnum,15); 
imagesc(rvec,zvec, Ez5);
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx5(1,:), cx5(2,:), 'm')
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
h=colorbar;
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(5), y0(3), xw, yw])
% set(h, 'ytick', ytickn, 'yticklabel', lbl1)
ylabel(h,'keV/m')
colormap(p, redblue)



%%

JE1 = log10(JE1);
JE2 = log10(JE2);
JE3 = log10(JE3);
JE4 = log10(JE4);
JE5 = log10(JE5);

cc3 = [-1,1.5];

p = subplot(ynum,xnum,16); 
imagesc(rvec,zvec, JE1);
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx1(1,:), cx1(2,:), 'm', 'linewidth',1.2)
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx3, 'ylim', yy3, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc3)
set(gca, 'position', [x0(1), y0(4), xw, yw])
ylabel(yylabel,'fontsize', labelfont)
colormap(p, whitejet)
text(1.2,  0.69, 'J.E*', 'fontsize', 17, 'backgroundcolor',[0.8,0.8,0.8])
xlabel(xxlabel, 'fontsize', labelfont)


p = subplot(ynum,xnum,17);
imagesc(rvec,zvec, JE2);
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx2(1,:), cx2(2,:), 'm', 'linewidth',1.2)
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx3, 'ylim', yy3, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc3)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(2), y0(4), xw, yw])
colormap(p, whitejet)
xlabel(xxlabel, 'fontsize', labelfont)


p = subplot(ynum,xnum,18); 
imagesc(rvec,zvec, JE3);
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx3(1,:), cx3(2,:), 'm', 'linewidth',1.2)
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx3, 'ylim', yy3, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc3)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(3), y0(4), xw, yw])
colormap(p, whitejet)
xlabel(xxlabel, 'fontsize', labelfont)


p = subplot(ynum,xnum,19); 
imagesc(rvec,zvec, JE4);
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx4(1,:), cx4(2,:), 'm', 'linewidth',1.2)
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
axis equal
set(gca, 'xlim', xx3, 'ylim', yy3, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc3)
set(gca,  'yticklabel', '')
set(gca, 'position', [x0(4), y0(4), xw, yw])
colormap(p, whitejet)
xlabel(xxlabel, 'fontsize', labelfont)

ytickn  = -1:0.5:1.5;
for ii=1:length(ytickn)
    lbl{ii} = ['10^{',num2str(ytickn(ii),'%3.0f'),'}'];
end
p = subplot(ynum,xnum,20);
imagesc(rvec,zvec, JE5);
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx5(1,:), cx5(2,:), 'm', 'linewidth',1.2)
fillout(rlim24,zlim24, [2, 2.37, 0.2, 0.6],'w');
plot(rlim24, zlim24, 'k');
hold off
h=colorbar;
axis equal
set(gca, 'xlim', xx3, 'ylim', yy3, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc3)
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(5), y0(4), xw, yw])
set(h, 'ytick', ytickn, 'yticklabel', lbl)
ylabel(h,'W/m^3') 
colormap(p, whitejet)
xlabel(xxlabel, 'fontsize', labelfont)
  

saveas(gca, filename0,'epsc')
saveas(gca, filename0,'png')
