 addpath C:\Users\sheila.dwyer\Documents\MATLAB\alm-master
close all
clear classes

goo = beamPath;

%Prometheus beam profile
zScan = (6+7.5+1+(24-[24,20,15, 10, 5]))*25.4e-3;
hWidth = [958, 1197, 1500, 1815, 2110]*1e-6;
vWidth = [1120, 1450, 1890, 2315, 2720]*1e-6;
goo.seedWaist(300e-6,-0.1, 532e-9)

green_path=beamPath;
green_path.seedWaist(254e-6, -0.1, 532e-9);

gooh = goo.fitBeamWidth(zScan,hWidth);
gooh.getWaists;
goov = goo.fitBeamWidth(zScan,vWidth);
goov.getWaists;
zdomain = -2:.001:2;%linspace(min(zScan),max(zScan),100);
figure(1)
gooh
hold on
plot(zScan,hWidth,'bo')
gooh.plotBeamWidth(zdomain,'b')
gooh.plotBeams(zdomain,.5e-3,'b')
%gooh.plotSummary(zdomain)
plot(zScan,vWidth,'ro')
goov.plotBeamWidth(zdomain,'r')
goov.plotBeams(zdomain,-.5e-3,'r')
hold off


% plot the results
zplot = 0:.01:0.4;
%CLF_path.plotSummary(zplot);




fiber = beamPath;
fiberScan = [117, 207, 307, 410, 512, 614]*1e-3;
f_vWidth = [408, 428, 473, 534, 633, 762]*1e-6;
f_hWidth = [452, 470, 521, 575, 647, 743]*1e-6;
fiber.seedWaist(300e-6,0, 532e-9);

fiberh = fiber.fitBeamWidth(fiberScan, f_hWidth)
fiberv = fiber.fitBeamWidth(fiberScan, f_vWidth)

figure(2)
hold on
plot(fiberScan,f_hWidth,'bo')
fiberh.plotBeamWidth(zdomain,'b')
%fiberh.plotBeams(zdomain,'b')
plot(fiberScan,f_vWidth,'ro');
fiberv.plotBeamWidth(zdomain,'r');
%fiberv.plotBeams(zdomain,-.5e-3,'r')
hold off
xlabel('meters from fiber port')
saveas(gcf, 'diamond_fiber_mode.png')
gooh.addComponent(component.lens(0.4123,0.43,'f=2578mm'));   %results in a 282um wasit at 0.6902m
%gooh.addComponenet(component.lens())
gooh.getWaists
figure(3)
gooh.plotBeamWidth(zdomain,'b')

target_q = fiberh.qPropagate(0)
target_q_v = fiberv.qPropagate(0)
result_q = gooh.qPropagate(1)

fiber_port_location = -1*result_q.waistZ+1 - target_q.waistZ
