0001 function elemseq = insertelem(ELEM, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 if ~isatelem(ELEM)
0029 error('The first argument must be a valid Accelerator Toolbox element');
0030 end
0031
0032
0033 ELEMS2INSERT = {};
0034
0035 POSITION = {};
0036 LENGTH = {};
0037
0038 OPTIONSET = struct;
0039
0040 k = 1;
0041 while k < nargin
0042 if isatelem(varargin{k})
0043 if ~k<nargin & ~isnumeric(varargin{k+1})
0044 errorstr = sprintf('Incorrect syntax:\n');
0045 errorstr=[errorstr,sprintf('Elements to be inserted must be followed by position\n')];
0046 errorstr=[errorstr,sprintf('in the argument list: ELEM1, pos1, ... ELEMN, POSN ')];
0047 error(errorstr);
0048 else
0049 ELEMS2INSERT{end+1} = varargin{k};
0050 k = k+2;
0051 end
0052 elseif ischar(varargin{k})
0053 switch lower(varargin{k})
0054 case 'drift'
0055 OPTIONSET.inherit = {'FamName','PassMethod'};
0056 OPTIONSET.slice = {'Length'};
0057 OPTIONSET.removeinner = {};
0058 OPTIONSET.removefirst = {};
0059 OPTIONSET.removelast = {};
0060 otherwise
0061 error('Options other than drift are not yet implemented');
0062 end
0063 else
0064 error('Incorrect syntax');
0065 end
0066
0067 end
0068
0069 if isempty(OPTIONSET)
0070
0071 OPTIONSET.inherit = {'FamName','PassMethod'};
0072 OPTIONSET.slice = {'Length'};
0073 OPTIONSET.removeinner = {};
0074 OPTIONSET.removefirst = {};
0075 OPTIONSET.removelast = {};
0076
0077 nelemins = length(ELEMS2INSERT);
0078 nelemnew = 1+2*ELEMS2INSERT;
0079
0080 L0 = ELEM.Length;
0081
0082 sp(1) = 0
0083
0084 for k = 1:nelemins
0085 sposition( =