1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
function [ok,tcur,cpr,alreadyran,needcompile,state0]=do_run(cpr)
// realize action associated to the run button
// performs necessary diagram (re-)compilation
// performs simulation initialisation
// performs simulation error recovery
//
// state : is current state
// state0 : is initial state value
//
// define user possible choices
// Copyright INRIA
if needcompile==4 then alreadyran=%f,end
if alreadyran&needcompile<=1 then
choix=['Continue';'Restart';'End']
elseif alreadyran then
choix=['Restart';'End']
else
choix=[]
end
// update parameters or compilation results
[cpr,state0_n,needcompile,ok]=do_update(cpr,state0,needcompile)
if ~ok then tcur=[],alreadyran=%f,return,end
if or(state0_n<>state0) then //initial state has been changed
state0=state0_n
cpr(1)=state0
if choix(1)=='Continue' then choix(1)=[],end
end
// ask user what to do
if choix<>[] then
to_do=x_choose(choix,'What do you want to do')
if to_do==0 then ok=%f,return,end
select choix(to_do)
case 'Continue' then
needstart=%f
state=cpr(1)
case 'Restart' then
needstart=%t
state=state0
case 'End' then
errcatch(-1,'continue')
needstart=%t
wpar=scs_m(1);tf=wpar(4);tolerances=wpar(3)
[state,t]=scicosim(cpr(1),tcur,tf,cpr(2),'finish',tolerances)
cpr(1)=state
alreadyran=%f
errcatch(-1)
if iserror(-1)==1 then
errclear(-1)
kfun=curblock()
corinv=cpr(4)
if kfun<>0 then
path=corinv(kfun)
//if size(path)==1 then path=path(1),end
xset('window',curwin)
bad_connection(path,..
['End problem with hilited block';
'see message in scilab window'])
else
message('End problem, see message in scilab window')
end
ok=%f
return
end
xset('window',curwin)
return
end
else
needstart=%t
if needcompile<>4 then state=cpr(1),end
end
win=xget('window')
if needstart then //scicos initialisation
tcur=0
cpr(1)=state0
wpar=scs_m(1);tf=wpar(4);tolerances=wpar(3)
if tf*tolerances==[] then
x_message(['Simulation parameters not set';'use setup button']);
return;end
errcatch(-1,'continue')
[state,t]=scicosim(cpr(1),tcur,tf,cpr(2),'start',tolerances)
cpr(1)=state
errcatch(-1)
if iserror(-1)==1 then
errclear(-1)
kfun=curblock()
corinv=cpr(4)
if kfun<>0 then
//path=get_subobj_path(corinv(kfun))
//if size(path)==1 then path=path(1),end
xset('window',curwin)
path=corinv(kfun)
bad_connection(path,..
['Initialisation problem with hilited block';
'see message in scilab window'])
else
message('Initialisation problem, see message in scilab window')
end
ok=%f
xset('window',curwin)
unsetmenu(curwin,'stop')
return
end
xset('window',win);
end
// simulation
wpar=scs_m(1);tf=wpar(4);tolerances=wpar(3)
setmenu(curwin,'stop')
timer()
errcatch(-1,'continue')
[state,t]=scicosim(cpr(1),tcur,tf,cpr(2),'run',tolerances)
cpr(1)=state
errcatch(-1)
if iserror(-1)==0 then
tcur=t
alreadyran=%t
else
errclear(-1)
kfun=curblock()
corinv=cpr(4)
if kfun<>0 then
//path=get_subobj_path(corinv(kfun))
//if size(path)==1 then path=path(1),end
path=corinv(kfun)
xset('window',curwin)
bad_connection(path,..
['Simulation problem with hilited block';
'see message in scilab window'])
else
message('Simulation problem, see message in scilab window')
end
ok=%f
end
xset('window',curwin)
disp(timer())
unsetmenu(curwin,'stop')
|