Interfacing function
eng


MODGEN_c

File content


//MODGEN_c Scicos generic symbol modulator block
//Classical interface function ver1.0 - scilab-4.1
//25 mars 2007 Author : - INRIA - A.Layec
function [x,y,typ]=MODGEN_c(job,arg1,arg2)
x=[];y=[];typ=[]
select job
case 'plot' then
  constel=arg1.model.rpar(:);
  standard_draw(arg1)
case 'getinputs' then
  [x,y,typ]=standard_inputs(arg1)
case 'getoutputs' then
  [x,y,typ]=standard_outputs(arg1)
case 'getorigin' then
  [x,y]=standard_origin(arg1)
case 'set' then
   x=arg1;
   graphics=arg1.graphics;model=arg1.model;
   exprs=graphics.exprs;

   while %t do

      [ok,constel,herit,exprs]=getvalue('Set generic modulator block',...
      ['Points constellation';'Inherit (no:0, yes:1)'],...
      list('vec',-1,'vec',1),exprs);

      if ~ok then break,end;

      //teste des points de la constellation
      if isreal(constel) then
        tt=find(size(constel)==2)
        if tt==[] then
          message('Set a complex vector of a matrix of size p,2 for constellation')
          ok=%F
        else
          if size(tt,'*')==1 then
            if tt==1 then
              constel=[constel(1,:)+%i*constel(2,:)]
            else
              constel=[constel(:,1)+%i*constel(:,2)]
            end
          else
             constel=[constel(:,1)+%i*constel(:,2)]
          end
        end
      end

      if ok then
         if herit==1 then
           model.dep_ut=[%t %f]
           [model,graphics,ok]=check_io(model,graphics,-1,[-1;-1],[],[])
         else
           model.dep_ut=[%t %f]
           [model,graphics,ok]=check_io(model,graphics,-1,[-1;-1],1,[])
         end
         graphics.exprs=exprs;
         model.ipar=size(constel,'*');
         model.rpar=[real(constel(:));imag(constel(:))]
         x.graphics=graphics; x.model=model;
         break;
      end
   end

case 'define' then
  nb=4
  nu=-1
  constel=[exp(%i*((0:5)*%pi/3+%pi/4))]
  herit=1

  model=scicos_model()
  model.sim=list('modgen',4)
  model.in=nu
  model.out=[nu;nu]
  model.evtin=[]
  model.evtout=[]
  model.dstate=[]
  model.rpar=[real(constel(:));imag(constel(:))]
  model.ipar=size(constel,'*')
  model.blocktype='d'
  model.firing=[]
  model.dep_ut=[%t %f]
  gr_i=['thick=xget(''thickness'')';
        'pat=xget(''pattern'')';
        'fnt=xget(''font'')';
        'ln_st=xget(""line style"")';
        'sz1=0.86*sz(1);sz2=0.86*sz(2)';
        'xxs=orig(1)+sz(1)/2';
        'yys=orig(2)+sz(2)/2';
        'nb=size(constel(:),''*'')/2';
        'if nb<16 then';
        '  ww=0.14*sz(1)';
        '  hh=0.14*sz(2)';
        'elseif nb>=32 then';
        '  ww=0.06*sz(1)';
        '  hh=0.06*sz(2)';
        'else';
        '  ww=0.1*sz(1)';
        '  hh=0.1*sz(2)';
        'end';
        'mmax=max([constel(:);imag(constel(:))])';
        'mmin=min([constel(:);imag(constel(:))])';
        'if(mmax>1)|(mmin<-1) then';
        '  aa_s=(mmax-mmin)/2';
        'else';
        '  aa_s=1';
        'end';
        'aa_s=aa_s/0.9';
        'aa1=0';
        'aa2=64*360';
        'xset(""line style"",2)';
        'xset(""line style"",ln_st)';
        'for ii=1:nb';
        '   xxx=xxs+sz1/2*constel(ii)/aa_s-ww/2';
        '   yyy=yys+sz2/2*constel(ii+nb(1))/aa_s+hh/2';
        '   xfarc(xxx,yyy,ww,hh,aa1,aa2)';
        'end';
        'xpoly([xxs;xxs],[orig(2);orig(2)+sz(2)],""lines"")';
        'xpoly([orig(1);orig(1)+sz(2)],[yys;yys],""lines"")';
        'xset(''font'',5,0)'
        'txt=''Modulator'';'
        'style=5;'
        'rectstr=stringbox(txt,orig(1),orig(2),0,style,0);'
        'w=(rectstr(1,3)-rectstr(1,2))*%zoom;'
        'h=(rectstr(2,2)-rectstr(2,4))*%zoom;'
        'xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');'
        'e=gce();'
        'e.font_style=style;'
        'xset(''thickness'',thick)';
        'xset(''pattern'',pat)';
        'xset(''font'',fnt(1),fnt(2))';]
  exprs=['exp(%i*((0:5)*%pi/3+%pi/4))',string(herit)];
  x=standard_define([2 2],model,exprs,gr_i)
//   x.graphics.id=["Modulator"];
end
endfunction