clear all


filename0 = 'Fig04' 

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

colormap(redblue)

A_Boundary_DIIID;

load('Rec_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('Fig04a.mat', 'Err', 'Eyr', 'Ezr', 'Et', 'JE', 'cx');
Er1 = Err;
Ey1 = Eyr;
Ez1 = Ezr;
Et1 = Et;
JE1 = JE;  
cx1 = cx;

 
%% DEN #2
ii = 2;

load('Fig04b.mat', 'Err', 'Eyr', 'Ezr', 'Et', 'JE', 'cx');
Er2 = Err;
Ey2 = Eyr;
Ez2 = Ezr;
Et2 = Et;
JE2 = JE;  
cx2 = cx;

 
%% DEN #3
ii = 3;
load('Fig04c.mat', 'Err', 'Eyr', 'Ezr', 'Et', 'JE', 'cx');
Er3 = Err;
Ey3 = Eyr;
Ez3 = Ezr;
Et3 = Et;
JE3 = JE;  
cx3 = cx;


%% DEN #4
ii = 4;
load('Fig04d.mat', 'Err', 'Eyr', 'Ezr', 'Et', 'JE', 'cx');
Er4 = Err;
Ey4 = Eyr;
Ez4 = Ezr;
Et4 = Et;
JE4 = JE;  
cx4 = cx;

%% DEN #5
ii = 5;
load('Fig04e.mat', 'Err', 'Eyr', 'Ezr', 'Et', 'JE', 'cx');
Er5 = Err;
Ey5 = Eyr;
Ez5 = Ezr;
Et5 = Et;
JE5 = JE;  
cx5 = cx;


%%
 
xx  = [min(rvec), max(rvec)];
yy  = [min(zvec), max(zvec)];
xx2  = [2, max(rvec)];
yy2  = [-0.2, 0.6092];

cc2 = [-1,1.5];

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.095 + [0:xnum-1]*(xw+0.01);
y0  = 0.05 + [0:ynum-1]*(yw+0.022);
y0  = flip(y0);


%%

hh=figure(1);
hh.Position = [3 100 850 1050];
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', 'linewidth', 1.25)
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')
text(0.2, 0.91, 'E_r', 'fontsize', 20, 'backgroundcolor',[0.8,0.8,0.8]) 
text(1.6, -1.05, 'FW cutoff', 'color','m', 'fontsize', 14)
colormap(p, redblue)


p = subplot(ynum,xnum,2);  
imagesc(rvec,zvec, Er2)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx2(1,:), cx2(2,:), 'm', 'linewidth', 1.25)
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); colormap(p, redblue)
imagesc(rvec,zvec, Er3)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx3(1,:), cx3(2,:), 'm', 'linewidth', 1.25)
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); colormap(p, redblue)
imagesc(rvec,zvec, Er4)
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx4(1,:), cx4(2,:), 'm', 'linewidth', 1.25)
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); colormap(p, redblue)
imagesc(rvec,zvec, Er5);
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx5(1,:), cx5(2,:), 'm', 'linewidth', 1.25)
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])
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); colormap(p, redblue)
imagesc(rvec,zvec, Ey1)
hold on
plot(rbbbs, zbbbs, lcfscolor)
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
% set(gca, 'xtick',[2.2,2.4]) 
set(gca, 'position', [x0(1), y0(2), xw, yw])
ylabel(yylabel,'fontsize', labelfont) 
text(0.2, 0.91, 'E_\phi', 'fontsize', 20, 'backgroundcolor',[0.8,0.8,0.8]) 
colormap(p, redblue)
text(1.4, -0.7, 'LCFS', 'color','k', 'fontsize', 14)


p = subplot(ynum,xnum,7); colormap(p, redblue)
imagesc(rvec,zvec, Ey2)
hold on
plot(rbbbs, zbbbs, lcfscolor)
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
% set(gca, 'xtick',[2.2,2.4])
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(2), y0(2), xw, yw])
colormap(p, redblue)


p = subplot(ynum,xnum,8); colormap(p, redblue)
imagesc(rvec,zvec, Ey3)
hold on
plot(rbbbs, zbbbs, lcfscolor)
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
% set(gca, 'xtick',[2.2,2.4])
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(3), y0(2), xw, yw])
colormap(p, redblue)


p = subplot(ynum,xnum,9); colormap(p, redblue)
imagesc(rvec,zvec, Ey4)
hold on
plot(rbbbs, zbbbs, lcfscolor)
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
% set(gca, 'xtick',[2.2,2.4])
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(4), y0(2), xw, yw])
colormap(p, redblue)


p = subplot(ynum,xnum,10); colormap(p, redblue)
imagesc(rvec,zvec, Ey5);
hold on
plot(rbbbs, zbbbs, lcfscolor)
hold off
h=colorbar;
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
% set(gca, 'xtick',[2.2,2.4])
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(5), y0(2), xw, yw])
ylabel(h,'keV/m')
colormap(p, redblue)


%%

cc1 = [-3,3];

%%

p = subplot(ynum,xnum,11); colormap(p, redblue)
imagesc(rvec,zvec, Ez1)
hold on
plot(rbbbs, zbbbs, lcfscolor)
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
% set(gca, 'xtick',[2.2,2.4]) 
set(gca, 'position', [x0(1), y0(3), xw, yw])
ylabel(yylabel,'fontsize', labelfont) 
text(0.2, 0.91, 'E_z', 'fontsize', 20, 'backgroundcolor',[0.8,0.8,0.8]) 
colormap(p, redblue)


p = subplot(ynum,xnum,12); colormap(p, redblue)
imagesc(rvec,zvec, Ez2)
hold on
plot(rbbbs, zbbbs, lcfscolor)
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
% set(gca, 'xtick',[2.2,2.4])
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(2), y0(3), xw, yw])
colormap(p, redblue)


p = subplot(ynum,xnum,13); colormap(p, redblue)
imagesc(rvec,zvec, Ez3)
hold on
plot(rbbbs, zbbbs, lcfscolor)
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
% set(gca, 'xtick',[2.2,2.4])
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(3), y0(3), xw, yw])
colormap(p, redblue)


p = subplot(ynum,xnum,14); colormap(p, redblue)
imagesc(rvec,zvec, Ez4)
hold on
plot(rbbbs, zbbbs, lcfscolor)
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
% set(gca, 'xtick',[2.2,2.4])
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(4), y0(3), xw, yw])
colormap(p, redblue)


p = subplot(ynum,xnum,15); colormap(p, redblue)
imagesc(rvec,zvec, Ez5);
hold on
plot(rbbbs, zbbbs, lcfscolor)
hold off
h=colorbar;
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc1)
% set(gca, 'xtick',[2.2,2.4])
set(gca, 'yticklabel', '')
set(gca, 'position', [x0(5), y0(3), xw, yw])
ylabel(h,'keV/m')
colormap(p, redblue)



%%


p = subplot(ynum,xnum,16); 
imagesc(rvec,zvec, log10(JE1));
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx1(1,:), cx1(2,:), 'm', 'linewidth', 1.25)
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc2)
set(gca, 'position', [x0(1), y0(4), xw, yw])
ylabel(yylabel,'fontsize', labelfont)
colormap(p, whitejet)
text(0.2, 0.95, 'J.E*', 'fontsize', 20, 'backgroundcolor',[0.8,0.8,0.8]);%, 'rotation', 90)
xlabel(xxlabel, 'fontsize', labelfont)


p = subplot(ynum,xnum,17);
imagesc(rvec,zvec, log10(JE2));
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx2(1,:), cx2(2,:), 'm', 'linewidth', 1.25)
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc2)
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, log10(JE3));
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx3(1,:), cx3(2,:), 'm', 'linewidth', 1.25)
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc2)
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, log10(JE4));
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx4(1,:), cx4(2,:), 'm', 'linewidth', 1.25)
hold off
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc2)
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, log10(JE5));
hold on
plot(rbbbs, zbbbs, lcfscolor)
plot(cx5(1,:), cx5(2,:), 'm', 'linewidth', 1.25)
hold off
h=colorbar;
axis equal
set(gca, 'xlim', xx, 'ylim', yy, 'fontsize', axisfont, 'ydir', 'normal')
set(gca, 'clim', cc2)
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')
