generate_sim_file - create directory and simulation scripts of a scicos diagram
generate_sim_file(dname)
- dname : string. the name of scicos_diagram to search in MODNUM directory (extension free)
//generate_sim_file
//fonction qui genere un ensemble de fichiers
//pour réaliser des simulations de diagramme scicos
//à partir de la ligne de commande scilab
//Le diagramme scicos est cherché dans les répertoires
//du projet.
//Lorsque le diagramme est trouvé la fonction
//crée un nouveau répertoire dname_sim dans le répertoire
//MODNUM+'/simu'.
//ce répertoire contient un fichier dname_sim.cos, correspondant au
//diagramme à simuler, un fichier dname_sim_ctxt.sce qui correspond
//au context du diagramme et un fichier dname_sim.sce qui correspond
//au script à éxécuter pour simuler le diagramme.
//Entrée : dname le nom du fichier cos à chercher dans MODNUM.
//Sortie : néant
function generate_sim_file(dname)
//test tt_ml
if ~exists('tt_ml') then
tt_ml=return_master_list(MODNUM);
end
dname=basename(dname);
//find directory path of dname+'.cos' file
path_dname=return_path_cos_file(dname);
if path_dname==[] then
disp('Unable to find '+dname+'.cos');
return;
end
//load scicos diagram
load(path_dname+dname+'.cos');
context=scs_m.props("context");
//convert context
tt_ctxt='scs_m.props.context=[';
for i=1:size(context,1)
str=string(context(i));
if str<>'' then
str=strsubst(str,'''','''''');
tt_ctxt=[tt_ctxt;
''''+str+''''];
end
end
tt_ctxt=[tt_ctxt;'];'];
//Definition of the target path
if MSDOS then
simu_path=MODNUM+'\simu\';
else
simu_path=MODNUM+'/simu/';
end
if fileinfo(simu_path+dname+'_sim')<>[] then
ok=%t;j=1;
while ok
if fileinfo(simu_path+dname+'_sim'+'_'+string(j))==[] then
ok=%f;
path_sim=simu_path+dname+'_sim'+'_'+string(j);
sim_path=dname+'_sim'+'_'+string(j);
else
j=j+1;
end
end
else
path_sim=simu_path+dname+'_sim';
sim_path=dname+'_sim';
end
//create target path
if MSDOS then
mk_cmd='mkdir '+'""'+path_sim+'""';
else
mk_cmd='mkdir '+path_sim;
end
unix_g(mk_cmd);
//put cxt in file
mputl(tt_ctxt,path_sim+'/'+dname+'_sim'+'_ctxt.sce');
//export diagram file
scs_m.props.title(1)=dname+'_sim';
if MSDOS then
scs_m.props.title(2)=path_sim+'\';
else
scs_m.props.title(2)=path_sim+'/';
end
//Load scicos library
exec(load_scicos_func,-1);
//save diagram
pal_mode=%f;
super_block=%f;
do_save(scs_m);
//def sript file
tt_sci=['//Define simulation name';
'sim_name='''+dname+'_sim'+''';';
'//Define simulation path';
'sim_path='''+sim_path+''';';
'//Load scicos diagram';
'load(MODNUM+''/simu/''+sim_path+''/''+sim_name+''.cos'');';
'//Define context'
'exec(MODNUM+''/simu/''+sim_path+''/''+sim_name+''_ctxt.sce'');';
'context=scs_m.props(""context"");execstr(context);';
'//Define Simulation end time';
'scs_m.props.tf=Tfin;';
'//Define other variables';
'';
'//Open Log file';
'u_log=mopen(MODNUM+''/simu/''+sim_path+''/''+sim_name+''.log'',''a'');';
'//Set flag (for display saved information in scilab window)';
'flag=1;';
'//Save inital state of simulation in Log file';
'wlog_init(u_log,flag);';
'//Save context in log file';
'wlog_ctxt(u_log,flag);';
'//Loop for iterative simulation';
'j=1;';
'//Save and display begin simulation date j';
'wlog_bst(u_log,j,flag);';
'//substitue context variable to be sweep';
'//scs_m.props.context=subst_ctxt(scs_m,''varname'',''varname='');';
'//Initialise Info and %scicos_context variable';
'if exists(''Info'')==0 then Info=list(); end';
'if exists(''%scicos_context'')==0 then %scicos_context=struct(); end';
'//Do simulation with scicos_simulate'
'Info=scicos_simulate(scs_m,Info,%scicos_context);';
'//Load result';
'//myvar=return_state_block(Info,""blockname"")';
'//Save and display util variable';
'//wlog_sv(u_log,tlist([''varname''],varvalue),flag);';
'//Save and Disp final simulation date j';
'wlog_fst(u_log,j,flag);';
'//post-processed result';
'//Save and display post-processed vector(matrix)';
'//wlog_psv(u_log,tlist([''varname''],varvalue,flag);';
'//Close final state of simulation in Log file';
'wlog_final(u_log,flag);';
'//close log file';
'mclose(u_log);';
];
//put script text in file
mputl(tt_sci,path_sim+'/'+dname+'_sim'+'.sce');
endfunction
IRCOM Group
Alan Layec