set(0, 'DefaultLineLineWidth', 0.75)
set(0, 'DefaultLineMarkerSize', 12)
set(0, 'DefaultAxesLineWidth', 0.75)
set(0, 'DefaultTextFontSize', 9)
set(0, 'DefaultAxesFontSize', 9)
set(0, 'DefaultTextHorizontalAlignment', 'left')
set(0, 'DefaultAxesBox', 'on')

close all, clear all
load lisstcalrings

figure, hold on
set(gcf, 'paperunits', 'inches', 'paperorientation', 'portrait', 'papersize', [3.1 2.9])
set(gcf, 'paperpositionmode', 'manual', 'paperposition', [0.05 0.05 3.0 2.8])
plot(1:32, chi1_rf2, 'b.-')
plot([1:32; 1:32], [chi1_rf2+chi1_se_rf2; chi1_rf2-chi1_se_rf2], 'k-')
ylabel('\chi_{i} [m^{-1} sr^{-1} count^{-1}]')
xlabel('Detector ring, i')
set(gca, 'xlim',[0 33], 'xgrid','on', 'xtick',[10 20 30])
set(gca, 'Box','on')	


figure, hold on
set(gcf, 'paperunits', 'inches', 'paperorientation', 'portrait', 'papersize', [3.1 2.9])
set(gcf, 'paperpositionmode', 'manual', 'paperposition', [0.05 0.05 3.0 2.8])
plot(1:32, chi1_mad_rf2, 'b.-'),
set(gca, 'xlim',[0 33], 'xgrid','on', 'xtick',[10 20 30])
xlabel('Detector ring, i')
ylabel('\chi_{i} fit mean relative error')


for kr = [4 6 7 15 19 32]

	disp(['DETECTOR RING ' num2str(kr)])

	x = [];
	dx = [];
	y = [];
	dy = [];
	
	figure, hold on
	set(gcf, 'paperunits', 'inches', 'paperorientation', 'portrait', 'papersize', [3.1 2.9])
	set(gcf, 'paperpositionmode', 'manual', 'paperposition', [0.05 0.05 3.0 2.8])
	
	for kf = 1:size(runlist,1)
		thisx = CSCAT_m{kf}(CSCAT_RINGS{kf}==kr);
		thisdx = 0.5.*(CSCAT_p84{kf}(CSCAT_RINGS{kf}==kr)-CSCAT_p16{kf}(CSCAT_RINGS{kf}==kr));
		thisy = VSFBAR_m{kf}(CSCAT_RINGS{kf}==kr);
		thisdy = VSFBAR_s{kf}(CSCAT_RINGS{kf}==kr);
		x = [x; thisx];
		dx = [dx; thisdx];
		y = [y; thisy];
		dy = [dy; thisdy];
		plot(thisx,thisy, runlist{kf,3},'markersize',6, 'MarkerEdgeColor',[0 0 0],'MarkerFaceColor',runlist{kf,2})
	end
	
	errbary = [y+3*dy y-3*dy]';
	errbarx = [x+3*dx x-3*dx]';
	errbary(errbary<=0) = min([min(min(errbary(errbary>0))) min(y(y>0))]);
	errbarx(errbarx<=0) = min([min(min(errbarx(errbarx>0))) min(x(x>0))]);
	
	plot([x x]',errbary,'k-')
	plot(errbarx,[y y]','k-')
	
	set(gca, 'xscale','log', 'yscale','log', 'box','on')
	
	%xhat = logspace(log10(min(x)),log10(max(x)), 100);
	xhat = get(gca, 'xlim')
	yhat_rf2 = chi1_rf2(kr).*xhat;
	plot(xhat, yhat_rf2, 'r-')
		
	
	%axis tight
	xlabel(['pscat_{' num2str(kr) '} [counts]'])
	ylabel(['\langle\beta_{Mie}\rangle_{' num2str(kr) '} [m^{-1} sr^{-1}]'])
	%title(['DETECTOR RING ' num2str(kr) ', n=' num2str(length(x))])

	
	
end
	

figure(1)
print(gcf, '-depsc', 'fig-chi_vs_ring')

figure(2)
print(gcf, '-depsc', 'fig-chifiterr_vs_ring')

figure(3)
print(gcf, '-depsc', 'fig-beta_vs_pscat_4')

figure(4)
print(gcf, '-depsc', 'fig-beta_vs_pscat_6')

figure(5)
print(gcf, '-depsc', 'fig-beta_vs_pscat_7')

figure(6)
print(gcf, '-depsc', 'fig-beta_vs_pscat_15')

figure(7)
print(gcf, '-depsc', 'fig-beta_vs_pscat_19')

figure(8)
print(gcf, '-depsc', 'fig-beta_vs_pscat_32')

