Skip to content
Snippets Groups Projects
Commit c729da0f authored by Charlotte Bond's avatar Charlotte Bond
Browse files

making functions more compatible with arbitrary input, i.e. no longer just...

making functions more compatible with arbitrary input, i.e. no longer just allows 1 space between mirror and name, i.e. m ETM
parent 99db0190
No related branches found
No related tags found
No related merge requests found
...@@ -35,30 +35,49 @@ function [block_idx,line_idx,mtype] = FT_find_mirror_in_blocks(blocks,mirror) ...@@ -35,30 +35,49 @@ function [block_idx,line_idx,mtype] = FT_find_mirror_in_blocks(blocks,mirror)
% Check for 'm' type and 'bs' type % Check for 'm' type and 'bs' type
while j<=2 while j<=2
mirror_str = sprintf('%s%s %s ',mcommand{j},mtype_str{i+1},mirror); % 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);
% Find block where mirror is defined % Search through blocks
block_idx = FT_find_text_in_all_blocks(blocks,mirror_str); b=1;
while b<=length(bidx)
% If mirror is found quit loop block_idx = bidx(b);
if length(block_idx)~=0 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; mtype = i;
i=3; i=3;
j=3; j=3;
elseif i==2 && j==2 b=length(bidx);
l=length(lidx);
elseif i==2 && j==2 && b==length(bidx) && l==length(lidx)
% Error message if mirror isn't found % Error message if mirror isn't found
result=sprintf('Component not found: mirror "%s" not found in blocks',mirror); result=sprintf('Component not found: mirror "%s" not found in blocks',mirror);
msgid=[baseid,':checkarguments'] msgid=[baseid,':checkarguments']
error(msgid,result); error(msgid,result);
end end
l=l+1;
end
b=b+1;
end
j=j+1; j=j+1;
end end
i=i+1; i=i+1;
end end
% Locate mirror line in block
line_idx = FT_find_text_in_active_block(blocks(block_idx),mirror_str);
end end
...@@ -18,8 +18,10 @@ function [const,block_idx] = FT_read_const_from_blocks(blocks,const_name) ...@@ -18,8 +18,10 @@ function [const,block_idx] = FT_read_const_from_blocks(blocks,const_name)
baseid = 'find_const_in_all_blocks'; baseid = 'find_const_in_all_blocks';
% Find block in which constant is defined % Find blocks where constant is defined
block_idx = FT_find_text_in_all_blocks(blocks,sprintf('const %s',const_name)); 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 % Error message if the constant name isn't found in the blocks or
% contant declared more than once % contant declared more than once
......
...@@ -17,11 +17,8 @@ ...@@ -17,11 +17,8 @@
function [blocks] = FT_replace_const_in_blocks(blocks,const_name,const) 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 % 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 % Find line where constant is defined
lidx = FT_find_element_in_active_block(blocks(block_idx),2,const_name); lidx = FT_find_element_in_active_block(blocks(block_idx),2,const_name);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment