f_empty = load('cmos_a0.64_empty_flux.dat');
f_flat = load('cmos_a0.64_flat_flux.dat');
f_texture = load('cmos_a0.64_texture_flux.dat');

lambdas = 1./f_empty(:,1);

R_texture = -f_texture(:,2)./f_empty(:,3);
A_texture_grid = (f_texture(:,3)-f_texture(:,4))./f_empty(:,3);
A_texture_sub = (f_texture(:,4)-f_texture(:,5))./f_empty(:,3);

R_flat = -f_flat(:,2)./f_empty(:,3);
A_flat_grid = (f_flat(:,3)-f_flat(:,4))./f_empty(:,3);
A_flat_sub = (f_flat(:,4)-f_flat(:,5))./f_empty(:,3);

lambdas_linear = linspace(0.7,1.0,50).';

R_texture_linear = interp1(lambdas,R_texture,lambdas_linear,"spline","extrap");
A_texture_grid_linear = interp1(lambdas,A_texture_grid,lambdas_linear,"spline","extrap");
A_texture_sub_linear = interp1(lambdas,A_texture_sub,lambdas_linear,"spline","extrap");

A_flat_sub_linear = interp1(lambdas,A_flat_sub,lambdas_linear,"spline","extrap");

plot(lambdas_linear,A_texture_sub_linear,'bo-',lambdas_linear,A_texture_grid_linear,'ro-',lambdas_linear,R_texture_linear,'go-');
axis([0.7 1.0 0 0.5]);
set(gca, 'xtick', [0.7:0.1:1.0]);
legend("Si substrate (absorption)", "W grid (absorption)", "device (reflection)", "location", "northeast");

figure;
plot(lambdas_linear,A_texture_sub_linear./A_flat_sub_linear,'mo-');
axis([0.7 1.0 1.4 2.0]);
set(gca, 'xtick', [0.7:0.1:1.0]);
legend("relative enhancement","location","southeast");

disp(sprintf("flat substrate absorption:     %0.6f, %0.6f",mean(A_flat_sub_linear),std(A_flat_sub_linear,1)));
disp(sprintf("textured substrate absorption:     %0.6f, %0.6f",mean(A_texture_sub_linear),std(A_texture_sub_linear,1)));
