Interfacing function
eng


TRAPINTEGRAL_m title

File content


//TRAPINTEGRAL_m Scicos vector intgerator by Trapezoidal method
//Classical interface function ver1.0 - scicoslab 4.3
//30 mai 2009 - INRIA - Author : A.Layec
function [x,y,typ]=TRAPINTEGRAL_m(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]=standard_outputs(arg1)
case 'getorigin' then
  [x,y]=standard_origin(arg1)
case 'set' then
  x=arg1
  graphics=arg1.graphics;
  exprs=graphics.exprs
  model=arg1.model;
  while %t do
   text=['Set discrete integral parameters';'(Trapezoidal)']
   [ok,step,x0_in,x0_out,exprs]=getvalue(text,...
      ['Step';'Initial input state';'Initial output sate'],...
      list('vec',1,'mat',[-1 -2],'mat',[-1 -2]),exprs)

    if ~ok then break,end

    nu=size(x0_in,1);
    mu=size(x0_in,2);
    if nu<>size(x0_out,1) | mu<>size(x0_out,2) then
      message('Initial input state and Initial output sate must have the same size');
      ok=%f;
    end
    if type(x0_in)<>type(x0_out) then
      message('Initial input state and Initial output sate must have the same type');
      ok=%f;
    else
      if (type(x0_in)==1) then
        if isreal(x0_in) then
          if ~isreal(x0_out) then
            message('Initial input state and Initial output sate must have the same type');
            ok=%f;
          end
        else
          if isreal(x0_out) then
            message('Initial input state and Initial output sate must have the same type');
            ok=%f;
          end
        end
      else
        if typeof(x0_in)<>typeof(x0_out) then
          message('Initial input state and Initial output sate must have the same type');
          ok=%f;
        end
      end
    end
    if ok then
      if (type(x0_in)==1) then
        if isreal(x0_in) then
          ut=1;
        else
          ut=2;
        end
      elseif (typeof(x0_in)=="int32") then 
        ut=3;
      elseif (typeof(x0_in)=="int16") then
        ut=4;
      elseif (typeof(x0_in)=="int8") then
        ut=5;
      elseif (typeof(x0_in)=="uint32") then
        ut=6;
      elseif (typeof(x0_in)=="uint16") then
        ut=7;
      elseif (typeof(x0_in)=="uint8") then
        ut=8;
      else
        message ("Bad type for discrete state.");
        ok=%f;
      end
    end

    if ok then
      [model,graphics,ok]=set_io(model,graphics,list([nu mu],ut),list([nu mu],ut),1,[])
      if ok then
        model.rpar     = step
        model.odstate  = list(x0_out,x0_in);
        graphics.exprs = exprs;
        x.graphics     = graphics;
        x.model        = model
        break
      end
    end
  end

case 'define' then
  x0_in  = 0
  x0_out = 0
  step   = 1
  nu     = 1
  mu     = 1

  model           = scicos_model()
  model.sim       = list('int_trap_m',4)
  model.in        = nu
  model.in2       = mu
  model.intyp     = 1
  model.out       = nu
  model.out2      = mu
  model.outtyp    = 1
  model.evtin     = 1
  model.rpar      = step
  model.odstate   = list(x0_in,x0_out)
  model.blocktype = 'd'

  exprs=[string(step);strcat(sci2exp(x0_in));strcat(sci2exp(x0_out))]
  gr_i=['thick=xget(''thickness'')'
        'pat=xget(''pattern'')'
        'fnt=xget(''font'')'
        'xpoly(orig(1)+[0.7;0.62;0.549;0.44;0.364;0.291]*sz(1),orig(2)+[0.947;0.947;0.884;0.321;0.255;0.255]*sz(2),"'lines"')'
        'txt=''Trapezoidal'';'
        '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