Interfacing function
eng


BIN2DEC_c

File content


//BIN2DEC_c Scicos Random Integer Generator block
//Classical interface function ver1.0 - scicoslab 4.3
//14 Février 2009 - INRIA - Author : A.Layec
function [x,y,typ]=BIN2DEC_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]=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,outsz,N,msb,is_sign,outtyp,exprs] = getvalue('Scicos Bit number to  Decimal number',...
          ['Output size';
           'Number of bits per integer';
           'MSB first (0:No/1:Yes)';
           'Signed number (0:No/1:Yes)';
           'Output data type (-1:automatic switch)'],...
           list('vec',1,'vec',1,'vec',1,'vec',1,'vec',1),exprs);

      if ~ok then break,end;

      //## check out size
      if outsz<=0 then
        message('Output Size must be positive.');
        ok=%f;
      end

      //## check number of bit per integer
      if N<=0 | N>=31 then
        message([' Number of bits per integer';...
                 'must be in [1;31].']);
        ok=%f;
      end

      //## check msb dialogue parameter
      if msb<0 | msb>1 then
        message([' The dialogue parameter';...
                 '''MSB first'' must be 0 or 1.']);
        ok=%f;
      end

      //## check is_sign dialogue parameter
      if is_sign<0 | is_sign>1 then
        message([' The dialogue parameter';...
                 '''Signed number'' must be 0 or 1.']);
        ok=%f;
      end

      //## check output data type
      if ~(or(outtyp==[1:8])|(outtyp==-1)) then
        message([' Set -1 for automatic switch for output data type';...
                 'or use a scicos datatype number (1,2,3,4,5,6,7 or 8)']);
        ok=%f;
      end

      if ok then

        //## compute output data type if needed
        if outtyp==-1 then
          if is_sign==1 then
            if or(N==[1:8]) then
              outtyp=5
            elseif or(N==[9:16]) then
              outtyp=4
            else
              outtyp=3
            end
          else
            if or(N==[1:8]) then
              outtyp=8
            elseif or(N==[9:16]) then
              outtyp=7
            else
              outtyp=6
            end
          end
        end

        [model,graphics,ok] = set_io(model,graphics,list([outsz*N,1],-1),list([outsz,1],outtyp),[],[])
        model.ipar     = [N,msb,is_sign]
        graphics.exprs = exprs;
        x.graphics     = graphics;
        x.model        = model;
        break;
      end

   end

 case 'define' then
   N       = 4  //## nb de bits par entier
   msb     = 1  //## msb en premier
   is_sign = 0  //## nombre signé(0:oui/1:non)
   outsz    = 1  //## taille de la sortie
   outtyp  = -1 //## type de donnée de la sortie

   model           = scicos_model()
   model.sim       = list('bin2dec',4)
   model.in        =  outsz*N
   model.in2       =  1
   model.intyp     = -1
   model.out       =  outsz
   model.out2      =  1
   model.outtyp    =  8
   model.evtin     =  []
   model.ipar      =  []
   model.blocktype =  'd'
   model.firing    =  [N;msb;is_sign]
   model.dep_ut    =  [%t %f]

   gr_i  =  ['txt=[''Bin2Dec''];';
             'xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');']
   label = [string(outsz);string(N);string(msb);string(is_sign);string(outtyp)];
   x     = standard_define([2.5 2],model,label,gr_i)
 end
endfunction