Interfacing function
eng


DOWNSMPL_f

File content


//DOWNSMPL_f Scicos downsample block
//Classical interface function ver1.0 - scilab-3
//29 janvier 2004  Author : - IRCOM GROUP - A.Layec
function [x,y,typ]=DOWNSMPL_f(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 Downsample block']
      [ok,ny,nech,init,herit,exprs]=getvalue(text,...
      ['Size of outputs';'Downsample factor';'Initial sample';...
      'Inherit (no:0, yes:1)'],...
      list('vec',1,'vec',1,'vec',1,'vec',1),exprs)

      if ~ok then break,end;
      //test
      if ~is_int(ny) then
        message('The size of outputs 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 ok then
          gr_i=['thick=xget(''thickness'')'
                'pat=xget(''pattern'')'
                'fnt=xget(''font'')'
                'l=0.15;h=0.2';
                'x0=0.31;y0=0.8;y1=0.35'
                '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

          nu=ny*nech
          if herit==1 then
            model.dep_ut=[%t %f]
            [model,graphics,ok]=check_io(model,graphics,nu,ny,[],[])
          else
            model.dep_ut=[%t %f]
            [model,graphics,ok]=check_io(model,graphics,nu,ny,1,[])
          end
          graphics.exprs=exprs
          model.in=nu
          model.out=ny
          model.ipar=[nech;init]
          x.graphics=graphics;x.model=model
          break;
      end
   end

case 'define' then
  ny=64
  herit=1
  nech=8
  nu=nech*ny
  init=0

  model=scicos_model()
  model.sim=list('sousecht',4)
  model.in=nu
  model.out=ny
  model.evtin=[]
  model.evtout=[]
  model.dstate=[]
  model.rpar=[]
  model.ipar=[nech;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.8;y1=0.35'
        '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=''M'';'
        '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(ny),string(nech),string(init),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