diff --git a/src/new/finesse/prepare_files/FT_DR_FP_MICH_initial_tuning.m b/src/new/finesse/prepare_files/FT_DR_FP_MICH_initial_tuning.m index 83e5aaa51b3c917b311b8a8dae94cee49cc890eb..2584612b7a7401ebd83ecfe2abd033a40c386ba7 100644 --- a/src/new/finesse/prepare_files/FT_DR_FP_MICH_initial_tuning.m +++ b/src/new/finesse/prepare_files/FT_DR_FP_MICH_initial_tuning.m @@ -94,12 +94,12 @@ function [tunings] = FT_DR_FP_MICH_initial_tuning(infile,outfile,commands,mirror tuning_threshold = 1e-10; relative_err = 1e-2; % Number of zooms - zooms = 3; + zooms = 4; % Number of points and ranges for the first and second round of scans npoints = 1000; - range = 120; + range = 180; zoom_npoints = 500; - zoom_range = 2; + zoom_range = 20; % Initilise Finesse FT = FT_init_Finesse(); @@ -149,8 +149,9 @@ function [tunings] = FT_DR_FP_MICH_initial_tuning(infile,outfile,commands,mirror % Read in intial maxtem maxtem = FT_read_maxtem_from_blocks(blocks); - % Start off with maxtem 0 - blocks = FT_replace_maxtem_in_blocks(blocks,0); + % Start off with maxtem at minimum (i.e. max order of tem modes) + [gc,max_order] = FT_read_TEM_from_blocks(blocks) + blocks = FT_replace_maxtem_in_blocks(blocks,max_order); % Perform tunigns twice, once with maxtem 0 and once with the value for % maxtem set in infile @@ -283,8 +284,12 @@ function [tunings] = FT_DR_FP_MICH_initial_tuning(infile,outfile,commands,mirror tuning(5) = phi_SRM; end - % Writing new output file, adding command lines back in - FT_write_blocks_into_file([blocks,command_blocks],outfile); + if length(commands)>0 + % Writing new output file, adding command lines back in + FT_write_blocks_into_file([blocks,command_blocks],outfile); + else + FT_write_blocks_into_file(blocks,outfile); + end end diff --git a/src/new/finesse/prepare_files/FT_read_TEM_from_blocks.m b/src/new/finesse/prepare_files/FT_read_TEM_from_blocks.m new file mode 100644 index 0000000000000000000000000000000000000000..676af8e76c6a222d1915f275162259dcd6f81e01 --- /dev/null +++ b/src/new/finesse/prepare_files/FT_read_TEM_from_blocks.m @@ -0,0 +1,85 @@ +%-------------------------------------------------------------------------- +% function [gc,max_order] = FT_read_TEM_from_blocks(blocks) +% +% A function for Matlab which reads the tem lines defining the mode content +% of the laser input beam from blocks containing FINESSE commands. This +% mode content is returned in the structure gc (see +% FT_init_gauss_coefficients.m). +% +% blocks: Block structure storing FINESSE code. +% +% gc: Structure storing coefficients describing the mode content of +% the laser beam found in blocks. +% max_order:The maximum order of the modes in the inupt beam +% +% Charlotte Bond 24.05.2013 +%-------------------------------------------------------------------------- +% + +function [gc,max_order] = FT_read_TEM_from_blocks(blocks) + + baseid = 'read_TEM_from_blocks'; + + % Find blocks where tems (or tem*s) are defined + % First look for tem + Gtype = 'HG'; + temtype = 'tem'; + block_idx = FT_find_element_in_all_blocks(blocks,1,'tem'); + + % If tem isn't found look for tem* + if length(block_idx)==0 + Gtype = 'LG'; + temtype = 'tem*'; + block_idx = FT_find_element_in_all_blocks(blocks,1,'tem*'); + + end + + if length(block_idx)==0 + % If can't find tem commands all laser power(and amp) is in + % HG00 mode + Gtype = 'HG'; + max_order = 0; + gc = FT_init_gauss_coefficients(Gtype,max_order); + gc = FT_set_mode_coefficient(gc,1,0,0); + else + % Otherwise read each tem/tem* mode + n=0; + for i=1:length(block_idx) + + tmp_block = blocks(block_idx(i)); + line_idx = FT_find_element_in_active_block(tmp_block,1,temtype); + + for j=1:length(line_idx) + + tmp_line = tmp_block.txt_lines(line_idx(j)); + n=n+1; + + % Read mode indices and coefficient + index1(n) = cell2mat(FT_parse_line(tmp_line,3)); + index2(n) = cell2mat(FT_parse_line(tmp_line,4)); + power = cell2mat(FT_parse_line(tmp_line,5)); + phase = cell2mat(FT_parse_line(tmp_line,6)); + c(n) = sqrt(power)*exp(-1i*phase*pi/180); + + end + + end + + % Calculate maximum order of specified tem modes + if strcmp(Gtype,'HG') + max_order = max(index1+index2); + else + max_order = max(2*index1+abs(index2)); + end + % Create gc structure storing mode amplitudes + gc = FT_init_gauss_coefficients(Gtype,max_order); + for n=1:length(index1) + gc = FT_set_mode_coefficient(gc,c(n),index1(n),index2(n)); + end + + + end + + +end + diff --git a/src/new/finesse/prepare_files/FT_read_maxtem_from_blocks.m b/src/new/finesse/prepare_files/FT_read_maxtem_from_blocks.m index 93344a9aa165916512d3e547d7c0148ba1f530de..c20f6cf17637852029ba2480283c660fe00f6395 100644 --- a/src/new/finesse/prepare_files/FT_read_maxtem_from_blocks.m +++ b/src/new/finesse/prepare_files/FT_read_maxtem_from_blocks.m @@ -15,16 +15,20 @@ function [maxtem] = FT_read_maxtem_from_blocks(blocks) % Find block in which maxtem is defined - block_idx = FT_find_text_in_all_blocks(blocks,'maxtem'); + block_idx = FT_find_element_in_all_blocks(blocks,1,'maxtem'); - if length(block_idx)~=0 + if length(block_idx)==1 % Find line in block in whih maxtem is defined line_idx = FT_find_element_in_active_block(blocks(block_idx),1,'maxtem'); % Read maxtem from line maxtem = cell2mat(FT_parse_line(blocks(block_idx).txt_lines(line_idx),2)); - else + elseif length(block_idx)==0 maxtem = 0; + else + result=sprintf('Invalid kat file: maxtem declared more than once'); + msgid=[baseid,'checkarguments']; + error(msgid,result) end end