From c729da0f1ec3ccea62bccd6bc1df4211058a1fec Mon Sep 17 00:00:00 2001 From: Charlotte Bond <czb@star.sr.bham.ac.uk> Date: Thu, 16 May 2013 13:46:46 +0100 Subject: [PATCH] making functions more compatible with arbitrary input, i.e. no longer just allows 1 space between mirror and name, i.e. m ETM --- .../prepare_files/FT_find_mirror_in_blocks.m | 57 ++++++++++++------- .../prepare_files/FT_read_const_from_blocks.m | 6 +- .../FT_replace_const_in_blocks.m | 5 +- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/new/finesse/prepare_files/FT_find_mirror_in_blocks.m b/src/new/finesse/prepare_files/FT_find_mirror_in_blocks.m index d85c63d..eda8779 100644 --- a/src/new/finesse/prepare_files/FT_find_mirror_in_blocks.m +++ b/src/new/finesse/prepare_files/FT_find_mirror_in_blocks.m @@ -35,30 +35,49 @@ function [block_idx,line_idx,mtype] = FT_find_mirror_in_blocks(blocks,mirror) % Check for 'm' type and 'bs' type while j<=2 - mirror_str = sprintf('%s%s %s ',mcommand{j},mtype_str{i+1},mirror); - - % Find block where mirror is defined - block_idx = FT_find_text_in_all_blocks(blocks,mirror_str); - - % If mirror is found quit loop - if length(block_idx)~=0 - mtype = i; - i=3; - j=3; - elseif i==2 && j==2 - % Error message if mirror isn't found - result=sprintf('Component not found: mirror "%s" not found in blocks',mirror); - msgid=[baseid,':checkarguments'] - error(msgid,result); + % Find blocks/lines where mirrors are defined + mirror_str = sprintf('%s%s',mcommand{j},mtype_str{i+1}); + [bidx,L1,L2,lines] = FT_find_element_in_all_blocks(blocks,1,mirror_str); + + % Search through blocks + b=1; + while b<=length(bidx) + + block_idx = bidx(b); + lidx = lines(L1(b):L2(b)); + + % Search through lines + l=1; + while l<=length(lidx) + + line_idx = lidx(l); + + % Find mirror name defined on line + line_str = blocks(block_idx).txt_lines(line_idx); + tmp_mirror = FT_get_element_from_line(line_str,2); + + % Does it match the name of the mirror we're lookign + % for. If not keep looking. + if strcmp(tmp_mirror,mirror) + mtype = i; + i=3; + j=3; + b=length(bidx); + l=length(lidx); + elseif i==2 && j==2 && b==length(bidx) && l==length(lidx) + % Error message if mirror isn't found + result=sprintf('Component not found: mirror "%s" not found in blocks',mirror); + msgid=[baseid,':checkarguments'] + error(msgid,result); + end + l=l+1; + end + b=b+1; end j=j+1; end - i=i+1; end - - % Locate mirror line in block - line_idx = FT_find_text_in_active_block(blocks(block_idx),mirror_str); end diff --git a/src/new/finesse/prepare_files/FT_read_const_from_blocks.m b/src/new/finesse/prepare_files/FT_read_const_from_blocks.m index 89b3b36..30e2fd8 100644 --- a/src/new/finesse/prepare_files/FT_read_const_from_blocks.m +++ b/src/new/finesse/prepare_files/FT_read_const_from_blocks.m @@ -18,8 +18,10 @@ function [const,block_idx] = FT_read_const_from_blocks(blocks,const_name) baseid = 'find_const_in_all_blocks'; - % Find block in which constant is defined - block_idx = FT_find_text_in_all_blocks(blocks,sprintf('const %s',const_name)); + % Find blocks where constant is defined + bidx = FT_find_element_in_all_blocks(blocks,1,'const'); + bidx2 = FT_find_element_in_all_blocks(blocks(bidx),2,const_name); + block_idx = bidx(bidx2); % Error message if the constant name isn't found in the blocks or % contant declared more than once diff --git a/src/new/finesse/prepare_files/FT_replace_const_in_blocks.m b/src/new/finesse/prepare_files/FT_replace_const_in_blocks.m index 0af63cf..d30e546 100644 --- a/src/new/finesse/prepare_files/FT_replace_const_in_blocks.m +++ b/src/new/finesse/prepare_files/FT_replace_const_in_blocks.m @@ -17,11 +17,8 @@ function [blocks] = FT_replace_const_in_blocks(blocks,const_name,const) - % Define string where the constant is defined - const_str = sprintf('const %s ',const_name); - % Find block in which constant is defined - block_idx = FT_find_text_in_all_blocks(blocks,const_str); + [const_old,block_idx] = FT_read_const_from_blocks(blocks,const_name); % Find line where constant is defined lidx = FT_find_element_in_active_block(blocks(block_idx),2,const_name); -- GitLab