//GENINT_c Scicos Random Integer Generator block //Classical interface function ver1.0 - scilab-4.1.2 //02 Mars 2008 - INRIA - Author : A.Layec function [x,y,typ]=GENINT_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,minv,maxv,rz,seed,datatyp,exprs] = getvalue('Scicos Random Integer Generator',... ['Min value';'Max value';'Return to Zero';'Initial Seed';'Output data type'],... list('vec',-1,'vec',-1,'vec',-1,'vec',1,'vec',1),exprs); if ~ok then break,end; //## check size of minv, maxv if or(size(minv)<>size(maxv)) then message('Min value and Max value must have the same size.') ok = %f end //## check value of minv, maxv if ok then if ~and(minv<maxv) then message('Min value must be less than Max value.'); ok = %f end end //## check size of rz if ok then if and(size(rz)==[1 1]) then rz = rz * ones(size(minv,1),size(minv,2)); //elseif and(size(rz)==size(minv)) then elseif or(size(rz)<>size(minv)) then message('''Return to Zero'' must have a size 1 or same size than ''Min'' and ''Max value''') ok = %f end end //## check values of rz if ok then if ~and((rz>=0) & (rz<=1)) then message('''Return to Zero'' must be 0 (no) or 1 (yes)') ok = %f end end //## check values of minv/maxv for rz = 0 if ok then ind = find(rz==0) for i=ind if (minv(i)==0) | (maxv(i)==0) then message('Lower or upper limit can''t be equal to zero when using not return to zero.') ok = %f break end end end //## change values of rz //## //## rz = 1 nothing to do //## rz = -2 case minv < 0 & maxv > 0 if ok then ind = find(rz==0) for i=ind if minv(i)<0 & maxv(i)>0 then rz(i)=-2 end end end //## check seed //if ok then // if and(size(seed)==[1 1]) then // seed = seed * ones(size(minv,1),size(minv,2)); // elseif or(size(seed)<>size(minv)) then // message('''Initial Seed'' value must have a size 1 or same size than ''Min'' and ''Max value''') // ok = %f; // end //end //## set datatyp if ok then if ~or(datatyp==[1:8]) then datatyp=1 end end if ok then [model,graphics,ok]=set_io(model,graphics,list(),list(size(minv),datatyp),1,[]) model.opar = list(int32(minv),int32(maxv),int32(rz)) select datatyp case 1 then model.odstate = list(int32(seed),zeros(size(minv,1),size(minv,2))) case 2 then model.odstate = list(int32(seed),zeros(size(minv,1),size(minv,2))+... %i*zeros(size(minv,1),size(minv,2))) case 3 then model.odstate = list(int32(seed),int32(zeros(size(minv,1),size(minv,2)))) case 4 then model.odstate = list(int32(seed),int16(zeros(size(minv,1),size(minv,2)))) case 5 then model.odstate = list(int32(seed),int8(zeros(size(minv,1),size(minv,2)))) case 6 then model.odstate = list(int32(seed),uint32(zeros(size(minv,1),size(minv,2)))) case 7 then model.odstate = list(int32(seed),uint16(zeros(size(minv,1),size(minv,2)))) case 8 then model.odstate = list(int32(seed),uint8(zeros(size(minv,1),size(minv,2)))) end graphics.exprs = exprs; x.graphics = graphics; x.model = model; break; end end case 'define' then minv = 0 maxv = 10 rz = 1 seed = 2344578 datatyp = 1 model = scicos_model() model.sim = list('genintc',4) model.out = size(minv,1) model.out2 = size(minv,2) model.outtyp = datatyp model.evtin = 1 model.odstate = list(int32(seed),zeros(size(minv,1),size(minv,2))) model.opar = list(int32(minv),int32(maxv),int32(rz)) model.blocktype = 'd' model.firing = [] model.dep_ut = [%f %f] gr_i = ['txt=[''Random'';''Integer'';''Generator''];'; 'xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');'] label = [sci2exp(minv);sci2exp(maxv);sci2exp(rz);sci2exp(seed);sci2exp(datatyp)]; x = standard_define([2.5 2],model,label,gr_i) end endfunction