📄 readsb.m
字号:
%logic for adding input/output
lgc_in = (in(in_b+3)>1) & (pt1~=2); %logic for input needs mux
lgc_in = lgc_in & (pt1 ~= 6) & (pt1 ~= 8) & (pt1 ~= 10) & (pt1 ~=9);
%product and sum do not need a mux
%lgc_in = lgc_in & (pt1 ~= 65) ;
%the following always need a mux.
lgc_in = lgc_in | (pt1==33) | (pt1==34) | (pt1==35) | (pt1==28) | (pt1==29) | (pt1==62);
lgc_ot = (in(in_b+4) > 1) & (pt1~=2); %logic for output needs Demux
lgc_ot = lgc_ot | (pt1>=54 & pt1<=57);
%resize block size
mask = 0;
if lgc_in & lgc_ot
mask = 1;
elseif lgc_in
mask = 2;
elseif lgc_ot
mask = 3;
end;
% add block
fprintf('.')
[temp, note_name] = sb2slmng(pt1,[chain '/' deblank(blkname)],posit,in(in_b:in_e),...
fl(fl_b:fl_e),[name_in(now,1),mask, rotat],...
name_fl(now,:),st(st_b:st_e));
% drawnow;
err = err + temp;
posit(4) = max(posit(4), 5*max(in(in_b+3),in(in_b+4)));
posit(3:4)=posit(1:2)+posit(3:4);
if isempty(note_name)
set_param([chain '/' deblank(blkname)], 'position', posit);
if hiden
set_param([chain '/' deblank(blkname)], 'hide name',0);
else
set_param([chain '/' deblank(blkname)], 'move name',0);
end
else
set_param(note_name, 'position', floor([(posit(1)+posit(3))/2, (posit(2)+posit(4))/2, (posit(1)+posit(3))/2, (posit(2)+posit(4))/2]));
end;
%save positions for line layout
blklocs(i,1:2) = posit(1:2);
blklocs(i,3:4) = posit(3:4);
orienta(i) = rotat*2;
% relocate all input blocks
dsl = in(in_b+7) - 2;
if in(in_b+3) > 0
for ji = 1:in(in_b+3)
innumb = in(in_b + dsl + ji + in(in_b+3));
if in(in_b + dsl + ji) == 0 & innumb > 0
xx = get_param([chain '/input' num2str(innumb)], 'position');
yy = get_param([chain '/' deblank(blkname)], 'inport');
yy = yy(ji,:);
yy(1) = max(0, yy(1)+(30+rem(ji,5)*25)*(2*rotat-1));
yy(2) = max(0,yy(2) - 10);
if ~isempty(xx) & ~isempty(yy)
if xx(1) > yy(1)
set_param([chain '/input' num2str(innumb)], 'position',[yy yy+20],...
'hide name',0);
in_ori(innumb) = 0;
if rotat
set_param([chain '/input' num2str(innumb)],'orientation',2);
in_ori(innumb) = 2;
end;
end;
end;
end;
end;
end;
%save the name for link usage
sto_nm(i,:)=[blkname blankt(length(blkname)+1:40)];
% find the minimum and maximum axis for the blocks
axiz(1) = min(axiz(1),posit(1));
axiz(2) = min(axiz(2),posit(2));
axiz(3) = max(axiz(3),posit(1)+posit(3));
axiz(4) = max(axiz(4),posit(2)+posit(4));
% for a super block, mark the location of the block
if pt1 == 2,
test = 0;
ij = 1;
while ~test & (ij <= gen_block(1))
tmp = deblank(setstr(name_st(ij,:)));
% case insensitive setup
indxX = find(tmp >=97 & tmp <= 122);
tmp(indxX) = tmp(indxX) - 32;
tmp2 = deblank(orblkname);
indxX = find(tmp2 >=97 & tmp2 <=122);
tmp2(indxX) = tmp2(indxX) - 32;
% end of case insensitive setup
if strcmp(tmp2,tmp)
test = 1;
son(ij) = now;
done(ij) = now;
name_st(ij,1:length(orblkname)) = abs(orblkname);
root = [root; ij];
[tmp, tmp2] = size(topblk);
tmp3 = [ chain '/' deblank(blkname) ];
if tmp > 0
if length(tmp3) > tmp2
topblk(1,length(tmp3)) = ' ';
elseif length(tmp3) < tmp2
tmp3(tmp2) = ' ';
end;
end;
topblk = [topblk; tmp3];
else %if
ij = ij+1;
if ij > gen_block(1)
fprintf('A nonexistent block ''')
fprintf('Superblock '); fprintf([chain '/' blkname]);
fprintf(''' has been used.\n');
end;
end; %if
end; %while
end; %if pt1
end; %for i = 1:name_in(now,2)
% input/output blocks
fprintf('.')
axiz(1) = max(axiz(1)-60,5);
axiz(2) = max(axiz(2),5);
axiz(3) = axiz(3)+40;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Relocate output blocks %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
in_b = 3;
dsl = in(9) - in_b;
innumb = in(in_b + 3);
if innumb > 0
for j = 1:innumb
blkname_in = ['output' num2str(j) '/1'];
if in(in_b + dsl + j) >0
ij = in(in_b + dsl + j);
ijk = in(in_b+dsl+j+innumb);
blkname_ot = [deblank(sto_nm(ij,:)) '/' num2str(ijk)];
z = get_param([chain '/' deblank(sto_nm(ij,:))],'outport');
blank_num = 1;
while (isempty(z) & (blank_num < 20))
z = get_param([chain,'/',deblank(sto_nm(ij,:)),setstr(ones(1,blank_num)*32)],'outport')
blank_num = blank_num + 1;
end;
z = z(ijk,:);
orien(1) = orienta(ij);
if orien(1) == 0
z(1) = z(1) + (30 + rem(ijk,5)*25);
else
z(1) = max(0,z(1) - (30 + rem(ijk,5)*25));
end;
z(2) = z(2) - 10;
set_param([chain '/output' num2str(j)],'position',[z z+20],...
'hide name',0,...
'Port',num2str(j));
orien(2) = 0;
if orien(1) ~= 0
set_param([chain '/output' num2str(j)],'orientation',2);
orien(2) = 2;
end;
end;
end;
end;
drawnow
bloc = get_param(chain,'blocks');
[n_bl,m_bl]=size(bloc);
clear bllc new_bllc
for i = 1:n_bl
bllc(i,:) = get_param([chain '/' deblank(bloc(i,:))],'position');
end;
shif_x = 20 - min(bllc(:,1));
shif_y = 20 - min(bllc(:,2));
new_bllc(:,1) = bllc(:,1) + shif_x;
new_bllc(:,3) = bllc(:,3) + shif_x;
new_bllc(:,2) = bllc(:,2) + shif_y;
new_bllc(:,4) = bllc(:,4) + shif_y;
blklocs(:,[1,3]) = blklocs(:,[1,3]) + shif_x;
blklocs(:,[2,4]) = blklocs(:,[2,4]) + shif_y;
for i=1:n_bl
set_param([chain '/' deblank(bloc(i,:))],'position',new_bllc(i,:));
end;
x_ma = max(new_bllc(:,3));
y_ma = max(new_bllc(:,4));
loca(1) = 14;
loca(2) = 98;
loca(3) = loca(1) + x_ma + 20;
loca(4) = loca(2) + y_ma + 20;
set_param(chain,'Location',loca);
drawnow;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Link all of the blocks %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% connect all lines
for i = 0:name_in(now,2) %number of blocks
% in_b = ind+in(ind+3*i-2)+2; dsl = 18;
if i == 0 %starting from superblock
in_b = 3;
% dsl = 20;
dsl = in(9) - in_b;
% if blk_dm(now,4) >4 & in(11) > 13
% dsl = 11 + in(11);
% end;
orien = [0 0];
else
in_b = rec_in(i);
dsl = in(in_b+7)-2; %it was assigned to be dsl=18;
orien = [0 orienta(i)];
end;
innumb = in(in_b+3);
if innumb >0 %when the input number greater than 0 make connection
for j = 1:innumb
if i>0
blkname_in = [deblank(sto_nm(i,:)) '/' num2str(j)];
else
blkname_in = ['output' num2str(j) '/1'];
end;
if in(in_b + dsl + j) >0
ij = in(in_b + dsl + j);
ijk = in(in_b+dsl+j+innumb);
blkname_ot = [deblank(sto_nm(ij,:)) '/' num2str(ijk)];
orien(1) = orienta(ij);
if i <= 0
z = get_param([chain '/' deblank(sto_nm(ij,:))],'outport');
blank_num = 1;
while (isempty(z) & (blank_num < 20))
z = get_param([chain,'/',deblank(sto_nm(ij,:)),setstr(ones(1,blank_num)*32)],'outport')
blank_num = blank_num + 1;
end;
z = z(ijk,:);
if orien(1) == 0
z(1) = z(1) + (30 + rem(ijk,5)*25);
else
z(1) = max(0,z(1) - (30 + rem(ijk,5)*25));
end;
z(2) = z(2) - 10;
% set_param([chain '/output' num2str(j)],'position',[z z+20],...
% 'hide name',0,...
% 'Port',num2str(j));
orien(2) = 0;
if orien(1) ~= 0
% set_param([chain '/output' num2str(j)],'orientation',2);
orien(2) = 2;
end;
end;
else
blkname_ot = ['input' num2str(in(in_b + dsl + j + innumb)) '/1'];
if (length(in_ori) >=in(in_b+dsl+j+innumb)) &...
(in(in_b+dsl+j+innumb) >0)
orien(1) = in_ori(in(in_b+dsl+j+innumb));
end;
orien(1) = orien(2);
end;
if in(in_b + dsl + j + innumb)
if sim_ver <= 1.2
xx=autoline(chain, blkname_ot, blkname_in, blklocs, orien);
else
add_line(chain, blkname_ot, blkname_in);
end;
end;
end; % for j=
end; % if innumb
if save_flag == 0
drawnow
end;
end; % for i = 1:name_in(now,2) %number of blocks
end %if name_in(i,2) =>0
tmp=max(blklocs);
if length(tmp) < 4
tmp = blklocs;
end;
% bdresize(1,chain);
% set_param(chain,'Location',[20,20,tmp(3)+110,tmp(4)+50]);
%close_system(chain);
blklocs = [];
fprintf('.\n')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% make marks and choose the next block %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (son(now) ~= 0) & (save_flag == 0)
close_system(chain);
end;
done(now) = 0;
% end of 'now'th process, find out if there is any block to be done.
% if it is, process the son process
ind = find(done >0);
if isempty(ind)
now = 0;
else
now = ind(1);
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Save the generated file %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load sb2sltmp
%remove the following line for 3.5 runable
% if xn > 0 | numz > 0
% set_param(sys,'Start callback',['load ' slstring]);
% set_param(sys,'Load callback',['load ' slstring]);
% end;
if save_flag
close_system(sys,1);
end
%warning, the following super block has not been used in the conversion.
ind = find( done < 0 );
if ~isempty(ind)
disp('Warning: the following blocks are in the file but never used');
for i = 1: length(ind)
disp(setstr(name_st(ind(i),:)));
end;
end;
%give out the final instruction for executable file
if err > 0
fprintf('\nConversion finished, ')
fprintf(num2str(err))
fprintf(' blocks have left unconverted.\n')
else
fprintf('\nConversion has been succesful.\n')
end;
if nargin > 1
fprintf('\nYour SIMULINK file is in '); fprintf(slfile);
fprintf('.\nRun '''); fprintf(slstring);
fprintf(''' to open '''); fprintf(slstring);
fprintf(''' SIMULINK window.\n');
end;
end;
%clean house
if xn>0 | numz>0
appsave('sb2sltmp','err',err);
clear
load sb2sltmp
%clear the space
% xs = [xs(1:5) slstring xs(14:length(xs)) zzz(13:length(zzz))];
% eval(xs);
fprintf('\nData file ''')
fprintf(slstring);
fprintf('.mat'' has been created.\n')
fprintf('''load ')
fprintf(slstring);
fprintf(''' before simulation\n')
eval(['save ' slstring])
end;
clear
if findstr(lower(computer),'vms')
eval('!del sb2sltmp.mat;*');
if exist('apptmp.mat')
eval('!del apptmp.mat;*');
end;
elseif findstr(lower(computer),'pc')
eval('!del sb2sltmp.mat');
if exist('apptmp.mat')
eval('!del apptmp.mat');
end;
else
eval('!rm sb2sltmp.mat');
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -