home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / control / syschnal.m < prev    next >
Text File  |  1999-04-29  |  4KB  |  134 lines

  1. # Copyright (C) 1996 A. Scottedward Hodel 
  2. #
  3. # This file is part of Octave. 
  4. #
  5. # Octave is free software; you can redistribute it and/or modify it 
  6. # under the terms of the GNU General Public License as published by the 
  7. # Free Software Foundation; either version 2, or (at your option) any 
  8. # later version. 
  9. # Octave is distributed in the hope that it will be useful, but WITHOUT 
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  11. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  12. # for more details.
  13. # You should have received a copy of the GNU General Public License 
  14. # along with Octave; see the file COPYING.  If not, write to the Free 
  15. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  16.  
  17. function old_names = syschnaml(olist,old_names,inames,listname)
  18.   # used internally in syschnam
  19.   # olist: index list
  20.   # old_names: original list names
  21.   # inames: new names
  22.   # listname: name of index list
  23.   #
  24.   # combines the two string lists old_names and inames
  25.  
  26.   # $Revision: 1.2 $
  27.   # $Log: syschnaml.m,v $
  28.   # Revision 1.2  1998/07/01 16:23:39  hodelas
  29.   # Updated c2d, d2c to perform bilinear transforms.
  30.   # Updated several files per bug updates from users.
  31.   #
  32.   # Revision 1.5  1997/02/28 23:47:26  hodel
  33.   # fixed bug in checking parameters; (inames dimension not checked against olist)
  34.   # a.s.hodel@eng.auburn.edu
  35.   #
  36.   # Revision 1.4  1997/02/13 15:56:37  hodel
  37.   # added code to convert zeros in the name matrix to blanks
  38.   # a.s.hodel@eng.auburn.edu
  39.   #
  40.   # Revision 1.3  1997/02/13 15:11:17  hodel
  41.   # fixed bug when len_my < len_out a.s.hodel@eng.auburn.edu
  42.   #
  43.   # Revision 1.2  1997/02/12 22:54:50  hodel
  44.   # fixed string matrix <-> numerical matrix problem
  45.   #
  46.   
  47.   probstr = [];
  48.   if( max(olist) > rows(old_names) )
  49.     probstr = ["index list value(s) exceed(s) number of signals (", ...
  50.       num2str(rows(old_names)),")"];
  51.  
  52.   elseif( length(olist) > rows(inames) )
  53.     probstr = ["index list dimension exceeds number of replacement names (", ...
  54.       num2str(rows(inames)),")"];
  55.  
  56.   elseif(isempty(olist))
  57.     probstr = [];    # do nothing, no changes
  58.  
  59.   elseif(min(size(olist)) != 1 )
  60.     probstr = "index list must be either a vector or an empty matrix";
  61.  
  62.   elseif(max(olist) > rows(old_names))
  63.     probstr = ["max(",listname,")=",num2str(max(olist))," > ", ...
  64.     num2str(rows(old_names)),", too big"];
  65.  
  66.   elseif(min(olist) < 1)
  67.     probstr = ["min(",listname,")=",num2str(min(olist))," < 1, too small"];
  68.  
  69.   else
  70.     if( length(olist)  == 1)
  71.     len_in = columns(inames);
  72.     len_out = columns(old_names);
  73.  
  74.       if (len_in < len_out)
  75.         inames(1,(len_in+1):(len_out)) = zeros(1,(len_out - len_in));
  76.       endif
  77.  
  78.       old_names(olist,1:length(inames)) = inames;
  79.     elseif(length(olist) > 1)
  80.       for ii=1:length(olist)
  81.         mystr = inames(ii,:);
  82.     len_my = columns(mystr);
  83.         len_out = columns(old_names);
  84.        
  85.         if (len_my < len_out)
  86.           mystr(1,(len_my+1):(len_out)) = " "*ones(1,(len_out - len_my));
  87.       len_my = len_out;
  88.         endif
  89.  
  90.         old_names(olist(ii),1:len_my) = mystr;
  91.       endfor
  92.     endif
  93.   endif
  94.   if(!isempty(probstr))
  95.     # the following lines are NOT debugging code!
  96.     disp("Problem in syschnam: old names are")
  97.     outlist(old_names,"    ")
  98.     disp("new names are")
  99.     outlist(inames,"    ")
  100.     disp("list indices are")
  101.     disp(olist)
  102.     error(sprintf("syschnam: \"%s\" dim=(%d x %d)--\n\t%s\n", ...
  103.     listname, rows(olist), columns(olist),probstr));
  104.   endif
  105.  
  106.   # change zeros  to blanks
  107.   if( find(old_names == 0) )
  108.     #disp("syschnaml: old_names contains zeros ")
  109.     #old_names
  110.     #disp("/syschnaml");
  111.  
  112.     [ii,jj] = find(old_names == 0);
  113.     for idx=1:length(ii)
  114.       old_names(ii(idx),jj(idx)) = " ";
  115.     endfor
  116.  
  117.     #disp("syschnaml: old_names fixed zeros ")
  118.     #old_names
  119.     #disp("/syschnaml");
  120.   endif
  121.  
  122.   # just in case it's not a string anymore
  123.   if( !isstr(old_names) )
  124.     old_names = setstr(old_names);
  125.   endif
  126.   
  127.   #disp("syschnaml: exit, old_names=")
  128.   #old_names
  129.   #disp("/syschnaml: exiting")
  130.   
  131. endfunction
  132.