clear all

filename0 = 'Fig03' 
% 
load('Rec_antenna', 'rvec', 'zvec', 'rho')
rvec1 = rvec;
zvec1 = zvec;

load('ehtable','whitejet','greyjet','redblue', 'color7');

A_Boundary_DIIID;

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


%%

load('Rec_FWcutoff_ne10e17',  'cutx','cuty');    


%%

load('Fig03b.mat', 'Err', 'Eyr', 'Ezr', 'Et', 'Sc', 'JE');
Er1 = Err;
Ey1 = Eyr;
Ez1 = Ezr;
Et1 = Et;
Sc1 = Sc;
Je1 = log10(JE);

load('Fig03a.mat', 'Err', 'Eyr', 'Ezr', 'Et', 'Sc', 'JE');
Er2 = Err;
Ey2 = Eyr;
Ez2 = Ezr;
Et2 = Et;
Sc2 = Sc;
Je2 = log10(JE);

load('Fig03c.mat', 'Err', 'Eyr', 'Ezr', 'Et', 'Sc', 'JE');
Er3 = Err;
Ey3 = Eyr;
Ez3 = Ezr;
Et3 = Et;
Sc3 = Sc;
Je3 = log10(JE);
 


%%

xx = [min(rvec) min(rvec) max(rvec) max(rvec)];
yy = [min(zvec) max(zvec) max(zvec) min(zvec)];

%%

fontsize0 = 12;
fontsize1 = 15;

%%

hh=figure(1);
hh.Position = [100 100 900 700];
set(gcf,'color','w');
colormap(redblue)

%%

xnum = 5;
ynum = 3;
xsize  = 0.15;
ysize  = 0.25;
yloca  = 0.14 + [0:ynum-1]*(ysize+0.03);
xloca  = 0.09 + [0:xnum-1]*(xsize+0.035);
yloca  = flip(yloca);


%%

xrange = [2,2.5];
yrange = [0.075,0.7];
crange = [0,1];
xtickk = [2.0 2.5];


%%

F1 = subplot(ynum,xnum,1);
imagesc(rvec, zvec, Sc2./max(max(Sc1))); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec1, zvec1, rho, [1.2:0.2:1.4], ':k');
clabel(C,h,'FontSize',12)
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange)
set(gca, 'position', [xloca(1) yloca(1) xsize ysize]);
set(gca, 'XTick',[2.1 2.3 2.5])
set(gca, 'fontsize', fontsize0) 
colormap(F1, flipud(hot));
ylabel('z (m)', 'fontsize', fontsize1);
text(1.77, 0.225, '(a) \Delta\theta = 0^\circ', 'fontsize', fontsize1+2, 'rotation', 90, 'backgroundcolor',[0.75,0.75,0.75]);
title('J_{ext0}', 'fontsize', fontsize1+2);
text(2.2, 0.23, 'LCFS', 'color','k', 'fontsize', fontsize0,'rotation',-80) 

 
 %%

F1 = subplot(ynum,xnum,6);
imagesc(rvec, zvec, Sc1./max(max(Sc2))); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange)
set(gca, 'position', [xloca(1) yloca(2) xsize ysize]);
set(gca, 'XTick',[2.1 2.3 2.5])
set(gca, 'fontsize', fontsize0)
ylabel('z (m)', 'fontsize', fontsize1);
colormap(F1, flipud(hot));
text(1.77, 0.225, '(b) \Delta\theta = -5^\circ', 'fontsize', fontsize1+2, 'rotation', 90, 'backgroundcolor',[0.75,0.75,0.75]);


%%

F1 = subplot(ynum,xnum,11);
imagesc(rvec, zvec, Sc3./max(max(Sc3))); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
hold off
[C] = colorbar;
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange)
set(gca, 'position', [xloca(1) yloca(3) xsize ysize]);
set(gca, 'XTick',[2.1 2.3 2.5])
set(gca, 'fontsize', fontsize0)
ylabel('z (m)', 'fontsize', fontsize1);
colormap(F1, flipud(hot));
ylabel(C, 'arbitrary unit', 'fontsize', fontsize0+1);
xlabel('r (m)', 'fontsize', fontsize1);
set(C, 'location', 'southoutside')
text(1.77, 0.225, '(c) \Delta\theta = 5^\circ', 'fontsize', fontsize1+2, 'rotation', 90, 'backgroundcolor',[0.75,0.75,0.75]);



 
%%

xrange = [1.5,2.5];
yrange = [-0.5,0.75];
crange = [-5,5];
xtickk = [1.7 2.1 2.5];


%%

F1 = subplot(ynum,xnum,2);
imagesc(rvec, zvec, Er2); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
plot(cutx, cuty, 'm')
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'XTick',xtickk)
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange)
set(gca, 'position', [xloca(2) yloca(1) xsize ysize]);
set(gca, 'fontsize', fontsize0)
text(1.6, 0.5, 'FW cutoff', 'color','m', 'fontsize', fontsize0)
colormap(F1, redblue);
title('E_{r}', 'fontsize', fontsize1+2);


%%
F1 = subplot(ynum,xnum,7);
imagesc(rvec, zvec, Er1); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange)
set(gca, 'position', [xloca(2) yloca(2) xsize ysize]);
set(gca, 'XTick',xtickk)
set(gca, 'fontsize', fontsize0);
colormap(F1, redblue); 


 %%
F1 = subplot(ynum,xnum,12);
imagesc(rvec, zvec, Er3); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange)
C=colorbar;
set(gca, 'position', [xloca(2) yloca(3) xsize ysize]);
set(gca, 'XTick',xtickk)
set(gca, 'fontsize', fontsize0); 
colormap(F1, redblue);
xlabel('r (m)', 'fontsize', fontsize1);
ylabel(C,'keV/m', 'fontsize', fontsize0+1);
set(C, 'location', 'southoutside')


%%

crange = [-1,1];

%%

F1 = subplot(ynum,xnum,3);
imagesc(rvec, zvec, Ey2); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange) 
set(gca, 'position', [xloca(3) yloca(1) xsize ysize]);
set(gca, 'XTick',xtickk)
set(gca, 'fontsize', fontsize0)
colormap(F1, redblue);
title('E_{\phi}', 'fontsize', fontsize1+2);

%%
F1 = subplot(ynum,xnum,8);
imagesc(rvec, zvec, Ey1); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange)
set(gca, 'position', [xloca(3) yloca(2) xsize ysize]);
set(gca, 'XTick',xtickk) 
set(gca, 'fontsize', fontsize0) 
colormap(F1, redblue); 


%%
F1 = subplot(ynum,xnum,13);
imagesc(rvec, zvec, Ey3); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange)
C=colorbar
set(gca, 'position', [xloca(3) yloca(3) xsize ysize]);
set(gca, 'XTick',xtickk) 
set(gca, 'fontsize', fontsize0)
xlabel('r (m)', 'fontsize', fontsize1); 
colormap(F1, redblue);
ylabel(C,'keV/m', 'fontsize', fontsize0+1);
set(C, 'location', 'southoutside')


%%

ytickn  = -1:1:2;
for ii=1:length(ytickn)
    lbl{ii} = ['10^{',num2str(ytickn(ii),'%3.0f'),'}'];
end

crange =[-1, 2];


%%
F1 = subplot(ynum,xnum,5);
imagesc(rvec, zvec, Je2); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange) 
set(gca, 'position', [xloca(5) yloca(1) xsize ysize]);
set(gca, 'XTick',xtickk) 
set(gca, 'fontsize', fontsize0)
colormap(F1, whitejet); 
title('J.E*', 'fontsize', fontsize1+2);


%%
F1 = subplot(ynum,xnum,10);
imagesc(rvec, zvec, Je1); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange)
set(gca, 'position', [xloca(5) yloca(2) xsize ysize]);
set(gca, 'XTick',xtickk)
set(gca, 'fontsize', fontsize0)
colormap(F1, whitejet);


%%
F1 = subplot(ynum,xnum,15);
imagesc(rvec, zvec, Je3); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange)
C=colorbar;
set(gca, 'position', [xloca(5) yloca(3) xsize ysize]);
set(gca, 'XTick',xtickk) 
set(gca, 'fontsize', fontsize0)
colormap(F1, whitejet);
xlabel('r (m)', 'fontsize', fontsize1);
ylabel(C,'W/m^3', 'fontsize', fontsize0+1);
set(C, 'ytick', ytickn, 'yticklabel', lbl)
set(C, 'location', 'southoutside')



%%

crange = [-5,5];

%%

F1 = subplot(ynum,xnum,4);
imagesc(rvec, zvec, Ez2); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange);
set(gca, 'position', [xloca(4) yloca(1) xsize ysize]);
set(gca, 'XTick',xtickk)
set(gca, 'fontsize', fontsize0) 
colormap(F1, redblue); 
title('E_{z}', 'fontsize', fontsize1+2);


%%
F1 = subplot(ynum,xnum,9);
imagesc(rvec, zvec, Ez1); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange)
set(gca, 'position', [xloca(4) yloca(2) xsize ysize]);
set(gca, 'XTick',xtickk) 
set(gca, 'fontsize', fontsize0) 
colormap(F1, redblue); 


%%
F1 = subplot(ynum,xnum,14);
imagesc(rvec, zvec, Ez3); 
hold on
plot(rbbbs, zbbbs, 'k--'); 
[C,h] = contour(rvec, zvec, rho, [1.2:0.2:1.4], ':k');
hold off
axis equal
set(gca, 'ydir', 'normal');
set(gca, 'xlim', xrange, 'ylim', yrange, 'clim', crange)
C=colorbar;
set(gca, 'position', [xloca(4) yloca(3) xsize ysize]);
set(gca, 'XTick',xtickk) 
set(gca, 'fontsize', fontsize0) 
colormap(F1, redblue);
xlabel('r (m)', 'fontsize', fontsize1);
ylabel(C,'keV/m', 'fontsize', fontsize0+1);
set(C, 'location', 'southoutside')


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