Interfacing function
eng


VECTORSCOPE_c

File content


//VECTORSCOPE_c Scicos vector visualization block
//Classical interface function ver1.0 - scilab-4.1
//24 Mai 2007 - INRIA - Author : A.Layec
function [x,y,typ]=VECTORSCOPE_c(job,arg1,arg2)
x=[];y=[];typ=[]
select job
case 'plot' then
  standard_draw(arg1)
case 'getinputs' then
  [x,y,typ]=standard_inputs(arg1)
case 'getoutputs' then
  x=[];y=[];typ=[];
case 'getorigin' then
  [x,y]=standard_origin(arg1)
case 'set' then
  x=arg1;
  graphics=arg1.graphics;
  exprs=graphics.exprs;
  model=arg1.model;

  //compatibility : add wdim
  if size(exprs,'*')==6 then exprs=[exprs;'[600;400]'], end

  while %t do
    [ok,nu,wid,Tse,nvec,y_dim,herit,wdim,exprs] = getvalue(..
        'Set Scope parameters',..
        ['In size';
         'Output window number (automatic:-1)';
         'Sampling period';
         'Number of vector to display';
         'Y axis bound [min,max] (autoscale:-1)';
         'Inherit (no:0, yes:1)';
         'Window sizes'],..
        list('vec',1,..
             'vec',1,..
             'vec',1,..
             'vec',1,..
             'vec',-1,..
             'vec',1,..
             'vec',-1),exprs)

    if ~ok then break,end //user cancel modification

    mess=[]

    //check values of user param
    if Tse<=0 then
      mess=[mess;'Sampling period must be greather than zero';' ']
      ok=%f
    end
    if size(y_dim,'*')>=2 then
      if y_dim(1)<>-1 & y_dim(2)<>-1 then
        if y_dim(1)>=y_dim(2) then
          mess=[mess;'Ymax must be greater than Ymin';' ']
          ok=%f
        end
      end
    end

    if size(wdim,'*')<>0 &size(wdim,'*')<>2 then
      mess=[mess;'Window dim must be [] or a 2 vector';' ']
      ok=%f
    end

    if ~ok then
      message(['Some specified values are inconsistent:';
                 ' ';mess])
    end

    //adjust size of ports block
    if ok then
      if nu==0 then nu=-1, end
      if herit==1 then
        [model,graphics,ok]=check_io(model,graphics,nu,[],[],[])
      else
        [model,graphics,ok]=check_io(model,graphics,nu,[],1,[])
      end
    end

    //auto adjustement of some values
    if ok then
      if Tse<=0 then Tse=1, end;
      if nvec<=0 then nvec=1, end;
      if size(y_dim,'*')==1 then //autoscale
        ymin=%eps;
        ymax=1;
        scaltyp=1
      else
        if y_dim(1)==-1 & y_dim(2)==-1 then //autoscale
          ymin=%eps;
          ymax=1;
          scaltyp=1
        else
          ymin=y_dim(1);
          ymax=y_dim(2);
          scaltyp=0
        end
      end
    end

    //set model
    if ok then
      if wdim==[] then wdim=[-1;-1];end
      ipar=[wid;nvec;scaltyp;wdim(:)]
      rpar=[Tse;ymin;ymax]
      model.rpar=rpar(:)
      model.ipar=ipar(:)
      graphics.exprs=exprs;  //for future work
      x.graphics=graphics;
      x.model=model
      break
    end

  end
case 'define' then
  //ipar
  wid     = -1        //ipar(1)
  nvec    =  1        //ipar(2)
  scaltyp =  1        //ipar(3)
  wdim    = [600;400] //ipar(4)/ipar(5)

  ipar = [wid;nvec;scaltyp;wdim]

  //rpar
  Tse   =  1    //rpar(1)
  ymin  =  %eps //rpar(4)
  ymax  =  %eps //rpar(5)

  rpar  =  [Tse;ymin;ymax]

  herit =  0
  nu    =  -1

  model=scicos_model()
  model.sim=list('vectorscope41',4)
  model.in=nu
  model.out=[]
  model.evtin=[1]
  model.evtout=[]
  model.dstate=[0]
  model.ipar=ipar(:)
  model.rpar=rpar(:)
  model.blocktype='d'
  model.firing=[]
  model.dep_ut=[%t %f]

  exprs=[string(nu)       //1 in size
         string(wid)      //2 windows id
         string(Tse)      //3 sampling period
         string(nvec)     //4 number of vectors
         sci2exp([-1 -1]) //5 y axis bounds
         string(herit)    //6 Inherit
         sci2exp(wdim)    //7 window size
        ];
  gr_i=['thick=xget(''thickness'');';
        'pat=xget(''pattern'');';
        'fnt=xget(''font'');';
        'xset(''thickness'',2);';
        'xrect(orig(1)+sz(1)/10,orig(2)+(1-1/10)*sz(2),sz(1)*8/10,sz(2)*8/10);';
        'l=0.12;';
        'h=0.12;';
        'a=orig(1)+sz(1)/5;';
        'b=orig(1)+(1-1/5)*sz(1);';
        'c=orig(2)+sz(2)/5;';
        'd=orig(2)+(1-1/5)*sz(2);';
        'ii=6;';
        'll=(b-a)/(ii-1);';
        'xd=(0:ii-1)*ll + a;';
        //CAMARCHEDANSB4SCICOS
        //'yd=rand(1:ii)*(d-c-h*sz(2)) + c + 0.5*h*sz(2);';
        'yd=[0.9,0.4,0.8,0.7,0.3,0.5]*(d-c-h*sz(2)) + c + 0.5*h*sz(2);';
        'xx=[orig(1)+sz(1)/5,xd;orig(1)+(1-1/5)*sz(1),xd];';
        'yy=[orig(2)+sz(2)/5,c*ones(1,ii);orig(2)+sz(2)/5,yd];';
        'xpoly(xx(:,1),yy(:,1));';
        'for jj=2:(ii+1)';
        '  xpoly(xx(:,jj),yy(:,jj));';
//        '  xfarc(xx(2,jj)-l/2*sz(1),yy(2,jj)+h*sz(2),l*sz(1),h*sz(2),0,64*360);';
        'end';
        'txt=''Time'';'
        'style=5;'
        'rectstr=stringbox(txt,orig(1),orig(2),0,style,1);'
        '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));';
       ]
  x=standard_define([2 2],model,exprs,gr_i)

end
endfunction