Interfacing function
eng


UPSMPL_c

File content


//UPSMPL_c Scicos upsample block
//Classical interface function ver1.0 - scilab-4.1
//27 Mars 2007  Author : - INRIA - A.Layec
function [x,y,typ]=UPSMPL_c(job,arg1,arg2)
x=[];y=[];typ=[]
select job
case 'plot' then
  nech=arg1.model.ipar(1);
  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

      text=['Set Upsample block']
      [ok,nu,nech,init,SFtyp,typ,herit,exprs]=getvalue(text,...
      ['Size of inputs';
       'Upsample factor';
       'Initial sample';...
       'Sample Based:0, Frame Based:1';...
       'Type (Resample:0, zero-insert:1)';
       'Inherit (no:0, yes:1)'],...
      list('vec',1,'vec',1,'vec',1,'vec',1,'vec',1,'vec',1),exprs)

      if ~ok then break,end;
      //test
      if ~is_int(nu) then
        message('The size of inputs must be integer.')
        ok=%F
      elseif ~is_int(nech) then
        message('The downsample factor must be integer.')
        ok=%F
      elseif ~is_int(init) then
        message('The offset must be integer.')
        ok=%F
      elseif init<1 then
        message('The initial sample must be positive.')
        ok=%F
      end
      if find(SFtyp==[0:1])==[] then
        message('Only sample(0) or frame(1) based mode is allowed.')
        ok=%F
      end
      if find(typ==[0:1])==[] then
        message('Type of upsample must be 0 or 1.')
        ok=%F
      end
      if (SFtyp==1)&(nu<=0) then
        message('Size of input must >0 for frame-based mode')
        ok=%F
      end

      if ok then
          gr_i=['thick=xget(''thickness'')'
                'pat=xget(''pattern'')'
                'fnt=xget(''font'')'
                'l=0.15;h=0.2';
                'x0=0.31;y0=0.15;y1=0.6'
                'x1=x0-l/2;x2=x0+l/2;y2=y1+h'
                'xpoly(orig(1)+[x0;x0]*sz(1),orig(2)+[y0;y1]*sz(2),""lines"")'
                'xfpoly(orig(1)+[x1;x2;x0]*sz(1),orig(2)+[y1;y1;y2]*sz(2),1)'
                'txt='''+string(nech(1))+''';'
                'style=2;'
                'rectstr=stringbox(txt,orig(1)+0.55*sz(1),orig(2)+0.4*sz(2),0,style,1);'
                'w=(rectstr(1,3)-rectstr(1,2))*%zoom;'
                'h=(rectstr(2,2)-rectstr(2,4))*%zoom;'
                'xstringb(orig(1)+0.55*sz(1),orig(2)+0.4*sz(2),txt,w,h,''fill'');'
                'xset(''thickness'',thick)'
                'xset(''pattern'',pat)'
                'xset(''font'',fnt(1),fnt(2))']
          graphics.gr_i=gr_i
          typ=2*SFtyp+typ
          if (typ==0|typ==1) then
            ny=nu
          elseif (typ==2|typ==3) then
            ny=nu*nech
          end
          if herit==1 then
            [model,graphics,ok]=check_io(model,graphics,nu,ny,[],[])
          else
            [model,graphics,ok]=check_io(model,graphics,nu,ny,1,[])
          end
          graphics.exprs=exprs
          model.in=nu
          model.out=ny
          model.dstate=[]
          model.ipar=[nech;typ;init]
          x.graphics=graphics;x.model=model
          break;
      end
   end

case 'define' then
  nu=1
  herit=1
  nech=8
  ny=nu
  SFtyp=0
  typ=0
  init=0

  model=scicos_model()
  model.sim=list('upsmplblk',4)
  model.in=nu
  model.out=ny
  model.evtin=[]
  model.evtout=[]
  model.dstate=[]
  model.rpar=[]
  model.ipar=[nech;2*SFtyp+typ;init]
  model.blocktype='d'
  model.firing=[]
  model.dep_ut=[%t %f]

  gr_i=['thick=xget(''thickness'')'
        'pat=xget(''pattern'')'
        'fnt=xget(''font'')'
        'l=0.15;h=0.2';
        'x0=0.31;y0=0.15;y1=0.6'
        'x1=x0-l/2;x2=x0+l/2;y2=y1+h'
        'xpoly(orig(1)+[x0;x0]*sz(1),orig(2)+[y0;y1]*sz(2),""lines"")'
        'xfpoly(orig(1)+[x1;x2;x0]*sz(1),orig(2)+[y1;y1;y2]*sz(2),1)'
        'txt=''N'';'
        'style=2;'
        'rectstr=stringbox(txt,orig(1)+0.55*sz(1),orig(2)+0.4*sz(2),0,style,1);'
        'w=(rectstr(1,3)-rectstr(1,2))*%zoom;'
        'h=(rectstr(2,2)-rectstr(2,4))*%zoom;'
        'xstringb(orig(1)+0.55*sz(1),orig(2)+0.4*sz(2),txt,w,h,''fill'');'
        'xset(''thickness'',thick)'
        'xset(''pattern'',pat)'
        'xset(''font'',fnt(1),fnt(2))']
  exprs=[string(nu),string(nech),string(init),string(SFtyp),string(typ),string(herit)]
  x=standard_define([2 2],model,exprs,gr_i)
end
endfunction

//X est une matrice de réels
//tt est un boolean
function tt=is_int(X)
 Y=matrix(X,size(X,'*'),1);
 Z=int(X);
 tt=%t;
 for i=1:size(Y,1)
    if (Z(i)-Y(i))<>0 then
      tt=tt&%f;
    else
     tt=tt&%t;
   end
 end
endfunction