[Scilab-users] Problem running xcos in batch mode from Scilab

Romain Desbats romain.desbats at ifsttar.fr
Wed Feb 19 11:34:40 CET 2014


Dear Scilab users, 

I am running a simple electrical model in xcos (see attached). This model reads a .csv input file and outputs a variable to the workspace. The model works fine when I compile it and run it by using the menus in xcos. 

What I would like is to run it in batch mode from Scilab in order optimise the model parameters. 

My plan is to use xcos_simulate to compile the diagram, to modify the cpr variable generated by the compilation (to change the model parameters) and than to simulate the model with scicosim . 

The problem is that calling the cpr variable after the compilation results in kind of "freezing" the workspace. 

- The variable browser shows "N/A" for all the variables (from image 1 to image 2 attached) 
- Calling cpr does not give any result (image 3 attached) 

Does anyone has any idea of what is happening? 

I am using Scilab 5.4.1. 

My code is as follows: 

// parameters 
data=csvRead('input.csv',';'); 
input_current=evstr(data(:,1)); 
size1=length(input_current); 

C=1/10000; 
R=12900; 

T=0.0001; // timestep 

time=[0:T:(size1-1)*T]'; // in s 

end_time=time($)+T; // end time in s 

// loading Xcos functions 
loadScicos; 
loadXcosLibs(); 
exec(loadpallibs,-1); 

// loading model 
importXcosDiagram('graphic_model.xcos') 

// compilation: scs_m is the result of the import, 
xcos_simulate(scs_m,4) // '4' is to perform compilation 

tf=end_time; 

atol=1.e-8; 
rtol=1.e-9; 
ttol=1.e-10; 
deltat=tf; 
scale=0; 
hmax=0; 

tol=[atol,rtol,ttol,deltat,scale,hmax]; 

// PROBLEM COMES WHEN EXECUTING NEXT LINE 

state=cpr.state; // cpr variable came from the compilation 
sim=cpr.sim; 

cpr.sim.rpar(5)=T; // timestep 
cpr.sim.rpar(5)=0; // initialisation 
cpr.sim.rpar(7)=R; // resistance 
cpr.sim.rpar(8)=C; // capacitor 

// initialisation 
[state,t]=scicosim(state,0,tf,sim,'start',tol); 
// run 
[state,t]=scicosim(state,t,tf,sim,'run',tol) 
//end 
[state,t]=scicosim(state,t,tf,sim,'finish',tol); 

graph_voltage=graph_voltage.values; // output variable 

Thanks a lot for your help. 

Best regards, 


Romain 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20140219/99fd53c4/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1.png
Type: image/png
Size: 121580 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20140219/99fd53c4/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2.png
Type: image/png
Size: 121447 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20140219/99fd53c4/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 3.png
Type: image/png
Size: 120644 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20140219/99fd53c4/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: input.csv
Type: text/csv
Size: 2222 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20140219/99fd53c4/attachment.csv>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graphic_model.xcos
Type: application/xml
Size: 74159 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20140219/99fd53c4/attachment.wsdl>


More information about the users mailing list