sxfamname.m 2.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
function varargout=sxfamname(idx,format)
%EBS.sxfamname	returns the name of Sextupole with index idx
%
%SXNAME=sxfamname(IDX)	returns the name of Sextupole with index IDX
% IDX: vector of indexes in the range [1 196] (1 is C4-1)
%       or n x 2 matrix in the form [cell index] with
%       cell in [1 32], index in [1 7]
%
%SXNAME=sxfamname(IDX,FORMAT)	uses FORMAT to generate the name
%                       (default : 'srmag/m-s******')
%
%[NM1,NM2...]=sxfamname(...)    May be used to generate several names
%
%[...,KDX]=sxfamname(...)       returns in addition the "hardware" index KDX
%
%KDX=sxfamname(IDX,'')          returns only the "hardware" index KDX
% 
% examples : 
% >> ebs.sxfamname(192)
% ans = 
%     'srmag/m-sd1ae/inj-inner'
% >>ebs.sxfamname([192 32 10]')
% ans = 
%     'srmag/m-sd1ae/inj-inner'
%     'srmag/m-sf2/all'
%     'srmag/m-sd1bd/all'
%
%   See also SXINDEX

if nargin < 2, format='srmag/m-s'; end

[kdx,celnum,id]=ebs.cellnum(6,idx);

if isempty(format) || strcmp(format,'noname')
    varargout={};
else
    
    devnamefun= @(celnum,id)textfunc(format,celnum,id);
   
    nms=arrayfun(devnamefun,celnum,id,'UniformOutput',false);
    nin=length(nms);
    if (nargout==nin) || (nargout==(nin+1))
        varargout=nms;
    else
        varargout={nms};
    end
end

nout=length(varargout);
if nargout > nout
    varargout{nout+1}=kdx;
end

    function devnam=textfunc(format,celnum,id)
        if celnum==3
            num='121121';
            pos={'ae','inj-outer';...
                'ae','inj-outer';...
                'bd','inj-outer';...
                'bd','inj-inner';...
                'ae','inj-inner';...
                'ae','inj-inner';...
                };
           foc='dfddfd';
        elseif celnum==4
            num='121121';
            pos={'ae','inj-inner';...
                'ae','inj-inner';...
                'bd','inj-inner';...
                'bd','inj-outer';...
                'ae','inj-outer';...
                'ae','inj-outer';...
                };
           foc='dfddfd';
        else
            num='121121';
            pos={'ae','all';...
                '','all';...
                'bd','all';...
                'bd','all';...
                '','all';...
                'ae','all';...
                };
            foc='dfddfd';
        end
        devnam=[format foc(id) num(id) pos{id,1} '/' pos{id,2}];
        
    end

end