⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readsb.m

📁 数字通信第四版原书的例程
💻 M
📖 第 1 页 / 共 3 页
字号:
       disp(setstr(name_st(i,:)))
     end
   else
     temp = length(ind);
       space='                                                                      ';
     if temp == 1
       disp(['There is one independant superblock tree, which is']);
     else
       disp(['There are ' num2str(temp) ' independant superblock trees, which are:']);
     end;
     for i=1:temp
       if (ind(i) < 10) & (gen_block(1) >= 10) 
         tmp = ['( ' num2str(ind(i)) ') '];
       else
         tmp = ['(' num2str(ind(i)) ') '];
       end;
       tmp = [tmp setstr(name_st(ind(i),:))];
       disp(tmp);
       if gen_block(1) <= 1
	  stack = [];
       else
          stack = [ind(i),1];
       end;
       while ~isempty(stack)
         k = length(stack);
         j = sub_blk(stack(k-1),stack(k));
         if j == 0
           if k <=2
             stack = [];
           else
             stack = stack(1:k-2);
           end;
         else
           if (j < 10) & (gen_block(1) >= 10) 
             tmp = ['( ' num2str(j) ') '];
           else
	     tmp = ['(' num2str(j) ') '];
           end;
           tmp = [tmp space(1:k) setstr(name_st(j,:))];
           disp(tmp);
           stack(k) = stack(k) + 1;
           if stack(k) > gen_block(1)
             error('readsb error, report to the mathworks.')
           end; 
           stack=[stack j 1];
         end;
       end;
     end;
   end;
   if gen_block(1) > 1
     test = 1;
   else
     test = 0;
   end;
   while test
     for i=1:gen_block(1)
       k=strcmp(topblk,deblank(setstr(name_st(i,:))));
       if k 
         test = 0;
       end;
     end;
     if test == 1
       topblk = ...
	input('Input the number or the string of your top superblock ==> ');
       if ~isstr(topblk)
         if topblk <= gen_block(1)
           topblk = deblank(setstr(name_st(topblk,:)));
         end; %if topblk
       end; %if ~isstr
     end; %if test
   end; %while
   clear ind i j k  test stack top_blk sub_blk
 end; %if test
 %end the finding structure procedure 1/8/93

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % Variable Layout                                                            %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % We have the variables:
 % gen_block :(1) number of super blks, number of row of
 %	          name_st, name_in, and name_fl
 %	      (2) number of characters, dimension of blk_st
 %	      (3) number of integers, dimension of blk_in
 %	      (4) number of real number, dimension of blk_fl
 % name_st :  gen_block(1) X 31 matrix, name(i,:) is the name
 %                of ith super block.
 % name_in :  (1) feature of super block. =0 continuous;
 %                =1 discrete; =33 state order =73 fuzzy
 %            (2) number of blocks in this superblock
 %            (3) number of inputs in this super block
 %            (4) number of outputs in this super block
 % name_fl :  real numbers of the super block. 
 %                it is zero when name_in(1)=0.
 % blk_dm :   (i,1) number of characters in this superblock
 %            (i,2) number of integer in this superblock
 %            (i,3) number of real number in this superblock
 %            (i,4) FORTRAN format of this superblock's integers
 % blk_st :   string. ith block string start from
 %               sum_{k=1}^{i-1}(blk_dm(k,1))+1
 %                   ==> sum_{k=1}^{i}(blk_dm(k,1))
 % blk_in :   integer. ith block integer start from
 %               sum_{k=1}^{i-1}(blk_dm(k,2))+1
 %                   ==> sum_{k=1}^{i}(blk_dm(k,2))
 % blk_fl :   real. ith block real start from
 %               sum_{k=1}^{i-1}(blk_dm(k,3))+1
 %                   ==> sum_{k=1}^{i}(blk_dm(k,3))
 %
 % End of reading variables from SystemBuild file

 %load data from sb2sldat
 sb2sldat
 clear face

 % Analyze the data series from the beginning of the file

 % setup flags to indicate blocks has been converted or not.
 % flag(i) == 1, ith block has not been processed yet.
 % flag(i) == 0, ith block has been done.
 flag = ones(gen_block(1),1);

 % set up flag to indicate tree structure
 % son(i) == 0, root block
 % son(i) == j, ith block is son of jth block
 % done(i) which one to be done.
 %
 son = zeros(gen_block(1),1);
 done = -ones(gen_block(1),1);

 % if topblk == [], find the order number of the root block
 % In the process, if there is more than one block sharing 
 % the same name, use the first encounted.
 % 'now' is the number of current processing block
 if ~isempty(topblk)
   now = 0; i = 1;
   xx=deblank(topblk);
   indxX = find(xx >=97 & xx <=122);
   xx(indxX) = xx(indxX) - 32;           
   while now ==0;
      tmp = deblank(setstr(name_st(i,:)));
      indxX = find((tmp >=97) & (tmp <=122));
      tmp(indxX) = tmp(indxX) - 32;
      if strcmp(xx,tmp)
	 now = i;
      else     
         i = i+1;
         if i > gen_block(1) % cannot find, then error.
            fprintf('block '); fprintf(topblk); 
	    fprintf(' is not a super block in the file\n');
            break;
         end; %if i>
      end;  %if same
   end; % while
 else %if isempty
   now = 1;
 end; %if ~isempty
 root = now;
 topblk = slstring;

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % open a new system window							%
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 new_system(slstring);
 simver(1.3);
 sys = slstring;
 set_param(sys,'Location',[14,98,100,100])
 open_system(sys)
 fprintf('\nTranslating '); fprintf(sys); fprintf('\n');

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % Block Setup, Main Procedure                                                %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %beginning of one-by-one block process the conversion
 while ~isempty(topblk) %now ~= 0

  % make chain loaded with all tree pathes for all the group definition
%  chain = [];
%  i = now;
%  while i~=0 & i~= root
%    %add tree structure chain
%    chain=[deblank(setstr(name_st(i,:))) '/' chain];
%    i = son(i);
%  end; %while
  chain = deblank(topblk(1,:));
  chain = deblank(chain);
  topblk(1,:) = [];
  now = root(1);
  root(1) = [];

  %add top to the chain
%  chain = [sys '/' chain];
%  %takeout the last '/'
%  if ~isempty(chain), 
%     while (chain(length(chain)) == '/') 
%	chain=chain(1:length(chain)-1); 
%     end;
%  end;

  % the initial starting point of string, integer and real number.
  if now ==1;
     ini_st = 1; ini_in = 1; ini_fl = 1;
  else
     ini_st = sum(blk_dm(1:now-1,1)) + 1;
     ini_in = sum(blk_dm(1:now-1,2)) + 1;
     ini_fl = sum(blk_dm(1:now-1,3)) + 1;
  end;

  % pull out the sting, integer and real number to a separated vector.
  st = blk_st(ini_st:ini_st+blk_dm(now,1)-1); %string
  in = blk_in(ini_in:ini_in+blk_dm(now,2)-1); %integer
  fl = blk_fl(ini_fl:ini_fl+blk_dm(now,3)-1); %real

  relocat = fl(1:4);
  zoomx = 1200/(relocat(3)-relocat(1));
  if zoomx <.4, zoomx = .4; end;
  zoomy = 760/(relocat(4)-relocat(2));
  if zoomy <.4, zoomy = .4; end;
  if son(now) ~= 0 %if it is not the super block, open system
     set_param(chain,'Location',[14,98,100,100])
     if save_flag == 0
       open_system(chain) %for final version, this line can be deleted
     end;
     fprintf('Translating '); fprintf(chain); fprintf('\n');
  else             % I/O port have not added yet for the top block
    if in(5) > 0
      for i=1:in(5)
        add_block('built-in/Inport',[chain '/input' num2str(i)]);
        set_param([chain '/input' num2str(i)],'position',...
		[1230,1010,1250,1033],...
		'Port',num2str(i));
      end;
    end %if
    if in(6) > 0
      for i=1:in(6)
       add_block('built-in/Outport',[chain '/output' num2str(i)]);
       set_param([chain '/output' num2str(i)],'position',...
		[0,0,20,20],...
		'Port',num2str(i));
      end;
    end %if
  end;

  % analyze integer
  ind = in(18);
  
  % record of in_b
  rec_in = [];

  % find the maximum and minimum axis
  axiz = [1000 , 1000 , 0 , 0]; % the number for set I/O port location
  %locate every block's information and define blocks
  if name_in(now,2) >= 0
    count_in=0; count_ot=0;
    for i = 1:name_in(now,2)     %number of blocks
      %The location of each block
      in_b = ind+in(ind+3*i-2)+2;
      in_e = ind+in(ind+3*i+1); 
      fl_b = in(19) + in(ind+3*i-1)+1;
      fl_e = in(19) + in(ind+3*i+2);
      st_b = in(20) + in(ind+3*i)+1;
      st_e = in(20) + in(ind+3*i+3);
      if i == name_in(now,2), 
        in_e = blk_dm(now,2); 
        fl_e = blk_dm(now,3);
        st_e = blk_dm(now,1);
      end;

      %double check to see if everything is okay.
      while in(in_b) ~= 8 | ~(in(in_b+7) == 20 |in(in_b+7) ==23)
         in_b = in_b+1;
         if in_b+7 > blk_dm(now,2)
            disp('Convert goes wrong; Please check your file.');
	    disp('If this message shows again, send your file to Mathworks');
            break;
         end;
      end; %while
      rec_in = [rec_in in_b];

      %The block type is in  in_b+1 and in_b+2;
      %The I/O number is in  in_b+3 and in_b+4;
      %State number   is in  in_b+5;
      %block id number is in in_b+6
      %block input con is in in_b+18+input_number            (blk#)
      %                  and in_b+18+in(in_b+3)+input_number (out#)
      %block ori struc is in in_b+19+in(in_b+3)*2 
      %block location x_axis in_b+20+in(in_b+3)*2
      %block location y_axis abs(in(in_b+21+in(in_b+3)*2))
      %block size x_axis     in_b+22+in(in_b+3)*2
      %block size y_axis     in_b+23+in(in_b+3)*2
      
      %blocks name
      blkname = setstr(st(st_b:st_e))';
      pt = min(find(blkname == '|'));
      blkname = blkname(1:pt-1);
      % bug fix for '/' in the sequence
      pt = find(blkname == '/');
      if ~isempty(pt)
        for i = length(pt) : -1 : 1
            blkname = [blkname(1:pt(i)), '/', blkname(pt(i)+1:length(blkname))];
        end;
      end;
      % end bug fix for '.' in the sequence
      orblkname = blkname;
      hiden = 0;

      %find the numbers for function coding, position and size
      if in(in_b+1) <= 0 | in(in_b+1) > 16
        disp('Illegal Block, send your file and description of this block to MathWorks and ask for solution.');
        in(in_b+1) = 16;
        pt1 = 1;
      end;
      if in(in_b+1) ~= 6 & in(in_b+1) ~= 16
        pt1 = pointer(in(in_b+1),in(in_b+2));           %code number
      else
	pt1 = 40;
      end;

      % block name
      if isempty(blkname) 
         blkname = [deblank(block(pt1,:)) num2str(in(in_b+6))];
         hiden = 1;
         orblkname = blkname;
      end;

      %avoid repeating name
      if i>1
         for j=1:(i-1)
            if strcmp(blkname,deblank(sto_nm(j,:)))
               blkname = [blkname num2str(in(in_b+6))];
            end; %if
         end; %for
       end; %if

      % size and location
      pt2 = in_b + in(in_b+7) + in(in_b + 3) * 2;     %location and size
      posit = in(pt2:pt2+3)';
      %%  relocation points  %%
      posit(1) = ceil((posit(1) - floor(relocat(1)))*zoomx);
      posit(2) = ceil((relocat(4) - posit(2))*zoomy);
      posit(3) = ceil(posit(3)*zoomx);
      posit(4) = ceil(posit(4)*zoomy);
      if posit(3) >= 200
         posit(3) = posit(3)/2;
      end;
      if posit(4) >= 200
        posit(4) = max(posit(4)/2,min(posit(4),max(in(in_b+3),in(in_b+4))*15));
        posit(4) = max(posit(4), max(in(in_b+3),in(in_b+4))*5+10);
      end;
      %      posit(3:4) = 0.8*posit(3:4);
      %      posit = 0.75*posit;
      %      posit(2) = 200-posit(2)-posit(4);       %position for SL
      %      posit(1) = posit(1)+20;
      posit = abs(posit);
      if in(in_b+1) == 2 & (in(in_b+2) == 2 | in(in_b+2) == 5)
         posit(3) = ceil(posit(3)/3);
         hiden = 1;
         posit(1) = posit(1) + posit(3);
      end;
      posit = posit - rem(posit,5);
      for kk=1:4
        if posit(kk) < 10
           posit(kk) = 10; 
        end;
      end;
      rotat = rem(floor(in(pt2-1)/2),2); %check the second last bit of the numb
      % > str_ori(in(in_b+1),in(in_b+2));

      %decide whether a super block for mux is necessary.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -