summaryrefslogtreecommitdiff
path: root/modules/scicos/macros
diff options
context:
space:
mode:
authorShashank2017-05-29 12:40:26 +0530
committerShashank2017-05-29 12:40:26 +0530
commit0345245e860375a32c9a437c4a9d9cae807134e9 (patch)
treead51ecbfa7bcd3cc5f09834f1bb8c08feaa526a4 /modules/scicos/macros
downloadscilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.gz
scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.bz2
scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.zip
CMSCOPE changed
Diffstat (limited to 'modules/scicos/macros')
-rwxr-xr-xmodules/scicos/macros/buildmacros.sce20
-rwxr-xr-xmodules/scicos/macros/scicos_auto/buildmacros.sce16
-rwxr-xr-xmodules/scicos/macros/scicos_auto/libbin0 -> 380 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_auto/lincos.binbin0 -> 42396 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_auto/lincos.sci290
-rwxr-xr-xmodules/scicos/macros/scicos_auto/names3
-rwxr-xr-xmodules/scicos/macros/scicos_auto/scicos_simulate.binbin0 -> 56424 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_auto/scicos_simulate.sci427
-rwxr-xr-xmodules/scicos/macros/scicos_auto/steadycos.binbin0 -> 39804 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_auto/steadycos.sci269
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%Block_e.binbin0 -> 1608 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%Block_e.sci34
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%Block_p.binbin0 -> 4272 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%Block_p.sci56
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%b_i_graphics.binbin0 -> 664 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%b_i_graphics.sci25
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%b_i_model.binbin0 -> 1148 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%b_i_model.sci26
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%c_i_block.binbin0 -> 752 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%c_i_block.sci25
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%c_i_graphics.binbin0 -> 664 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%c_i_graphics.sci25
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%c_i_model.binbin0 -> 1148 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%c_i_model.sci26
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%debug_scicos.binbin0 -> 832 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%debug_scicos.sci29
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%diagram_p.binbin0 -> 1560 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%diagram_p.sci34
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%graphics_e.binbin0 -> 1312 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%graphics_e.sci29
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%graphics_i_Block.binbin0 -> 360 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%graphics_i_Block.sci24
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%graphics_p.binbin0 -> 1080 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%graphics_p.sci30
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%l_i_block.binbin0 -> 636 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%l_i_block.sci25
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%l_i_graphics.binbin0 -> 664 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%l_i_graphics.sci25
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%l_i_model.binbin0 -> 1148 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%l_i_model.sci26
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%model_e.binbin0 -> 1300 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%model_e.sci29
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%model_i_Block.binbin0 -> 360 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%model_i_Block.sci24
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%model_p.binbin0 -> 2092 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%model_p.sci40
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%params_p.binbin0 -> 1240 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%params_p.sci34
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%s_i_block.binbin0 -> 636 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%s_i_block.sci25
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%s_i_graphics.binbin0 -> 664 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%s_i_graphics.sci25
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%s_i_model.binbin0 -> 1148 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/%s_i_model.sci26
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/CC4.binbin0 -> 10188 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/CC4.sci121
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/CFORTR.binbin0 -> 6392 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/CFORTR.sci84
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/CFORTR2.binbin0 -> 17484 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/CFORTR2.sci164
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/Compute_cic.binbin0 -> 34060 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/Compute_cic.sci257
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/FORTR.binbin0 -> 5860 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/FORTR.sci75
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/Link_modelica_C.binbin0 -> 6228 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/Link_modelica_C.sci75
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/MODCOM.binbin0 -> 21436 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/MODCOM.sci211
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/Sinks.cosf837
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/adjust.binbin0 -> 64332 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/adjust.sci465
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/adjust_in2out2.binbin0 -> 5500 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/adjust_in2out2.sci58
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/bad_connection.binbin0 -> 18512 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/bad_connection.sci131
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/build_block.binbin0 -> 9984 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/build_block.sci86
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/build_modelica_block.binbin0 -> 8972 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/build_modelica_block.sci77
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/buildmacros.sce16
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/buildnewblock.binbin0 -> 20284 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/buildnewblock.sci186
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/c_pass1.binbin0 -> 70328 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/c_pass1.sci499
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/c_pass2.binbin0 -> 399136 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/c_pass2.sci2615
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/c_pass3.binbin0 -> 35472 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/c_pass3.sci257
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/check_io.binbin0 -> 15612 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/check_io.sci141
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/check_mac.binbin0 -> 896 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/check_mac.sci29
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/color.tst61
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/compile_init_modelica.binbin0 -> 14860 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/compile_init_modelica.sci140
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/compile_modelica.binbin0 -> 18680 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/compile_modelica.sci141
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/context_evstr.binbin0 -> 3548 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/context_evstr.sci50
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/cos2cosf.binbin0 -> 27212 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/cos2cosf.sci233
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/countblocks.binbin0 -> 1820 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/countblocks.sci38
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/create_modelica.binbin0 -> 36936 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/create_modelica.sci333
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/default_color.binbin0 -> 1556 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/default_color.sci36
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/default_options.binbin0 -> 2412 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/default_options.sci43
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/delete_unconnected.binbin0 -> 9616 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/delete_unconnected.sci101
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/dialog.binbin0 -> 608 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/dialog.sci25
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/dig_bound_compound.binbin0 -> 10444 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/dig_bound_compound.sci100
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_compile.binbin0 -> 9984 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_compile.sci109
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_compile_superblock42.binbin0 -> 829896 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_compile_superblock42.sci6005
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_delete1.binbin0 -> 41648 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_delete1.sci253
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_edit_pal.bug32
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_eval.binbin0 -> 27640 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_eval.sci207
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_purge.binbin0 -> 7324 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_purge.sci78
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_terminate.binbin0 -> 9692 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_terminate.sci104
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_update.binbin0 -> 14204 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_update.sci124
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_version.binbin0 -> 364580 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/do_version.sci2328
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/entity_menu.sce520
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/extract_implicit.binbin0 -> 20984 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/extract_implicit.sci144
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/findinlist.binbin0 -> 2856 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/findinlist.sci38
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/findinlistcmd.binbin0 -> 4200 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/findinlistcmd.sci51
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/gen_modelica.binbin0 -> 13832 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/gen_modelica.sci114
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/genfunc.binbin0 -> 4216 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/genfunc.sci58
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/genfunc1.binbin0 -> 31004 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/genfunc1.sci260
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/genfunc2.binbin0 -> 31120 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/genfunc2.sci260
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/genmac.binbin0 -> 7912 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/genmac.sci90
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get2index.binbin0 -> 6132 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get2index.sci81
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get_connected.binbin0 -> 6092 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get_connected.sci65
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get_dynamic_lib_dir.binbin0 -> 4636 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get_dynamic_lib_dir.sci51
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get_errorcmd.binbin0 -> 9668 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get_errorcmd.sci108
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get_model_name.binbin0 -> 2708 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get_model_name.sci45
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get_subobj_path.binbin0 -> 2556 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get_subobj_path.sci36
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get_tree_elt.binbin0 -> 1252 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/get_tree_elt.sci34
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/getmodelicacpath.binbin0 -> 3892 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/getmodelicacpath.sci67
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/global_case.binbin0 -> 4540 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/global_case.sci48
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/haltscicos.binbin0 -> 808 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/haltscicos.sci27
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/hilite_path.binbin0 -> 4900 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/hilite_path.sci68
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/init_agenda.binbin0 -> 4564 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/init_agenda.sci53
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/is_modelica_block.binbin0 -> 936 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/is_modelica_block.sci29
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/libbin0 -> 3340 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/link_olibs.binbin0 -> 6136 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/link_olibs.sci104
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/lnkptrcomp.binbin0 -> 4580 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/lnkptrcomp.sci50
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/loadpallibs.binbin0 -> 1464 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/loadpallibs.sci33
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/mark_prt.binbin0 -> 3572 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/mark_prt.sci47
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/message.binbin0 -> 2592 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/message.sci45
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/mfrequ_clk.binbin0 -> 20320 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/mfrequ_clk.sci104
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/modelica.binbin0 -> 1784 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/modelica.sci31
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/modelicac.binbin0 -> 6156 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/modelicac.sci79
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/modipar.binbin0 -> 48168 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/modipar.sci304
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/names126
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/reading_incidence.binbin0 -> 13952 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/reading_incidence.sci128
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/recur_scicos_block_link.binbin0 -> 9224 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/recur_scicos_block_link.sci79
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/sample_clk.binbin0 -> 59564 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/sample_clk.sci295
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_block.binbin0 -> 1916 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_block.sci30
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_block_link.binbin0 -> 4044 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_block_link.sci59
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_cpr.binbin0 -> 2028 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_cpr.sci30
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_diagram.binbin0 -> 1760 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_diagram.sci30
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_flat.binbin0 -> 81596 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_flat.sci456
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_graphics.binbin0 -> 7744 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_graphics.sci61
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_include_paths.binbin0 -> 2588 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_include_paths.sci46
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_link.binbin0 -> 2716 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_link.sci34
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_model.binbin0 -> 8656 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_model.sci56
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_params.binbin0 -> 4292 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_params.sci48
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_sim.binbin0 -> 11800 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_sim.sci75
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_state.binbin0 -> 3116 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_state.sci34
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_txtedit.binbin0 -> 1836 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scicos_txtedit.sci30
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/script2var.binbin0 -> 8500 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/script2var.sci89
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scs_full_path.binbin0 -> 2140 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scs_full_path.sci31
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scs_show.binbin0 -> 2740 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scs_show.sci47
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scstxtedit.binbin0 -> 1764 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/scstxtedit.sci62
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/set_io.binbin0 -> 24572 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/set_io.sci284
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/setvalue.binbin0 -> 45944 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/setvalue.sci282
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/shiftcors.binbin0 -> 1604 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/shiftcors.sci32
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/split_lasterror.binbin0 -> 2744 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/split_lasterror.sci47
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_define.binbin0 -> 4708 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_define.sci52
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_draw.binbin0 -> 35532 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_draw.sci251
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_draw_ports.binbin0 -> 28752 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_draw_ports.sci211
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_draw_ports_up.binbin0 -> 6612 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_draw_ports_up.sci56
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_inputs.binbin0 -> 7036 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_inputs.sci76
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_origin.binbin0 -> 576 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_origin.sci26
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_outputs.binbin0 -> 7044 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/standard_outputs.sci75
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/translator.binbin0 -> 12732 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/translator.sci113
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/update_scs_m.binbin0 -> 24948 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/update_scs_m.sci242
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/update_version.binbin0 -> 1448 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/update_version.sci40
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/validvar.binbin0 -> 3852 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/validvar.sci48
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/value2modelica.binbin0 -> 4188 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/value2modelica.sci49
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/xml2modelica.binbin0 -> 5352 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_scicos/xml2modelica.sci60
-rwxr-xr-xmodules/scicos/macros/scicos_utils/block_parameter_error.binbin0 -> 3572 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_utils/block_parameter_error.sci32
-rwxr-xr-xmodules/scicos/macros/scicos_utils/buildmacros.sce16
-rwxr-xr-xmodules/scicos/macros/scicos_utils/find_scicos_version.binbin0 -> 5264 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_utils/find_scicos_version.sci78
-rwxr-xr-xmodules/scicos/macros/scicos_utils/fixedpointgcd.binbin0 -> 2288 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_utils/fixedpointgcd.sci13
-rwxr-xr-xmodules/scicos/macros/scicos_utils/get_scicos_version.binbin0 -> 200 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_utils/get_scicos_version.sci25
-rwxr-xr-xmodules/scicos/macros/scicos_utils/initial_scicos_tables.binbin0 -> 2676 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_utils/initial_scicos_tables.sci20
-rwxr-xr-xmodules/scicos/macros/scicos_utils/libbin0 -> 528 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_utils/names9
-rwxr-xr-xmodules/scicos/macros/scicos_utils/returntoscilab.binbin0 -> 1868 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_utils/returntoscilab.sci39
-rwxr-xr-xmodules/scicos/macros/scicos_utils/scicos_getvalue.binbin0 -> 51936 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_utils/scicos_getvalue.sci311
-rwxr-xr-xmodules/scicos/macros/scicos_utils/scicos_workspace_init.binbin0 -> 5132 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_utils/scicos_workspace_init.sci56
-rwxr-xr-xmodules/scicos/macros/scicos_utils/with_modelica_compiler.binbin0 -> 976 bytes
-rwxr-xr-xmodules/scicos/macros/scicos_utils/with_modelica_compiler.sci33
290 files changed, 26058 insertions, 0 deletions
diff --git a/modules/scicos/macros/buildmacros.sce b/modules/scicos/macros/buildmacros.sce
new file mode 100755
index 000000000..1fc8c45d3
--- /dev/null
+++ b/modules/scicos/macros/buildmacros.sce
@@ -0,0 +1,20 @@
+
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2007-2008 - INRIA - Allan CORNET <allan.cornet@inria.fr>
+// Copyright (C) 2008 - INRIA - Pierre MARECHAL <pierre.marechal@inria.fr>
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+
+lines(0);
+CurrentDirScicos = get_absolute_file_path("buildmacros.sce");
+macrosdirs = ["scicos_auto","scicos_utils","scicos_scicos"];
+
+for i=1:size(macrosdirs,"*") do
+ exec(CurrentDirScicos+"/"+macrosdirs(i)+"/buildmacros.sce");
+end
+
+clear my_script_path CurrentDirScicos macrosdirs
diff --git a/modules/scicos/macros/scicos_auto/buildmacros.sce b/modules/scicos/macros/scicos_auto/buildmacros.sce
new file mode 100755
index 000000000..5ce4f79d8
--- /dev/null
+++ b/modules/scicos/macros/scicos_auto/buildmacros.sce
@@ -0,0 +1,16 @@
+
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2007-2008 - INRIA - Allan CORNET <allan.cornet@inria.fr>
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+
+if (isdef("genlib") == %f) then
+ exec(SCI+"/modules/functions/scripts/buildmacros/loadgenlib.sce");
+end
+//------------------------------------
+genlib("scicos_autolib","SCI/modules/scicos/macros/scicos_auto",%f,%t);
+//------------------------------------
diff --git a/modules/scicos/macros/scicos_auto/lib b/modules/scicos/macros/scicos_auto/lib
new file mode 100755
index 000000000..9be083f6e
--- /dev/null
+++ b/modules/scicos/macros/scicos_auto/lib
Binary files differ
diff --git a/modules/scicos/macros/scicos_auto/lincos.bin b/modules/scicos/macros/scicos_auto/lincos.bin
new file mode 100755
index 000000000..de2bed985
--- /dev/null
+++ b/modules/scicos/macros/scicos_auto/lincos.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_auto/lincos.sci b/modules/scicos/macros/scicos_auto/lincos.sci
new file mode 100755
index 000000000..06632dd1f
--- /dev/null
+++ b/modules/scicos/macros/scicos_auto/lincos.sci
@@ -0,0 +1,290 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// Copyright (C) DIGITEO - Clément DAVID <clement.david@scilab.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ./license.txt
+//
+
+function sys = lincos(scs_m,x0,u0,param)
+ // NAME
+ // lincos - Constructs by linearization a linear state-space
+ // model from a general dynamical system described by a
+ // scicos diagram
+
+ // CALLING SEQUENCE
+ //
+ // sys = lincos(scs_m [,x0,u0 [,param] ])
+ //
+ //
+ // PARAMETERS
+ //
+ // scs_m: a Scicos data structure
+ // x0: column vector. Continuous state around which linearization to be done (default 0)
+ // u0: column vector. Input around which linearization to be done (default 0)
+ // param: list with two elements (default list(1.d-6,0))
+ // param(1): scalar. Perturbation level for linearization; the following variation is used
+ // del([x;u])_i = param(1)+param(1)*1d-4*abs([x;u])_i
+ // param(2): scalar. Time t.
+ //
+ // sys: state-space system
+ //
+ // DESCRIPTION
+ // Constructs by linearization a linear state-space
+ // model from a general dynamical system described by a
+ // scicos diagram scs_m. Input and output ports, normally
+ // used inside superblocks, should be used to specify
+ // inputs and outputs in the scicos diagram. Suppose the
+ // scicos diagram to be linearized is called mysystem and
+ // it is saved in mysystem.cos in the current directory. The scicos
+ // diagram scs_m can be obtained either by
+ // scs_m = scicos('mysystem.cos');
+ // followed by a quit in the scicos menu, or by
+ // load('mysystem.cos')
+ // which creates by default a variable called scs_m.
+
+
+ //** This function can be (ab)used from the Scilab command line and
+ //** inside a Scicos "context". In order to handle the different situations,
+ //** the required library are loaded if not already present in the
+ //** "semiglobal-local-environment".
+
+ if ~exists("scicos_diagram") then
+ loadXcosLibs();
+ end
+
+ if exists("scicos_scicoslib")==0 then
+ load("SCI/modules/scicos/macros/scicos_scicos/lib") ;
+ end
+
+ if exists("scicos_autolib")==0 then
+ load("SCI/modules/scicos/macros/scicos_auto/lib") ;
+ end
+
+ if exists("scicos_utilslib")==0 then
+ load("SCI/modules/scicos/macros/scicos_utils/lib") ;
+ end
+
+ // Define Scicos data tables ===========================================
+ if ( ~isdef("modelica_libs") | ..
+ ~isdef("scicos_pal_libs") ) then
+ [modelica_libs, scicos_pal_libs, %scicos_with_grid, %scs_wgrid] = initial_scicos_tables();
+ end
+ // =====================================================================
+ [lhs, rhs] = argn(0);
+
+ if rhs < 1 then
+ error(msprintf(gettext("%s: Wrong number of input argument(s): At least %d expected.\n"), "lincos", 1));
+ end
+ if typeof(scs_m)<>"diagram" & typeof(scs_m)<>"cpr" then
+ error(msprintf(gettext("%s: Wrong type for input argument #%d: A diagram expected.\n"), "lincos", 1));
+ end
+
+ // compile and post-process the diagram
+ if typeof(scs_m)=="diagram" then
+
+ // Propagate context through all blocks
+ %state0 = list();
+ needcompile = 4;
+ %cpr = struct();
+ %cpr.state = %state0;
+ %scicos_context = struct();
+ context = scs_m.props.context;
+
+ [%scicos_context, ierr] = script2var(context, %scicos_context);
+ [scs_m,%cpr,needcompile,ok] = do_eval(scs_m, %cpr, %scicos_context);
+ if ~ok then
+ error(msprintf(gettext("%s: Error during block parameters evaluation.\n"), "lincos"));
+ end
+
+ IN = [];
+ OUT = [];
+
+ // check version
+ current_version = get_scicos_version()
+ scicos_ver = find_scicos_version(scs_m)
+ if scicos_ver<>current_version then
+ scs_m=do_version(scs_m, scicos_ver);
+ end
+
+ // looking for I/O
+ for i=1:size(scs_m.objs)
+ if typeof(scs_m.objs(i))=="Block" then
+ if or(scs_m.objs(i).gui==["IN_f", "INPUTPORT"]) then
+ scs_m.objs(i).gui="INPUTPORT";
+ IN=[IN scs_m.objs(i).model.ipar]
+ elseif or(scs_m.objs(i).gui==["OUT_f", "OUTPUTPORT"]) then
+ scs_m.objs(i).gui="OUTPUTPORT";
+ OUT=[OUT scs_m.objs(i).model.ipar]
+ elseif or(scs_m.objs(i).gui==["CLKIN_f","CLKINV_f", "INPUTPORTEVTS"]) then
+ scs_m.objs(i).gui="INPUTPORTEVTS";
+ scs_m.objs(i).model.sim(1)="bidon"
+ elseif or(scs_m.objs(i).gui==["CLKOUT_f","CLKOUTV_f", "OUTPUTPORTEVTS"]) then
+ scs_m.objs(i).gui="OUTPUTPORTEVTS";
+ scs_m.objs(i).model.sim(1)="bidon"
+ end
+ end
+ end
+
+ if IN == [] then
+ error(msprintf(gettext("%s: Unable to find diagram inputs\n"), "lincos"));
+ end
+ if OUT == [] then
+ error(msprintf(gettext("%s: Unable to find diagram outputs\n"), "lincos"));
+ end
+
+ IN=-gsort(-IN);
+ if or(IN<>[1:size(IN,"*")]) then
+ error(msprintf(gettext("%s: Input ports are not numbered properly.\n"),"lincos"))
+ end
+
+ OUT=-gsort(-OUT);
+ if or(OUT<>[1:size(OUT,"*")]) then
+ error(msprintf(gettext("%s: Output ports are not numbered properly.\n"),"lincos"))
+ end
+
+ //compile scs_m
+ [bllst, connectmat, clkconnect,cor,corinv,ok] = c_pass1(scs_m);
+ if ~ok then
+ error(msprintf(gettext("%s: Diagram does not compile in pass %d.\n"),"lincos",1));
+ end
+
+ %cpr = c_pass2(bllst,connectmat,clkconnect,cor,corinv);
+
+ if %cpr==list() then
+ ok = %f ;
+ end
+
+ if ~ok then
+ error(msprintf(gettext("%s: Diagram does not compile in pass %d.\n"),"lincos",2))
+ end
+
+ // compile and post-process the diagram end
+ end
+
+ sim = %cpr.sim;
+ state = %cpr.state;
+ //
+ inplnk = sim.inplnk;
+ inpptr = sim.inpptr;
+ outlnk = sim.outlnk;
+ outptr = sim.outptr;
+ ipptr = sim.ipptr;
+
+ ki=[];ko=[];nyptr=1;
+ for kfun=1:length(sim.funs)
+ if sim.funs(kfun)=="output" then
+ sim.funs(kfun)="bidon"
+ ko=[ko;[kfun,sim.ipar(ipptr(kfun))]];
+ elseif sim.funs(kfun)=="input" then
+ sim.funs(kfun)="bidon"
+ ki=[ki;[kfun,sim.ipar(ipptr(kfun))]];
+ end
+ end
+
+ [junk,ind]=gsort(-ko(:,2));ko=ko(ind,1);
+ [junk,ind]=gsort(-ki(:,2));ki=ki(ind,1);
+
+ pointo=[];
+ for k=ko'
+ pointo=[pointo;inplnk(inpptr(k))]
+ end
+ pointi=[];
+
+ for k=ki'
+ pointi=[pointi;outlnk(outptr(k))]
+ end
+
+ nx=size(state.x,"*");
+ nu=0; for k=pointi', nu=nu+size(state.outtb(k),"*"), end
+ ny=0; for k=pointo', ny=ny+size(state.outtb(k),"*"), end
+
+ if rhs<3 then
+ x0=zeros(nx,1);u0=zeros(nu,1);
+ else
+ if size(x0,"*")<>nx then
+ if nx == 0 then
+ error(msprintf(gettext("%s: Wrong size for input argument #%d: Empty matrix expected.\n"), "lincos", 2));
+ else
+ error(msprintf(gettext("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"),"lincos", 2, nx, 1))
+ end
+ elseif size(u0,"*")<>nu then
+ if nx == 0 then
+ error(msprintf(gettext("%s: Wrong size for input argument #%d: Empty matrix expected.\n"), "lincos", 3));
+ else
+ error(msprintf(gettext("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"),"lincos", 3, nx, 1))
+ end
+ end
+ end
+
+ if rhs==4 then
+ del = param(1)+param(1)*1d-4*abs([x0;u0])
+ t = param(2)
+ else
+ del = 1.d-6*(1+1d-4*abs([x0;u0]) )
+ t = 0;
+ end
+
+ x0 = x0(:);
+ u0 = u0(:);
+
+ state.x=x0;
+
+ Uind = 1
+ for k=pointi'
+ state.outtb(k) = matrix(u0(Uind:Uind+size(state.outtb(k),"*")-1),size(state.outtb(k)));
+ Uind = size(state.outtb(k),"*")+1;
+ end
+
+ [state,t]=scicosim(state,t,t,sim,"start",[.1,.1,.1,.1]);
+ [state,t]=scicosim(state,t,t,sim,"linear",[.1,.1,.1,.1]);
+ Yind=1
+ for k=pointo'
+ y0(Yind:Yind+size(state.outtb(k),"*")-1)=state.outtb(k)(:);
+ Yind=size(state.outtb(k),"*")+1
+ end
+ xp0=state.x;
+ zo0=[xp0;y0];
+
+ F=zeros(nx+ny,nx+nu);
+ z0=[x0;u0];
+ zer=zeros(nx+nu,1);
+
+ for i=1:nx+nu
+ dz=zer;dz(i)=del(i);
+ z=z0+dz;
+ state.x=z(1:nx);
+ Uind=nx+1
+ for k=pointi'
+ state.outtb(k)=matrix(z(Uind:Uind+size(state.outtb(k),"*")-1),size(state.outtb(k)));
+ Uind=size(state.outtb(k),"*")+1;
+ end
+ [state,t]=scicosim(state,t,t,sim,"linear",[.1,.1,.1,.1]);
+ zo=[]
+ Yind=1
+ for k=pointo'
+ zo(Yind:Yind+size(state.outtb(k),"*")-1)=state.outtb(k)(:);
+ Yind=size(state.outtb(k),"*")+1
+ end
+ zo=[state.x;zo];
+ F(:,i)=(zo-zo0)/del(i);
+ end
+ [state,t]=scicosim(state,t,t,sim,"finish",[.1,.1,.1,.1]);
+
+ sys = syslin("c",F(1:nx,1:nx),F(1:nx,nx+1:nx+nu),F(nx+1:nx+ny,1:nx),F(nx+1:nx+ny,nx+1:nx+nu));
+
+endfunction
diff --git a/modules/scicos/macros/scicos_auto/names b/modules/scicos/macros/scicos_auto/names
new file mode 100755
index 000000000..10baea247
--- /dev/null
+++ b/modules/scicos/macros/scicos_auto/names
@@ -0,0 +1,3 @@
+lincos
+scicos_simulate
+steadycos
diff --git a/modules/scicos/macros/scicos_auto/scicos_simulate.bin b/modules/scicos/macros/scicos_auto/scicos_simulate.bin
new file mode 100755
index 000000000..8405cc1b2
--- /dev/null
+++ b/modules/scicos/macros/scicos_auto/scicos_simulate.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_auto/scicos_simulate.sci b/modules/scicos/macros/scicos_auto/scicos_simulate.sci
new file mode 100755
index 000000000..2235c8661
--- /dev/null
+++ b/modules/scicos/macros/scicos_auto/scicos_simulate.sci
@@ -0,0 +1,427 @@
+// Scicos
+//
+// Copyright (C) Scilab Enterprises - 2013 - Bruno JOFRET
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// Copyright (C) 2011 - INRIA - Serge Steer
+
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ./license.txt
+//
+
+function Info = scicos_simulate(scs_m, Info, updated_vars, flag, Ignb)
+ // Function for running scicos simulation in batch mode
+ // Info = scicos_simulate(scs_m[,Info][,updated_vars][,flag][,Ignb])
+ //
+ // scs_m: scicos diagram (obtained by "load file.cos"). Note that
+ // the version of file.cos must be the current version. If not, load
+ // into scicos and save.
+ //
+ // updated_vars: a scilab struct containing values of
+ // symbolic variables used in the context and Scicos blocks. This
+ // is often used to change a parameter in the diagram context. In that
+ // case, make sure that in the diagram context the variable is defined such
+ // that it can be modified. Say a variable "a" is to be defined in the
+ // context having value 1, and later in batch mode, we want to change
+ // the value of "a". In that case, in the context of the diagram place:
+ // if ~exists('a') then a=1,end
+ // If you want then to run the simulation in batch mode using the value
+ // a=2, set:
+ // updated_vars.a=2
+ //
+ // Info: a list. It must be list() at the first call, then use output
+ // Info as input Info for the next calls. Info contains compilation and
+ // simulation information and is used to avoid recompilation when not
+ // needed.
+ //
+ // flag: string. If it equals 'nw' (no window), then blocks using
+ // graphical windows are not executed. Note that the list of such
+ // blocks must be updated as new blocks are added.
+ //
+ // Ignb : matrix of string : The name of blocks to ignore.
+ // If flag is set and equal to 'nw' then Ignb contains
+ // name of blocks that are added to the list
+ // of blocks to ignore.
+ //
+
+
+ //** check/set rhs parameters
+ //---------------------------
+ if argn(2) == 1 then
+ //scicos_simulate(scs_m)
+ Info = list()
+ updated_vars = struct()
+ flag = ""
+ Ignb = ""
+ elseif argn(2) == 2 then
+ //scicos_simulate(scs_m, Info)
+ //or scicos_simulate(scs_m,updated_vars)
+ //or scicos_simulate(scs_m,flag)
+ select typeof(Info)
+ case "st" then //scicos_simulate(scs_m,updated_vars)
+ updated_vars = Info
+ Info=list()
+ ku=2
+ flag = ""
+ case "string" then //scicos_simulate(scs_m,flag)
+ flag=Info
+ Info=list()
+ kf=2
+ updated_vars = struct()
+ else //scicos_simulate(scs_m,Info)
+ flag = ""
+ updated_vars = struct()
+ ki=2
+ end
+ Ignb = ""
+ elseif argn(2) == 3 then
+ //scicos_simulate(scs_m, Info,updated_vars) or scicos_simulate(scs_m, Info,"nw")
+ if type(updated_vars) == 10 then
+ flag = updated_vars
+ updated_vars = struct()
+ else
+ ku=3
+ flag = ""
+ end
+ Ignb = ""
+ elseif argn(2) >= 4 then
+ //scicos_simulate(scs_m, Info,updated_vars,"nw") or
+ //scicos_simulate(scs_m, Info,"nw",updated_vars)
+ ku=3;kf=4
+ if type(updated_vars) == 10 then
+ [updated_vars,flag]=(flag,updated_vars)
+ kf=3;ku=4
+ end
+ if argn(2) == 4 then Ignb = "",end
+ else
+ error(msprintf(_("%s: Wrong number of input arguments. Must be between %d and %d.\n"),...
+ "scicos_simulate", 1, 5))
+ end
+
+ //Check variable types
+ if typeof(scs_m)<>"diagram" then
+ error(msprintf(_("%s: Wrong type for input argument #%d: %s data structure expected.\n"),...
+ "scicos_simulate",1,"scs_m"))
+ end
+ if type(Info)<>15 then
+ error(msprintf(_("%s: Wrong type for input argument #%d: A list expected.\n"),..
+ "scicos_simulate",2))
+ end
+ if typeof(updated_vars)<>"st" then
+ error(msprintf(_("%s: Wrong type for input argument #%d: A list expected.\n"),...
+ "scicos_simulate",ku))
+ end
+ if and(stripblanks(flag)<>["nw" ""]) then
+ error(msprintf(_("%s: Wrong value for input argument #%d: ''%s'' expected.\n"),...
+ "scicos_simulate",kf,"nw"))
+ end
+ if type(Ignb) <> 10 then
+ error(msprintf(_("%s: Wrong type for input argument #%d: String array expected.\n"),...
+ "scicos_simulate",5))
+ end
+
+ if or(sciargs() == "-nogui")|or(sciargs() == "-nwni") then
+ flag = "nw"
+ end
+ //**blocks to ignore requested by user
+ Ignb = matrix(Ignb,1,-1)//make it row vector
+
+ //**blocks to ignore in any cases
+ Ignore=["affich",...
+ "affich2"]
+ //**blocks to ignore with flag=="nw"
+ Ignoreb = ["bouncexy", ...
+ "cscope", ...
+ "cmscope", ...
+ "canimxy", ...
+ "canimxy3d", ...
+ "cevscpe", ...
+ "cfscope", ...
+ "cscopxy", ...
+ "cscopxy3d", ...
+ "cmatview", ...
+ "cmat3d", ...
+ "bplatform2"]
+
+ //** load the scicos function libraries
+ //------------------------------------
+
+ if exists("scicos_scicoslib")==0 then
+ load("SCI/modules/scicos/macros/scicos_scicos/lib") ;
+ end
+
+ if exists("scicos_autolib")==0 then
+ load("SCI/modules/scicos/macros/scicos_auto/lib") ;
+ end
+
+ if exists("scicos_utilslib")==0 then
+ load("SCI/modules/scicos/macros/scicos_utils/lib") ;
+ end
+
+ // Define Scicos data tables ===========================================
+ [modelica_libs, scicos_pal_libs, %scicos_with_grid, %scs_wgrid] = initial_scicos_tables();
+ // =====================================================================
+
+ //** initialize a "scicos_debug_gr" variable
+ %scicos_debug_gr = %f;
+
+
+ //** redefine some functions
+ prot = funcprot();funcprot(0);
+ do_terminate = do_terminate1
+ funcprot(prot)
+
+
+ //check version
+ current_version = get_scicos_version()
+ scicos_ver = find_scicos_version(scs_m)
+
+ //do version
+ if scicos_ver <> current_version then
+ ierr = execstr("scs_m = do_version(scs_m, scicos_ver)","errcatch")
+ if ierr <> 0 then
+ messagebox(_("Can''t convert old diagram (problem in version)"),"modal")
+ return
+ end
+ end
+
+ //** prepare from and to workspace stuff
+ //-------------------------------------
+ scicos_workspace_init()
+
+ if flag == "nw" then
+ Ignore = [Ignore,Ignoreb]
+ end
+ //add user ignored blocks if any
+ Ignore = [Ignore, Ignb]
+
+ //** retrieve Info list
+ if Info <> list() then
+ [%tcur, %cpr, alreadyran, needstart, needcompile, %state0] = Info(:)
+ else
+ %tcur = 0;
+ %cpr = list();
+ alreadyran = %f;
+ needstart = %t;
+ needcompile = 4;
+ %state0 = list();
+ end
+
+ //** set solver
+ tolerances = scs_m.props.tol
+ solver = tolerances(6)
+ %scicos_solver = solver
+ //** set variables of context
+ [%scicos_context, ierr] = script2var(scs_m.props.context,struct())
+ //overload %scicos_context variables with those defined by updated_vars
+ contextvars=fieldnames(%scicos_context)
+ updatedvars=fieldnames(updated_vars)
+ for k=1:size(updatedvars,"*")
+ u=updatedvars(k)
+ if or(u==contextvars) then
+ %scicos_context(u)=updated_vars(u)
+ else
+ mprintf(_("Warning the variable %s does not match any context variable name\nignored"),u)
+ end
+ end
+ if ierr == 0 then //++ no error
+ [scs_m, %cpr, needcompile, ok] = do_eval(scs_m, %cpr,%scicos_context)
+ if ~ok then
+ error(msprintf(gettext("%s: Error during block parameters evaluation.\n"), "scicos_simulate"));
+ end
+ if needcompile <> 4 & size(%cpr) > 0 then
+ %state0 = %cpr.state
+ end
+ alreadyran = %f
+ else
+ error(["Incorrect context definition, " + lasterror()])
+ end
+
+ // perform block suppression only on partial compilation and full compilation
+ if needcompile > 1 then
+ need_suppress =%t
+ else
+ need_suppress = %f
+ end
+
+ [%cpr, %state0_n, needcompile, alreadyran, ok] = do_update(%cpr, ...
+ %state0, needcompile)
+
+ if ~ok then
+ error(msprintf(gettext("%s: Error during block parameters update.\n"), "scicos_simulate"));
+ end
+
+ if or(%state0_n <> %state0) then //initial state has been changed
+ %state0 = %state0_n
+ [alreadyran, %cpr, Resume_line, TOWS_vals, Names] = do_terminate1(scs_m, %cpr)
+ choix = []
+ end
+ if (%cpr.sim.xptr($) - 1) < size(%cpr.state.x,"*") & solver < 100 then
+ warning(msprintf(_("Diagram has been compiled for implicit solver\nswitching to implicit solver.\n")))
+ solver = 100
+ tolerances(6) = solver
+ elseif (%cpr.sim.xptr($) - 1) == size(%cpr.state.x,"*") & ...
+ (or (solver == [100 101 102])) & size(%cpr.state.x,"*") <> 0 then
+ warning(msprintf(_("Diagram has been compiled for explicit solver\nswitching to explicit solver.\n")))
+ solver = 0
+ tolerances(6) = solver
+ end
+
+ if need_suppress then //this is done only once
+ for i = 1:length(%cpr.sim.funs)
+ if type(%cpr.sim.funs(i)) <> 13 then
+ if find(%cpr.sim.funs(i)(1) == Ignore) <> [] then
+ if (%cpr.sim.funs(i)(1) == "bplatform2") then
+ %cpr.sim.funtyp(i) = 4; // BPLATFORM block has function type 5, so need to set it to 4, like the trash block.
+ end
+ %cpr.sim.funs(i)(1) = "trash";
+ end
+ end
+ end
+ end
+
+ if needstart then //scicos initialization
+ if alreadyran then
+ [alreadyran, %cpr, Resume_line, TOWS_vals, Names] = do_terminate1(scs_m, %cpr)
+ alreadyran = %f
+ end
+ %tcur = 0
+ %cpr.state = %state0
+ tf = scs_m.props.tf;
+ if tf*tolerances == [] then
+ error(_("Simulation parameters not set:"));
+ end
+ ierr = execstr("[state, t] = scicosim(%cpr.state, %tcur, tf, %cpr.sim," + ..
+ "''start'', tolerances)","errcatch")
+ if ierr <> 0 then
+ error(_("Initialization problem:"))
+ end
+ %cpr.state = state
+ end
+
+ ierr = execstr("[state, t] = scicosim(%cpr.state, %tcur, tf, %cpr.sim," + ..
+ "''run'', tolerances)","errcatch")
+ if ierr == 0 then
+ %cpr.state = state
+ alreadyran = %t
+ if (tf - t) < tolerances(3) then
+ needstart = %t
+ [alreadyran, %cpr, Resume_line, TOWS_vals, Names] = do_terminate1(scs_m, %cpr)
+ for i=1:size(Names, "c")
+ ierr = execstr(Names(i)+" = TOWS_vals("+string(i)+");", "errcatch");
+ if ierr <> 0 then
+ str_err = split_lasterror(lasterror());
+ message(["Simulation problem" ; "Unable to find To Workspace Variable {"+Names(i)+"}:" ; str_err]);
+ break;
+ end
+ end
+ else
+ %tcur = t
+ end
+ else
+ error([_("Simulation problem: ");lasterror()])
+ end
+
+ Info = list(%tcur, %cpr, alreadyran, needstart, needcompile, %state0)
+
+ // Executing the resume() function at the end, because it does not return control
+ if ~isempty(Names) then
+ execstr(Resume_line);
+ end
+endfunction
+
+function [alreadyran, %cpr, Resume_line, TOWS_vals, Names] = do_terminate1(scs_m, %cpr)
+ // Copyright INRIA
+
+ // Default return values
+ Resume_line = "";
+ TOWS_vals = struct("values",[],"time",[]);
+ Names = [];
+
+ if prod(size(%cpr)) < 2 then
+ alreadyran = %f
+ return
+ end
+
+ par = scs_m.props;
+
+ if alreadyran then
+ alreadyran = %f
+ // terminate current simulation
+ ierr = execstr("[state, t] = scicosim(%cpr.state, par.tf, par.tf, %cpr.sim, ''finish'', par.tol)", "errcatch")
+
+ %cpr.state = state
+ if ierr <> 0 then
+ error([_("End problem: ");lasterror()])
+ end
+
+ // Restore saved variables in Scilab environment ("To workspace" block)
+
+ // First step: Search the %cpr tree for TOWS_c blocks, and extract the variable names.
+ path = %cpr.sim;
+ buff_sizes = [];
+ increment = 1;
+ for i=1:size(path.funs)
+ increment2 = path.ipptr(i+1);
+ if (increment2 - increment <> 0) then // ipar has at least a few elements
+ space = increment2 - increment; // The number of elements that the current block pushed into ipar
+ if (path.funs(i) == "tows_c") then // Found a Tow_workspace block
+ varNameLen = space - 2; // Space minus 'buffer_size' and 'var length' ipar elements
+ varNameCode = path.ipar(increment+2:increment+2+varNameLen-1); // varName is stored in Scilab code
+ varName = ascii(varNameCode);
+ Names = [Names varName]; // Append varName in Names
+ buff_size = path.ipar(increment); // Retrieve buffer size
+ buff_sizes = [buff_sizes buff_size];
+ end
+ increment = increment2;
+ end
+ end
+ // At the end, Names contains the string names of the variables and buff_sizes the respective buffer sizes
+
+ // Second step: Link the variable names to their values vectors,
+ //and call '[names(1), names(2), ...] = resume(names(1), names(2), ...)' to save the variable into Scilab
+ if ~isempty(Names) then
+ for i=1:size(Names, "c")
+ execstr("NamesIval = "+Names(i)+"_val;");
+ execstr("NamesIvalt = "+Names(i)+"_valt;");
+ // If input is a matrix, use function matrix() to reshape the saved values
+ // Check condition using time vector, if we have more values than time stamps, split it
+ if (size(NamesIval, "r") > size(NamesIvalt, "r")) then // In this case, size(Names(i), 'r') = buff_sizes(i) * nCols2
+ nRows = size(NamesIvalt, "r");
+ nCols = size(NamesIval, "c");
+ nCols2 = size(NamesIval, "r") / nRows;
+ NamesIval = matrix(NamesIval, nCols, nCols2, nRows);
+ end
+ if i == 1 then
+ // Replace default struct with value vector of first element of 'Names'
+ TOWS_vals.values = NamesIval;
+ TOWS_vals.time = NamesIvalt;
+ Resume_line_args = Names(1);
+ else
+ ierr = execstr("TOWS_vals = [TOWS_vals struct(''values'', NamesIval, ''time'', NamesIvalt)];", "errcatch");
+ if ierr <> 0 then
+ str_err = split_lasterror(lasterror());
+ message(["Simulation problem" ; "Unable to find To Workspace Variable {"+Names(i)+"}:" ; str_err]);
+ break;
+ end
+ Resume_line_args = Resume_line_args + ", " + Names(i); // Concatenate the variable names up to the last one
+ end
+ end
+ Resume_line = "[" + Resume_line_args + "] = resume(" + Resume_line_args + ");"; // Build the message
+ // Will execute Resume_line at the end of the main function, because it does not return control
+ end
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_auto/steadycos.bin b/modules/scicos/macros/scicos_auto/steadycos.bin
new file mode 100755
index 000000000..74619b0ff
--- /dev/null
+++ b/modules/scicos/macros/scicos_auto/steadycos.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_auto/steadycos.sci b/modules/scicos/macros/scicos_auto/steadycos.sci
new file mode 100755
index 000000000..38eb06495
--- /dev/null
+++ b/modules/scicos/macros/scicos_auto/steadycos.sci
@@ -0,0 +1,269 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// Copyright (C) DIGITEO - Clément DAVID <clement.david@scilab.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ./license.txt
+//
+
+function [X,U,Y,XP] = steadycos(scs_m,X,U,Y,Indx,Indu,Indy,Indxp,param)
+ // NAME
+ // steadycos - Finds an equilibrium state of a general
+ // dynamical system described by a scicos diagram
+
+ // CALLING SEQUENCE
+ //
+ // [X,U,Y,XP] = steadycos(scs_m,X,U,Y,Indx,Indu,Indy [,Indxp [,param ] ])
+ //
+ // scs_m: a Scicos data structure
+ // X: column vector. Continuous state. Can be set to [] if zero.
+ // U: column vector. Input. Can be set to [] if zero.
+ // Y: column vector. Output. Can be set to [] if zero.
+ // Indx: index of entries of X that are not fixed. If all can vary, set to 1:$
+ // Indu: index of entries of U that are not fixed. If all can vary, set to 1:$
+ // Indy: index of entries of Y that are not fixed. If all can vary, set to 1:$
+ // Indxp: index of entries of XP (derivative of x) that need not be zero.
+ // If all can vary, set to 1:$. Default [].
+ // param: list with two elements (default list(1.d-6,0))
+ // param(1): scalar. Perturbation level for linearization; the following variation is used
+ // del([x;u])_i = param(1)+param(1)*1d-4*abs([x;u])_i
+ // param(2): scalar. Time t.
+ //
+
+ //** This function can be (ab)used from the Scilab command line and
+ //** inside a Scicos "context". In order to handle the different situations,
+ //** the required library are loaded if not already present in the
+ //** "semiglobal-local-environment".
+
+ if ~exists("scicos_diagram") then
+ loadXcosLibs();
+ end
+
+ if exists("scicos_scicoslib")==0 then
+ load("SCI/modules/scicos/macros/scicos_scicos/lib") ;
+ end
+
+ if exists("scicos_autolib")==0 then
+ load("SCI/modules/scicos/macros/scicos_auto/lib") ;
+ end
+
+ if exists("scicos_utilslib")==0 then
+ load("SCI/modules/scicos/macros/scicos_utils/lib") ;
+ end
+
+ // Define Scicos data tables ===========================================
+ if ( ~isdef("modelica_libs") | ..
+ ~isdef("scicos_pal_libs") ) then
+ [modelica_libs, scicos_pal_libs, %scicos_with_grid, %scs_wgrid] = initial_scicos_tables();
+ end
+ // =====================================================================
+
+ [lhs,rhs] = argn(0) ;
+
+ if rhs < 1 then
+ error(msprintf(gettext("%s: Wrong number of input argument(s): At least %d expected.\n"), "steadycos", 1));
+ end
+ if typeof(scs_m)<>"diagram" & typeof(scs_m)<>"cpr" then
+ error(msprintf(gettext("%s: Wrong type for input argument #%d: A diagram expected.\n"), "steadycos", 1));
+ end
+
+ // compile and post-process the diagram
+ if typeof(scs_m)=="diagram" then
+
+ // Propagate context through all blocks
+ %state0 = list();
+ needcompile = 4;
+ %cpr = struct();
+ %cpr.state = %state0;
+ %scicos_context = struct();
+ context = scs_m.props.context;
+
+ [%scicos_context, ierr] = script2var(context, %scicos_context);
+ [scs_m,%cpr,needcompile,ok] = do_eval(scs_m, %cpr, %scicos_context);
+ if ~ok then
+ error(msprintf(gettext("%s: Error during block parameters evaluation.\n"), "lincos"));
+ end
+
+ IN = [];
+ OUT = [];
+
+ // check and do version
+ current_version = get_scicos_version()
+ scicos_ver = find_scicos_version(scs_m)
+ if scicos_ver<>current_version then
+ scs_m=do_version(scs_m,scicos_ver);
+ end
+
+ if rhs==7 then
+ Indxp=[ ];param=list(1.d-6,0)
+ elseif rhs==8 then
+ param=list(1.d-6,0)
+ elseif rhs==9 then
+ else
+ error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"), "steadycos", 7, 9));
+ end
+
+ for i=1:length(scs_m.objs)
+ if typeof(scs_m.objs(i))=="Block" then
+ if or(scs_m.objs(i).gui==["IN_f", "INPUTPORT"]) then
+ scs_m.objs(i).gui="INPUTPORT";
+ IN=[IN scs_m.objs(i).model.ipar]
+ elseif or(scs_m.objs(i).gui==["OUT_f", "OUTPUTPORT"]) then
+ scs_m.objs(i).gui="OUTPUTPORT";
+ OUT=[OUT scs_m.objs(i).model.ipar]
+ end
+ end
+ end
+
+ if IN == [] then
+ error(msprintf(gettext("%s: Unable to find diagram inputs\n"), "steadycos"));
+ end
+ if OUT == [] then
+ error(msprintf(gettext("%s: Unable to find diagram outputs\n"), "steadycos"));
+ end
+
+ IN=-gsort(-IN);
+ if or(IN<>[1:size(IN,"*")]) then
+ error(msprintf(gettext("%s: Input ports are not numbered properly.\n"), "steadycos"))
+ end
+
+ OUT=-gsort(-OUT);
+ if or(OUT<>[1:size(OUT,"*")]) then
+ error(msprintf(gettext("%s: Output ports are not numbered properly.\n"), "steadycos"))
+ end
+
+ // compile scs_m
+ [bllst,connectmat,clkconnect,cor,corinv,ok] = c_pass1(scs_m);
+ if ~ok then
+ error(msprintf(gettext("%s: Diagram does not compile in pass %d.\n"),"steadycos",1));
+ end
+ %cpr = c_pass2(bllst,connectmat,clkconnect,cor,corinv);
+ if %cpr==list() then
+ ok=%f,
+ end
+ if ~ok then
+ error(msprintf(gettext("%s: Diagram does not compile in pass %d.\n"),"steadycos",2));
+ end
+
+ // compile and post-process the diagram end
+ end
+
+ sim=%cpr.sim;state=%cpr.state;
+ //
+ inplnk=sim.inplnk;inpptr=sim.inpptr;
+ outlnk=sim.outlnk;outptr=sim.outptr;ipptr=sim.ipptr;
+
+ ki=[];ko=[];nyptr=1;
+ for kfun=1:length(sim.funs)
+ if sim.funs(kfun)=="output" then
+ sim.funs(kfun)="bidon"
+ ko=[ko;[kfun,sim.ipar(ipptr(kfun))]];
+
+ elseif sim.funs(kfun)=="input" then
+ sim.funs(kfun)="bidon"
+ ki=[ki;[kfun,sim.ipar(ipptr(kfun))]];
+
+ end
+ end
+ [junk,ind]=gsort(-ko(:,2));ko=ko(ind,1);
+ [junk,ind]=gsort(-ki(:,2));ki=ki(ind,1);
+
+ pointo=[];
+ for k=ko'
+ pointo=[pointo;inplnk(inpptr(k))]
+ end
+ pointi=[];
+ for k=ki'
+ pointi=[pointi;outlnk(outptr(k))]
+ end
+ nx=size(state.x,"*");
+ nu=0; for k=pointi', nu=nu+size(state.outtb(k),"*"), end
+ ny=0; for k=pointo', ny=ny+size(state.outtb(k),"*"), end
+
+ if X==[] then X=zeros(nx,1);end
+ if Y==[] then Y=zeros(ny,1);end
+ if U==[] then U=zeros(nu,1);end
+ if param(1)==0 then param(1)=1.d-6;end
+
+ t = param(2)
+
+ ux0 = [U(Indu);X(Indx)];
+ sindu = size(U(Indu),"*");
+ sindx = size(X(Indx),"*");
+ [err,uxopt,gopt] = optim(cost,ux0)
+ U(Indu) = uxopt(1:sindu);
+ X(Indx) = uxopt(sindu+1:sindx+sindu);
+ state.x = X;
+ Uind=1
+
+ for k=pointi'
+ state.outtb(k) = matrix(U(Uind:Uind+size(state.outtb(k),"*")-1),size(state.outtb(k)));
+ Uind = size(state.outtb(k),"*")+1;
+ end
+
+ [state,t] = scicosim(state,t,t,sim,"start",[.1,.1,.1,.1]);
+ [state,t] = scicosim(state,t,t,sim,"linear",[.1,.1,.1,.1]);
+ [state,t] = scicosim(state,t,t,sim,"finish",[.1,.1,.1,.1]);
+
+ XP=state.x;
+ Yind=1
+
+ for k=pointo'
+ Y(Yind:Yind+size(state.outtb(k),"*")-1) = state.outtb(k)(:);
+ Yind = size(state.outtb(k),"*")+1
+ end
+
+endfunction
+//**-------------------------------------------------------------------------------------------
+
+function [f,g,ind]=cost(ux,ind)
+ state;
+ X;
+ U;
+ X(Indx)=ux(sindu+1:sindx+sindu);
+ U(Indu)=ux(1:sindu);
+ state.x=X;
+ Uind=1
+ for k=pointi'
+ state.outtb(k) = matrix(U(Uind:Uind+size(state.outtb(k),"*")-1),size(state.outtb(k)));
+ Uind = size(state.outtb(k),"*")+1;
+ end
+ // state.outtb(pointi)=U;
+
+ [state,t] = scicosim(state,t,t,sim,"start",[.1,.1,.1,.1]);
+ [state,t] = scicosim(state,t,t,sim,"linear",[.1,.1,.1,.1]);
+ [state,t] = scicosim(state,t,t,sim,"finish",[.1,.1,.1,.1]);
+
+ zer=ones(X);zer(Indxp)=0;xp=zer.*state.x;
+
+ Yind=1
+ for k=pointo'
+ y(Yind:Yind+size(state.outtb(k),"*")-1)=state.outtb(k)(:);
+ Yind = size(state.outtb(k),"*")+1
+ end
+ // y=state.outtb(pointo);
+ zer = ones(y);
+ zer(Indy) = 0;
+ err = zer.*(Y-y);
+ f=.5*(norm(xp,2)+norm(err,2));
+
+ sys = lincos(%cpr,X,U,param); //** lincos is used here
+
+ g = xp'*[sys.B(:,Indu) sys.A(:,Indx)] - err'*[sys.D(:,Indu) sys.C(:,Indx)];
+
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/%Block_e.bin b/modules/scicos/macros/scicos_scicos/%Block_e.bin
new file mode 100755
index 000000000..e391c73ef
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%Block_e.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%Block_e.sci b/modules/scicos/macros/scicos_scicos/%Block_e.sci
new file mode 100755
index 000000000..07ea438aa
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%Block_e.sci
@@ -0,0 +1,34 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function varargout=%Block_e(i,o)
+ //function used only for backward compatibility of scicos blocks gui
+ warning("Obsolete use of o(i) in this scicos block")
+ varargout=list()
+ for k=1:size(i,"*")
+ ik=i(k)
+ if ik==1 then
+ varargout($+1)="Block"
+ else
+ varargout($+1)=getfield(ik,o)
+ end
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%Block_p.bin b/modules/scicos/macros/scicos_scicos/%Block_p.bin
new file mode 100755
index 000000000..417197671
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%Block_p.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%Block_p.sci b/modules/scicos/macros/scicos_scicos/%Block_p.sci
new file mode 100755
index 000000000..6287851a2
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%Block_p.sci
@@ -0,0 +1,56 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function %Block_p(block)
+ txt=["GUI : "+block.gui
+ "Graphics: "
+ " "+graphics2txt(block.graphics)
+ "Model : "
+ " "+model2txt(block.model)]
+ write(%io(2),txt,"(a)")
+endfunction
+
+function txt=graphics2txt(graphics)
+ fn=getfield(1,graphics)
+ txt=[]
+ for k=2:size(fn,"*")
+ txt=[txt
+ sci2exp(graphics(fn(k)),fn(k))]
+ end
+endfunction
+
+function txt=model2txt(model)
+ sim=model.sim
+ if type(sim)==15 then
+ txt=sim(1)+" type: "+string(sim(2))
+ else
+ txt=sim+" type: 0"
+ end
+ fn=getfield(1,model)
+ for k=3:size(fn,"*")
+ if fn(k)=="rpar" & type(model(fn(k)))==15 then
+ txt=[txt;fn(k)+" : SuperBlock"];
+ else
+ txt=[txt
+ sci2exp(model(fn(k)),fn(k))];
+ end
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%b_i_graphics.bin b/modules/scicos/macros/scicos_scicos/%b_i_graphics.bin
new file mode 100755
index 000000000..94e38c125
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%b_i_graphics.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%b_i_graphics.sci b/modules/scicos/macros/scicos_scicos/%b_i_graphics.sci
new file mode 100755
index 000000000..20cb6ff98
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%b_i_graphics.sci
@@ -0,0 +1,25 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function g=%b_i_graphics(i,b,g)
+ //function used only for backward compatibility of scicos blocks gui
+ setfield(i+1,b,g)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%b_i_model.bin b/modules/scicos/macros/scicos_scicos/%b_i_model.bin
new file mode 100755
index 000000000..99f28c0c1
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%b_i_model.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%b_i_model.sci b/modules/scicos/macros/scicos_scicos/%b_i_model.sci
new file mode 100755
index 000000000..da9a2fbb8
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%b_i_model.sci
@@ -0,0 +1,26 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function m=%b_i_model(i,b,m)
+ //function used only for backward compatibility of scicos blocks gui
+ if i>13 then warning("Field "+string(i)+" no longer in model, check"),end
+ setfield(i+1,b,m)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%c_i_block.bin b/modules/scicos/macros/scicos_scicos/%c_i_block.bin
new file mode 100755
index 000000000..99da9215d
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%c_i_block.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%c_i_block.sci b/modules/scicos/macros/scicos_scicos/%c_i_block.sci
new file mode 100755
index 000000000..91f89238f
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%c_i_block.sci
@@ -0,0 +1,25 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function o=%c_i_block(i,b,o)
+ //function used only for backward compatibility of scicos blocks gui
+ if i<>1 then setfield(i,b,o),end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%c_i_graphics.bin b/modules/scicos/macros/scicos_scicos/%c_i_graphics.bin
new file mode 100755
index 000000000..dcfe2d467
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%c_i_graphics.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%c_i_graphics.sci b/modules/scicos/macros/scicos_scicos/%c_i_graphics.sci
new file mode 100755
index 000000000..cdba9d78c
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%c_i_graphics.sci
@@ -0,0 +1,25 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function g=%c_i_graphics(i,b,g)
+ //function used only for backward compatibility of scicos blocks gui
+ setfield(i+1,b,g)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%c_i_model.bin b/modules/scicos/macros/scicos_scicos/%c_i_model.bin
new file mode 100755
index 000000000..49dc36880
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%c_i_model.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%c_i_model.sci b/modules/scicos/macros/scicos_scicos/%c_i_model.sci
new file mode 100755
index 000000000..ea3641795
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%c_i_model.sci
@@ -0,0 +1,26 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function m=%c_i_model(i,b,m)
+ //function used only for backward compatibility of scicos blocks gui
+ if i>13 then warning("Field "+string(i)+" no longer in model, check"),end
+ setfield(i+1,b,m)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%debug_scicos.bin b/modules/scicos/macros/scicos_scicos/%debug_scicos.bin
new file mode 100755
index 000000000..f99f48325
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%debug_scicos.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%debug_scicos.sci b/modules/scicos/macros/scicos_scicos/%debug_scicos.sci
new file mode 100755
index 000000000..50dc73ff6
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%debug_scicos.sci
@@ -0,0 +1,29 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [block] = %debug_scicos(block,flag)
+ if execstr("load(TMPDIR+''/debug_scicos'')","errcatch")<>0 then
+ disp("Instantiate the Debug block")
+ else
+ [block] = debug_scicos(block,flag)
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%diagram_p.bin b/modules/scicos/macros/scicos_scicos/%diagram_p.bin
new file mode 100755
index 000000000..48803c642
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%diagram_p.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%diagram_p.sci b/modules/scicos/macros/scicos_scicos/%diagram_p.sci
new file mode 100755
index 000000000..fa9320fe8
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%diagram_p.sci
@@ -0,0 +1,34 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function %diagram_p(scs_m)
+ %params_p(scs_m.props)
+ nams=[]
+ for o=scs_m.objs
+ if typeof(o)=="Block" then
+ nams=[nams;o.gui]
+ end
+ end
+ if nams <> [] then
+ nums=part(string(1:size(nams,"*"))',1:6)
+ write(%io(2),nums+nams,"(a)")
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%graphics_e.bin b/modules/scicos/macros/scicos_scicos/%graphics_e.bin
new file mode 100755
index 000000000..061280b82
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%graphics_e.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%graphics_e.sci b/modules/scicos/macros/scicos_scicos/%graphics_e.sci
new file mode 100755
index 000000000..18e19e1f9
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%graphics_e.sci
@@ -0,0 +1,29 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function varargout=%graphics_e(i,o)
+ //function used only for backward compatibility of scicos blocks gui
+ warning("Obsolete use of graphics(i) in this scicos block")
+ varargout=list()
+ for k=1:size(i,"*")
+ varargout($+1)=getfield(i(k)+1,o)
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%graphics_i_Block.bin b/modules/scicos/macros/scicos_scicos/%graphics_i_Block.bin
new file mode 100755
index 000000000..ee03e4050
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%graphics_i_Block.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%graphics_i_Block.sci b/modules/scicos/macros/scicos_scicos/%graphics_i_Block.sci
new file mode 100755
index 000000000..0edce5f45
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%graphics_i_Block.sci
@@ -0,0 +1,24 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function g=%graphics_i_Block(i,b,g)
+ setfield(i,b,g)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%graphics_p.bin b/modules/scicos/macros/scicos_scicos/%graphics_p.bin
new file mode 100755
index 000000000..31ded4dcc
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%graphics_p.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%graphics_p.sci b/modules/scicos/macros/scicos_scicos/%graphics_p.sci
new file mode 100755
index 000000000..ce052bcce
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%graphics_p.sci
@@ -0,0 +1,30 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function %graphics_p(graphics)
+ fn=getfield(1,graphics)
+ txt=[]
+ for k=2:size(fn,"*")
+ txt=[txt
+ sci2exp(graphics(fn(k)),fn(k))]
+ end
+ write(%io(2),txt,"(a)")
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%l_i_block.bin b/modules/scicos/macros/scicos_scicos/%l_i_block.bin
new file mode 100755
index 000000000..81b71c550
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%l_i_block.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%l_i_block.sci b/modules/scicos/macros/scicos_scicos/%l_i_block.sci
new file mode 100755
index 000000000..19b2e04b3
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%l_i_block.sci
@@ -0,0 +1,25 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function o=%l_i_block(i,b,o)
+ //function used only for backward compatibility of scicos blocks gui
+ setfield(i,b,o)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%l_i_graphics.bin b/modules/scicos/macros/scicos_scicos/%l_i_graphics.bin
new file mode 100755
index 000000000..fb663e044
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%l_i_graphics.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%l_i_graphics.sci b/modules/scicos/macros/scicos_scicos/%l_i_graphics.sci
new file mode 100755
index 000000000..e7ace032d
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%l_i_graphics.sci
@@ -0,0 +1,25 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function g=%l_i_graphics(i,b,g)
+ //function used only for backward compatibility of scicos blocks gui
+ setfield(i+1,b,g)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%l_i_model.bin b/modules/scicos/macros/scicos_scicos/%l_i_model.bin
new file mode 100755
index 000000000..20057f5b3
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%l_i_model.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%l_i_model.sci b/modules/scicos/macros/scicos_scicos/%l_i_model.sci
new file mode 100755
index 000000000..fe1f35ef5
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%l_i_model.sci
@@ -0,0 +1,26 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function m=%l_i_model(i,b,m)
+ //function used only for backward compatibility of scicos blocks gui
+ if i>13 then warning("Field "+string(i)+" no longer in model, check"),end
+ setfield(i+1,b,m)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%model_e.bin b/modules/scicos/macros/scicos_scicos/%model_e.bin
new file mode 100755
index 000000000..25e41d107
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%model_e.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%model_e.sci b/modules/scicos/macros/scicos_scicos/%model_e.sci
new file mode 100755
index 000000000..00ced7b14
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%model_e.sci
@@ -0,0 +1,29 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function varargout=%model_e(i,o)
+ //function used only for backward compatibility of scicos blocks gui
+ warning("Obsolete use of model(i) in this scicos block")
+ varargout=list()
+ for k=1:size(i,"*")
+ varargout($+1)=getfield(i(k)+1,o)
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%model_i_Block.bin b/modules/scicos/macros/scicos_scicos/%model_i_Block.bin
new file mode 100755
index 000000000..a956bf297
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%model_i_Block.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%model_i_Block.sci b/modules/scicos/macros/scicos_scicos/%model_i_Block.sci
new file mode 100755
index 000000000..14fd59dd8
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%model_i_Block.sci
@@ -0,0 +1,24 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function g=%model_i_Block(i,b,g)
+ setfield(i,b,g)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%model_p.bin b/modules/scicos/macros/scicos_scicos/%model_p.bin
new file mode 100755
index 000000000..672557c4d
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%model_p.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%model_p.sci b/modules/scicos/macros/scicos_scicos/%model_p.sci
new file mode 100755
index 000000000..11ac4b812
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%model_p.sci
@@ -0,0 +1,40 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function %model_p(model)
+
+ sim=model.sim
+ if type(sim)==15 then
+ if type(sim(1))==13 then
+ txt="scifunc"
+ else
+ txt=sim(1)+" type: "+string(sim(2))
+ end
+ else
+ txt=sim+" type: 0"
+ end
+ fn=getfield(1,model)
+ for k=3:size(fn,"*")
+ txt=[txt
+ sci2exp(model(fn(k)),fn(k))]
+ end
+ write(%io(2),txt,"(a)")
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%params_p.bin b/modules/scicos/macros/scicos_scicos/%params_p.bin
new file mode 100755
index 000000000..849fd5e3c
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%params_p.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%params_p.sci b/modules/scicos/macros/scicos_scicos/%params_p.sci
new file mode 100755
index 000000000..02bd86d6e
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%params_p.sci
@@ -0,0 +1,34 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function %params_p(par)
+ write(%io(2),params2txt(par),"(a)")
+endfunction
+
+function txt=params2txt(par)
+ fn=getfield(1,par)
+ txt=[]
+ for k=2:size(fn,"*")
+ txt=[txt
+ sci2exp(par(fn(k)),fn(k))]
+ end
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/%s_i_block.bin b/modules/scicos/macros/scicos_scicos/%s_i_block.bin
new file mode 100755
index 000000000..d5a94ab14
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%s_i_block.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%s_i_block.sci b/modules/scicos/macros/scicos_scicos/%s_i_block.sci
new file mode 100755
index 000000000..066de9578
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%s_i_block.sci
@@ -0,0 +1,25 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function o=%s_i_block(i,b,o)
+ //function used only for backward compatibility of scicos blocks gui
+ setfield(i,b,o)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%s_i_graphics.bin b/modules/scicos/macros/scicos_scicos/%s_i_graphics.bin
new file mode 100755
index 000000000..71c0486cb
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%s_i_graphics.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%s_i_graphics.sci b/modules/scicos/macros/scicos_scicos/%s_i_graphics.sci
new file mode 100755
index 000000000..db813d681
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%s_i_graphics.sci
@@ -0,0 +1,25 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function g=%s_i_graphics(i,b,g)
+ //function used only for backward compatibility of scicos blocks gui
+ setfield(i+1,b,g)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/%s_i_model.bin b/modules/scicos/macros/scicos_scicos/%s_i_model.bin
new file mode 100755
index 000000000..3abf96781
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%s_i_model.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/%s_i_model.sci b/modules/scicos/macros/scicos_scicos/%s_i_model.sci
new file mode 100755
index 000000000..abd18d912
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/%s_i_model.sci
@@ -0,0 +1,26 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function m=%s_i_model(i,b,m)
+ //function used only for backward compatibility of scicos blocks gui
+ if i>13 then warning("Field "+string(i)+" no longer in model, check"),end
+ setfield(i+1,b,m)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/CC4.bin b/modules/scicos/macros/scicos_scicos/CC4.bin
new file mode 100755
index 000000000..8ca51d641
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/CC4.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/CC4.sci b/modules/scicos/macros/scicos_scicos/CC4.sci
new file mode 100755
index 000000000..f7fb15579
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/CC4.sci
@@ -0,0 +1,121 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+function [ok,tt,cancel]=CC4(funam,tt)
+ // Copyright INRIA
+ //
+ cancel=%f
+
+ if tt==[] then
+
+ textmp=["#include ""scicos_block4.h""";
+ ""
+ "void "+funam+"(scicos_block *block,int flag)";
+ ];
+ ttext=[];
+ textmp($+1)="{"
+ textmp=[textmp]
+
+ textmp($+1)=" /* init */"
+ textmp($+1)=" if (flag == 4) {"
+ textmp($+1)=" ";
+ if out<>0 then
+ textmp($+1)=" /* output computation */ ";
+ textmp($+1)=" } else if(flag == 1) {"
+ textmp($+1)=" ";
+ end
+
+ if nx<>0 then
+ textmp($+1)=" /* derivative or residual computation */"
+ textmp($+1)=" } else if(flag == 0) {"
+ textmp($+1)=" ";
+ end
+
+ if nzcr<>0 then
+ textmp($+1)=" /* zero crossing surface and mode computation */"
+ textmp($+1)=" } else if(flag == 9) {"
+ textmp($+1)=" ";
+ end
+
+ if nz<>0 then
+ textmp($+1)=" /* computation of next discrete state*/ "
+ textmp($+1)=" } else if(flag == 2) { "
+ textmp($+1)=" ";
+
+ elseif min(nx,nzcr+nevin)>0 then
+ textmp($+1)=" /* computation of jumped state*/ "
+ textmp($+1)=" } else if(flag == 2) {"
+ textmp($+1)=" ";
+ end
+
+ if nevout<>0 then
+ textmp($+1)=" /* computation of output event times*/"
+ textmp($+1)=" } else if(flag == 3) {"
+ textmp($+1)=" "
+ end
+ textmp($+1)=" /* ending */"
+ textmp($+1)=" } else if (flag == 5) {"
+ textmp($+1)=" ";
+ textmp($+1)=" }"
+ textmp($+1)="}"
+ textmp=[textmp;" "; ttext];
+ else
+ textmp=tt;
+ end
+
+ tt = textmp
+ ok = %t
+ //## set param of scstxtedit
+ ptxtedit=scicos_txtedit(clos = 0,...
+ typ = "Cfunc",...
+ head = ["Function definition in C";
+ "Here is a skeleton of the functions which";
+ " you should edit."]);
+
+ while 1==1
+
+ [txt,Quit] = scstxtedit(textmp,ptxtedit);
+
+ if ptxtedit.clos==1 then
+ break;
+ end
+
+ if txt<>[] then
+ [libss,ok,cancel]=get_dynamic_lib_dir(txt,funam,"c")
+
+ if ~cancel & ok then
+ [ok]=scicos_block_link(funam,txt,"c",libss)
+ if ok then
+ ptxtedit.clos=1
+ tt=txt
+ ok = %t;
+ end
+ textmp=txt;
+ end
+ end
+
+ if Quit==1 then
+ ok = %f;
+ cancel =%t;
+ break;
+ end
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/CFORTR.bin b/modules/scicos/macros/scicos_scicos/CFORTR.bin
new file mode 100755
index 000000000..f91f85108
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/CFORTR.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/CFORTR.sci b/modules/scicos/macros/scicos_scicos/CFORTR.sci
new file mode 100755
index 000000000..367887afc
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/CFORTR.sci
@@ -0,0 +1,84 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [ok,tt]=CFORTR(funam,tt,inp,out)
+ //
+ ni=size(inp,"*")
+ no=size(out,"*")
+ if tt==[] then
+
+ tete1=["#include <machine.h>";"#include <math.h>";...
+ "void "+funam+"(flag,nevprt,t,xd,x,nx,z,nz,tvec,";..
+ " ntvec,rpar,nrpar,ipar,nipar"]
+
+ tete2= " "
+ decl=""
+ for i=1:ni
+ tete2=tete2+",u"+string(i)+",nu"+string(i)
+ decl=decl+",*nu"+string(i)
+ end
+ for i=1:no
+ tete2=tete2+",y"+string(i)+",ny"+string(i)
+ decl=decl+",*ny"+string(i)
+ end
+ tete2=tete2+")"
+
+ tete3=[" double *t,xd[],x[],z[],tvec[];";..
+ " int *flag,*nevprt,*nx,*nz,*ntvec,*nrpar,ipar[],*nipar"+decl+";"]
+
+
+ tete4= " double rpar[]"
+ for i=1:ni
+ tete4=tete4+",u"+string(i)+"[]"
+ end
+ for i=1:no
+ tete4=tete4+",y"+string(i)+"[]"
+ end
+ tetev=[" ";" "]
+
+ textmp=[tete1;tete2;tetev;tete3;tete4+";";
+ "/* modify below this line */";
+ "{"
+ "}"
+ tetev];
+ else
+ textmp=tt;
+ end
+
+ while 1==1
+ [txt]=x_dialog(["Function definition in C";
+ "Here is a skeleton of the functions which you should edit"],..
+ textmp);
+
+ if txt<>[] then
+ tt=txt
+ [ok]=scicos_block_link(funam,tt,"c")
+ if ok then
+ textmp=txt;
+ end
+ break;
+ else
+ ok=%f;break;
+ end
+ end
+
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/CFORTR2.bin b/modules/scicos/macros/scicos_scicos/CFORTR2.bin
new file mode 100755
index 000000000..63027bdb2
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/CFORTR2.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/CFORTR2.sci b/modules/scicos/macros/scicos_scicos/CFORTR2.sci
new file mode 100755
index 000000000..59cf905c5
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/CFORTR2.sci
@@ -0,0 +1,164 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [ok,tt,cancel]=CFORTR2(funam,tt)
+
+ //
+ cancel=%f
+
+ if tt==[] then
+
+ textmp=[
+ "#include <math.h>";
+ "#include <stdlib.h>";
+ "#include <scicos_block.h>";
+ "void "+funam+"(scicos_block *block,int flag)";
+ ];
+ ttext=[];
+ textmp($+1)="{"
+ textmp=[textmp;
+ " /* ";
+ " int block->nevprt;"
+ " int block->nz;"
+ " double* block->z;"
+ " int block->nx;"
+ " double* block->x;"
+ " double* block->xd;"
+ " double* block->res;"
+ " int block->nin;"
+ " int *block->insz;"
+ " double **block->inptr;"
+ " int block->nout;"
+ " int *block->outsz;"
+ " double **block->outptr;"
+ " int block->nevout;"
+ " int block->nrpar;"
+ " double *block->rpar;"
+ " int block->nipar;"
+ " int *block->ipar;"
+ " int block->ng;"
+ " double *block->g;"
+ " int *block->jroot;"
+ " char block->label[41];"
+ " */"]
+
+ textmp($+1)=" if (flag == 4) { /* initialization */"
+ textmp($+1)=" "+funam+"_bloc_init(block,flag);"
+ ttext=[ttext;"int "+funam+"_bloc_init(scicos_block *block,int flag)";
+ "{";
+ "return 0;}"];
+ textmp($+1)=" "
+ if nout<>0 then
+ textmp($+1)=" } else if(flag == 1) { /* output computation*/"
+ textmp($+1)=" set_block_error("+funam+"_bloc_outputs(block,flag));"
+ ttext=[ttext;"int "+funam+"_bloc_outputs(scicos_block *block,int flag)";
+ "{";
+ "return 0;}"];
+ end
+
+ if nx<>0 then
+ textmp($+1)=" } else if(flag == 0) { /* derivative or residual computation*/",
+ textmp($+1)=" set_block_error("+funam+"_bloc_deriv(block,flag));"
+ ttext=[ttext;"int "+funam+"_bloc_deriv(scicos_block *block,int flag)";
+ "{";
+ "return 0;}"];
+ end
+
+ if ng <>0 then
+ textmp($+1)=" } else if(flag == 9) {/* zero crossing surface and mode computation*/",
+ textmp($+1)=" set_block_error("+funam+"_bloc_zcross(block,flag));";
+ ttext=[ttext;"int "+funam+"_bloc_zcross(scicos_block *block,int flag)";
+ "{";
+ "return 0;}"];
+ end
+
+ if nz<>0 then
+ textmp($+1)=" } else if(flag == 2) { /* computation of next discrte state*/ ",
+ textmp($+1)=" set_block_error("+funam+"_bloc_states(block,flag));";
+ ttext=[ttext;"int "+funam+"_bloc_states(scicos_block *block,int flag)";
+ "{";
+ "return 0;}"];
+ elseif min(nx,ng+nevin)>0 then
+ textmp($+1)=" } else if(flag == 2) { /* computation of jumped state*/ ",
+ textmp($+1)=" set_block_error("+funam+"_bloc_states(block,flag));";
+ ttext=[ttext;"int "+funam+"_bloc_states(scicos_block *block,int flag)";
+ "{";
+ "return 0;}"];
+ end
+
+ if nevout<>0 then
+ textmp($+1)=" } else if(flag == 3) { /* computation of output event times*/",
+ textmp($+1)=" set_block_error("+funam+"_bloc_evtout(block,flag));";
+ ttext=[ttext;"int "+funam+"_bloc_evtout(scicos_block *block,int flag)";
+ "{";
+ "return 0;}"];
+ end
+ textmp($+1)=" } else if (flag == 5) { /* ending */"
+ textmp($+1)=" set_block_error("+funam+"_bloc_ending(block,flag));";
+ ttext=[ttext;"int "+funam+"_bloc_ending(scicos_block *block,int flag)";
+ "{";
+ "return 0;}"];
+ textmp($+1)=" }"
+ textmp($+1)="}"
+ textmp=[textmp;" "; ttext];
+ else
+ textmp=tt;
+ end
+
+ tt = textmp
+ ok = %t
+ //## set param of scstxtedit
+ ptxtedit=scicos_txtedit(clos = 0,...
+ typ = "Cfunc",...
+ head = ["Function definition in C";
+ "Here is a skeleton of the functions which";
+ " you should edit."]);
+
+ while 1==1
+
+ [txt,Quit] = scstxtedit(textmp,ptxtedit);
+
+ if ptxtedit.clos==1 then
+ break;
+ end
+
+ if txt<>[] then
+ [libss,ok,cancel]=get_dynamic_lib_dir(txt,funam,"c")
+
+ if ~cancel & ok then
+ [ok]=scicos_block_link(funam,txt,"c",libss)
+ if ok then
+ ptxtedit.clos=1
+ tt=txt
+ ok = %t;
+ end
+ textmp=txt;
+ end
+ end
+
+ if Quit==1 then
+ ok = %f;
+ cancel =%t;
+ break;
+ end
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/Compute_cic.bin b/modules/scicos/macros/scicos_scicos/Compute_cic.bin
new file mode 100755
index 000000000..a4275fc29
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/Compute_cic.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/Compute_cic.sci b/modules/scicos/macros/scicos_scicos/Compute_cic.sci
new file mode 100755
index 000000000..7ff47fd02
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/Compute_cic.sci
@@ -0,0 +1,257 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+function ok=Compute_cic(method,Nunknowns)
+ global icpr
+ ok=%f
+
+ if icpr==list() then
+ return
+ end
+
+ tolerances=scs_m.props.tol
+ solver=tolerances(6)
+ if (and (solver <> [100 101 102])) then solver=100; end
+ tolerances(6)=solver
+ Atol=tolerances(1)
+ Rtol=tolerances(2)
+ %tcur=0;
+ tf=tolerances(3)
+ state=icpr.state;
+ nx=size(state.x,"r");
+ nx2=round(nx/2);
+ nxModelica=evstr(Nunknowns);
+
+ if nxModelica~=nx2 then
+ messagebox(msprintf(_("Your model contains states defined in standard Scicos blocks.\n"+..
+ "Current initialization interface does not support mixed models.")),"error","modal");
+ return
+ end
+
+ //------------------------------
+ ierr=0;
+ try
+ ierr=execstr("[state,t]=scicosim(state,%tcur,tf,icpr.sim,''start'',tolerances)","errcatch")
+ if ierr<>0 then
+ messagebox(msprintf(_("Initialisation problem in %s "),"Scicosim-start"),"error","modal");
+ return
+ end
+ catch
+ messagebox(msprintf(_("Initialisation problem in %s "),"Scicosim-start"),"error","modal");
+ return
+ end
+ //--------------------------------------------------------------
+ Ida_ierr=0;
+ if method=="Ida (init)" then
+ try
+ // scicos menu, not any more in xcos
+ // setmenu(curwin,'stop')
+ Ida_ierr=execstr("[state,t]=scicosim(state,%tcur,tf,icpr.sim,''run'',tolerances)","errcatch")
+ // unsetmenu(curwin,'stop')
+ if Ida_ierr<>0 then,
+ messagebox(msprintf(_("Initialisation problem in %s "),"Sundials"),"error","modal");
+ end
+ catch
+ messagebox(msprintf(_("Initialisation problem in %s "),"Sundials"),"error","modal");
+ end
+ end
+ //--------------------------------------------------------------
+ if method=="Kinsol" then
+ try
+ // scicos menu, not any more in xcos
+ // setmenu(curwin,'stop')
+ ierr=execstr("[state2,t]=scicosim(state,%tcur,tf,icpr.sim,''Kinsol'',tolerances)","errcatch")
+ if ierr==0 & (or(isnan(state2.x)) | or(isinf(state2.x))) then
+ ierr=-1;
+ end
+ if ierr==0 then
+ state=state2;
+ end
+ // unsetmenu(curwin,'stop')
+ if ierr<>0 then,
+ messagebox(msprintf(_("Initialisation problem in %s "),"Kinsol"),"error","modal");
+ end
+ catch
+ messagebox(msprintf(_("Initialisation problem in %s "),"Kinsol"),"error","modal");
+ end
+ end
+ //--------------------------------------------------------------
+ if method=="Fsolve" then
+ try
+ x0=state.x(1:nx2);
+ [xres]=fsolve(x0,fsim);
+ ierr=0
+ if or(isnan(xres)) | or(isinf(xres)) then
+ ierr=-1;
+ end
+ if ierr==0 then
+ for i=1:nx2, state.x(i)=xres(i);end
+ fsim(xres);// just to perform an idoit to update outputs in mixed_models
+ end
+ catch
+ messagebox(msprintf(_("Initialisation problem in %s "),"Fsolve"), "error","modal");
+ end
+ end
+ //--------------------------------------------------------------
+ if method=="Optim" then
+ try
+ x0=state.x(1:nx2);
+ [f,xres]=optim(fsumsquare,x0);
+ ierr=0
+ if or(isnan(xres)) | or(isinf(xres)) then
+ ierr=-1;
+ end
+ if ierr==0 then
+ for i=1:nx2, state.x(i)=xres(i);end
+ fsim(xres);// just to perform an idoit to update outputs in mixed_models
+ end
+ catch
+ messagebox(msprintf(_("Initialisation problem in the %s method"),"Optim"), "error","modal");
+ end
+ end
+ //--------------------------------------------------------------
+ if method=="Nelder_Mead" then
+ try
+ x0=state.x(1:nx2);
+ [xmin,fmin,epsilo,ls,fs] = neldermead(rand(nx2,nx2+1),Atol,1,0.5,1.5)
+
+ for i=1:nx2, state.x(i)=xmin(i);end
+ catch
+ messagebox(msprintf(_("Initialisation problem in the %s method")," Nelder_Mead"), "error","modal");
+ end
+ end
+ //--------------------------------------------------------------
+ if method=="Hompack77" then
+ try
+ ierr=execstr("[state,t]=scicosim(state,%tcur,tf,icpr.sim,''hompack77'',tolerances)","errcatch")
+ if ierr<>0 then,
+ messagebox(msprintf(_("Initialisation problem in the %s method"),"hompack77"), "error","modal");
+ end
+ catch
+ messagebox(msprintf(_("Initialisation problem in the %s method"),"hompack77"), "error","modal");
+ end
+
+ end
+ //--------------------------------------------------------------
+ if method=="Fsolve_Stepping" then
+ x0=state.x(1:nx2);
+ Res0=fsim(x0);
+ Lambda=0;
+ Steps=1000;
+ xres=x0;
+ for i=1:Steps
+ Lambda=i/Steps;
+ [xres]=fsolve(xres,fsim_step);
+ if modulo(i,10)==0 then,
+ disp("Source-stepping: progress="+string(i/Steps*100)+"%, Error="+string(norm(fsim_step(xres))));
+ end
+ end
+ for i=1:nx2, state.x(i)=xres(i);end
+ end
+ //--------------------------------------------------------------
+ if method=="Sundials_Stepping" then
+ end
+ //--------------------------------------------------------------
+ Err="?"
+ if Ida_ierr==0 & ierr==0 then
+ ss=fsim(state.x(1:nx2));if ss~=[] then Err=string(max(abs(ss)));else Err="0";end//using inf norm
+ end
+
+ try
+ if Ida_ierr==0 then //cossimdaskr is followed by a cosend in case of error
+ ierr=execstr("[state,t]=scicosim(state,%tcur,tf,icpr.sim,''finish'',tolerances)","errcatch")
+ if ierr<>0 then
+ messagebox(_("Initialisation problem in the finish phase"), "error","modal");
+ return
+ end
+ end
+ catch
+ messagebox(_("Initialisation problem in the finish phase"), "error","modal");
+ return
+ end
+ ok=%t;
+endfunction
+
+//------------------------------------------------------------
+function res=fsim(xin)
+ nx=size(xin,"r");
+ if nx==0 then res=[];return ;end
+ state1=state
+ for i=1:nx, state1.x(i)=xin(i);end
+ ierr=execstr("[state2,t]=scicosim(state1,%tcur,tf,icpr.sim,''linear'',tolerances)","errcatch")
+ res=state2.x(1:nx);
+endfunction
+
+function res=fsim_step(xin)
+ res=fsim(xin)-(1-Lambda)*Res0;
+endfunction
+
+
+function [sumsq,grad,ind]=fsumsquare(xin,ind)
+ nx=size(xin,"r");
+ tolerances=scs_m.props.tol;
+ atol=tolerances(1);
+ rtol=tolerances(2);
+
+ grad=[]
+ if ind==2 | ind==4 | ind==3 then
+ res=fsim(xin);
+ sumsq=0; for i=1:nx,sumsq=sumsq+res(i)*res(i);end
+ end
+
+ if ind==3 | ind==4 then
+ for j=1:nx
+ xin_p=xin;
+ ewt_j=1/(abs(xin_p(j)*rtol+atol+%eps));
+ delta_j=max(abs(xin_p(j))*%eps,1/ewt_j);
+ xin_p(j)=xin_p(j)+delta_j;
+ res_p=fsim(xin_p);
+ sumsq_p=0; for i=1:nx,sumsq_p=sumsq_p+(res_p(i)^2-res(i)^2)/delta_j;end
+ grad(j)=sumsq_p;
+ end
+ end
+
+endfunction
+
+
+function [xmin,fmin,epsilo,ls,fs] = neldermead(s,epsil,alpha,beta,gama)
+ // saved in the last versions
+endfunction
+
+
+function y=fsim2(x)
+ x0=x(1);x1=x(2);x2=x(3);x3=x(4);
+ x4=x(5);x5=x(6);x6=x(7);x7=x(8);
+
+ v0 = -x3;
+ v1 = -x2;
+
+ y(1) = x4+v0;
+ y(2) = x6+v1;
+ y(3) = x7-x6;
+ y(4) = x5-x4;
+ y(5) = 1e-14-x3*x2;
+ y(6) = v0+x2;
+ y(7) = v0+abs(x1);
+ y(8) = v1+abs(x0);
+
+ disp(y');
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/FORTR.bin b/modules/scicos/macros/scicos_scicos/FORTR.bin
new file mode 100755
index 000000000..39ad31053
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/FORTR.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/FORTR.sci b/modules/scicos/macros/scicos_scicos/FORTR.sci
new file mode 100755
index 000000000..7303b695d
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/FORTR.sci
@@ -0,0 +1,75 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [ok,tt]=FORTR(funam,tt,inp,out)
+ //
+ ni=size(inp,"*")
+ no=size(out,"*")
+ if tt==[] then
+
+ tete1=[" subroutine "+funam+"(flag,nevprt,t,xd,x,nx,z,nz,tvec,";..
+ " $ ntvec,rpar,nrpar,ipar,nipar"]
+
+ tete2= " $ "
+ for i=1:ni
+ tete2=tete2+",u"+string(i)+",nu"+string(i)
+ end
+ for i=1:no
+ tete2=tete2+",y"+string(i)+",ny"+string(i)
+ end
+ tete2=tete2+")"
+
+ tete3=[" double precision t,xd(*),x(*),z(*),tvec(*)";..
+ " integer flag,nevprt,nx,nz,ntvec,nrpar,ipar(*)"]
+
+ tete4= " double precision rpar(*)"
+ for i=1:ni
+ tete4=tete4+",u"+string(i)+"(*)"
+ end
+ for i=1:no
+ tete4=tete4+",y"+string(i)+"(*)"
+ end
+ tetec=["c";"c"];tetev=[" ";" "];
+ tetend=" end"
+
+ textmp=[tete1;tete2;tetec;tete3;tete4;tetec;tetev;tetec;tetend];
+ else
+ textmp=tt;
+ end
+
+ while 1==1
+ [txt]=x_dialog(["Function definition in fortran";
+ "Here is a skeleton of the functions which you should edit"],..
+ textmp);
+
+ if txt<>[] then
+ tt=txt
+ [ok]=scicos_block_link(funam,tt,"f")
+ if ok then
+ textmp=txt;
+ end
+ break;
+ else
+ ok=%f;break;
+ end
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/Link_modelica_C.bin b/modules/scicos/macros/scicos_scicos/Link_modelica_C.bin
new file mode 100755
index 000000000..cc50d1845
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/Link_modelica_C.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/Link_modelica_C.sci b/modules/scicos/macros/scicos_scicos/Link_modelica_C.sci
new file mode 100755
index 000000000..64deb6152
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/Link_modelica_C.sci
@@ -0,0 +1,75 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// Copyright (C) DIGITEO - 2010 - Allan CORNET
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+// -----------------------------------------------------------------------------
+function ok = Link_modelica_C(Cfile)
+ mlibs = pathconvert(modelica_libs, %t, %t);
+ Cfile = pathconvert(Cfile, %f, %t)
+ name = basename(Cfile);
+ path = fileparts(Cfile, "path");
+
+ // build the list of external functions libraries
+ // remove repreated directories from mlibs
+ rep = [];
+ for k = 1:size(mlibs, "*")
+ for j = k + 1:size(mlibs, "*")
+ if stripblanks(mlibs(k)) == stripblanks(mlibs(j)) then
+ rep = [rep, j];
+ end
+ end
+ end
+ mlibs(rep) = [];
+
+ // add dynamic libraries in same directory that .mo
+ // compatibility feature with 4.x.x
+ libs = [];
+ ext = getdynlibext();
+ for k = 1:size(mlibs, "*")
+ fileSearched = findfiles(mlibs(k), "*" + ext);
+ for j = 1:size(fileSearched, "*")
+ [pathx, fnamex, extensionx] = fileparts(fileSearched(j));
+ libsname = fullfile(pathx, fnamex);
+ if getos() == "Windows" then
+ libsname = strsubst(libsname, "\", "/");
+ end
+ libs = [libs; libsname];
+ end
+ end
+
+ // add modelica_libs to the list of directories to be searched for *.h
+ IncludePaths = "";
+ extToSearch = ".h";
+
+ for k = 1:size(mlibs, "*")
+ pathSearch = mlibs(k);
+ pathSearch = strsubst(pathSearch, "\", "/");
+ filesFounded = findfiles(pathSearch, "*" + ext);
+ if filesFounded <> [] then
+ IncludePaths = IncludePaths + " -I""" + pathSearch + """";
+ end
+ end
+
+ //** build shared library with the C code
+ files = name;
+ ok = buildnewblock(name, files, "", "", libs, TMPDIR, "", IncludePaths);
+
+endfunction
+// -----------------------------------------------------------------------------
diff --git a/modules/scicos/macros/scicos_scicos/MODCOM.bin b/modules/scicos/macros/scicos_scicos/MODCOM.bin
new file mode 100755
index 000000000..0a779970f
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/MODCOM.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/MODCOM.sci b/modules/scicos/macros/scicos_scicos/MODCOM.sci
new file mode 100755
index 000000000..3263dd10d
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/MODCOM.sci
@@ -0,0 +1,211 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [ok,tt]=MODCOM(funam,tt,vinp,vout,vparam,vparamv,vpprop)
+ //
+ [dirF,nameF,extF]=fileparts(funam);
+
+ //the new head
+ class_txt_new=build_classhead(funam,vinp,vout,vparam,vparamv,vpprop)
+
+ if (tt==[]) then
+ tete4= ["";" // Real x(start=1), y(start=2);"]
+ tete5="equation";
+
+ tete6=[" // exemple"];
+ tete7=" //der(x)=x-x*y;";
+ tete8=" //der(y)+2*y=x*y;";
+ tete9="end "+nameF+";";
+ textmp=[class_txt_new;tete4;tete5;tete6;tete7;tete8;tete9];
+ else
+ modif=%f;
+ for i=1:size(tt,"*")
+ if strindex(stripblanks(tt(i)),...
+ "////do not modif above this line ////")<>[] then
+ //Alan, 07/10/07
+ //tt(1:i-1) : the current head
+ textmp=[class_txt_new;tt(i+1:$)]
+ modif=%t
+ break
+ end
+ end
+ if ~modif then textmp=tt, end;
+ end
+
+ editblk=%f
+ //## set param of scstxtedit
+ ptxtedit = scicos_txtedit(clos = 0,...
+ typ = "ModelicaClass",...
+ head = ["Function definition in Modelica";
+ "Here is a skeleton of the functions"+...
+ " which you should edit"])
+
+ while %t
+
+ if (extF=="" | (extF==".mo" & fileinfo(funam)==[])) then
+ editblk=%t;
+ [txt,Quit] = scstxtedit(textmp,ptxtedit);
+ elseif (extF==".mo" & fileinfo(funam)<>[]) then
+ txt=tt;
+ end
+
+
+ if ptxtedit.clos==1 then
+ break;
+ end
+
+ if txt<>[] then
+ //## TODO : compilation
+ //## printf("Compil !!");
+ ok=%t;
+
+ //** saving in the filename
+ if ok then
+ tarpath=pathconvert(TMPDIR+"/Modelica/",%f,%t);
+
+ if (extF=="") then
+ funam=tarpath+nameF+".mo";
+ mputl(txt,funam);
+ elseif fileinfo(funam)==[] then
+ mputl(txt,funam);
+ end
+ ptxtedit.clos = 1;
+ tt = txt;
+ end
+ textmp = txt;
+ end
+
+ if editblk then
+ if Quit==1 then
+ ok=%f;
+ break;
+ end
+ elseif txt==[] then
+ ok=%f; // cancel bouton
+ break
+ end
+ end
+endfunction
+
+//build_classhead : build the head of the modelica function
+function class_txt=build_classhead(funam,vinp,vout,vparam,vparamv,vpprop)
+
+ [dirF,nameF,extF]=fileparts(funam);
+
+ ni=size(vinp,"r"); //** number of inputs
+ no=size(vout,"r"); //** number of outputs
+ np=size(vparam,"r"); //** number of params
+
+ tete1=["class "+nameF]
+
+ //** parameters head
+ if np<>0 then
+ tete1b= " //parameters";
+ for i=1:np
+ //** param
+ if vpprop(i)==0 then
+ head=" parameter Real "
+ if size(vparamv(i),"*")==1 then
+ head=head+msprintf("%s = %e;", vparam(i), vparamv(i));
+ else
+ head=head+vparam(i)+"["+string(size(vparamv(i),"*"))+"]={";
+ for j=1:size(vparamv(i),"*")
+ head=head+msprintf("%e", vparamv(i)(j));
+ if j<>size(vparamv(i),"*") then
+ head=head+","
+ end
+ end
+ head=head+"};"
+ end
+ //** state
+ elseif vpprop(i)==1 then
+ head=" Real "
+ if size(vparamv(i),"*")==1 then
+ head=head+msprintf("%s (start=%e);", vparam(i), vparamv(i));
+ else
+ head=head+vparam(i)+"["+string(size(vparamv(i),"*"))+"](start={";
+ for j=1:size(vparamv(i),"*")
+ head=head+msprintf("%e", vparamv(i)(j));
+ if j<>size(vparamv(i),"*") then
+ head=head+","
+ end
+ end
+ head=head+"});"
+ end
+ //** fixed state
+ elseif vpprop(i)==2 then
+ head=" Real "
+ if size(vparamv(i),"*")==1 then
+ head=head+msprintf("%s (fixed=true,start=%e);", vparam(i), vparamv(i));
+ else
+ head=head+vparam(i)+"["+string(size(vparamv(i),"*"))+"](start={";
+ P_fix="fixed={"
+ for j=1:size(vparamv(i),"*")
+ head=head+msprintf("%e", vparamv(i)(j));
+ P_fix=P_fix+"true"
+ if j<>size(vparamv(i),"*") then
+ head=head+","
+ P_fix=P_fix+","
+ end
+ end
+ head=head+"},"+P_fix+"});"
+ end
+ end
+ tete1b=[tete1b
+ head]
+ end
+ else
+ tete1b=[];
+ end
+
+ //** inputs head
+ if ni<>0 then
+ tete2= " Real ";
+ for i=1:ni
+ tete2=tete2+vinp(i);
+ if (i==ni) then tete2=tete2+";";else tete2=tete2+",";end
+ end
+ tete2=[" //input variables";
+ tete2];
+ else
+ tete2=[];
+ end
+
+ //** outputs head
+ if no<>0 then
+ tete3= " Real "
+ for i=1:no
+ tete3=tete3+vout(i);
+ if (i==no) then tete3=tete3+";";else tete3=tete3+",";end
+ end
+ tete3=[" //output variables";
+ tete3];
+ else
+ tete3=[];
+ end
+
+ tete4=" ////do not modif above this line ////"
+ //-----------------------------------------
+
+ class_txt=[tete1;
+ " ////automatically generated ////";
+ tete1b;tete2;tete3;tete4]
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/Sinks.cosf b/modules/scicos/macros/scicos_scicos/Sinks.cosf
new file mode 100755
index 000000000..0b96104ab
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/Sinks.cosf
@@ -0,0 +1,837 @@
+scs_m=scicos_diagram(..
+ version="scicos4.2",..
+ props=scicos_params(..
+ wpar=[600,450,0,0,600,450],..
+ Title=["Sinks","SCI/modules/scicos/macros/scicos_scicos/"],..
+ tol=[0.0001,0.000001,1.000E-10,100001,0,0],..
+ tf=100000,..
+ context=[],..
+ void1=[],..
+ options=tlist(["scsopt","3D","Background","Link","ID","Cmap"],list(%t,33),[8,1],[1,5],..
+ list([5,1],[4,1]),[0.8,0.8,0.8]),..
+ void2=[],..
+ void3=[],..
+ doc=list()))
+scs_m.objs(1)=scicos_block(..
+ gui="AFFICH_m",..
+ graphics=scicos_graphics(..
+ orig=[0,0],..
+ sz=[60,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["[1,1]";"1";"1";"1";"5";"1";"0"],..
+ pin=0,..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list(..
+ ["fnt=xget(''font'')";
+ "xset(''font'',ipar(1),ipar(2))";
+ "str='' ''+part(''0'',ones(1,ipar(5)-ipar(6)-2))+''.''+part(''0'',ones(1,ipar(6)))";
+ "str(1:model.in*model.in2)=str";
+ "str=matrix(str,model.in,model.in2)";
+ "rr=xstringl(orig(1),orig(2),str)";
+ "xstring(orig(1)+max(0,(sz(1)-rr(3))/2),orig(2)+max(0,(sz(2)-rr(4))/2),str)";
+ "xset(''font'',fnt(1),fnt(2))"],8),..
+ id="",..
+ in_implicit="E",..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("affich2",4),..
+ in=1,..
+ in2=1,..
+ intyp=1,..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[-1;0;0;1;1;0;0],..
+ odstate=list(),..
+ rpar=[],..
+ ipar=[1;1;1;1000;5;1;1],..
+ opar=list(),..
+ blocktype="c",..
+ firing=[],..
+ dep_ut=[%t,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(2)=scicos_block(..
+ gui="CMSCOPE",..
+ graphics=scicos_graphics(..
+ orig=[90,0],..
+ sz=[40,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["1 1";"1 3 5 7 9 11 13 15";"-1";"[]";"[]";"-1 -5";"1 5";"30 30";"20";"0";""],..
+ pin=[0;0],..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list("xstringb(orig(1),orig(2),''MScope'',sz(1),sz(2),''fill'')",8),..
+ id="",..
+ in_implicit=["E";"E"],..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("cmscope",4),..
+ in=[1;1],..
+ in2=[1;1],..
+ intyp=[1;1],..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=[0;30;30;-1;1;-5;5],..
+ ipar=[-1;2;20;-1;-1;-1;-1;1;1;1;3],..
+ opar=list(),..
+ blocktype="c",..
+ firing=[],..
+ dep_ut=[%t,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(3)=scicos_block(..
+ gui="CSCOPXY",..
+ graphics=scicos_graphics(..
+ orig=[160,0],..
+ sz=[40,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["1";"4";"1";"-1";"[]";"[600;400]";"-15";"15";"-15";"15";"2"],..
+ pin=[0;0],..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list(..
+ ["thick=xget(''thickness'');xset(''thickness'',2);";
+ "t=(0:0.2:2*%pi)'';";
+ "xx=orig(1)+(1/5+(cos(3*t)+1)*3/10)*sz(1);";
+ "yy=orig(2)+(1/4.3+(sin(t+1)+1)*3/10)*sz(2);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick)"],8),..
+ id="",..
+ in_implicit=["E";"E"],..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("cscopxy",4),..
+ in=[1;1],..
+ in2=[1;1],..
+ intyp=[1;1],..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=[-15;15;-15;15],..
+ ipar=[-1;1;2;4;1;1;-1;-1;600;400;1],..
+ opar=list(),..
+ blocktype="d",..
+ firing=[],..
+ dep_ut=[%f,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(4)=scicos_block(..
+ gui="WRITEC_f",..
+ graphics=scicos_graphics(..
+ orig=[230,0],..
+ sz=[60,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["1";"foo";"c ";"2";"0"],..
+ pin=0,..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list(..
+ ["txt=[''write to'';''C binary file''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"],8),..
+ id="",..
+ in_implicit="E",..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("writec",2),..
+ in=1,..
+ in2=[],..
+ intyp=1,..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[-1;0;0;0;0;0],..
+ odstate=list(),..
+ rpar=[],..
+ ipar=[3;12;40;40;2;0;15;24;24],..
+ opar=list(),..
+ blocktype="d",..
+ firing=[],..
+ dep_ut=[%t,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(5)=scicos_block(..
+ gui="CANIMXY",..
+ graphics=scicos_graphics(..
+ orig=[320,0],..
+ sz=[40,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["1";"-4";"1";"-1";"[]";"[]";"-15";"15";"-15";"15";"2"],..
+ pin=[0;0],..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list(..
+ ["thick=xget(''thickness'');xset(''thickness'',2);";
+ "t=(0:0.3:2*%pi)'';";
+ "xx=orig(1)+(1/5+(cos(2.2*t)+1)*3/10)*sz(1);";
+ "yy=orig(2)+(1/4.3+(sin(t)+1)*3/10)*sz(2);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick);"],8),..
+ id="",..
+ in_implicit=["E";"E"],..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("canimxy",4),..
+ in=[1;1],..
+ in2=[1;1],..
+ intyp=[1;1],..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=[-15;15;-15;15],..
+ ipar=[-1;1;2;-4;1;0;-1;-1;-1;-1;1],..
+ opar=list(),..
+ blocktype="d",..
+ firing=[],..
+ dep_ut=[%f,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(6)=scicos_block(..
+ gui="CSCOPE",..
+ graphics=scicos_graphics(..
+ orig=[390,0],..
+ sz=[40,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["1 3 5 7 9 11 13 15";"-1";"[]";"[600;400]";"-15";"15";"30";"20";"0";""],..
+ pin=0,..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list(..
+ ["thick=xget(''thickness'');xset(''thickness'',2);";
+ "xrect(orig(1)+sz(1)/10,orig(2)+(1-1/10)*sz(2),sz(1)*8/10,sz(2)*8/10);";
+ "xx=[orig(1)+sz(1)/5,orig(1)+sz(1)/5;";
+ "orig(1)+(1-1/4)*sz(1),orig(1)+sz(1)/5];";
+ "yy=[orig(2)+sz(2)/5,orig(2)+sz(2)/5;";
+ "orig(2)+sz(2)/5,orig(2)+(1-1/3)*sz(2)];";
+ "xarrows(xx,yy);";
+ "t=(0:0.3:2*%pi)'';";
+ "xx=orig(1)+(1/5+3*t/(10*%pi))*sz(1);";
+ "yy=orig(2)+(1/4.3+(sin(t)+1)*3/10)*sz(2);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick)"],8),..
+ id="",..
+ in_implicit="E",..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("cscope",4),..
+ in=-1,..
+ in2=1,..
+ intyp=1,..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=[0;-15;15;30],..
+ ipar=[-1;1;20;1;3;5;7;9;11;13;15;-1;-1;600;400],..
+ opar=list(),..
+ blocktype="c",..
+ firing=[],..
+ dep_ut=[%t,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(7)=scicos_block(..
+ gui="OUTIMPL_f",..
+ graphics=scicos_graphics(..
+ orig=[0,70],..
+ sz=[20,20],..
+ flip=%t,..
+ theta=0,..
+ exprs="1",..
+ pin=0,..
+ pout=[],..
+ pein=[],..
+ peout=[],..
+ gr_i=list("prt=string(model.ipar);xstringb(orig(1),orig(2),prt,sz(1),sz(2))",8),..
+ id="",..
+ in_implicit="I",..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim="outimpl",..
+ in=-1,..
+ in2=1,..
+ intyp=1,..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=[],..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=[],..
+ ipar=1,..
+ opar=list(),..
+ blocktype="c",..
+ firing=[],..
+ dep_ut=[%f,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=tlist(["modelica","model","inputs","outputs","parameters"],"PORT","n",[],..
+ list([],list()))),..
+ doc=list())
+scs_m.objs(8)=scicos_block(..
+ gui="CLKOUTV_f",..
+ graphics=scicos_graphics(..
+ orig=[50,70],..
+ sz=[20,30],..
+ flip=%t,..
+ theta=0,..
+ exprs="1",..
+ pin=[],..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list(" ",8),..
+ id="",..
+ in_implicit=[],..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim="output",..
+ in=[],..
+ in2=[],..
+ intyp=1,..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=[],..
+ ipar=1,..
+ opar=list(),..
+ blocktype="d",..
+ firing=[],..
+ dep_ut=[%f,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(9)=scicos_block(..
+ gui="CEVENTSCOPE",..
+ graphics=scicos_graphics(..
+ orig=[100,70],..
+ sz=[40,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["1";"1";"-1";"[]";"[600;400]";"30"],..
+ pin=[],..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list(..
+ ["thick=xget(''thickness'');xset(''thickness'',2);";
+ "xrect(orig(1)+sz(1)/10,orig(2)+(1-1/10)*sz(2),sz(1)*8/10,sz(2)*8/10);";
+ "xx=[orig(1)+sz(1)/5,orig(1)+sz(1)/5;";
+ "orig(1)+(1-1/5)*sz(1),orig(1)+sz(1)/5];";
+ "yy=[orig(2)+sz(2)/5,orig(2)+sz(2)/5;";
+ "orig(2)+sz(2)/5,orig(2)+(1-1/5)*sz(2)];";
+ "xarrows(xx,yy);";
+ "t=(0:0.3:2*%pi)'';";
+ "xx=orig(1)+(1/5+3*t/(10*%pi))*sz(1);";
+ "yy=orig(2)+(1/4.3+(sin(t)+1)*3/10)*sz(2);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick);"],8),..
+ id="",..
+ in_implicit=[],..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("cevscpe",4),..
+ in=[],..
+ in2=[],..
+ intyp=1,..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=30,..
+ ipar=[-1;1;1;-1;-1;600;400],..
+ opar=list(),..
+ blocktype="d",..
+ firing=[],..
+ dep_ut=[%f,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(10)=scicos_block(..
+ gui="OUT_f",..
+ graphics=scicos_graphics(..
+ orig=[170,70],..
+ sz=[20,20],..
+ flip=%t,..
+ theta=0,..
+ exprs="1",..
+ pin=0,..
+ pout=[],..
+ pein=[],..
+ peout=[],..
+ gr_i=list(" ",8),..
+ id="",..
+ in_implicit="E",..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim="output",..
+ in=-1,..
+ in2=-2,..
+ intyp=-1,..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=[],..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=[],..
+ ipar=1,..
+ opar=list(),..
+ blocktype="c",..
+ firing=[],..
+ dep_ut=[%f,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(11)=scicos_block(..
+ gui="WFILE_f",..
+ graphics=scicos_graphics(..
+ orig=[220,70],..
+ sz=[60,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["1";"foo";"(7(e10.3,1x))";"2"],..
+ pin=0,..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list(..
+ ["txt=[''write to'';''output file''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"],8),..
+ id="",..
+ in_implicit="E",..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim="writef",..
+ in=1,..
+ in2=[],..
+ intyp=1,..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[-1;0;0;0;0;0],..
+ odstate=list(),..
+ rpar=[],..
+ ipar=[3;13;0;2;15;24;24;41;7;41;14;1;0;51;3;52;1;33;42;42],..
+ opar=list(),..
+ blocktype="d",..
+ firing=[],..
+ dep_ut=[%t,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(12)=scicos_block(..
+ gui="CFSCOPE",..
+ graphics=scicos_graphics(..
+ orig=[310,70],..
+ sz=[40,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["1 3 5 7 9 11 13 15";"-1";"[]";"[600;400]";"-15";"15";"30";"2";"1"],..
+ pin=[],..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list(..
+ ["thick=xget(''thickness'');xset(''thickness'',2);";
+ "xrect(orig(1)+sz(1)/10,orig(2)+(1-1/10)*sz(2),sz(1)*8/10,sz(2)*8/10);";
+ "xx=[orig(1)+sz(1)/5,orig(1)+sz(1)/5;";
+ "orig(1)+(1-1/4)*sz(1),orig(1)+sz(1)/5];";
+ "yy=[orig(2)+sz(2)/5,orig(2)+sz(2)/5;";
+ "orig(2)+sz(2)/5,orig(2)+(1-1/3)*sz(2)];";
+ "xarrows(xx,yy);";
+ "t=(0:0.3:2*%pi)'';";
+ "xx=orig(1)+(1/5+3*t/(10*%pi))*sz(1);";
+ "yy=orig(2)+(1/4.3+(sin(t)+1)*3/10)*sz(2);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick)"],8),..
+ id="",..
+ in_implicit=[],..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("cfscope",4),..
+ in=[],..
+ in2=[],..
+ intyp=1,..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=[0;-15;15;30],..
+ ipar=[-1;1;2;1;3;5;7;9;11;13;15;-1;-1;600;400;1;1],..
+ opar=list(),..
+ blocktype="c",..
+ firing=[],..
+ dep_ut=[%t,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(13)=scicos_block(..
+ gui="WRITEAU_f",..
+ graphics=scicos_graphics(..
+ orig=[380,70],..
+ sz=[60,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["2";"0"],..
+ pin=0,..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list(..
+ ["txt=[''write AU to'';''/dev/audio''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"],8),..
+ id="",..
+ in_implicit="E",..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("writeau",2),..
+ in=1,..
+ in2=[],..
+ intyp=1,..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[-1;0;0;0;0;0],..
+ odstate=list(),..
+ rpar=[],..
+ ipar=[10;30;12;40;2;0;48;13;14;31;48;10;30;13;18;24],..
+ opar=list(),..
+ blocktype="d",..
+ firing=[],..
+ dep_ut=[%t,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(14)=scicos_block(..
+ gui="CSCOPXY3D",..
+ graphics=scicos_graphics(..
+ orig=[0,140],..
+ sz=[40,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["1";
+ "1 2 3 4 5 6 7 13";
+ "1 1 1 1 1 1 1 1";
+ "-1";
+ "[]";
+ "[600;400]";
+ "-15 15";
+ "-15 15";
+ "-15 15";
+ "50 280";
+ "2"],..
+ pin=[0;0;0],..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list(..
+ ["thick=xget(''thickness'');xset(''thickness'',2);";
+ "t=(0:0.2:2*%pi)'';";
+ "xx=orig(1)+(1/5+(cos(3*t)+1)*3/10)*sz(1);";
+ "yy=orig(2)+(1/4.3+(sin(t+1)+1)*3/10)*sz(2);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick)"],8),..
+ id="",..
+ in_implicit=["E";"E";"E"],..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("cscopxy3d",4),..
+ in=[1;1;1],..
+ in2=[1;1;1],..
+ intyp=[1;1;1],..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=[-15;15;-15;15;-15;15;50;280],..
+ ipar=[-1;8;2;1;2;3;4;5;6;7;13;1;1;1;1;1;1;1;1;8;-1;-1;600;400;1],..
+ opar=list(),..
+ blocktype="d",..
+ firing=[],..
+ dep_ut=[%f,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(15)=scicos_block(..
+ gui="CANIMXY3D",..
+ graphics=scicos_graphics(..
+ orig=[70,140],..
+ sz=[40,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["1";
+ "1 2 3 4 5 6 7 13";
+ "1 1 1 1 1 1 1 1";
+ "-1";
+ "[]";
+ "[]";
+ "-15 15";
+ "-15 15";
+ "-15 15";
+ "50 280";
+ "2"],..
+ pin=[0;0;0],..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list(..
+ ["thick=xget(''thickness'');xset(''thickness'',2);";
+ "t=(0:0.3:2*%pi)'';";
+ "xx=orig(1)+(1/5+(cos(2.2*t)+1)*3/10)*sz(1);";
+ "yy=orig(2)+(1/4.3+(sin(t)+1)*3/10)*sz(2);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick);"],8),..
+ id="",..
+ in_implicit=["E";"E";"E"],..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("canimxy3d",4),..
+ in=[1;1;1],..
+ in2=[1;1;1],..
+ intyp=[1;1;1],..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=[-15;15;-15;15;-15;15;50;280],..
+ ipar=[-1;8;2;1;2;3;4;5;6;7;13;1;1;1;1;1;1;1;1;8;-1;-1;-1;-1;1],..
+ opar=list(),..
+ blocktype="d",..
+ firing=[],..
+ dep_ut=[%f,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(16)=scicos_block(..
+ gui="CMATVIEW",..
+ graphics=scicos_graphics(..
+ orig=[140,140],..
+ sz=[40,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["jetcolormap(25)";"0";"100"],..
+ pin=0,..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list("xstringb(orig(1),orig(2),''Mat. View'',sz(1),sz(2),''fill'')",8),..
+ id="",..
+ in_implicit="E",..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("cmatview",4),..
+ in=-1,..
+ in2=-2,..
+ intyp=1,..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=[0.24;1;0;0;0;0;0;0;0;0;0;0.02;0.18;0.34;0.5;0.66;0.82;0.98;1;1;1;1;1;1;0.9;
+ 0.74;0.58;0;0;0;0.06;0.22;0.38;0.54;0.7;0.86;1;1;1;1;1;1;1;0.86;0.7;0.54;0.38;
+ 0.22;0.06;0;0;0;0.58;0.74;0.9;1;1;1;1;1;1;0.98;0.82;0.66;0.5;0.34;0.18;0.02;0;
+ 0;0;0;0;0;0;0;0],..
+ ipar=[0;100;25],..
+ opar=list(),..
+ blocktype="c",..
+ firing=[],..
+ dep_ut=[%t,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(17)=scicos_block(..
+ gui="CMAT3D",..
+ graphics=scicos_graphics(..
+ orig=[210,140],..
+ sz=[40,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["-1";"-1";"jetcolormap(25)";"0";"100"],..
+ pin=0,..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list("xstringb(orig(1),orig(2),''Mat. 3D'',sz(1),sz(2),''fill'')",8),..
+ id="",..
+ in_implicit="E",..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("cmat3d",4),..
+ in=-1,..
+ in2=-2,..
+ intyp=1,..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=[0;0;0;0;0;0;0;0;0;0.02;0.18;0.34;0.5;0.66;0.82;0.98;1;1;1;1;1;1;0.9;0.74;0.58;
+ 0;0;0;0.06;0.22;0.38;0.54;0.7;0.86;1;1;1;1;1;1;1;0.86;0.7;0.54;0.38;0.22;0.06;
+ 0;0;0;0.58;0.74;0.9;1;1;1;1;1;1;0.98;0.82;0.66;0.5;0.34;0.18;0.02;0;0;0;0;0;0;
+ 0;0;0;-1;-1],..
+ ipar=[0;100;25;1;1],..
+ opar=list(),..
+ blocktype="c",..
+ firing=[],..
+ dep_ut=[%t,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
+scs_m.objs(18)=scicos_block(..
+ gui="TOWS_c",..
+ graphics=scicos_graphics(..
+ orig=[280,140],..
+ sz=[70,40],..
+ flip=%t,..
+ theta=0,..
+ exprs=["128","A","0"],..
+ pin=0,..
+ pout=[],..
+ pein=0,..
+ peout=[],..
+ gr_i=list(..
+ ["txt=[''To workspace''];";"xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"],..
+ 8),..
+ id="A",..
+ in_implicit="E",..
+ out_implicit=[]),..
+ model=scicos_model(..
+ sim=list("tows_c",4),..
+ in=-1,..
+ in2=-2,..
+ intyp=-1,..
+ out=[],..
+ out2=[],..
+ outtyp=1,..
+ evtin=1,..
+ evtout=[],..
+ state=[],..
+ dstate=[],..
+ odstate=list(),..
+ rpar=[],..
+ ipar=[128;1;-10],..
+ opar=list(),..
+ blocktype="d",..
+ firing=[],..
+ dep_ut=[%f,%f],..
+ label="",..
+ nzcross=0,..
+ nmode=0,..
+ equations=list()),..
+ doc=list())
diff --git a/modules/scicos/macros/scicos_scicos/adjust.bin b/modules/scicos/macros/scicos_scicos/adjust.bin
new file mode 100755
index 000000000..c8b998a2c
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/adjust.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/adjust.sci b/modules/scicos/macros/scicos_scicos/adjust.sci
new file mode 100755
index 000000000..588ac5b9f
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/adjust.sci
@@ -0,0 +1,465 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// - Alan Layec <alan.layec@inria.fr>
+// - Fady Nassif <fady.nassif@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [ok,bllst]=adjust(bllst,inpptr,outptr,inplnk,outlnk)
+ //
+ //adjust : a piece of the adjust_inout function.
+ // Only one pass -see c_pass2.sci-
+ //
+ //
+ //in parameters : bllst : list of blocks
+ // inpptr : vector of regular input port number
+ // (of size nblk+1)
+ // outptr : vector of regular output port number
+ // (of size nblk+1)
+ // inplnk : vector of link number connected to regular input port
+ // (of size max(inpptr)-1)
+ // outlnk : vector of link number connected to regular output port
+ // (of size max(outptr)-1)
+ //
+ //out parameters : ok : a boolean flag to known if adjust_inout have
+ // succeeded to resolve the in/out port size
+ // - ok = %t : all size have been resolved in bllst
+ // - ok = %f : problem in size adjustement
+ // bllst : modified list of blocks
+ //
+ //18/05/06, Alan : improvement in order to take into
+ //account two dimensional ports size.
+ //
+ //28/12/06, Alan : type for source port and target port must
+ // be the same.
+ //
+ //04/01/07, Fady :Can test the case of negatives equals target's dimensions.
+ //
+ //10/05/07, Alan : - if-then-else event-select case
+
+
+
+ //Adjust in2/out2, inttyp/outtyp
+ //in accordance to in/out in bllst
+ [ko,bllst]=adjust_in2out2(bllst);
+ if ~ko then ok=%f,return, end //if adjust_in2out2 failed then exit
+ //adjust_inout with flag ok=%f
+ //
+ [outoin,outoinptr]=connmat(inpptr,outptr,inplnk,outlnk)
+ for i=1:length(bllst)
+ if size(bllst(i).in,1)<>size(bllst(i).intyp,2) then
+ bllst(i).intyp=bllst(i).intyp(1)*ones(size(bllst(i).in,1),1);
+ end
+ if size(bllst(i).out,1)<>size(bllst(i).outtyp,2) then
+ bllst(i).outtyp=bllst(i).outtyp(1)*ones(size(bllst(i).out,1),1);
+ end
+ end
+ //loop on number of block
+ for hh=1:length(bllst)
+ ok=%t
+ for blkout=1:length(bllst) //second loop on number of block
+ for portout=1:outptr(blkout+1)-outptr(blkout) //loop on number of regular
+ //output port
+ jj=outptr(blkout)+portout-1 //get current number of output port
+
+ if [outoinptr(jj):outoinptr(jj+1)-1]<>[] then
+ for kk=outoinptr(jj):outoinptr(jj+1)-1 //loop on
+ blkin=outoin(kk,1) //
+ portin=outoin(kk,2) //
+
+ //nnin/nnout are the size (two dimensions) of the
+ //target port and the source port of the observed link
+ //before adjust
+ nnout(1,1)=bllst(blkout).out(portout)
+ nnout(1,2)=bllst(blkout).out2(portout)
+ nnin(1,1)=bllst(blkin).in(portin)
+ nnin(1,2)=bllst(blkin).in2(portin)
+ //intyp/outtyp are the type of the
+ //target port and the source port of the observed link
+ intyp=bllst(blkin).intyp(portin)
+ outtyp=bllst(blkout).outtyp(portout)
+
+ //check intyp outtyp
+ if(intyp>0 & outtyp>0) then
+ if intyp<>outtyp then
+ if (intyp==1 & outtyp==2) then
+ bllst(blkin).intyp(portin)=2;
+ elseif (intyp==2 & outtyp==1) then
+ bllst(blkout).outtyp(portout)=2;
+ else
+ bad_connection(corinv(blkout),portout,..
+ nnout,outtyp,..
+ corinv(blkin),portin,..
+ nnin,intyp,1)
+ ok=%f;
+ return
+ end
+ end
+ elseif(outtyp>0&intyp<0) then
+ ww=find(bllst(blkin).intyp==intyp)
+ bllst(blkin).intyp(ww)=outtyp
+ ww=find(bllst(blkin).outtyp==intyp)
+ bllst(blkin).outtyp(ww)=outtyp
+ elseif(outtyp<0&intyp>0) then
+ ww=find(bllst(blkout).outtyp==outtyp)
+ bllst(blkout).outtyp(ww)=intyp
+ ww=find(bllst(blkout).intyp==outtyp)
+ bllst(blkout).intyp(ww)=intyp
+ else
+ ok=%f
+ end
+
+ //loop on the two dimensions of source/target port
+ for ndim=1:2
+ //nin/nout are the size (two dimensions) of the
+ //target port and the source port of the observed link
+ nout(1,1)=bllst(blkout).out(portout)
+ nout(1,2)=bllst(blkout).out2(portout)
+ nin(1,1)=bllst(blkin).in(portin)
+ nin(1,2)=bllst(blkin).in2(portin)
+
+ //first case : dimension of source and
+ // target ports are explicitly informed
+ // informed with positive size
+ if (nout(1,ndim)>0&nin(1,ndim)>0) then
+ //if dimension of source and target port doesn't match
+ //then call bad_connection, set flag ok to false and exit
+ if nin(1,ndim)<>nout(1,ndim) then
+ bad_connection(corinv(blkout),portout,..
+ nnout,outtyp,..
+ corinv(blkin),portin,nnin,intyp)
+ ok=%f;return
+ end
+
+ //second case : dimension of source port is
+ // positive and dimension of
+ // target port is negative
+ elseif (nout(1,ndim)>0&nin(1,ndim)<0) then
+ //find vector of input ports of target block with
+ //first/second dimension equal to size nin(1,ndim)
+ //and assign it to nout(1,ndim)
+ ww=find(bllst(blkin).in==nin(1,ndim))
+ if ww<>[] then
+ bllst(blkin).in(ww)=nout(1,ndim)
+ end
+ ww=find(bllst(blkin).in2==nin(1,ndim))
+ if ww<>[] then
+ bllst(blkin).in2(ww)=nout(1,ndim)
+ end
+ //find vector of output ports of target block with
+ //first/second dimension equal to size nin(1,ndim)
+ //and assign it to nout(1,ndim)
+ ww=find(bllst(blkin).out==nin(1,ndim))
+ if ww<>[] then
+ bllst(blkin).out(ww)=nout(1,ndim)
+ end
+ ww=find(bllst(blkin).out2==nin(1,ndim))
+ if ww<>[] then
+ bllst(blkin).out2(ww)=nout(1,ndim)
+ end
+
+
+ //third case : dimension of source port is
+ // negative and dimension of
+ // target port is positive
+ elseif (nout(1,ndim)<0&nin(1,ndim)>0) then
+ //find vector of output ports of source block with
+ //first/second dimension equal to size nout(1,ndim)
+ //and assign it to nin(1,ndim)
+ ww=find(bllst(blkout).out==nout(1,ndim))
+ if ww<>[] then
+ bllst(blkout).out(ww)=nin(1,ndim)
+ end
+ ww=find(bllst(blkout).out2==nout(1,ndim))
+ if ww<>[] then
+ bllst(blkout).out2(ww)=nin(1,ndim)
+ end
+ //find vector of input ports of source block with
+ //first/second dimension equal to size nout(1,ndim)
+ //and assign it to nin(1,ndim)
+ ww=find(bllst(blkout).in==nout(1,ndim))
+ if ww<>[] then
+ bllst(blkout).in(ww)=nin(1,ndim)
+ end
+ ww=find(bllst(blkout).in2==nout(1,ndim))
+ if ww<>[] then
+ bllst(blkout).in2(ww)=nin(1,ndim)
+ end
+
+
+ //fourth case : a dimension of source port is
+ // null
+ elseif (nout(1,ndim)==0) then
+ //set ww to be the vector of size of the ndim
+ //dimension of input port of the source block
+ if ndim==1 then
+ ww=bllst(blkout).in(:)
+ elseif ndim==2 then
+ ww=bllst(blkout).in2(:)
+ end
+
+ //test if all size of the ndim dimension of input
+ //port of the source block is positive
+ if min(ww)>0 then
+
+ //test if the dimension of the target port
+ //is positive
+ if nin(1,ndim)>0 then
+
+ //if the sum of the size of the ndim dimension of the input
+ //port of the source block is equal to the size of the ndim dimension
+ //of the target port, then the size of the ndim dimension of the source
+ //port is equal to the size of ndim dimension of the target port
+ if sum(ww)==nin(1,ndim) then
+ if ndim==1 then
+ bllst(blkout).out(portout)=nin(1,ndim)
+ elseif ndim==2 then
+ bllst(blkout).out2(portout)=nin(1,ndim)
+ end
+ //else call bad_connection, set flag ok to false and exit
+ else
+ bad_connection(corinv(blkout),0,0,1,-1,0,0,1)
+ ok=%f;return
+ end
+
+ //if the ndim dimension of the target port is negative
+ //then the size of the ndim dimension of the source port
+ //is equal to the sum of the size of the ndim dimension
+ //of input ports of source block, and flag ok is set to false
+ else
+ if ndim==1 then
+ bllst(blkout).out(portout)=sum(ww)
+ elseif ndim==2 then
+ bllst(blkout).out2(portout)=sum(ww)
+ end
+ ok=%f
+ end
+
+ else
+ //set nww to be the vector of all negative size of input ports
+ //of the source block
+ nww=ww(find(ww<0))
+
+ //if all negative size have same size and if size of the
+ //ndim dimension of target port is positive then assign
+ //size of the ndim dimension of the source port to nin(1,ndim)
+ if norm(nww-nww(1),1)==0 & nin(1,ndim)>0 then
+ if ndim==1 then
+ bllst(blkout).out(portout)=nin(1,ndim)
+ elseif ndim==2 then
+ bllst(blkout).out2(portout)=nin(1,ndim)
+ end
+
+ //compute a size to be the difference between the size
+ //of the ndim dimension of target block and sum of positive
+ //size of input ports of source block divided by the number
+ //of input ports of source block with same negative size
+ k=(nin(1,ndim)-sum(ww(find(ww>0))))/size(nww,"*")
+
+ //if this size is a positive integer then assign it
+ //to the size of the ndim dimension of input ports of the
+ //source block which have negative size
+ if k==int(k)&k>0 then
+ if ndim==1 then
+ bllst(blkout).in(find(ww<0))=k
+ elseif ndim==2 then
+ bllst(blkout).in2(find(ww<0))=k
+ end
+
+ //else call bad_connection, set flag ok to false and exit
+ else
+ bad_connection(corinv(blkout),0,0,1,-1,0,0,1)
+ ok=%f;return
+ end
+
+ //set flag ok to false
+ else
+ ok=%f
+ end
+
+ end
+
+ //fifth case : a dimension of target port is
+ // null
+ elseif (nin(1,ndim)==0) then
+ //set ww to be the vector of size of the ndim
+ //dimension of output port of the target block
+ if ndim==1 then
+ ww=bllst(blkin).out(:)
+ elseif ndim==2 then
+ ww=bllst(blkin).out2(:)
+ end
+
+ //test if all size of the ndim dimension of output
+ //port of the target block is positive
+ if min(ww)>0 then
+ //test if the dimension of the source port
+ //is positive
+ if nout(1,ndim)>0 then
+
+ //if the sum of the size of the ndim dimension of the output
+ //port of the target block is equal to the size of the ndim dimension
+ //of the source port, then the size of the ndim dimension of the target
+ //port is equal to nout(1,ndim)
+ if sum(ww)==nout(1,ndim) then
+ if ndim==1 then
+ bllst(blkin).in(portin)=nout(1,ndim)
+ elseif ndim==1 then
+ bllst(blkin).in2(portin)=nout(1,ndim)
+ end
+ //else call bad_connection, set flag ok to false and exit
+ else
+ bad_connection(corinv(blkin),0,0,1,-1,0,0,1)
+ ok=%f;return
+ end
+ else
+ //if the ndim dimension of the source port is negative
+ //then the size of the ndim dimension of the target port
+ //is equal to the sum of the size of the ndim dimension
+ //of output ports of target block, and flag ok is set to false
+ if ndim==1 then
+ bllst(blkin).in(portin)=sum(ww)
+ elseif ndim==2 then
+ bllst(blkin).in2(portin)=sum(ww)
+ end
+ ok=%f
+ end
+
+ else
+ //set nww to be the vector of all negative size of output ports
+ //of the target block
+ nww=ww(find(ww<0))
+
+ //if all negative size have same size and if size of the
+ //ndim dimension of the source port is positive then assign
+ //size of the ndim dimension of the target port to nout(1,ndim)
+ if norm(nww-nww(1),1)==0 & nout(1,ndim)>0 then
+ if ndim==1 then
+ bllst(blkin).in(portin)=nout(1,ndim)
+ elseif ndim==2 then
+ bllst(blkin).in2(portin)=nout(1,ndim)
+ end
+
+ //compute a size to be the difference between the size
+ //of the ndim dimension of the source block and sum of positive
+ //size of output ports of the target block divided by the number
+ //of output ports of target block with same negative size
+ k=(nout(1,ndim)-sum(ww(find(ww>0))))/size(nww,"*")
+
+ //if this size is a positive integer then assign it
+ //to the size of the ndim dimension of output ports of the
+ //target block which have negative size
+ if k==int(k)&k>0 then
+ if ndim==1 then
+ bllst(blkin).out(find(ww<0))=k
+ elseif ndim==2 then
+ bllst(blkin).out2(find(ww<0))=k
+ end
+
+ //else call bad_connection, set flag ok to false and exit
+ else
+ bad_connection(corinv(blkin),0,0,1,-1,0,0,1)
+ ok=%f;return
+ end
+
+ //set flag ok to false
+ else
+ ok=%f
+ end
+ end
+
+ //sixth (& last) case : dimension of both source
+ // and target port are negatives
+ else
+ ok=%f //set flag ok to false
+ end
+
+ end
+ end
+ else
+ //there is no target port
+ nout(1,1)=bllst(blkout).out(portout)
+ nout(1,2)=bllst(blkout).out2(portout)
+ //loop on the two dimensions of source port
+ for ndim=1:2
+ //a dimension of the source port is
+ // null
+ if (nout(1,ndim)==0) then
+ if ndim==1 then
+ ww=bllst(blkout).in(:)
+ if min(ww)>0 then
+ bllst(blkout).out(portout)=sum(ww)
+ ok=%f
+ end
+ elseif ndim==2 then
+ ww=bllst(blkout).in2(:)
+ if min(ww)>0 then
+ bllst(blkout).out2(portout)=sum(ww)
+ ok=%f
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+
+ if ok then return, end //if ok then exit adjust
+ end
+ //if failed then display message and set flag ok to false
+ messagebox(["Not enough information to determine port sizes";
+ "Compile the diagram before running."],"modal");
+ ok=%f
+
+endfunction
+
+//connmat :
+//
+//in parameters : inpptr : vector of regular input port number
+// (of size nblk+1)
+// outptr : vector of regular output port number
+// (of size nblk+1)
+// inplnk : vector of link number connected to regular input port
+// (of size max(inpptr)-1)
+// outlnk : vector of link number connected to regular output port
+// (of size max(outptr)-1)
+//
+//out parameters : outoin :
+//
+// outoinptr :
+//
+function [outoin,outoinptr]=connmat(inpptr,outptr,inplnk,outlnk)
+ outoin=[];outoinptr=1
+ for k=1:outptr($)-1
+ ii=[]
+ for j=outlnk(k)
+ ii=[ii;find(inplnk==j)]
+ end
+ outoini=[];jj=0
+ for j=ii
+ // m=int32(max(find(inpptr<=int32(j))))
+ m=max(find(inpptr<=j))
+ n=j-inpptr(m)+1
+ outoini=[outoini;[m,n]]
+ jj=jj+1
+ end
+ outoinptr=[outoinptr;outoinptr($)+jj]
+ outoin=[outoin;outoini]
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/adjust_in2out2.bin b/modules/scicos/macros/scicos_scicos/adjust_in2out2.bin
new file mode 100755
index 000000000..91d9b5dd9
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/adjust_in2out2.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/adjust_in2out2.sci b/modules/scicos/macros/scicos_scicos/adjust_in2out2.sci
new file mode 100755
index 000000000..46ba92b8c
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/adjust_in2out2.sci
@@ -0,0 +1,58 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [ok,bllst]=adjust_in2out2(bllst)
+ //adjust_in2out2
+ //Alan
+ //adjust in2,intyp,out2, outtyp in accordance to
+ //in out (for compatibility)
+ ok=%t
+ nblk=size(bllst);
+ //Check dimension of vectors in/in2,out/out2
+ //and intyp/outyp for each block
+ for i=1:nblk
+ //input port
+ sz_in=size(bllst(i).in,"*");
+ sz_in2=size(bllst(i).in2,"*");
+ sz_intyp=size(bllst(i).intyp,"*");
+ //adjust dimension of in2
+ if sz_in2<sz_in then
+ bllst(i).in2=[bllst(i).in2;ones(sz_in-sz_in2,1)]
+ end
+ //adjust dimension of intyp
+ if sz_intyp<sz_in then
+ bllst(i).intyp=[bllst(i).intyp;ones(sz_in-sz_intyp,1)]
+ end
+
+ //output port
+ sz_out=size(bllst(i).out,"*");
+ sz_out2=size(bllst(i).out2,"*");
+ sz_outtyp=size(bllst(i).outtyp,"*");
+ //adjust dimension of out2
+ if sz_out2<sz_out then
+ bllst(i).out2=[bllst(i).out2;ones(sz_out-sz_out2,1)]
+ end
+ //adjust dimension of outtyp
+ if sz_outtyp<sz_out then
+ bllst(i).outtyp=[bllst(i).outtyp;ones(sz_out-sz_outtyp,1)]
+ end
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/bad_connection.bin b/modules/scicos/macros/scicos_scicos/bad_connection.bin
new file mode 100755
index 000000000..2e0f608a5
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/bad_connection.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/bad_connection.sci b/modules/scicos/macros/scicos_scicos/bad_connection.sci
new file mode 100755
index 000000000..baf83baad
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/bad_connection.sci
@@ -0,0 +1,131 @@
+// Xcos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// - Alan Layec <alan.layec@inria.fr>
+// Copyright (C) 2011 <bernard.dujardin@contrib.scilab.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function bad_connection(path_out,prt_out,nout,outtyp,path_in,prt_in,nin,intyp,typ)
+ // alert for badly connected blocks
+ // path_out : Path of the "from block" in scs_m
+ // path_in : Path of the "to block" in scs_m
+ // Alan, 28/12/06 : added rhs parameter : outtyp/intyp and typ flag.
+ // typ : a flag. If not present or equal to zero then
+ // display a message concerning size.
+ // Else if equal to 1 then display a message
+ // concerning type.
+ //!
+
+ if %scicos_debug_gr then
+ disp("bad_connection...")
+ end
+
+ rhs = argn(2) ;
+ if (rhs == 8) then typ=0, end
+
+ if type(path_out)==15 then //set of modelica blocks
+ // look for modelica bloc associated with prt_out
+ outports=list()
+ for b=path_out,
+ path=list();
+ for l=b(1:$-1),
+ path($+1)=l;path($+1)="model";path($+1)="rpar";path($+1)="objs";
+ end
+ path($+1)=b($);
+ if size(path)==1 then path=path(1),end
+ mb=scs_m.objs(path)
+ k=find(mb.graphics.out_implicit=="E")
+ for kk=k,outports($+1)=path,end
+ end
+ path_out=outports(prt_out)
+ end
+ if type(path_in)==15 then //set of modelica blocks
+ // look for modelica bloc associated with prt_in
+ inports=list()
+ for b=path_in,
+ path=list();
+ for l=b(1:$-1),
+ path($+1)=l;path($+1)="model";path($+1)="rpar";path($+1)="objs";
+ end
+ path($+1)=b($);
+ if size(path)==1 then path=path(1),end
+ mb=scs_m.objs(path)
+ k=find(mb.graphics.in_implicit=="E")
+ for kk=k,inports($+1)=path,end
+ end
+ path_in=inports(prt_in)
+ end
+
+ if type(path_out)==15 then //problem with implicit block
+ messagebox([gettext("Problem with the block generated from modelica blocks.")],"warning", "modal")
+ return;
+ end
+
+
+ // warn the output port block
+ if typ==0 then
+ msg = "<html><body>";
+ msg = msg + gettext("Block has connected output port<br />with incompatible size:");
+ msg = msg + "<ul>";
+ msg = msg + "<li>" + msprintf(gettext("Output port %s size is: %s"),string(prt_out), sci2exp(nout)) + "</li>";
+ if prt_in <> -1 then
+ msg = msg + "<li>" + msprintf(gettext("Input port %s size is: %s"),string(prt_in), sci2exp(nin)) + "</li>";
+ end
+ msg = msg + "</ul>";
+ msg = msg + "</body></html>";
+ else
+ msg = "<html><body>";
+ msg = gettext("Block has connected output port<br />with incompatible type.");
+ msg = msg + "<ul>";
+ msg = msg + "<li>" + msprintf(gettext("Output port %s type is: %s"),string(prt_out), sci2exp(outtyp)) + "</li>";
+ if prt_in <> -1 then
+ msg = msg + "<li>" + msprintf(gettext("Input port %s type is: %s"),string(prt_in), sci2exp(intyp)) + "</li>";
+ end
+ msg = msg + "</ul>";
+ msg = msg + "</body></html>";
+ end
+
+ hilite_path(path_out, msg);
+
+ // warn the input port block
+ if prt_in <> -1 then
+ if typ==0 then
+ msg = "<html><body>";
+ msg = msg + gettext("Block has connected input port<br />with incompatible size:");
+ msg = msg + "<ul>";
+ msg = msg + "<li>" + msprintf(gettext("Output port %s size is: %s"),string(prt_out), sci2exp(nout)) + "</li>";
+ msg = msg + "<li>" + msprintf(gettext("Input port %s size is: %s"),string(prt_in), sci2exp(nin)) + "</li>";
+ msg = msg + "</ul>";
+ msg = msg + "</body></html>";
+ else
+ msg = "<html><body>";
+ msg = msg + gettext("Block has connected input port<br />with incompatible type:");
+ msg = msg + "<ul>";
+ msg = msg + "<li>" + msprintf(gettext("Output port %s type is: %s"),string(prt_out), sci2exp(outtyp)) + "</li>";
+ msg = msg + "<li>" + msprintf(gettext("Input port %s type is: %s"),string(prt_in), sci2exp(intyp)) + "</li>";
+ msg = msg + "</ul>";
+ msg = msg + "</body></html>";
+ end
+
+ if or(path_in<>path_out) then
+ hilite_path(path_in, msg)
+ end
+ end
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/build_block.bin b/modules/scicos/macros/scicos_scicos/build_block.bin
new file mode 100755
index 000000000..4daa6ae18
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/build_block.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/build_block.sci b/modules/scicos/macros/scicos_scicos/build_block.sci
new file mode 100755
index 000000000..d452cfd07
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/build_block.sci
@@ -0,0 +1,86 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// Copyright (C) DIGITEO - 2010 - Jérôme PICARD
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [model, ok] = build_block(o)
+
+ // build the simulation function associated with the block if necessary
+
+ model = o.model;
+ graphics = o.graphics;
+ if model.sim(1)=="scifunc" then
+ if model.ipar <> 0 then
+ model.opar=model.ipar;
+ model.ipar=0;
+ end
+ if isempty(model.opar) <> %f then
+ messagebox(sprintf(gettext("%s: Error: A scifunc block has not been defined."), "build_block"),"modal","error");
+ ok = %f
+ return
+ end
+ model.sim = list(genmac(model.opar,size(model.in,"*"),size(model.out,"*")),3);
+ elseif type(model.sim) == 15 then
+ modsim = modulo(model.sim(2),10000)
+ if int(modsim/1000) == 1 then // Fortran Block
+ funam = model.sim(1)
+ if ~c_link(funam) then
+ tt = graphics.exprs(2);
+ ok = scicos_block_link(funam, tt, "f")
+ end
+ elseif int(modsim/1000) == 2 then // C Block
+ [model,ok]=recur_scicos_block_link(o,"c")
+ elseif model.sim(2) == 30004 then //modelica generic file type 30004
+ //funam = model.sim(1); tt = graphics.exprs(2);
+ if type(graphics.exprs) == 15 then // compatibility
+ funam = model.sim(1);
+ tt = graphics.exprs(2);
+ else
+ funam = model.equations.model
+ tt = graphics.exprs.funtxt;
+ end
+ [dirF, nameF, extF] = fileparts(funam);
+ [modelica_path, modelica_directory] = getModelicaPath();
+ if (extF == "") then
+ funam = modelica_directory + nameF + ".mo";
+ mputl(tt, funam);
+ end
+
+ //next lines removed in ScicosLab
+ // //++ Check that modelica compiler is available
+ // //++ Otherwise, give some feedback and quit
+ // if ~with_modelica_compiler() then
+ // messagebox(sprintf(gettext("%s: Error: Modelica compiler (MODELICAC) is unavailable."), "build_block"),"modal","error");
+ // ok = %f
+ // end
+
+
+ // compilerpath = 'modelicac' //** thanks to automatic detection
+
+ // // build compilation command line, execute it and test for result
+ // strCmd = compilerpath + ' -c ' + funam + ' -o ' + fullfile(tarpath, nameF + '.moc')
+ // if execstr('unix_s(''' + strCmd + ''')', 'errcatch') <> 0 then
+ // error(sprintf(gettext("%s: Error : the following command line failed to execute: %s.\n"), "build_block", strCmd))
+ // ok = %f
+ // end
+ end
+ end
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/build_modelica_block.bin b/modules/scicos/macros/scicos_scicos/build_modelica_block.bin
new file mode 100755
index 000000000..9ae3399e6
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/build_modelica_block.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/build_modelica_block.sci b/modules/scicos/macros/scicos_scicos/build_modelica_block.sci
new file mode 100755
index 000000000..0553715ad
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/build_modelica_block.sci
@@ -0,0 +1,77 @@
+// Scicos
+//
+// Copyright (C) INRIA - Serge Steer <serge.steer@inria.fr> - 2003
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [model,ok]=build_modelica_block(blklstm,corinvm,cmmat,NiM,NoM,NvM,scs_m,path)
+ // given the blocks definitions in blklstm and connections in cmmat this
+ // function first create the associated modelicablock and writes its code
+ // in the file named 'imppart_'+name+'.mo' in the directory given by path
+ // Then modelica compiler is called to produce the C code of scicos block
+ // associated to this modelica block. filbally the C code is compiled and
+ // dynamically linked with Scilab.
+ // The correspondind model data structure is returned.
+
+
+ //## get the name of the generated main modelica file
+ name=stripblanks(scs_m.props.title(1))+"_im";
+
+ //## generation of the txt for the main modelica file
+ //## plus return ipar/rpar for the model of THE modelica block
+ [txt,rpar,ipar]=create_modelica(blklstm,corinvm,cmmat,NvM,name,scs_m);
+
+ //## write txt in the file path+name+'.mo'
+ path=pathconvert(stripblanks(path),%t,%t)
+ mputl(txt,path+name+".mo");
+ mprintf("%s\n",["--------------------------------------------\";
+ msprintf(_(" Main Modelica : %s"),path+name+".mo")
+ ""])
+
+ //## search for
+
+ Mblocks = [];
+ for i=1:lstsize(blklstm)
+ if type(blklstm(i).sim)==15 then
+ if blklstm(i).sim(2)==30004 then
+ o = scs_m(scs_full_path(corinvm(i)))
+ Mblocks=[Mblocks;
+ o.graphics.exprs.nameF]
+ end
+ end
+ end
+
+ //generating XML and Flat_Model
+ //## compile modelica files
+ [ok,name,nipar,nrpar,nopar,nz,nx,nx_der,nx_ns,nin,nout,nm,ng,dep_u]=compile_modelica(path+name+".mo",Mblocks);
+
+ if ~ok then return,end
+
+ //nx is the state dimension
+ //ng is the number of surfaces
+ //name1 of the model+flat
+
+ //build model data structure of the block equivalent to the implicit part
+ model=scicos_model(sim=list(name,10004),..
+ in=ones(nin,1),out=ones(nout,1),..
+ state=zeros(nx*2,1),..
+ dstate=zeros(nz,1),..
+ rpar=rpar,..
+ ipar=ipar,..
+ dep_ut=[dep_u %t],nzcross=ng,nmode=nm)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/buildmacros.sce b/modules/scicos/macros/scicos_scicos/buildmacros.sce
new file mode 100755
index 000000000..a39a7d3a7
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/buildmacros.sce
@@ -0,0 +1,16 @@
+
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2007-2008 - INRIA - Allan CORNET <allan.cornet@inria.fr>
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+
+if (isdef("genlib") == %f) then
+ exec(SCI+"/modules/functions/scripts/buildmacros/loadgenlib.sce");
+end
+//------------------------------------
+genlib("scicos_scicoslib","SCI/modules/scicos/macros/scicos_scicos",%f,%t);
+//------------------------------------
diff --git a/modules/scicos/macros/scicos_scicos/buildnewblock.bin b/modules/scicos/macros/scicos_scicos/buildnewblock.bin
new file mode 100755
index 000000000..1be3414f7
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/buildnewblock.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/buildnewblock.sci b/modules/scicos/macros/scicos_scicos/buildnewblock.sci
new file mode 100755
index 000000000..f0291b7d4
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/buildnewblock.sci
@@ -0,0 +1,186 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// - Alan Layec <alan.layec@inria.fr> - 2007
+// - Allan CORNET - 2008
+// - Rachid Djenidi
+// - Simone Mannori
+//
+// Copyright (C) DIGITEO - Allan CORNET - 2010 - fully rewritten
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+//=============================================================================
+function [ok]=buildnewblock(blknam, files, filestan, filesint, libs, rpat, ldflags, cflags)
+
+ //** buildnewblock : generates Makefiles for
+ // the generated C code of a scicos block,
+ // compile and link it in Scilab
+ //
+ // Input : blknam : a prefix
+ // files : files to be compiled
+ // filestan : files to be compiled and included in
+ // resu the standalone code
+ // filesint : files to be compiled and included in
+ // the interfacing of standalone code
+ // libs : a vector of string of object files
+ // to include in the building process
+ // rpat : a target directory
+ // ldflags : linker flags
+ // cflags : C compiler flags
+ //
+ // Output : ok : a flag to say if build is ok
+
+ //** check rhs paramaters
+ [lhs,rhs] = argn(0);
+
+ if rhs <= 1 then files = blknam, end
+ if rhs <= 2 then filestan = "", end
+ if rhs <= 3 then filesint = "", end
+ if rhs <= 4 then libs = "", end
+ if rhs <= 5 then rpat = TMPDIR, end
+ if rhs <= 6 then ldflags = "", end
+ if rhs <= 7 then cflags = "", end
+
+ // Add .c extension if it is not already added
+ exts_files = fileext(files);
+ exts_filestan = fileext(filestan);
+ exts_filesint = fileext(filesint);
+
+ for i = 1:size(files, "*")
+ if exts_files(i) == "" & files(i) <> "" then
+ files(i) = files(i) + ".c";
+ end
+ end
+
+ for i = 1:size(filestan, "*")
+ if exts_filestan(i) == "" & filestan(i) <> "" then
+ filestan(i) = filestan(i) + ".c";
+ end
+ end
+
+ for i = 1:size(filesint, "*")
+ if exts_filesint(i) == "" & ~isdir(filesint(i)) & filesint(i) <> "" then
+ filesint(i) = filesint(i) + ".c";
+ end
+ end
+
+ // add a external file if it exists
+ // added for compatibility with 4.x
+ // By RN ...
+ if isfile(rpat + "/" + blknam + "f.f") then
+ files=[files, blknam + "f.f"];
+ end
+
+ //** adjust path and name of object files
+ // to include in the building process
+ if (libs ~= emptystr() & libs <> []) then
+ libs = pathconvert(libs, %f, %t);
+ end
+
+ //** otherlibs treatment
+ [ok, libs, for_link] = link_olibs(libs, rpat);
+ if ~ok then
+ ok = %f;
+ message(["sorry compiling problem"; lasterror()]);
+ return;
+ end
+
+ //** unlink if necessary
+ [a, b] = c_link(blknam);
+ while a
+ ulink(b);
+ [a, b] = c_link(blknam);
+ end
+
+ //** save path in case of error in ilib_compile
+ oldpath = pwd();
+
+ if getos() <> "Windows" then
+ if isdir(SCI+"/../../include/scilab/scicos_blocks/") then
+ //** Binary version
+ cflags = cflags + " -I" + SCI + "/../../include/scilab/scicos/";
+ cflags = cflags + " -I" + SCI + "/../../include/scilab/scicos_blocks/";
+ cflags = cflags + " -I" + SCI + "/../../include/scilab/dynamic_link/";
+ else
+ //** it is a source version
+ cflags = cflags + " -I" + SCI + "/modules/scicos/includes/";
+ cflags = cflags + " -I" + SCI + "/modules/scicos_blocks/includes/";
+ cflags = cflags + " -I" + SCI + "/modules/dynamic_link/includes/";
+ end
+ else
+ // Load dynamic_link Internal lib if it's not already loaded
+ if ~exists("dynamic_linkwindowslib") then
+ load("SCI/modules/dynamic_link/macros/windows/lib");
+ end
+ cflags = cflags + strcat(" -I""" + dlwGetXcosIncludes() + """");
+ ldflags = ldflags + strcat(" """ + dlwGetLibrariesPath() + dlwGetXcosLibraries() + """");
+ end
+
+ if (rpat == "" | rpat == []) & isdir(filesint) then
+ // Prepare Block "Code Generation" from Menu
+ chdir(filesint);
+ else
+ // generate Block in TMPDIR (default)
+ chdir(TMPDIR);
+ end
+
+ // Since all files Xcos generated files of all diagrams are in the same TEMP directory
+ // Here, we force to rebuild (not a simple incremental build on Windows)
+ if getos() == "Windows" then
+ VC_rebuild_mode = dlwForceRebuild();
+ dlwForceRebuild(%t);
+ end
+
+ ierr = execstr("libn =ilib_for_link(blknam,files,"""",""c"","""",""loader.sce"","""",ldflags,cflags)","errcatch");
+
+ // restore previous build mode
+ if getos() == "Windows" then
+ dlwForceRebuild(VC_rebuild_mode);
+ end
+
+ if ierr <> 0 then
+ ok = %f;
+ chdir(oldpath);
+ disp(["sorry compiling problem"; lasterror()]);
+ return;
+ end
+
+ if (rpat == "" | rpat == []) & isdir(filesint) then
+ NAME_BLOCK_C_SCI = filesint + filesep() + blknam + "_c.sci";
+ if isfile(NAME_BLOCK_C_SCI) then
+ ierr = exec(NAME_BLOCK_C_SCI, "errcatch");
+ if ierr <> 0 then
+ ok = %f;
+ chdir(oldpath);
+ return
+ end
+ end
+ end
+
+ ierr = exec("loader.sce", "errcatch");
+ if ierr <> 0 then
+ ok = %f;
+ else
+ ok = %t;
+ end
+
+ chdir(oldpath);
+
+endfunction
+
+//=============================================================================
diff --git a/modules/scicos/macros/scicos_scicos/c_pass1.bin b/modules/scicos/macros/scicos_scicos/c_pass1.bin
new file mode 100755
index 000000000..291d2ea10
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/c_pass1.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/c_pass1.sci b/modules/scicos/macros/scicos_scicos/c_pass1.sci
new file mode 100755
index 000000000..a31a5ede5
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/c_pass1.sci
@@ -0,0 +1,499 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// - Serge Steer <serge.steer@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [blklst,cmat,ccmat,cor,corinv,ok,scs_m,flgcdgen,freof]=c_pass1(scs_m,flgcdgen)
+ //derived from c_pass1 for implicit diagrams
+ //%Purpose
+ // Determine one level blocks and connections matrix
+ //%Parameters
+ // scs_m : scicos data structure
+ // ksup :
+ // blklst : a list containing the "model" information structure for each block
+ //
+ // cmat : nx6 matrix. Each row contains, in order, the block
+ // number and the port number and the port type of an outgoing scicopath,
+ // and the block number and the port number and the port type of the target
+ // ingoing scicopath. for regular links
+ //
+ // ccmat : nx4 matrix. Each row contains, in order, the block
+ // number and the port number of an outgoing scicopath,
+ // and the block number and the port number of the target
+ // ingoing scicopath for clock connections
+
+ // cor : is a list with same recursive structure as scs_m each leaf
+ // contains the index of associated block in blklst
+ // corinv : corinv(nb) is the path of nb ith block defined in blklst
+ // in the scs_m structure
+ //!
+ // Serge Steer 2003, Copyright INRIA
+ // flgcdgen: is a flag containing the numbre of event input of the diagram
+ // it is used only in the Codegeneration case.
+ // freof : it is a vector containing the frequency and the offset of the major clock.
+ // it is used only in the Codegeneration case.
+ // Fady Nassif 2007. INRIA.
+ //c_pass1;
+
+ if argn(2)<=1 then flgcdgen=-1, end
+ freof=[];
+ MaxBlock=countblocks(scs_m);
+ blklst=[];cmat=[],ccmat=[],cor=[],corinv=[]
+ [cor,corinvt,links_table,cur_fictitious,sco_mat,ok]=scicos_flat(scs_m);
+ if ~ok then
+ disp(mprintf("%s: flat failed", "c_pass1"));
+ return;
+ end
+ [links_table,sco_mat,ok]=global_case(links_table,sco_mat)
+ if ~ok then
+ disp(mprintf("%s: global case failed", "c_pass1"));
+ return;
+ end
+ index1=find((sco_mat(:,2)=="-1")& (sco_mat(:,5)<>"10"))
+ if index1<>[] then
+ for i=index1
+ [path]=findinlist(cor,-evstr(sco_mat(i,1)))
+ full_path=path(1)
+ if flgcdgen<>-1 then full_path=[numk full_path];scs_m=all_scs_m;end
+ hilite_path(full_path,"Error in compilation, There is a FROM ''"+(sco_mat(i,3))+ "'' without a GOTO",%t)
+ ok=%f;
+ disp(mprintf("%s: invalid connection matrix", "c_pass1"));
+ return;
+ end
+ end
+
+ nb=size(corinvt);
+ reg=1:nb
+ //form the block lists
+
+ blklst=list();kr=0 ; //regular block list
+ blklstm=list();km=0; //modelica block list
+
+ //if ind(i)>0 ith block is a regular block and stored in blklst(ind(i))
+ //if ind(i)<0 ith block is a modelica block and stored in blklstm(-ind(i))
+
+ ind=[];
+
+ for kb=1:nb
+ o=scs_m(scs_full_path(corinvt(kb)));
+ if is_modelica_block(o) then
+ km=km+1;blklstm(km)=o.model;
+ ind(kb)=-km;
+ [modelx,ok]=build_block(o); // compile modelica block type 30004
+ if ~ok then
+ disp(mprintf("%s: unable to build modelica block", "c_pass1"));
+ return
+ end
+ else
+ [model,ok]=build_block(o);
+ if ~ok then
+ disp(mprintf("%s: unable to build block", "c_pass1"));
+ return,
+ end
+
+ if or(model.sim(1)==["plusblk"]) then
+ [model,links_table]=adjust_sum(model,links_table,kb);
+ end
+
+ kr=kr+1;blklst(kr)=model;
+ ind(kb)=kr;
+ end
+
+ end
+
+ if (find(sco_mat(:,5)==string(4))<>[]) then
+ if flgcdgen ==-1 then
+ [links_table,blklst,corinvt,ind,ok]=sample_clk(sco_mat,links_table,blklst,corinvt,scs_m,ind,flgcdgen)
+ else
+ [links_table,blklst,corinvt,ind,ok,scs_m,flgcdgen,freof]=sample_clk(sco_mat,links_table,blklst,corinvt,scs_m,ind,flgcdgen)
+ end
+ if ~ok then
+ disp(mprintf("%s: unable to sample the whole diagram", "c_pass1"));
+ return,
+ end
+ end
+ nb=size(corinvt)
+ nl=size(links_table,1)/2
+
+ // Check if size match !
+ if(size(links_table(:,1:3), "r") == size(matrix([1;1]*(1:nl),-1,1), "r") ..
+ & size(matrix([1;1]*(1:nl),-1,1), "r") == size(links_table(:,4), "r"))
+ links_table=[links_table(:,1:3) matrix([1;1]*(1:nl),-1,1) ..
+ links_table(:,4) ];
+ else
+ disp(mprintf("%s: invalid links table size", "c_pass1"));
+ return
+ end
+ imp=find(ind<0)
+
+ reg(imp)=[]
+
+ if imp==[] then //no modelica block exists
+ cmat=matfromT(links_table(find(links_table(:,5)==1),:),nb); //data flow links
+ ccmat=cmatfromT(links_table(find(links_table(:,5)==-1),:),nb); //event links
+ corinv=corinvt
+ else // mixed diagram
+ nm=size(imp,"*") //number of modelica blocks
+ nr=nb-nm //number of regular blocks
+ cmmat=mmatfromT(links_table(find(links_table(:,5)==2),:),nb); //modelica links
+ cmat=matfromT(links_table(find(links_table(:,5)==1),:),nb); //data flow links
+ ccmat=cmatfromT(links_table(find(links_table(:,5)==-1),:),nb);//event links
+
+ //build connections between modelica world and regular one. These
+ //links should be data flow links
+ // links from modelica world to regular world
+ fromM=find(dsearch(cmat(:,1),imp,"d")>0);
+
+ // links from regular world to modelica world
+ toM=find(dsearch(cmat(:,3),imp,"d")>0);
+
+ // merge the modelica to modelica as data flow links
+ [varM, kfrom, kto] = intersect(fromM, toM);
+ fromM(kfrom) = [];
+ toM(kto) = [];
+
+ NoM=size(fromM,"*");
+ if NoM>0 then
+ //add modelica Output ports in Modelica world
+ mo=modelica();mo.model="OutPutPort";mo.outputs="vo";mo.inputs="vi";
+ for k=1:NoM,blklstm($+1)=scicos_model(equations=mo);end
+ //add modelica connections to these Output ports, set negative
+ //value to port numbers to avoid conflits with other blocks
+ cmmat=[cmmat;
+ cmat(fromM,1:2) zeros(NoM,1) -(nm+(1:NoM)'),ones(NoM,1),ones(NoM,1)];
+
+ nm=nm+NoM;
+ //add regular connection with regular block replacing the modelica world
+ cmat(fromM,1:2)=[-(nr+1)*ones(NoM,1),(1:NoM)'];
+ end
+
+ NiM=size(toM,"*");
+ if NiM>0 then
+ //add modelica Input ports in Modelica world
+ mo=modelica();mo.model="InPutPort";mo.outputs="vo";mo.inputs="vi";
+ for k=1:NiM,blklstm($+1)=scicos_model(equations=mo);end
+ //add modelica connections to these Input ports set negative
+ //value to port numbers to avoid conflits with other blocks
+ cmmat=[cmmat;
+ -(nm+(1:NiM)'), ones(NiM,1),zeros(NiM,1), cmat(toM,3:4), ones(NiM,1) ];
+
+ nm=nm+NiM;
+ //add regular connection with regular block replacing the modelica world
+ cmat(toM,3:4)=[-(nr+1)*ones(NiM,1),(1:NiM)'];
+ end
+
+ NvM=size(varM, "*");
+ if NvM>0 then
+ //add modelica Values (both input and output) ports in Modelica world
+ l=[cmat(varM,1:2), zeros(NvM,1), cmat(varM,3:4), ones(NvM,1)];
+ cmmat=[cmmat;
+ l];
+
+ // remove the corresponding explicit link
+ cmat(varM, :) = [];
+ end
+
+ // modelica blocks with events ports are not allowed yet
+ if size(ccmat,1)>0 then
+ if or(dsearch(ccmat(:,[1 3]),imp,"d")>0) then
+ messagebox("An implicit block has an event port","modal","error");
+ disp(mprintf("%s: implicit block with event port", "c_pass1"));
+ ok=%f;return
+ end
+ end
+
+ //renumber blocks according to their types
+
+ corinv=list();corinvm=list();
+
+ for kb=1:nb
+
+ if ind(kb)<0 then // modelica block
+
+ km=-ind(kb);
+
+ //replace by negative value to avoid conflicts
+
+ cmmat(find(cmmat(:,1)==kb),1)=-km ;
+
+ cmmat(find(cmmat(:,4)==kb),4)=-km;
+
+ corinvm(km)=corinvt(kb);
+
+ else
+
+ kr=ind(kb);
+
+ cmat (find(cmat (:,1)==kb),1)=-kr;
+
+ cmat (find(cmat (:,3)==kb),3)=-kr;
+
+ ccmat(find(ccmat(:,1)==kb),1)=-kr;
+
+ ccmat(find(ccmat(:,3)==kb),3)=-kr;
+
+ corinv(kr)=corinvt(kb);
+
+ end
+
+ end
+
+ //renumbering done, replace negative value by positive ones
+
+
+
+ cmat(:,[1 3])=abs(cmat(:,[1 3])) ;
+
+ ccmat(:,[1 3])=abs(ccmat(:,[1 3])) ;
+
+ cmmat=abs(cmmat) ;
+
+ //create regular block associated to all modelica blocks
+
+ [model,ok]=build_modelica_block(blklstm,corinvm,cmmat,NiM,NoM,NvM,scs_m,TMPDIR+"/");
+
+ if ~ok then
+ disp(mprintf("%s: build the modelica meta-block failed", "c_pass1"));
+ return
+ end
+
+ blklst(nr+1)=model;
+
+ //make compiled modelica block refer to the set of corresponding
+
+ //modelica blocks
+
+ corinv(nr+1)=corinvm //it may be useful to adapt function making use
+
+ //of corinv
+
+ //adjust the numbering of regular block in sco_mat
+
+ //if modelica's blocks exist
+
+ //Fady 08/11/2007
+
+ for i=1:size(sco_mat,1)
+
+ if eval(sco_mat(i,1))<MaxBlock then
+
+ sco_mat(i,1)=string(ind(eval(sco_mat(i,1))))
+
+ end
+
+ end
+
+ sco_mat=[sco_mat;[string(size(blklst)) "-1" "scicostimeclk0" "1" "10"]]
+
+ end
+
+ cor=update_cor(cor,reg)
+
+
+
+ // Taking care of the clk 0;
+
+ //*** this part has been taken from c_pass2 modified and placed here it must be tested ***
+
+ //Fady 08/11/2007
+
+ nbl=size(blklst)
+
+ fff=ones(nbl,1)==1
+
+ clkptr=zeros(nbl+1,1);clkptr(1)=1; typ_l=fff;
+
+ for i=1:nbl
+
+ ll=blklst(i);
+
+ clkptr(i+1)=clkptr(i)+size(ll.evtout,"*");
+
+ //tblock(i)=ll.dep_ut($);
+
+ typ_l(i)=ll.blocktype=="l";
+
+ end
+
+ all_out=[]
+
+ for k=1:size(clkptr,1)-1
+
+ if ~typ_l(k) then
+
+ kk=[1:(clkptr(k+1)-clkptr(k))]'
+
+ all_out=[all_out;[k*ones(kk),kk]]
+
+ end
+
+ end
+
+ all_out=[all_out;[0,0]]
+ //add time event if needed
+ tblock=find((sco_mat(:,2)=="-1")&(sco_mat(:,5)=="10"))
+ ind=sco_mat(tblock,1);
+ if ind<>[] then
+ ind=eval(ind(:))
+ //ind=find(tblock)
+ //ind=ind(:)
+ for k=ind'
+ ccmat=[ccmat;[all_out,ones(all_out)*[k,0;0,0]]]
+ end
+ for Ii=1:length(blklst)
+ if type(blklst(Ii).sim(1))==10 then
+ if part(blklst(Ii).sim(1),1:7)=="capteur" then
+ ccmat=[ccmat;[0 0 Ii 0]]
+ end
+ end
+ end
+ end
+ //***
+endfunction
+//**-----------------------------------------------------------------------------------------------------------------
+
+function [model,links_table]=adjust_sum(model,links_table,k)
+ //sum blocks have variable number of input ports, adapt the associated
+ //model data structure and input connection to take into account the
+ //actual number of connected ports
+ // Serge Steer 2003, Copyright INRIA
+ in=find(links_table(:,1)==k&links_table(:,3)==1)
+ nin=size(in,"*")
+ model.in=-ones(nin,1)
+ links_table(in,2)=(1:nin)'
+endfunction
+
+
+function mat=mmatfromT(Ts,nb)
+ //S. Steer, R. Nikoukhah 2003. Copyright INRIA
+ Ts(:,1)=abs(Ts(:,1));
+ K=unique(Ts(find(Ts(:,1)>nb),1)); // identificator of blocks to be removed
+ //remove superblocks port and split connections
+ Ts=remove_fictitious(Ts,K)
+
+ // from connection matrix
+ Imat=[];
+ for u=matrix(unique(Ts(:,4)),1,-1)
+ kue=matrix(find(Ts(:,4)==u),-1,1); //identical links
+ Imat=[Imat;[kue(2:$) kue(1).*ones(kue(2:$))]];
+ end
+ mat=[Ts(Imat(:,1),1:3) Ts(Imat(:,2),1:3)]
+endfunction
+
+
+function mat=matfromT(Ts,nb)
+ //S. Steer, R. Nikoukhah 2003. Copyright INRIA
+
+ Ts(:,1)=abs(Ts(:,1))
+ K=unique(Ts(find(Ts(:,1)>nb),1)); // identificator of blocks to be removed
+ //remove superblocks port and split connections
+ Ts=remove_fictitious(Ts,K)
+
+ // from connection matrix
+ Imat=[];
+ for u=matrix(unique(Ts(:,4)),1,-1)
+ kue=matrix(find(Ts(:,4)==u&Ts(:,3)==-1),-1,1); //look for outputs
+ jue=matrix(find(Ts(:,4)==u&Ts(:,3)==1),-1,1); //look for inputs
+ Imat=[Imat;[ones(jue).*.kue jue.*.ones(kue)]];
+ end
+ mat=[Ts(Imat(:,1),1:2) Ts(Imat(:,2),1:2)]
+endfunction
+
+function mat=cmatfromT(Ts,nb)
+ //S. Steer, R. Nikoukhah 2003. Copyright INRIA
+ //this function has been modified to support
+ // CLKGOTO et CLKFROM
+ // Fady NASSIF: 11/07/2007
+ k=find(Ts(:,1)<0) //superblock ports links and CLKGOTO/CLKFROM
+ K=unique(Ts(k,1));
+ Ts=remove_fictitious(Ts,K)
+
+ if Ts==[] then mat=[],return,end
+ // if size(Ts,1)<>int(size(Ts,1)/2)*2 then disp('PB'),pause,end
+ [s,k]=gsort(Ts(:,[4,3]),"lr","i");Ts=Ts(k,:)
+ // modified to support the CLKGOTO/CLKFROM
+ //mat=[Ts(1:2:$,1:2) Ts(2:2:$,1:2)]
+ //----------------------------------
+
+ J=find(Ts(:,3)==1); //find the destination block of the link
+ v=find([Ts(:,3);-1]==-1) // find the source block of the link
+ // many destination blocks can be connected to one source block
+ // so we have to find the number of destination blocks for each source block
+ // v(2:$)-v(1:$-1)-1
+ // then create the vector I that must be compatible with the vector J.
+ I=duplicate(v(1:$-1),v(2:$)-v(1:$-1)-1);
+ mat=[Ts(I,1:2),Ts(J,1:2)]
+
+ //----------------------------------
+ K=unique(Ts(Ts(:,1)>nb))
+ Imat=[];
+ for u=matrix(K,1,-1)
+ jue=matrix(find(mat(:,1)==u),-1,1); //look for outputs
+ kue=matrix(find(mat(:,3)==u),-1,1); //look for inputs
+ Imat=[ones(jue).*.kue jue.*.ones(kue)];
+ mat1=[mat(Imat(:,1),1:2), mat(Imat(:,2),3:4)];
+ mat([jue;kue],:)=[];
+ mat=[mat;mat1];
+ end
+
+endfunction
+
+function Ts=remove_fictitious(Ts,K)
+ //removes fictitious blocks connected links are replaced by a single one
+ //S. Steer, R. Nikoukhah 2003. Copyright INRIA
+ count=min(Ts(:,4))
+ for i=1:size(K,"*")
+ ki=K(i);
+ v1=find(Ts(:,1)==ki);
+ if v1<>[] then
+ v=unique(Ts(v1,4));
+ Ts(v1,:)=[];
+ if size(v)==1 then
+ ind=find(Ts(:,4)==v);
+ else
+ ind = find(dsearch(Ts(:,4),gsort(v,"g","i"),"d")<>0);
+ end
+ if size(ind,"*")>1 then
+ count=count-1;
+ Ts(ind,4)=count
+ else
+ Ts(ind,:)=[]
+ end
+ end
+ end
+endfunction
+
+function cor=update_cor(cor,reg)
+ n=size(cor)
+ for k=1:n
+ if type(cor(k))==15 then
+ cor(k)=update_cor(cor(k),reg)
+ else
+ p=find(cor(k)==reg)
+ if p<>[] then
+ cor(k)=p
+ elseif cor(k)<0 then // GOTO FROM cases
+ cor(k)=0
+ elseif cor(k)<>0 then
+ cor(k)=size(reg,"*")+1
+ end
+ end
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/c_pass2.bin b/modules/scicos/macros/scicos_scicos/c_pass2.bin
new file mode 100755
index 000000000..ce70baab7
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/c_pass2.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/c_pass2.sci b/modules/scicos/macros/scicos_scicos/c_pass2.sci
new file mode 100755
index 000000000..04cf4f1e4
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/c_pass2.sci
@@ -0,0 +1,2615 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function cpr=c_pass2(bllst,connectmat,clkconnect,cor,corinv,flag)
+ // cor ; correspondance table with initial block ordering
+ //
+ // bllst: list with nblk elts where nblk denotes number of blocks.
+ // Each element must be a list with 16 elements:
+ // 1- a list containing function name and function type
+ // 2- vector of number of inputs
+ // 3- vector of number of outputs
+ // 4- vector of number of clock inputs
+ // 5- vector of number of clock outputs
+ // 6- vector (column) of continuous initial condition
+ // 7- vector (column) of discrete initial condition
+ // 8- vector (column) of real parameters
+ // 9- vector (column) of integer parameters
+ // 10- string: 'l' for synchro (ifthenelse,eselect) or 'm'
+ // (memo) or 'x' for blocks that need to be called during
+ // integration even in the absence of state (only if with workspace)
+ // 11- vector of size <number of clock outputs> including
+ // preprogrammed event firing times (<0 if no firing)
+ // 12- boolean vector (column): 1:nin entry for dependence on u,
+ // last on t
+ // 13- block label
+ // 14- number of zero crossings
+ // 15- number of modes
+ // 16- empty list (equation for modelica blocks)
+ //
+ // connectmat: nx4 matrix. Each row contains, in order, the block
+ // number and the port number of an outgoing scicopath,
+ // and the block number and the port number of the target
+ // ingoing scicopath.
+ //
+ // clkconnect: same as connectmat but for clock scicopaths.
+ //
+ // define some constants
+ if argn(2) <6 then flag="verbose",end
+ show_trace=%f
+ if show_trace then mprintf("c_pass1:\t%f\n", timer()),end
+
+ show_pause=%f;
+ show_comment=%f;
+
+ if bllst==list() then
+ messagebox(_("No block can be activated"),"modal","error")
+ cpr=list()
+ ok=%f;
+ return
+ end
+
+ //correction of clkconnect.. Must be done before
+ clkconnect(find(clkconnect(:,2)==0),2)=1;
+
+
+
+
+ if exists("%scicos_solver")==0 then %scicos_solver=0,end
+
+ clkptr=1,cliptr=1,typ_l=[],
+ nblk=size(bllst)
+
+ //take care of the heritage
+ [bllst,inplnk,outlnk,clkptr,cliptr,inpptr,outptr,dep_u,dep_uptr,dep_t,..
+ typ_l,typ_r,typ_m,tblock,typ_cons,typ_zx,ok]=mini_extract_info(bllst,..
+ connectmat,clkconnect)
+ if show_trace then mprintf("c_pass20:\t%f\n", timer()),end
+ if ~ok then
+ cpr=list()
+ return
+ end
+ [outoin,outoinptr]=conn_mat(inpptr,outptr,inplnk,outlnk)
+
+ [critev]=critical_events(connectmat,clkconnect,dep_t,typ_r,..
+ typ_l,typ_zx,outoin,outoinptr,clkptr)
+ [clkconnect,exe_cons]=pak_ersi(connectmat,clkconnect,typ_r,..
+ typ_l,outoin,outoinptr,tblock,typ_cons,clkptr)
+
+
+ [ordclk,ordptr,cord,typ_l,clkconnect,connectmat,bllst,dep_t,dep_u,..
+ dep_uptr,corinv,clkptr,cliptr,critev,ok]=paksazi2(typ_l,clkconnect,..
+ connectmat,bllst,dep_t,dep_u,dep_uptr,corinv,clkptr,cliptr,critev)
+
+ if ~ok then
+ cpr=list()
+ return
+ end
+
+ if show_pause then
+ mprintf("fin de paksazi")
+ pause
+ end
+
+ if show_trace then mprintf("c_pass31:\t%f\n", timer()),end
+
+ //extract various info from bllst
+ [lnksz,lnktyp,inplnk,outlnk,clkptr,cliptr,inpptr,outptr,xptr,zptr,..
+ ozptr,typ_mod,rpptr,ipptr,opptr,xc0,xcd0,xd0,oxd0,rpar,..
+ ipar,opar,typ_z,typ_x,typ_m,funs,funtyp,initexe,labels,uids,..
+ bexe,boptr,blnk,blptr,ok]=extract_info(bllst,connectmat,clkconnect,typ_l);
+ typ_z0=typ_z;
+
+
+
+ if ~ok then
+ messagebox(_("Problem in port size or type."),"modal","error");
+ cpr=list()
+ return,
+ end
+
+ if show_trace then mprintf("c_pass41:\t%f\n", timer()),end
+
+ //form a matrix which gives destinations of each block
+ [outoin,outoinptr]=conn_mat(inpptr,outptr,inplnk,outlnk)
+ [evoutoin,evoutoinptr]=synch_clkconnect(typ_l,clkconnect)
+ //
+ if show_trace then mprintf("c_pass50:\t%f\n", timer()),end
+
+ [execlk_cons]=discard(clkptr,cliptr,clkconnect,exe_cons)
+
+ clkconnect=[];exe_cons=[]
+
+ if show_trace then mprintf("c_pass501:\t%f\n", timer()),end
+
+ // Set execution scheduling tables
+ [ordclk,iord,oord,zord,typ_z,ok]=scheduler(inpptr,outptr,clkptr,execlk_cons,..
+ outoin,outoinptr,evoutoin,evoutoinptr,typ_z,typ_x,typ_l,bexe,boptr,blnk,blptr,..
+ ordclk,ordptr,cord,dep_t,dep_u,dep_uptr);
+
+ if ~ok then
+ cpr=list()
+ return,
+ end
+
+ if show_trace then mprintf("c_pass51:\t%f\n", timer()),end
+ //form scicos arguments
+
+ nb=size(typ_z,"*");
+ zcptr=ones(nb+1,1);
+ modptr=ones(nb+1,1);
+
+ for i=1:nb
+ zcptr(i+1)=zcptr(i)+typ_z(i)
+ modptr(i+1)=modptr(i)+sign(typ_z(i))*typ_mod(i);
+ end
+
+ ztyp=sign(typ_z0) //completement inutile pour simulation
+ // utiliser pour la generation de code
+
+ if xptr($)==1 & zcptr($)>1 then
+ mess=msprintf(_("No continuous-time state. Thresholds are ignored; this \nmay be OK if you don''t generate external events with them.\nIf you want to reactivate the thresholds, then you need\n\nto include a block with continuous-time state in your diagram.\n You can for example include DUMMY CLSS block (linear palette)."))
+ messagebox(mess,"modal","error");
+ end
+
+ subscr=[]
+ ncblk=0;nxblk=0;ndblk=0;ndcblk=0;
+ sim=scicos_sim(funs=funs,xptr=xptr,zptr=zptr,ozptr=ozptr,..
+ zcptr=zcptr,inpptr=inpptr,outptr=outptr,..
+ inplnk=inplnk,outlnk=outlnk,rpar=rpar,rpptr=rpptr,..
+ ipar=ipar,ipptr=ipptr,opar=opar,opptr=opptr,..
+ clkptr=clkptr,ordptr=ordptr,execlk=ordclk,..
+ ordclk=ordclk,cord=cord,oord=oord,zord=zord,..
+ critev=critev(:),nb=nb,ztyp=ztyp,nblk=nblk,..
+ ndcblk=ndcblk,subscr=subscr,funtyp=funtyp,..
+ iord=iord,labels=labels,uids=uids,modptr=modptr);
+
+ //initialize agenda
+ [tevts,evtspt,pointi]=init_agenda(initexe,clkptr)
+ if show_trace then mprintf("c_pass61:\t%f\n", timer()),end
+
+ //mod=0*ones(modptr($)-1,1)
+
+ outtb=list();
+ outtb=buildouttb(lnksz,lnktyp);
+
+ iz0=zeros(nb,1);
+
+ if max(funtyp)>10000 &%scicos_solver==0 then
+ warning(_("Diagram contains implicit blocks, compiling for implicit Solver."))
+ %scicos_solver=100
+ end
+ if or(%scicos_solver==[100, 101, 102]) then xc0=[xc0;xcd0],end
+ state=scicos_state()
+ state.x=xc0
+ state.z=xd0
+ state.oz=oxd0
+ state.iz=iz0
+ state.tevts=tevts
+ state.evtspt=evtspt
+ state.pointi=pointi
+ state.outtb=outtb
+ // state.mod=mod
+
+ cpr=scicos_cpr(state=state,sim=sim,cor=cor,corinv=corinv);
+
+ if show_trace then mprintf("c_pass71:\t%f\n", timer()),end
+
+endfunction
+
+
+//donne les sources d'activation du sch�ma
+function [vec_clk]=get_clocks(clkconnect,clkptr)
+ vec_clk=[]
+ if (find(clkconnect(:,1)==0) ~=[]) then
+ //activation continue
+ vec_clk=[vec_clk;0 0];
+ end
+ for blk=1:size(clkptr,1)-1
+ if ~typ_l(blk) then
+ for port=1:clkptr(blk+1)-clkptr(blk)
+ vec_clk=[vec_clk; blk port];
+ end
+ end
+ end
+endfunction
+
+
+
+//insere le vecteur primary dans vec_clk apr�s la ligne comptenant le bloc i
+function vec_clk0=set_primary_clk(vec_clk,primary,i)
+
+ if vec_clk~=[] then
+ n_vc0=find(vec_clk==i)
+ n_vc0=n_vc0($)
+ vec_clk0=vec_clk(1:n_vc0)
+ vec_clk1=vec_clk(n_vc0+1:size(vec_clk,1))
+ for k=1:size(primary,1)
+ if find(primary(k)==vec_clk0)==[] then
+ vec_clk0($+1)=primary(k)
+ end
+ end
+ for k=1:size(vec_clk1,1)
+ if find(vec_clk1(k)==vec_clk0)==[] then
+ vec_clk0($+1)=vec_clk1(k)
+ end
+ end
+ else
+ vec_clk0=primary
+ end
+
+endfunction
+
+//insere la sous-matrice primary dans vec_clk apr�s la ligne k
+function vec_clk0=set_primary_clkport(vec_clk,primary,i)
+
+ if vec_clk~=[] then
+ vec_clk0=vec_clk(1:i,:)
+ vec_clk1=vec_clk(i+1:size(vec_clk,1),:)
+ for k=1:size(primary,1)
+ f=find(primary(k,1)==vec_clk0(:,1))
+ if f==[] then
+ vec_clk0=[vec_clk0;primary(k,:)]
+ end
+ end
+ n_vc1=size(vec_clk1,1)
+ if n_vc1>0 then
+ for k=1:n_vc1
+ f=find(vec_clk1(k,1)==vec_clk0(:,1))
+ if f==[] then
+ vec_clk0=[vec_clk0;vec_clk1(k,:)]
+ end
+ end
+ end
+ else
+ vec_clk0=primary
+ end
+
+endfunction
+
+//insere la sous-matrice ordoclk0 dans ordclk apr�s le block k
+function [ordptr,ordclk,blocs_traites]=set_ordclk(ordclk,..
+ ordoclk0,k,j,ordptr,blocs_traites)
+ if ordoclk0~=[] then
+ if ordclk==[] then
+ ordclk=[ordclk;ordoclk0];
+ ordptr($+1)=ordptr($)+size(ordoclk0,1);
+ blocs_traites=[blocs_traites;k] //k
+ else
+ m=max(find(blocs_traites==k))
+ if j>1 & m~=[] then
+ ordclk=[ordclk(1:ordptr(m+1)-1,:);ordoclk0;ordclk(ordptr(m+1):$,:)]
+ ordptr=[ordptr(1:m+1);ordptr(m+1:$)+size(ordoclk0,1)]
+ blocs_traites=[blocs_traites(1:m);k;blocs_traites(m+1:$)]
+ else
+ ind=find(blocs_traites <k)
+ m=max(ind)
+ if m==size(blocs_traites,1) then
+ ordclk=[ordclk;ordoclk0]
+ ordptr($+1)=ordptr($)+size(ordoclk0,1);
+ blocs_traites=[blocs_traites;k]
+ else
+ if m~=[] then
+ ordclk=[ordclk(1:ordptr(m+1)-1,:);ordoclk0;ordclk(ordptr(m+1):$,:)]
+ ordptr=[ordptr(1:m+1);ordptr(m+1:$)+size(ordoclk0,1)]
+ blocs_traites=[blocs_traites(1:m);k;blocs_traites(m+1:$)]
+ else
+ ordclk=[ordoclk0;ordclk]
+ ordptr=[1;ordptr+size(ordoclk0,1)]
+ blocs_traites=[k;blocs_traites]
+ end
+ end
+ end
+ end
+ else
+ if j>1 & find((blocs_traites==k))~=[] then
+ m=max(find(blocs_traites==k))
+ ordptr=[ordptr(1:m+1);ordptr(m+1:$)+size(ordoclk0,1)]
+ blocs_traites=[blocs_traites(1:m);k;blocs_traites(m+1:$)]
+ else
+ ind=find(blocs_traites <k)
+ m=max(ind)
+ if m==size(blocs_traites,1) then
+ ordptr($+1)=ordptr($)+size(ordoclk0,1);
+ blocs_traites=[blocs_traites;k]
+ else
+ if m~=[] then
+ ordptr=[ordptr(1:m+1);ordptr(m+1:$)+size(ordoclk0,1)]
+ blocs_traites=[blocs_traites(1:m);k;blocs_traites(m+1:$)]
+ else
+ ordptr=[1;ordptr+size(ordoclk0,1)]
+ blocs_traites=[k;blocs_traites]
+ end
+ end
+ end
+ end
+endfunction
+
+
+//donne les blocs activant blk
+function [parents]=get_parents(parents,blk)
+ f=find(clkconnect(:,3)==blk)
+ n_f=size(f,2)
+ if n_f>0 then
+ for i=1:n_f
+ clki1=clkconnect(f(i),1)
+ clki2=clkconnect(f(i),2)
+ g=find(clki1==parents(:,1))
+ if g==[] | (g~=[] & parents(g,2)~=clki2) then
+ parents=[parents;clki1,clki2]
+ end
+ end
+ end
+endfunction
+
+
+function [blks,blksptr]=depend_on(connectmat,dep_u,dep_uptr)
+ // returns the blocks on which depend directly a block
+ blks=[];blksptr=1
+ for i=1:size(dep_uptr,"*")-1
+ indport=find(dep_u(dep_uptr(i):dep_uptr(i+1)-1));
+ f=[]
+ for j=indport
+ f=[f,find(connectmat(:,3)==i&connectmat(:,4)==j)]
+ end
+ blkis=unique(connectmat(f,1))
+ blks=[blks;blkis]
+ blksptr=[blksptr;blksptr($)+size(blkis,"*")]
+ end
+endfunction
+
+function [eblks,eblksptr]=update_event_depend_on(eblks,eblksptr,clkconnect,cliptr,bls)
+ // updates the blocks activating a block
+ nb1=size(cliptr,"*")
+ eblksptr($:nb1)=eblksptr($)
+ for i=bls
+ f=find(clkconnect(:,3)==i)
+ blkis=unique(clkconnect(f,1))
+ dblkis=size(blkis,"*")-(eblksptr(i+1)-eblksptr(i))
+ Ibef=eblksptr(1):eblksptr(i)-1;
+ Iaft=eblksptr(i+1):eblksptr($)-1;
+ eblks=[eblks(Ibef);blkis;eblks(Iaft)]
+ eblksptr(i+1:$)=eblksptr(i+1:$)+dblkis
+ end
+endfunction
+
+
+function [fblks,fblksptr]=update_event_activates(fblks,fblksptr,clkconnect,clkptr,bls)
+ // returns the blocks activated by a block (assumed typ_l)
+ nb1=size(cliptr,"*")
+ fblksptr($:nb1)=fblksptr($)
+ for i=bls
+ f=find(clkconnect(:,1)==i)
+ blkis=unique(clkconnect(f,3))
+ dblkis=size(blkis,"*")-(fblksptr(i+1)-fblksptr(i))
+ Ibef=fblksptr(1):fblksptr(i)-1;
+ Iaft=fblksptr(i+1):fblksptr($)-1;
+ fblks=[fblks(Ibef);blkis;fblks(Iaft)]
+ fblksptr(i+1:$)=fblksptr(i+1:$)+dblkis
+ end
+endfunction
+
+
+function [eblks,eblksptr]=event_depend_on(clkconnect,cliptr)
+ // returns the blocks activating a block
+ eblks=[];eblksptr=1
+ for i=1:size(cliptr,"*")-1
+ f=find(clkconnect(:,3)==i)
+ blkis=unique(clkconnect(f,1))
+ eblks=[eblks;blkis]
+ eblksptr=[eblksptr;eblksptr($)+size(blkis,"*")]
+ end
+endfunction
+
+
+function [fblks,fblksptr]=event_activates(clkconnect,clkptr)
+ // returns the blocks activated by a block of type typ_l
+ fblks=[];fblksptr=1
+ for i=1:size(typ_l,"*")
+ if typ_l(i) then
+ f=find(clkconnect(:,1)==i)
+ blkis=unique(clkconnect(f,3))
+ fblks=[fblks;blkis]
+ else
+ blkis=[]
+ end
+ fblksptr=[fblksptr;fblksptr($)+size(blkis,"*")]
+ end
+endfunction
+
+
+function uni=merge_mat(m1,m2)
+ // for m1 and m2 with two columns containing >=0 values
+ uni=[m1;m2]
+ n=max(uni(:,2))+1;
+ [j,ind]=unique(uni(:,1)*n+uni(:,2))
+ uni=uni(-gsort(-ind),:)
+endfunction
+
+function [typ_l,clkconnect,connectmat,vbllst,dep_t,dep_u,dep_uptr,..
+ corinv,clkptr,cliptr,critev]=duplicate_block(bl,typ_l,clkconnect,..
+ connectmat,vbllst,dep_t,dep_u,dep_uptr,corinv,clkptr,cliptr,critev)
+
+ nblock=size(typ_l,1)+1
+ g=find(clkconnect(:,1)==bl)
+ if g<> [] then
+ xx=clkconnect(g,:)
+ xx(:,1)=nblock
+ clkconnect=[clkconnect;xx]
+ end
+
+ g=find(connectmat(:,3)==bl)
+ xx=connectmat(g,:)
+ xx(:,3)=nblock*ones(size(xx,1),1)
+ connectmat=[connectmat;xx]
+
+ typ_l($+1)=%t
+ critev=[critev;critev(clkptr(bl):clkptr(bl+1)-1)]
+ vbllst(nblock)=vbllst(bl)
+ dep_t(nblock)=dep_t(bl)
+ dep_u=[dep_u;dep_u(dep_uptr(bl))]
+ dep_uptr($+1)=dep_uptr($)+1
+
+ corinv(nblock)=corinv(bl)
+ clkptr(nblock+1)=clkptr(nblock)+clkptr(bl+1)-clkptr(bl)
+ cliptr(nblock+1)=cliptr(nblock)+cliptr(bl+1)-cliptr(bl)
+
+endfunction
+
+function [childs]=get_allchilds(primary,fblks,fblksptr,typ_l)
+
+ oldtaille=0
+ childs=primary(:)'
+ taille=size(childs,"*")
+
+ while oldtaille<>taille
+ oldtaille=taille
+ for i=childs(typ_l(childs))
+ bb=fblks(fblksptr(i):fblksptr(i+1)-1)
+ childs=union(childs,bb)
+ end
+ taille=size(childs,"*")
+ end
+endfunction
+
+
+function ok=is_alg_event_loop(typ_l,clkconnect)
+ clkconnect(find(clkconnect(:,1)==0),:)=[]
+ lclkconnect=clkconnect(typ_l(clkconnect(:,1))&typ_l(clkconnect(:,3)),[1,3])
+ n=size(typ_l,"*")
+ oldvec=zeros(n,1)
+ vec(lclkconnect(:,1))=1
+ i=0
+ ok=%f
+ while i<=n
+ i=i+1
+ oldvec=vec // not optimal to use large v
+ vec(lclkconnect(:,2))=vec(lclkconnect(:,1))+1
+ if and(vec==oldvec) then
+ ok=%t
+ return
+ end
+ end
+endfunction
+
+function [ordclk,ordptr,cord,typ_l,clkconnect,connectmat,bllst,dep_t,dep_u,dep_uptr,corinv,clkptr,cliptr,critev,ok]=paksazi2(typ_l,clkconnect,connectmat,bllst,dep_t,dep_u,dep_uptr,corinv,clkptr,cliptr,critev)
+
+ ordclk=[];ordptr=1;cord=[];
+ lordclk=list()
+
+ vbllst=1:length(bllst)
+
+ zz=get_clocks(clkconnect,clkptr)
+ //testing event algebraic loops
+ ok=is_alg_event_loop(typ_l,clkconnect)
+ if ~ok then
+ disp(mprintf("%s: alg_event_loop failed", "c_pass2"));
+ messagebox(_("Algebraic loop on events."),"modal","error");
+ return
+ end
+
+
+ ok=%t
+ [fblks,fblksptr]=event_activates(clkconnect,clkptr)
+ [blks,blksptr]=depend_on(connectmat,dep_u,dep_uptr)
+ [eblks,eblksptr]=event_depend_on(clkconnect,cliptr)
+
+
+ for i=1:size(zz,1)
+
+ nblock=size(typ_l,1); // number of blocks in diagram
+
+ todo=zz(i,:)
+ while todo<>[]
+
+ blk=todo(1,1);port=todo(1,2);
+ if blk==0 |find(definedfields(lordclk)==clkptr(blk)+port-1)==[] then
+
+ f=find(clkconnect(:,1)==blk&clkconnect(:,2)==port);
+ if f<>[] then
+ primary0=clkconnect(f,3);prt0=clkconnect(f,4)
+ else
+ primary0=[]
+ end
+
+ if show_comment then mprintf("Processing blk " + string(blk) + " port "+...
+ + string(port) + "\n"),end
+
+ if primary0<>[] then // delete redundant links
+ [jj,k]=unique(primary0*(1+max(prt0))+prt0)
+ index=setdiff(1:size(primary0,1),k)
+ clkconnect(f(index),:)=[] // does not affect e(f)blks
+
+ primary=unique(primary0)
+
+ [balg,vec]=ini_ordo3(primary)
+ if balg then
+ disp(mprintf("%s: ini_ordo (3) failed", "c_pass2"));
+ messagebox(_("Algebraic loop."),"modal","error"),
+ ok=%f
+ return
+ end
+
+ pvec=vec(primary)+.5*typ_l(primary) // same order typ_l to the right
+ [mi,In]=gsort(-pvec)
+ primary=primary(In)
+ lp=find(typ_l(primary))
+ lprimary=primary(lp)
+
+ bouclalg=%f
+ lp_backw=lp($:-1:1)
+ for i=lp_backw
+ for J=primary(i+1:$)'
+ if intersect(get_allchilds(primary(i)),get_allchilds(J))<>[] then
+ bouclalg=%t
+ break
+ end
+ end
+ if bouclalg then break,end
+ end
+
+ if show_comment&bouclalg then mprintf("found intersect \n"),end
+
+ if ~bouclalg then
+ [bouclalg,Vec,typ_l,clkconnect,connectmat,bllst,dep_t,dep_u,..
+ dep_uptr,corinv,clkptr,cliptr,critev]=ini_ordo2(primary,..
+ clkconnect,connectmat,bllst,typ_l,dep_t,dep_u,dep_uptr,..
+ corinv,clkptr,cliptr,critev)
+ if bouclalg then
+ if show_comment then mprintf("found non convergence\n"),pause,end
+ i=lp(1) // first typ_l
+ if i==[] then
+ disp(mprintf("%s: ini_ordo (2) failed", "c_pass2"));
+ messagebox(_("Algebraic loop."),"modal","error")
+ ok=%f
+ return
+ end
+ J=primary(i+1:$)
+ end
+ end
+
+ if bouclalg then
+ modif=%f
+ bl=primary(i)
+
+ nout=clkptr(bl+1)-clkptr(bl)
+ //duplicate bl if it receives other links
+ f=find(clkconnect(:,1)==blk&clkconnect(:,2)==port&clkconnect(:,3)==bl)
+ h=find(clkconnect(:,3)==bl) // this is always one
+ if size(f,2)<>size(h,2) then
+ nblock=nblock+1
+ clkconnect(f,3)=nblock
+ if show_comment then
+ mprintf("duplicating pivot"+string(bl)+" to obtain "+string(nblock) + "\n"),
+ end
+ [typ_l,clkconnect,connectmat,vbllst,dep_t,dep_u,dep_uptr,..
+ corinv,clkptr,cliptr,critev]=duplicate_block(bl,typ_l,clkconnect,..
+ connectmat,vbllst,dep_t,dep_u,dep_uptr,corinv,clkptr,cliptr,critev)
+ vec(nblock)=vec(bl)
+ //update pointer
+ blks_bl=blks(blksptr(bl):blksptr(bl+1)-1)
+ blks=[blks;blks_bl]
+ blksptr($+1)=blksptr($)+size(blks_bl,"*")
+ //
+ bls=[bl,nblock,fblks(fblksptr(bl):fblksptr(bl+1)-1)']
+ [eblks,eblksptr]=..
+ update_event_depend_on(eblks,eblksptr,clkconnect,cliptr,bls)
+ bl=nblock // use new block as pivot
+ lprimary(i)=bl
+ end
+
+ for bli=J(:)'
+ modif=%t
+ f=find(clkconnect(:,1)==blk&clkconnect(:,2)==port&clkconnect(:,3)==bli)
+ clkconnect(f,1)=bl
+ clkconnect(f,2)=1
+ xx= clkconnect(f,:)
+ for jj=2:nout
+ if show_comment then
+ mprintf("No block duplication but link between "+string(blk)+..
+ " and "+string(bli)+" replaced with links from "+..
+ string(bl)+" to "+string(bli) + "\n"),
+ end
+ xx(:,2)=jj;
+ clkconnect=[clkconnect;xx]
+ end
+ end
+
+ [eblks,eblksptr]=update_event_depend_on(eblks,eblksptr,clkconnect,cliptr,J(:)')
+ bls=[blk,bl];bls(find(bls==0))=[];bls=bls(typ_l(bls)); //exclude non typ_l and 0
+ [fblks,fblksptr]=update_event_activates(fblks,fblksptr,clkconnect,clkptr,bls)
+
+ // can (must) be done outside the for loop
+ // [fblks2,fblksptr2]=event_activates(clkconnect,clkptr)
+ // [eblks2,eblksptr2]=event_depend_on(clkconnect,cliptr)
+ //but then it must be updated
+ // if norm(eblksptr-eblksptr2)>0 then mprintf('roro2');pause,end
+ // if norm(fblksptr-fblksptr2)>0 then mprintf('soso2');pause,end
+ // if norm(eblks-eblks2)>0 then mprintf('roro');pause,end
+ // if norm(fblks-fblks2)>0 then mprintf('soso');pause,end
+
+
+ if ~modif then messagebox(_("Algebraic loop."),"modal","error"),ok=%f,return,end
+ else
+ primary0=primary0(k);
+ prt0=prt0(k)
+ [primary0,prt0]=aggregate(primary0,prt0)
+ [mi,In]=gsort(-Vec(primary0))
+ if blk<>0 then
+ lordclk(clkptr(blk)+port-1)=[primary0(In),prt0(In)]
+
+ if show_comment then
+ mprintf("for blk port "+string(blk)+" "+string(port)+..
+ " ordclk is :\n"), disp(lordclk(clkptr(blk)+port-1)),
+ end
+ else
+ cord=[primary0(In),prt0(In)]
+ end
+
+ todo(1,:)=[]
+ L=[];
+ for Bi=lprimary'
+ C=[1:clkptr(Bi+1)-clkptr(Bi)]'
+ L=[L;Bi*ones(C),C]
+ end
+ todo=merge_mat(todo,L)
+ end
+ else
+ if blk<>0 then
+ J=clkptr(blk)+port-1
+ lordclk(J)=[]
+ if show_comment then
+ mprintf("for blk port "+string(blk)+" "+string(port)+..
+ " ordclk is"), mprintf(lordclk(J) + "\n"),
+ end
+ else
+ cord=[]
+ end
+
+ todo(1,:)=[]
+ end
+ else
+ todo(1,:)=[]
+ end
+ end
+ end
+
+ for J=1:clkptr($)-1
+ ordclk=[ordclk;lordclk(J)]
+ ordptr=[ordptr;ordptr($)+size(lordclk(J),1)]
+ end
+
+ bllst=list(bllst(vbllst))
+
+endfunction
+
+function [primary0,port0]=aggregate(primary0,port0)
+ primary=discardprimary([primary0,port0]) // must rewrite
+ primary0=primary(:,1);port0=primary(:,2)
+endfunction
+
+
+function [parents]=get_parents2(parents,blk,port)
+ k=size(parents,1)+1;
+ f=find(clkconnect(:,3)==blk)
+ n_f=size(f,2)
+ if n_f>0 then
+ for i=1:n_f
+ if clkconnect(f(i),4)==port then
+ clki1=clkconnect(f(i),1)
+ clki2=clkconnect(f(i),2)
+ g=find(clki1==parents(:,1))
+ if g==[] | (g~=[] & parents(g,2)~=clki2) then
+ parents(k,1)=clki1
+ parents(k,2)=clki2
+ k=k+1
+ end
+ end
+ end
+ end
+endfunction
+
+//suppression des liens inutiles
+function [clkconnect,amaj]=find_del_inutile(clkconnect,vec_plus,typ_l)
+ amaj=[]
+ for i=1:size(vec_plus,1)
+ blk=vec_plus(i,1)
+ port=vec_plus(i,2)
+ parents=get_parents2([],blk,port)
+ j=1
+ done=%f
+ n_p=size(parents,1)
+ while j<=n_p & ~done
+ par1=parents(j,1)
+ if par1~=0 & typ_l(par1) then
+ n_out=clkptr(par1+1)-clkptr(par1)
+ f=find(par1==parents(:,1))
+ if size(f,2)==n_out then
+ if show_comment then
+ mprintf("find_del_inutile:")
+ mprintf("link between blocks "+string(par1)+" and "+string(blk)+..
+ " are deleted\n")
+ pause
+ end
+ [clkconnect]=del_inutile(clkconnect,par1,n_out,blk,port)
+ done=%t
+ amaj=[amaj;par1;blk]
+ end
+ end
+ j=j+1
+ end
+ end
+endfunction
+
+function [clkconnect]=del_inutile(clkconnect,blk0,n_out,blk,port)
+ f=find(clkconnect(:,1)==blk0)
+ del=[]
+ for i=1:size(f,2)
+ if clkconnect(f(i),3)==blk & clkconnect(f(i),4)==port then
+ del=[del;f(i)]
+ end
+ end
+ clkconnect(del,:)=[]
+ p=get_parents([],blk0)
+ n_p=size(p,1)
+ for i=1:n_p
+ clkconnect($+1,:)=[p(i,1),p(i,2),blk,port]
+ end
+endfunction
+
+
+function blk0=get_father(blk1,vectmp)
+ gg=find(clkconnect(:,3)==blk1) // parents of blk1
+ del=find(clkconnect(gg,1)==0)
+ gg(del)=[] // remove continuous-time source
+ // it is inactive
+ hh=find(vectmp(clkconnect(gg,1))>0) // keep active ones
+ blk0=unique(clkconnect(gg(hh),1)) // active parent(s)
+ blk0=blk0(typ_l(blk0)) // can be a vector
+endfunction
+
+function [bouclalg,vec,typ_l,clkconnect,connectmat,bllst,dep_t,dep_u,..
+ dep_uptr,corinv,clkptr,cliptr,critev]=ini_ordo2(primary,..
+ clkconnect,connectmat,bllst,typ_l,dep_t,dep_u,dep_uptr,corinv,clkptr,..
+ cliptr,critev)
+
+ n_p=size(primary,1)
+
+ nblock=size(typ_l,1);
+ //initialisation de vec
+ //on initialise vec � -1
+ vec=-ones(nblock,1)
+ vec(primary(:,1))=1
+
+ bouclalg=%f
+ fromfixe=%f
+ oldvec2=[]
+ counter2=0
+
+ [wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr]=prim_calc(primary)
+
+ while ~fromfixe
+ vec=update_vec3(vec,wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr)
+ //
+ if and(vec==oldvec2) then
+ fromfixe=%t
+ else
+ oldvec2=vec
+ end
+ counter2=counter2+1
+ if (counter2>n_p+1) then
+ bouclalg=%t
+ // mprintf('Algebraic Loop detection.')
+ break
+ end
+ end
+endfunction
+
+function [bouclalg,vec]=ini_ordo3(primary)
+
+ n_p=size(primary,1)
+
+ nblock=size(typ_l,1);
+ //initialisation de vec
+ //on initialise vec � -1
+ vec=-ones(nblock,1)
+ vec(primary(:,1))=0
+
+ bouclalg=%f
+ fromfixe=%f
+ oldvec2=[]
+ counter2=0
+
+ [wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr]=prim_calc(primary)
+
+ while ~fromfixe
+ vec=update_vec4(vec,wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr)
+
+ if and(vec==oldvec2) then
+ fromfixe=%t
+ else
+ oldvec2=vec
+ end
+ counter2=counter2+1
+ if (counter2>n_p+1) then
+ bouclalg=%t
+ // mprintf('Algebraic Loop detection.')
+ break
+ end
+ end
+endfunction
+
+
+function vec=update_vec3(vec,wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr)
+ for i=1:size(wprimptr,"*")-1
+ w=wprim(wprimptr(i):wprimptr(i+1)-1)
+ g0=g0prim(g0primptr(i):g0primptr(i+1)-1)
+ g=gprim(gprimptr(i):gprimptr(i+1)-1)
+ // detecting algebraic loops within a single cluster
+ //mprintf([px,py,size(blks,'*')])
+ vec(w)=max(vec(w))
+ if (g0 ~= []) then
+ vec(w(1))=max(vec(w(1)),max(vec(g0))+1)
+ end
+ //g=g(find(vec(g)>-1)) //not optimal test max(vec(g))
+ if g~=[] then
+ vec(w)=vec(w)-1
+ vec(w)=max(vec(w),max(vec(g)))+1
+ end
+ end
+endfunction
+
+function vec=update_vec4(vec,wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr)
+ for i=1:size(wprimptr,"*")-1
+ w=wprim(wprimptr(i):wprimptr(i+1)-1)
+ g0=g0prim(g0primptr(i):g0primptr(i+1)-1)
+ if g0<>[] then vec(w(1))=max(vec(w(1)),max(vec(g0))), end
+ vec(w(2:$))=vec(w(1))+1
+ end
+endfunction
+
+function [wprim,wprimptr,g0prim,g0primptr,gprim,gprimptr]=prim_calc(primary)
+ wprim=[];wprimptr=1
+ gprim=[];gprimptr=1
+ g0prim=[];g0primptr=1
+
+
+ for i=1:size(primary,"*")
+ w0=primary(i)
+ if typ_l(w0) then
+ w=get_allchilds(w0,fblks,fblksptr,typ_l)
+ j=find(w==w0)
+ w([1,j])=w([j,1]) // put w0 on top
+ else
+ w=w0;
+ end
+ wprim=[wprim;w(:)]
+ wprimptr($+1)=wprimptr($)+size(w,"*")
+
+ px=blksptr(w(1));py=blksptr(w(1)+1)-1
+ //mprintf([px,py,size(blks,'*')])
+ g0prim=[g0prim;blks(px:py)]
+ g0primptr($+1)=g0primptr($)+size(px:py,2)
+
+ g=[]
+ for i1=2:size(w,"*") // 1 is done already
+ px=blksptr(w(i1));py=blksptr(w(i1)+1)-1
+ g=[g;blks(px:py)]
+ end
+ gprim=[gprim;g]
+ gprimptr($+1)=gprimptr($)+size(g,"*")
+ end
+endfunction
+
+function primary=discardprimary(primary)
+ // discard
+ mma=max(primary(:,2))+1
+ con=mma*primary(:,1)+primary(:,2)
+ [junk,ind]=gsort(-con);con=-junk
+ primary=primary(ind,:)
+ // discard duplicate calls to the same block port
+ if size(con,"*")>=2 then
+ primary(find(con(2:$)-con(1:$-1)==0),:)=[]
+ end
+ // group calls to different ports of the same block.
+ primary=[primary(:,1),2^(primary(:,2)-ones(primary(:,2)))]
+ primary=int(primary)
+ con=primary(:,1)
+ clkconnectjj=[]
+ if size(con,"*")>=2 then
+ iini=[find(con(2:$)-con(1:$-1)<>0),size(primary,1)]
+ else
+ iini=1
+ end
+ for ii=iini
+ clkconnectjj=[clkconnectjj;[primary(ii,1),..
+ mysum(primary(find(primary(:,1)==primary(ii,1)),2))]]
+ end
+ primary=clkconnectjj
+endfunction
+
+
+
+
+function [ordclk,iord,oord,zord,typ_z,ok]=scheduler(inpptr,outptr,clkptr,execlk_cons,..
+ outoin,outoinptr,evoutoin,evoutoinptr,typ_z,typ_x,typ_l,bexe,boptr,..
+ blnk,blptr,ordclk,ordptr,cord,dep_t,dep_u,dep_uptr);
+
+ nblk=size(typ_x,1)
+ //compute iord
+ if execlk_cons<>[] then
+ vec=-ones(1,nblk)
+ no_tu_dep=execlk_cons(:,1)
+ wec=zeros(1,nblk)
+ wec(no_tu_dep')=execlk_cons(:,2)'
+ vec(no_tu_dep)=0*no_tu_dep'
+ [r,ok]=newc_tree2(vec,outoin,outoinptr,dep_u,dep_uptr)
+
+ iord=[r,wec(r)']
+ else
+ iord=[]
+ end
+ //
+ if ~ok then
+ disp(mprintf("%s: scheduling failed", "c_pass2"));
+ messagebox(_("Algebraic loop."),"modal","error");
+ iord=[],oord=[],zord=[],critev=[]
+ return,
+ end
+
+ n=size(cord,1)
+ vec=-ones(1,nblk);
+ vec(cord(:,1))=0;
+ typp=zeros(typ_l);typp(typ_l)=1
+
+ ext_cord1=cord;
+ j=1
+ while %t
+ ii=ext_cord1(j,1)
+ if typ_l(ii)
+ for i=[clkptr(ii):clkptr(ii+1)-1]
+ ext_cord1=[ext_cord1;ordclk([ordptr(i):ordptr(i+1)-1],:)];
+ end
+ end
+ j=j+1
+ if j>size(ext_cord1,1) then break;end
+ end
+ // code to replace faulty unique which reorders
+ yy=ext_cord1(:,1)'
+ [xx,kkn]=unique(yy);
+ ext_cord=yy(-gsort(-kkn))
+ //ext_cord=unique(ext_cord1(:,1)');
+ //for i=ext_cord
+ // if typ_l(i) then typ_z(i)=clkptr(i+1)-clkptr(i)-1;end
+ //end // adding zero crossing surfaces to cont. time synchros
+
+ //a supprimer
+
+ [ext_cord_old,ok]=newc_tree3(vec,dep_u,dep_uptr,typp);
+
+ if or(gsort(ext_cord_old)<>gsort(ext_cord)) then pause,end
+ //
+ //pour mettre a zero les typ_z qui ne sont pas dans ext_cord
+ //noter que typ_z contient les tailles des nzcross (peut etre >1)
+ typ_z(ext_cord)=-typ_z(ext_cord)
+ typ_z=-min(typ_z,0)
+
+ if ~ok then mprintf("serious bug, report.");pause;end
+ // ext_cord=ext_cord(n+1:$);
+
+ typ_z_save=typ_z
+
+ fin=0
+ while ~fin
+ fin=1
+ for i=ext_cord($:-1:1)
+ for ii=[outoin(outoinptr(i):outoinptr(i+1)-1,1)',..
+ evoutoin(evoutoinptr(i):evoutoinptr(i+1)-1,1)']
+ //ii est un block affecte par changement de sortie du
+ //i-eme block de oord
+ if typ_z(ii) then
+ if typ_z(i)==0 then typ_z(i)=1;fin=0;end
+ end
+ if typ_x(ii) then
+ if ~typ_x(i) then typ_x(i)=%t;fin=0;end
+ end
+ if typ_z(i)&typ_x(i) then break,end
+ end
+ end
+ end
+ //supprimer les blocks a supprimer
+ ind=find(typ_z(cord(:,1)));
+ zord=cord(ind,:)
+ ind=find(typ_x(cord(:,1)));
+ oord=cord(ind,:)
+ typ_z=typ_z_save
+ //critev: vecteur indiquant si evenement est important pour tcrit
+ //Donc les blocks indiques sont des blocks susceptibles de produire
+ //des discontinuites quand l'evenement se produit
+ maX=max([ext_cord1(:,2);ordclk(:,2)])+1;
+ cordX=ext_cord1(:,1)*maX+ext_cord1(:,2);
+
+ // 1: important; 0:non
+ //n=clkptr(nblk+1)-1 //nb d'evenement
+ n=size(ordptr,"*")-1 //nb d'evenement
+
+ //a priori tous les evenemets sont non-importants
+ //critev=zeros(n,1)
+ for i=1:n
+ for hh=ordptr(i):ordptr(i+1)-1
+ jj= ordclk(hh,1) //block excite par evenement i
+ //Following line is not correct because of ever active synchros
+ if or(jj*maX+ordclk(hh,2)==cordX) then
+ ordclk(hh,2)=-ordclk(hh,2)
+ end
+ end
+ end
+endfunction
+
+function [ord,ok]=tree3(vec,dep_ut,typ_l)
+ //compute blocks execution tree
+ ok=%t
+ nb=size(vec,"*")
+ for j=1:nb+2
+ fini=%t
+ for i=1:nb
+ if vec(i)==j-1&typ_l(i)<>-1 then
+ if j==nb+2 then
+ disp(mprintf("%s: tree (3) failed", "c_pass2"));
+ messagebox(_("Algebraic loop."),"modal","error");ok=%f;ord=[];return;
+ end
+ if typ_l(i)==1 then
+ fini=%f;
+ kk=bexe(boptr(i):boptr(i+1)-1)';
+ else
+ kk=[];
+ for ii=blnk(blptr(i):blptr(i+1)-1)'
+ if vec(ii)>-1 & (dep_ut(ii,1) | (typ_l(ii)==1)) then
+ fini=%f;
+ kk=[kk ii];
+ end
+ end
+ end
+ vec(kk)=j*ones(kk) ; //mprintf(vec)
+ end
+ end
+ if fini then break;end
+ end
+ [k,ord]=gsort(-vec);
+ ord(find(k==1))=[];
+endfunction
+
+function [clkconnectj_cons]=discard(clkptr,cliptr,clkconnect,exe_cons)
+
+ if exe_cons<>[] then
+ clkconnectj=exe_cons
+ mma=max(clkconnectj(:,2))+1
+ con=mma*(clkconnectj(:,1))+clkconnectj(:,2)
+ [junk,ind]=gsort(-con);con=-junk
+ clkconnectj=clkconnectj(ind,:)
+ // discard duplicate calls to the same block port
+ if size(con,"*")>=2 then
+ clkconnectj(find(con(2:$)-con(1:$-1)==0),:)=[]
+ end
+ // group calls to different ports of the same block.
+ clkconnectj=[clkconnectj(:,1),2^(clkconnectj(:,2)-ones(clkconnectj(:,2)))]
+ clkconnectj=int(clkconnectj)
+ con=clkconnectj(:,1)
+ clkconnectj_cons=[]
+ if size(con,"*")>=2 then
+ iini=[find(con(2:$)-con(1:$-1)<>0),size(clkconnectj,1)]
+ else
+ iini=1
+ end
+ for ii=iini
+ clkconnectj_cons=[clkconnectj_cons;[clkconnectj(ii,1),..
+ mysum(clkconnectj(find(clkconnectj(:,1)==clkconnectj(ii,1)),2))]]
+ end
+ else
+ clkconnectj_cons=[]
+ end
+endfunction
+
+function a=mysum(b)
+ if b<>[] then a=sum(b), else a=[], end
+endfunction
+
+function [lnksz,lnktyp,inplnk,outlnk,clkptr,cliptr,inpptr,outptr,xptr,zptr,..
+ ozptr,typ_mod,rpptr,ipptr,opptr,xc0,xcd0,xd0,oxd0,rpar,..
+ ipar,opar,typ_z,typ_x,typ_m,funs,funtyp,initexe,labels,uids,..
+ bexe,boptr,blnk,blptr,ok]=extract_info(bllst,connectmat,clkconnect,typ_l)
+
+ ok=%t
+ nbl=length(bllst)
+ clkptr=zeros(nbl+1,1);clkptr(1)=1
+ cliptr=clkptr;inpptr=cliptr;outptr=inpptr;
+ xptr=1;zptr=1;ozptr=1;
+ rpptr=clkptr;ipptr=clkptr;opptr=clkptr;
+ //
+ xc0=[];xcd0=[];xd0=[];
+ oxd0=list()
+ rpar=[];ipar=[];
+ opar=list();
+
+ fff=ones(nbl,1)==1
+ typ_z=zeros(nbl,1);typ_x=fff;typ_m=fff;typ_mod=zeros(nbl,1);
+
+ initexe=[];
+ funs=list();
+ funtyp=zeros(typ_z)
+ labels=[]
+ uids=[]
+ [ok,bllst]=adjust_inout(bllst,connectmat)
+ if ok then
+ [ok,bllst]=adjust_typ(bllst,connectmat)
+ end
+
+ // placed here to make sure nzcross and nmode correctly updated
+ if ~ok then
+ lnksz=[],lnktyp=[],inplnk=[],outlnk=[],clkptr=[],cliptr=[],inpptr=[],outptr=[],..
+ xptr=[],zptr=[],ozptr=[],rpptr=[],ipptr=[],opptr=[],xc0=[],..
+ xcd0=[],xd0=[],oxd0=list(),rpar=[],ipar=[],opar=list(),..
+ typ_z=[],typ_x=[],typ_m=[],funs=[],funtyp=[],initexe=[],..
+ labels=[],uids=[],bexe=[],boptr=[],blnk=[],blptr=[]
+ return;
+ end
+ for i=1:nbl
+ ll=bllst(i)
+
+ if type(ll.sim)==15 then
+ funs(i)=ll.sim(1)
+ funtyp(i,1)=ll.sim(2)
+ else
+ funs(i)=ll.sim;
+ funtyp(i,1)=0;
+ end
+ if funtyp(i,1)>999&funtyp(i,1)<10000 then
+ if ~c_link(funs(i)) then
+ messagebox(msprintf(_("A C or Fortran block is used but not linked.\n"+..
+ "You can save your compiled diagram and load it.\n"+..
+ "This will automatically link the C or Fortran function.")),"modal","error")
+ end
+ end
+ inpnum=ll.in;outnum=ll.out;cinpnum=ll.evtin;coutnum=ll.evtout;
+ //
+ inpptr(i+1)=inpptr(i)+size(inpnum,"*")
+ outptr(i+1)=outptr(i)+size(outnum,"*")
+ cliptr(i+1)=cliptr(i)+size(cinpnum,"*")
+ clkptr(i+1)=clkptr(i)+size(coutnum,"*")
+ //
+ X0=ll.state(:)
+ if funtyp(i,1)<10000 then
+ xcd0=[xcd0;0*X0]
+ xc0=[xc0;X0]
+ xptr(i+1)=xptr(i)+size(ll.state,"*")
+ else
+ xcd0=[xcd0;X0($/2+1:$)]
+ xc0=[xc0;X0(1:$/2)]
+ xptr(i+1)=xptr(i)+size(ll.state,"*")/2
+ end
+
+ //dstate
+ if (funtyp(i,1)==3 | funtyp(i,1)==5 | funtyp(i,1)==10005) then //sciblocks
+ if ll.dstate==[] then xd0k=[]; else xd0k=var2vec(ll.dstate);end
+ else
+ xd0k=ll.dstate(:)
+ end
+ xd0=[xd0;xd0k]
+ zptr(i+1)=zptr(i)+size(xd0k,"*")
+
+ //odstate
+ if type(ll.odstate)==15 then
+ if ((funtyp(i,1)==5) | (funtyp(i,1)==10005)) then //sciblocks : don't extract
+ if lstsize(ll.odstate)>0 then
+ oxd0($+1)=ll.odstate
+ ozptr(i+1)=ozptr(i)+1;
+ else
+ ozptr(i+1)=ozptr(i);
+ end
+ elseif ((funtyp(i,1)==4) | (funtyp(i,1)==10004) |...
+ (funtyp(i,1)==2004) | (funtyp(i,1)==12004)) //C blocks : extract
+ ozsz=lstsize(ll.odstate);
+ if ozsz>0 then
+ for j=1:ozsz, oxd0($+1)=ll.odstate(j), end;
+ ozptr(i+1)=ozptr(i)+ozsz;
+ else
+ ozptr(i+1)=ozptr(i);
+ end
+ else
+ ozptr(i+1)=ozptr(i);
+ end
+ else
+ //add an error message here please !
+ ozptr(i+1)=ozptr(i);
+ end
+
+ //mod
+ typ_mod(i)=ll.nmode;
+ if typ_mod(i)<0 then
+ messagebox(msprintf(_("Number of modes in block #%d cannot be determined."),i),"modal","error")
+ ok=%f
+ end
+
+ //real paramaters
+ if (funtyp(i,1)==3 | funtyp(i,1)==5 | funtyp(i,1)==10005) then //sciblocks
+ if ll.rpar==[] then rpark=[]; else rpark=var2vec(ll.rpar);end
+ else
+ rpark=ll.rpar(:)
+ end
+ rpar=[rpar;rpark]
+ rpptr(i+1)=rpptr(i)+size(rpark,"*")
+
+ //integer parameters
+ if type(ll.ipar)==1 then
+ ipar=[ipar;ll.ipar(:)]
+ ipptr(i+1)=ipptr(i)+size(ll.ipar,"*")
+ else
+ ipptr(i+1)=ipptr(i)
+ end
+
+ //object parameters
+ if type(ll.opar)==15 then
+ if ((funtyp(i,1)==5) | (funtyp(i,1)==10005)) then //sciblocks : don't extract
+ if lstsize(ll.opar)>0 then
+ opar($+1)=ll.opar
+ opptr(i+1)=opptr(i)+1;
+ else
+ opptr(i+1)=opptr(i);
+ end
+ elseif ((funtyp(i,1)==4) | (funtyp(i,1)==10004) |...
+ (funtyp(i,1)==2004) | (funtyp(i,1)==12004)) then //C blocks : extract
+ oparsz=lstsize(ll.opar);
+ if oparsz>0 then
+ for j=1:oparsz, opar($+1)=ll.opar(j), end;
+ opptr(i+1)=opptr(i)+oparsz;
+ else
+ opptr(i+1)=opptr(i);
+ end
+ else
+ opptr(i+1)=opptr(i);
+ end
+ else
+ //add an error message here please !
+ opptr(i+1)=opptr(i);
+ end
+
+ // typ_z(i)=ll.blocktype=='z'
+ typ_z(i)=ll.nzcross
+ if typ_z(i)<0 then
+ messagebox(msprintf(_("Number of zero crossings in block #%d cannot be determined."),i),"modal","error")
+ ok=%f
+ end
+ typ_x(i)=ll.state<>[]|ll.blocktype=="x" // some blocks like delay
+ // need to be in oord even
+ // without state
+
+ typ_m(i)=ll.blocktype=="m"
+ //
+ if ll.evtout<>[] then
+ ll11=ll.firing
+ prt=find(ll11>=zeros(ll11))
+ nprt=prod(size(prt))
+ initexe=[initexe;[i*ones(nprt,1),matrix(prt,nprt,1),matrix(ll11(prt),nprt,1)]];
+ end
+
+ if type(ll.label)==10 then
+ labels=[labels;ll.label(1)]
+ else
+ labels=[labels;" "]
+ end
+
+ if type(ll.uid)==10 then
+ uids=[uids;ll.uid(1)]
+ else
+ uids=[uids;" "]
+ end
+ end
+
+ clkconnect=clkconnect(find(clkconnect(:,1)<>0),:);
+
+ con=clkptr(clkconnect(:,1))+clkconnect(:,2)-1;
+ [junk,ind]=gsort(-con);con=-junk;
+ clkconnect=clkconnect(ind,:);
+ //
+ bclkconnect=clkconnect(:,[1 3]);
+ boptr=1;
+ bexe=[];
+ for i=1:nbl
+ r=bclkconnect(find(bclkconnect(:,1)==i),2);
+ bexe=[bexe;r];
+ boptr=[boptr;boptr($)+size(r,1)];
+ end
+ //
+
+ blptr=1;
+ blnk=[];
+
+ for i=1:nbl
+ r=connectmat(find(connectmat(:,1)==i),3:4);
+ blnk=[blnk;r];
+ blptr=[blptr;blptr($)+size(r,1)];
+ end
+ //
+
+ nlnk=size(connectmat,1)
+ inplnk=zeros(inpptr($)-1,1);outlnk=zeros(outptr($)-1,1);ptlnk=1;
+ lnksz=[];lnktyp=[];
+ for jj=1:nlnk
+ ko=outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)
+ ki=inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)
+ if ko<>0 & ki<>0 then
+ if ko>ki then
+ outlnk(outlnk>ko)=outlnk(outlnk>ko)-1
+ outlnk(outlnk==ko)=ki
+ inplnk(inplnk>ko)=inplnk(inplnk>ko)-1
+ inplnk(inplnk==ko)=ki
+ ptlnk=-1+ptlnk
+ lnksz(ko,1)=[];
+ lnksz(ko,2)=[];
+ lnktyp(ko) =[];
+ elseif ki>ko
+ outlnk(outlnk>ki)=outlnk(outlnk>ki)-1
+ outlnk(outlnk==ki)=ko
+ inplnk(inplnk>ki)=inplnk(inplnk>ki)-1
+ inplnk(inplnk==ki)=ko
+ ptlnk=-1+ptlnk
+ lnksz(ki,1)=[];
+ lnksz(ki,2)=[];
+ lnktyp(ki) =[];
+ end
+ elseif ko<>0 then
+ inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)=ko
+ elseif ki<>0 then
+ outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)=ki
+ else
+ outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)=ptlnk
+ inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)=ptlnk
+ lnksz(ptlnk,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2));
+ lnksz(ptlnk,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2));
+ lnktyp(ptlnk)=bllst(connectmat(jj,1)).outtyp(connectmat(jj,2));
+ ptlnk=1+ptlnk
+ end
+ end
+
+ //store unconnected outputs, if any, at the end of outtb
+ unco=find(outlnk==0);
+ for j=unco
+ m=max(find(outptr<=j))
+ n=j-outptr(m)+1
+ nm=bllst(m).out(n)
+ if nm<1 then
+ under_connection(corinv(m),n,nm,-1,0,0,1),ok=%f,return,
+ end
+ nm2=bllst(m).out2(n)
+ if nm2<1 then
+ under_connection(corinv(m),n,nm2,-1,0,0,1),ok=%f,return,
+ end
+ lnksz($+1,1)=bllst(m).out(n);
+ lnksz($,2)=bllst(m).out2(n);
+ lnktyp($+1)=bllst(m).outtyp(n);
+ outlnk(j)=max(outlnk)+1
+ end
+
+ //store unconnected inputs, if any, at the end of outtb
+ unco=find(inplnk==0);
+ for j=unco
+ m=max(find(inpptr<=j))
+ n=j-inpptr(m)+1
+ nm=bllst(m).in(n)
+ if nm<1 then
+ under_connection(corinv(m),n,nm,-2,0,0,1),ok=%f,return,
+ end
+ nm2=bllst(m).in2(n)
+ if nm2<1 then
+ under_connection(corinv(m),n,nm2,-2,0,0,1),ok=%f,return,
+ end
+ lnksz($+1,1)=bllst(m).in(n);
+ lnksz($,2)=bllst(m).in2(n);
+ lnktyp($+1)=bllst(m).intyp(n);
+ inplnk(j)=max([inplnk;max(outlnk)])+1
+ end
+
+endfunction
+
+function [outoin,outoinptr]=conn_mat(inpptr,outptr,inplnk,outlnk)
+ outoin=[];outoinptr=1
+ nblk=size(inpptr,1)-1
+ for i=1:nblk
+ k=outptr(i):outptr(i+1)-1
+ ii=[]
+ for j=outlnk(k)'
+ ii=[ii,find(inplnk==j)]
+ end
+ outoini=[];jj=0
+ for j=ii
+ m=max(find(inpptr<=j))
+ n=j-inpptr(m)+1
+ outoini=[outoini;[m,n]]
+ jj=jj+1
+ end
+ outoinptr=[outoinptr;outoinptr($)+jj]
+ outoin=[outoin;outoini]
+ end
+endfunction
+
+function [ord,ok]=tree2(vec,outoin,outoinptr,dep_ut)
+ //compute blocks execution tree
+ ok=%t;
+
+ nb=size(vec,"*");
+ for j=1:nb+2
+ fini=%t
+ for i=1:nb
+ if vec(i)==j-1 then
+ if j==nb+2 then
+ disp(mprintf("%s: tree (2) failed", "c_pass2"));
+ messagebox(_("Algebraic loop."),"modal","error");ok=%f;ord=[];return;
+ end
+ for k=outoinptr(i):outoinptr(i+1)-1
+ ii=outoin(k,1);
+ //indport=find(dep_u(dep_uptr(ii):dep_uptr(ii+1)-1)==1);
+ //if (indport ~=[] &vec(ii)>-1) then
+ if (dep_ut(ii) &vec(ii)>-1) then
+ fini=%f;
+ vec(ii)=j;
+ end
+ end
+ end
+ end
+ if fini then break;end
+ end
+
+ [k,ord]=gsort(-vec);
+ ord(find(k==1))=[];
+ ord=ord(:)
+endfunction
+
+
+//adjust_inout : it resolves positive, negative and null size
+// of in/out port dimensions of connected block.
+// If it's not done in a first pass, the second
+// pass try to resolve negative or null port
+// dimensions by asking user to informed dimensions
+// with underconnection function.
+// It is a fixed point algorithm.
+//
+//in parameters : bllst : list of blocks
+//
+// connectmat : matrix of connection
+// connectmat(lnk,1) : source block
+// connectmat(lnk,2) : source port
+// connectmat(lnk,3) : target block
+// connectmat(lnk,4) : target port
+//
+//out parameters : ok : a boolean flag to known if adjust_inout have
+// succeeded to resolve the in/out port size
+// - ok = %t : all size have been resolved in bllst
+// - ok = %f : problem in size adjustement
+//
+// bllst : modified list of blocks
+//
+//18/05/06, Alan : improvement in order to take into
+// account two dimensional port size.
+//
+//28/12/06, Alan : type for source port and target port must
+// be the same.
+//
+//29/12/06, Fady : type for source and target can be different
+// in one condition that they are double and complex.
+// the result on the link will be complex.
+//
+//04/01/07, Fady : Can test the case of negatives equals target's dimensions.
+//
+//19/01/07, Alan : - Return correct information for user in editor
+// with preceding test of Fady in the first pass
+// - Second pass reviewed : under_connection returns two dimensions now
+//
+//10/05/07, Alan : - if-then-else event-select case
+
+function [ok,bllst]=adjust_inout(bllst,connectmat)
+
+ //Adjust in2/out2, inttyp/outtyp
+ //in accordance to in/out in bllst
+ [ko,bllst]=adjust_in2out2(bllst);
+ if ~ko then ok=%f,return, end //if adjust_in2out2 failed then exit
+ //adjust_inout with flag ok=%f
+
+ nlnk=size(connectmat,1) //nlnk is the number of link
+
+ //loop on number of block (pass 1 and pass 2)
+ for hhjj=1:length(bllst)+1
+ //%%%%% pass 1 %%%%%//
+ for hh=1:length(bllst)+1 //second loop on number of block
+ ok=%t
+ for jj=1:nlnk //loop on number of link
+
+ //intyp/outtyp are the type of the
+ //target port and the source port of the observed link
+ outtyp = bllst(connectmat(jj,1)).outtyp(connectmat(jj,2))
+ intyp = bllst(connectmat(jj,3)).intyp(connectmat(jj,4))
+ //nnin/nnout are the size (two dimensions) of the
+ //target port and the source port of the observed link
+ //before adjust
+ nnout(1,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2))
+ nnout(1,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2))
+ nnin(1,1)=bllst(connectmat(jj,3)).in(connectmat(jj,4))
+ nnin(1,2)=bllst(connectmat(jj,3)).in2(connectmat(jj,4))
+
+ //This Part is done in adjust_typ
+
+ //check intyp/outtyp
+ // if intyp<>outtyp then
+ // if (intyp==1 & outtyp==2) then
+ // bllst(connectmat(jj,3)).intyp(connectmat(jj,4))=2;
+ // elseif (intyp==2 & outtyp==1) then
+ // bllst(connectmat(jj,1)).outtyp(connectmat(jj,2))=2;
+ // else
+ // if bllst(connectmat(jj,3)).sim(2)<0 //if-then-else/eselect case
+ // bllst(connectmat(jj,3)).intyp(connectmat(jj,4))=...
+ // bllst(connectmat(jj,1)).outtyp(connectmat(jj,2))
+ // else
+ // bad_connection(corinv(connectmat(jj,1)),connectmat(jj,2),..
+ // nnout,outtyp,..
+ // corinv(connectmat(jj,3)),connectmat(jj,4),..
+ // nnin,intyp,1)
+ // ok=%f;
+ // return
+ // end
+ // end
+ // end
+
+ //loop on the two dimensions of source/target port
+ for ndim=1:2
+ //check test source/target sizes
+ //in case of negatif equal target dimensions
+ //nin/nout are the size (two dimensions) of the
+ //target port and the source port of the observed link
+ nout(1,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2))
+ nout(1,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2))
+ nin(1,1)=bllst(connectmat(jj,3)).in(connectmat(jj,4))
+ nin(1,2)=bllst(connectmat(jj,3)).in2(connectmat(jj,4))
+
+ //first case : dimension of source and
+ // target ports are explicitly informed
+ // informed with positive size
+ if(nout(1,ndim)>0&nin(1,ndim)>0) then
+ //if dimension of source and target port doesn't match
+ //then call bad_connection, set flag ok to false and exit
+ if nin(1,ndim)<>nout(1,ndim) then
+ bad_connection(corinv(connectmat(jj,1)),connectmat(jj,2),..
+ nnout,outtyp,..
+ corinv(connectmat(jj,3)),connectmat(jj,4),..
+ nnin,intyp)
+ ok=%f;return
+ end
+
+ //second case : dimension of source port is
+ // positive and dimension of
+ // target port is negative
+ elseif(nout(1,ndim)>0&nin(1,ndim)<0) then
+ //find vector of input ports of target block with
+ //first/second dimension equal to size nin(1,ndim)
+ //and assign it to nout(1,ndim)
+ ww=find(bllst(connectmat(jj,3)).in==nin(1,ndim))
+ bllst(connectmat(jj,3)).in(ww)=nout(1,ndim)
+ ww=find(bllst(connectmat(jj,3)).in2==nin(1,ndim))
+ bllst(connectmat(jj,3)).in2(ww)=nout(1,ndim)
+
+ //find vector of output ports of target block with
+ //first/second dimension equal to size nin(1,ndim)
+ //and assign it to nout(1,ndim)
+ ww=find(bllst(connectmat(jj,3)).out==nin(1,ndim))
+ bllst(connectmat(jj,3)).out(ww)=nout(1,ndim)
+ ww=find(bllst(connectmat(jj,3)).out2==nin(1,ndim))
+ bllst(connectmat(jj,3)).out2(ww)=nout(1,ndim)
+
+ //find vector of output ports of target block with
+ //ndim dimension equal to zero and sum the ndim
+ //dimension of all input ports of target block
+ //to be the new dimension of the ndim dimension
+ //of the output ports of the target block
+ if ndim==1 then
+ ww=find(bllst(connectmat(jj,3)).out==0)
+ if (ww<>[]&min(bllst(connectmat(jj,3)).in(:))>0) then
+ bllst(connectmat(jj,3)).out(ww)=sum(bllst(connectmat(jj,3)).in(:))
+ end
+ elseif ndim==2 then
+ ww=find(bllst(connectmat(jj,3)).out2==0)
+ if (ww<>[]&min(bllst(connectmat(jj,3)).in2(:))>0) then
+ bllst(connectmat(jj,3)).out2(ww)=sum(bllst(connectmat(jj,3)).in2(:))
+ end
+ end
+
+ //if nzcross of the target block match with
+ //the negative dimension nin(1,ndim) then
+ //adjust it to nout(1,ndim)
+ if bllst(connectmat(jj,3)).nzcross==nin(1,ndim) then
+ bllst(connectmat(jj,3)).nzcross=nout(1,ndim)
+ end
+ //if nmode of the target block match with
+ //the negative dimension nin(1,ndim) then
+ //adjust it to nout(1,ndim)
+ if bllst(connectmat(jj,3)).nmode==nin(1,ndim) then
+ bllst(connectmat(jj,3)).nmode=nout(1,ndim)
+ end
+
+ //third case : dimension of source port is
+ // negative and dimension of
+ // target port is positive
+ elseif(nout(1,ndim)<0&nin(1,ndim)>0) then
+ //find vector of output ports of source block with
+ //first/second dimension equal to size nout(1,ndim)
+ //and assign it to nin(1,ndim)
+ ww=find(bllst(connectmat(jj,1)).out==nout(1,ndim))
+ bllst(connectmat(jj,1)).out(ww)=nin(1,ndim)
+ ww=find(bllst(connectmat(jj,1)).out2==nout(1,ndim))
+ bllst(connectmat(jj,1)).out2(ww)=nin(1,ndim)
+
+ //find vector of input ports of source block with
+ //first/second dimension equal to size nout(1,ndim)
+ //and assign it to nin(1,ndim)
+ ww=find(bllst(connectmat(jj,1)).in==nout(1,ndim))
+ bllst(connectmat(jj,1)).in(ww)=nin(1,ndim)
+ ww=find(bllst(connectmat(jj,1)).in2==nout(1,ndim))
+ bllst(connectmat(jj,1)).in2(ww)=nin(1,ndim)
+
+ //find vector of input ports of source block with
+ //ndim dimension equal to zero and sum the ndim
+ //dimension of all output ports of source block
+ //to be the new dimension of the ndim dimension
+ //of the input ports of the source block
+ if ndim==1 then
+ ww=find(bllst(connectmat(jj,1)).in==0)
+ if (ww<>[]&min(bllst(connectmat(jj,1)).out(:))>0) then
+ bllst(connectmat(jj,1)).in(ww)=sum(bllst(connectmat(jj,1)).out(:))
+ end
+ elseif ndim==2 then
+ ww=find(bllst(connectmat(jj,1)).in2==0)
+ if (ww<>[]&min(bllst(connectmat(jj,1)).out2(:))>0) then
+ bllst(connectmat(jj,1)).in2(ww)=sum(bllst(connectmat(jj,1)).out2(:))
+ end
+ end
+
+ //if nzcross of the source block match with
+ //the negative dimension nout(1,ndim) then
+ //adjust it to nin(1,ndim)
+ if bllst(connectmat(jj,1)).nzcross==nout(1,ndim) then
+ bllst(connectmat(jj,1)).nzcross=nin(1,ndim)
+ end
+ //if nmode of the source block match with
+ //the negative dimension nout(1,ndim) then
+ //adjust it to nin(1,ndim)
+ if bllst(connectmat(jj,1)).nmode==nout(1,ndim) then
+ bllst(connectmat(jj,1)).nmode=nin(1,ndim)
+ end
+
+ //fourth case : a dimension of source port is
+ // null
+ elseif(nout(1,ndim)==0) then
+ //set ww to be the vector of size of the ndim
+ //dimension of input port of the source block
+ if ndim==1 then
+ ww=bllst(connectmat(jj,1)).in(:)
+ elseif ndim==2 then
+ ww=bllst(connectmat(jj,1)).in2(:)
+ end
+
+ //test if all size of the ndim dimension of input
+ //port of the source block is positive
+ if min(ww)>0 then
+ //test if the dimension of the target port
+ //is positive
+ if nin(1,ndim)>0 then
+
+ //if the sum of the size of the ndim dimension of the input
+ //port of the source block is equal to the size of the ndim dimension
+ //of the target port, then the size of the ndim dimension of the source
+ //port is equal to nin(1,ndim)
+ if sum(ww)==nin(1,ndim) then
+ if ndim==1 then
+ bllst(connectmat(jj,1)).out(connectmat(jj,2))=nin(1,ndim)
+ elseif ndim==2 then
+ bllst(connectmat(jj,1)).out2(connectmat(jj,2))=nin(1,ndim)
+ end
+ //else call bad_connection, set flag ok to false and exit
+ else
+ bad_connection(corinv(connectmat(jj,1)),0,0,1,-1,0,0,1)
+ ok=%f;return
+ end
+
+ //if the ndim dimension of the target port is negative
+ //then the size of the ndim dimension of the source port
+ //is equal to the sum of the size of the ndim dimension
+ //of input ports of source block, and flag ok is set to false
+ else
+ if ndim==1 then
+ bllst(connectmat(jj,1)).out(connectmat(jj,2))=sum(ww)
+ elseif ndim==2 then
+ bllst(connectmat(jj,1)).out2(connectmat(jj,2))=sum(ww)
+ end
+ ok=%f
+ end
+
+ else
+ //set nww to be the vector of all negative size of input ports
+ //of the source block
+ nww=ww(find(ww<0))
+
+ //if all negative size have same size and if size of the
+ //ndim dimension of the target port is positive then assign
+ //size of the ndim dimension of the source port to nin(1,ndim)
+ if norm(nww-nww(1),1)==0 & nin(1,ndim)>0 then
+ if ndim==1 then
+ bllst(connectmat(jj,1)).out(connectmat(jj,2))=nin(1,ndim)
+ elseif ndim==2 then
+ bllst(connectmat(jj,1)).out2(connectmat(jj,2))=nin(1,ndim)
+ end
+
+ //compute a size to be the difference between the size
+ //of the ndim dimension of the target block and sum of positive
+ //size of input ports of the source block divided by the number
+ //of input ports of source block with same negative size
+ k=(nin(1,ndim)-sum(ww(find(ww>0))))/size(nww,"*")
+
+ //if this size is a positive integer then assign it
+ //to the size of the ndim dimension of input ports of the
+ //source block which have negative size
+ if k==int(k)&k>0 then
+ if ndim==1 then
+ bllst(connectmat(jj,1)).in(find(ww<0))=k
+ elseif ndim==2 then
+ bllst(connectmat(jj,1)).in2(find(ww<0))=k
+ end
+ //else call bad_connection, set flag ok to false and exit
+ else
+ bad_connection(corinv(connectmat(jj,1)),0,0,1,-1,0,0,1)
+ ok=%f;return
+ end
+
+ //set flag ok to false
+ else
+ ok=%f
+ end
+
+ end
+
+ //fifth case : a dimension of target port is
+ // null
+ elseif(nin(1,ndim)==0) then
+ //set ww to be the vector of size of the ndim
+ //dimension of output port of the target block
+ if ndim==1 then
+ ww=bllst(connectmat(jj,3)).out(:)
+ elseif ndim==2 then
+ ww=bllst(connectmat(jj,3)).out2(:)
+ end
+
+ //test if all size of the ndim dimension of output
+ //port of the target block is positive
+ if min(ww)>0 then
+ //test if the dimension of the source port
+ //is positive
+ if nout(1,ndim)>0 then
+
+ //if the sum of the size of the ndim dimension of the output
+ //port of the target block is equal to the size of the ndim dimension
+ //of the source port, then the size of the ndim dimension of the target
+ //port is equal to nout(1,ndim)
+ if sum(ww)==nout(1,ndim) then
+ if ndim==1 then
+ bllst(connectmat(jj,3)).in(connectmat(jj,4))=nout(1,ndim)
+ elseif ndim==2 then
+ bllst(connectmat(jj,3)).in2(connectmat(jj,4))=nout(1,ndim)
+ end
+ //else call bad_connection, set flag ok to false and exit
+ else
+ bad_connection(corinv(connectmat(jj,3)),0,0,1,-1,0,0,1)
+ ok=%f;return
+ end
+
+ //if the ndim dimension of the source port is negative
+ //then the size of the ndim dimension of the target port
+ //is equal to the sum of the size of the ndim dimension
+ //of output ports of target block, and flag ok is set to false
+ else
+ if ndim==1 then
+ bllst(connectmat(jj,3)).in(connectmat(jj,4))=sum(ww)
+ elseif ndim==2 then
+ bllst(connectmat(jj,3)).in2(connectmat(jj,4))=sum(ww)
+ end
+ ok=%f
+ end
+
+ else
+ //set nww to be the vector of all negative size of output ports
+ //of the target block
+ nww=ww(find(ww<0))
+
+ //if all negative size have same size and if size of the
+ //ndim dimension of the source port is positive then assign
+ //size of the ndim dimension of the target port to nout(1,ndim)
+ if norm(nww-nww(1),1)==0 & nout(1,ndim)>0 then
+ if ndim==1 then
+ bllst(connectmat(jj,3)).in(connectmat(jj,4))=nout(1,ndim)
+ elseif ndim==2 then
+ bllst(connectmat(jj,3)).in2(connectmat(jj,4))=nout(1,ndim)
+ end
+
+ //compute a size to be the difference between the size
+ //of the ndim dimension of the source block and sum of positive
+ //size of output ports of the target block divided by the number
+ //of output ports of target block with same negative size
+ k=(nout(1,ndim)-sum(ww(find(ww>0))))/size(nww,"*")
+
+ //if this size is a positive integer then assign it
+ //to the size of the ndim dimension of output ports of the
+ //target block which have negative size
+ if k==int(k)&k>0 then
+ if ndim==1 then
+ bllst(connectmat(jj,3)).out(find(ww<0))=k
+ elseif ndim==2 then
+ bllst(connectmat(jj,3)).out2(find(ww<0))=k
+ end
+ //else call bad_connection, set flag ok to false and exit
+ else
+ bad_connection(corinv(connectmat(jj,3)),0,0,1,-1,0,0,1)
+ ok=%f;return
+ end
+
+ //set flag ok to false
+ else
+ ok=%f
+ end
+
+ end
+
+ //sixth (& last) case : dimension of both source
+ // and target port are negatives
+ else
+ ok=%f //set flag ok to false
+ end
+ end
+ end
+ if ok then return, end //if ok is set true then exit adjust_inout
+ end
+ //if failed then display message
+ messagebox(msprintf(_("Not enough information to find port sizes.\n"+..
+ "I try to find the problem.")),"modal","info");
+
+ //%%%%% pass 2 %%%%%//
+ //Alan 19/01/07 : Warning : Behavior have changed, To Be more Tested
+ findflag=%f //set findflag to false
+
+ for jj=1:nlnk //loop on number of block
+ //nin/nout are the size (two dimensions) of the
+ //target port and the source port of the observed link
+ nout(1,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2))
+ nout(1,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2))
+ nin(1,1)=bllst(connectmat(jj,3)).in(connectmat(jj,4))
+ nin(1,2)=bllst(connectmat(jj,3)).in2(connectmat(jj,4))
+
+ //loop on the two dimensions of source/target port
+ //only case : target and source ports are both
+ // negatives or null
+ if nout(1,1)<=0&nin(1,1)<=0 | nout(1,2)<=0&nin(1,2)<=0 then
+ findflag=%t;
+ //
+ ninnout=under_connection(corinv(connectmat(jj,1)),connectmat(jj,2),nout(1,ndim),..
+ corinv(connectmat(jj,3)),connectmat(jj,4),nin(1,ndim),1)
+ //
+ if size(ninnout,2) <> 2 then ok=%f;return;end
+ if ninnout==[] then ok=%f;return;end
+ if ninnout(1,1)<=0 | ninnout(1,2)<=0 then ok=%f;return;end
+ //
+ ww=find(bllst(connectmat(jj,1)).out==nout(1,1))
+ bllst(connectmat(jj,1)).out(ww)=ninnout(1,1)
+ ww=find(bllst(connectmat(jj,1)).out2==nout(1,1))
+ bllst(connectmat(jj,1)).out2(ww)=ninnout(1,1)
+
+ ww=find(bllst(connectmat(jj,1)).out==nout(1,2))
+ bllst(connectmat(jj,1)).out(ww)=ninnout(1,2)
+ ww=find(bllst(connectmat(jj,1)).out2==nout(1,2))
+ bllst(connectmat(jj,1)).out2(ww)=ninnout(1,2)
+ //
+
+ if bllst(connectmat(jj,1)).nzcross==nout(1,1) then
+ bllst(connectmat(jj,1)).nzcross=ninnout(1,1)
+ end
+ if bllst(connectmat(jj,1)).nzcross==nout(1,2) then
+ bllst(connectmat(jj,1)).nzcross=ninnout(1,2)
+ end
+ //
+ if bllst(connectmat(jj,1)).nmode==nout(1,1) then
+ bllst(connectmat(jj,1)).nmode=ninnout(1,1)
+ end
+ if bllst(connectmat(jj,1)).nmode==nout(1,2) then
+ bllst(connectmat(jj,1)).nmode=ninnout(1,2)
+ end
+ //
+ ww=find(bllst(connectmat(jj,1)).in==nout(1,1))
+ bllst(connectmat(jj,1)).in(ww)=ninnout(1,1)
+ ww=find(bllst(connectmat(jj,1)).in2==nout(1,1))
+ bllst(connectmat(jj,1)).in2(ww)=ninnout(1,1)
+
+ ww=find(bllst(connectmat(jj,1)).in==nout(1,2))
+ bllst(connectmat(jj,1)).in(ww)=ninnout(1,2)
+ ww=find(bllst(connectmat(jj,1)).in2==nout(1,2))
+ bllst(connectmat(jj,1)).in2(ww)=ninnout(1,2)
+ //
+ ww=find(bllst(connectmat(jj,1)).in==0)
+ if (ww<>[]&min(bllst(connectmat(jj,1)).out(:))>0) then
+ bllst(connectmat(jj,1)).in(ww)=sum(bllst(connectmat(jj,1)).out)
+ end
+
+ ww=find(bllst(connectmat(jj,1)).in2==0)
+ if (ww<>[]&min(bllst(connectmat(jj,1)).out2(:))>0) then
+ bllst(connectmat(jj,1)).in2(ww)=sum(bllst(connectmat(jj,1)).out2)
+ end
+ //
+ ww=find(bllst(connectmat(jj,3)).in==nin(1,1))
+ bllst(connectmat(jj,3)).in(ww)=ninnout(1,1)
+ ww=find(bllst(connectmat(jj,3)).in2==nin(1,1))
+ bllst(connectmat(jj,3)).in2(ww)=ninnout(1,1)
+
+ ww=find(bllst(connectmat(jj,3)).in==nin(1,2))
+ bllst(connectmat(jj,3)).in(ww)=ninnout(1,2)
+ ww=find(bllst(connectmat(jj,3)).in2==nin(1,2))
+ bllst(connectmat(jj,3)).in2(ww)=ninnout(1,2)
+ //
+ if bllst(connectmat(jj,3)).nzcross==nin(1,1) then
+ bllst(connectmat(jj,3)).nzcross=ninnout(1,1)
+ end
+ if bllst(connectmat(jj,3)).nzcross==nin(1,2) then
+ bllst(connectmat(jj,3)).nzcross=ninnout(1,2)
+ end
+ if bllst(connectmat(jj,3)).nmode==nin(1,1) then
+ bllst(connectmat(jj,3)).nmode=ninnout(1,1)
+ end
+ if bllst(connectmat(jj,3)).nmode==nin(1,2) then
+ bllst(connectmat(jj,3)).nmode=ninnout(1,2)
+ end
+ //
+ ww=find(bllst(connectmat(jj,3)).out==nin(1,1))
+ bllst(connectmat(jj,3)).out(ww)=ninnout(1,1)
+ ww=find(bllst(connectmat(jj,3)).out2==nin(1,1))
+ bllst(connectmat(jj,3)).out2(ww)=ninnout(1,1)
+
+ ww=find(bllst(connectmat(jj,3)).out==nin(1,2))
+ bllst(connectmat(jj,3)).out(ww)=ninnout(1,2)
+ ww=find(bllst(connectmat(jj,3)).out2==nin(1,2))
+ bllst(connectmat(jj,3)).out2(ww)=ninnout(1,2)
+ //
+ ww=find(bllst(connectmat(jj,3)).out==0)
+ if (ww<>[]&min(bllst(connectmat(jj,3)).in(:))>0) then
+ bllst(connectmat(jj,3)).out(ww)=sum(bllst(connectmat(jj,3)).in(:))
+ end
+ ww=find(bllst(connectmat(jj,3)).out2==0)
+ if (ww<>[]&min(bllst(connectmat(jj,3)).in2(:))>0) then
+ bllst(connectmat(jj,3)).out2(ww)=sum(bllst(connectmat(jj,3)).in2(:))
+ end
+ end
+ end
+
+ //if failed then display message
+ if ~findflag then
+ messagebox(msprintf(_("I cannot find a link with undetermined size.\n"+..
+ "My guess is that you have a block with unconnected \n"+..
+ "undetermined output ports.")),"modal","error");
+ ok=%f;return;
+ end
+ end
+endfunction
+
+function id = getBlockIds(path)
+ // Return a block id path from a block index path
+ //
+ // path: the path in the index form
+ // id: th path in the uid form
+
+ scs_m; // check scs_m access
+ id=[];
+
+ k = path(:);
+ for i = k
+ b = scs_m.objs(i);
+ if typeof(b) == "Block" & size(scs_m.objs(i).doc) >= 1 then
+ id($ + 1) = scs_m.objs(i).doc(1);
+ end
+ if typeof(b.model.rpar) == "diagram" then
+ scs_m = b.model.rpar;
+ end
+ end
+endfunction
+
+//19/01/07, Alan : under_connection show bad link and returns two dimensions now
+function ninnout=under_connection(path_out,prt_out,nout,path_in,prt_in,nin,flagg)
+ // alert for badly connected blocks
+ // path_out : Path of the "from block" in scs_m
+ // path_in : Path of the "to block" in scs_m
+ //!
+
+ if path_in==-1 then
+ msg = "<html><body>";
+ msg = msg + gettext("One of this block output has negative size.<br />Please check.");
+ msg = msg + "</body></html>";
+ hilite_path(path_out, msg);
+ ninnout=0
+ return
+ end
+
+ if path_in==-2 then
+ msg = "<html><body>";
+ msg = msg + gettext("Block input has negative size:");
+ msg = msg + "<ul>";
+ msg = msg + "<li>" + msprintf(gettext("Input port %s size is: %s"), string(prt_out), sci2exp(nout)) + "</li>";
+ msg = msg + "</ul>";
+ msg = msg + "</body></html>";
+ hilite_path(path_out, msg);
+ ninnout=0
+ return
+ end
+
+ // different use case (Unable to report on a non opened diagram)
+ if isdef("Code_gene_run") then
+ messagebox([gettext("Unable to report an error into a SuperBlock"); gettext("Please compile the diagram to report the error.")], "Compilation error", "error", "modal");
+ ninnout=0
+ return
+ end
+
+ msg = "<html><body>";
+ if flagg==1 then
+ msg = msg + gettext("<em>Please update the diagram to avoid this warning.</em><br />Block output port has a non-determined size:");
+ msg = msg + "<ul>";
+ msg = msg + "<li>" + msprintf(gettext("Output port %s size is: %s"), string(prt_out), sci2exp(nout)) + "</li>";
+ msg = msg + "<li>" + msprintf(gettext("Input port %s size is: %s"), string(prt_in), sci2exp(nin)) + "</li>";
+ else
+ msg = msg + gettext("<em>Please update the diagram to avoid this warning.</em><br />Block output port has a non-determined type:");
+ msg = msg + "<ul>";
+ msg = msg + "<li>" + msprintf(gettext("Output port %s type."), string(prt_out)) + "</li>";
+ msg = msg + "<li>" + msprintf(gettext("Input port %s type."), string(prt_in)) + "</li>";
+ end
+ msg = msg + "</ul>";
+ msg = msg + "</body></html>";
+ hilite_path(path_out, msg)
+
+ if or(path_in<>path_out) then
+ msg = "<html><body>";
+ if flagg==1 then
+ msg = msg + gettext("<em>Please update the diagram to avoid this warning.</em><br />Block input port has a non-determined size:");
+ msg = msg + "<ul>";
+ msg = msg + "<li>" + msprintf(gettext("Output port %s size is: %s"), string(prt_out), sci2exp(nout)) + "</li>";
+ msg = msg + "<li>" + msprintf(gettext("Input port %s size is: %s"), string(prt_in), sci2exp(nin)) + "</li>";
+ else
+ msg = msg + gettext("<em>Please update the diagram to avoid this warning.</em><br />Block input port has a non-determined type:");
+ msg = msg + "<ul>";
+ msg = msg + "<li>" + msprintf(gettext("Output port %s type."), string(prt_out)) + "</li>";
+ msg = msg + "<li>" + msprintf(gettext("Input port %s type."), string(prt_in)) + "</li>";
+ end
+ msg = msg + "</ul>";
+ msg = msg + "</body></html>";
+ hilite_path(path_in, msg)
+ end
+
+ mess=msprintf(_("Highlighted block(s) have connected ports \nwith sizes that cannot be determined by the context.\nWhat is the size of this link?"))
+
+ if flagg==1 then
+ ninnout=evstr(dialog(mess,"[1,1]"))
+ else
+ ninnout=evstr(dialog(mess,"1"))
+ end
+endfunction
+
+function [clkconnect,exe_cons]=pak_ersi(connectmat,clkconnect,..
+ typ_r,typ_l,outoin,outoinptr,tblock,typ_cons,clkptr)
+
+ //add every event to the time event because time includes all events
+ all_out=[]
+ for k=1:size(clkptr,1)-1
+ if ~typ_l(k) then
+ kk=[1:(clkptr(k+1)-clkptr(k))]'
+ all_out=[all_out;[k*ones(kk),kk]]
+ end
+ end
+ all_out=[all_out;[0,0]]
+
+ //add time event if needed
+ ind=find(tblock)
+ ind=ind(:)
+ for k=ind'
+ clkconnect=[clkconnect;[all_out,ones(all_out)*[k,0;0,0]]]
+ end
+ if show_trace then mprintf("c_pass4444:\t%f\n", timer()),end
+ ind1=find(typ_cons)
+ ind=[ind;ind1(:)]
+ exe_cons=[ind,zeros(ind)]
+
+ vec=-ones(1,nblk);
+ vec(ind)=0
+ [r,ok]=newc_tree4(vec,outoin,outoinptr,typ_r)
+
+ exe_cons=[exe_cons;r]
+
+ if show_trace then mprintf("c_pass4445:\t%f\n", timer()),end
+
+ [clkr,clkc]=size(clkconnect);
+ mm=max(clkconnect(:,2))+1;
+ cll=clkconnect(:,1)*mm+clkconnect(:,2);
+ [cll,ind]=gsort(-cll);
+ clkconnect=clkconnect(ind,:);
+ if cll<>[] then mcll=max(-cll)+1, else mcll=1;end
+ cll=[-1;-cll;mcll];
+ ii=find(cll(2:$)-cll(1:$-1)<>0)
+
+ for k=1:size(ii,"*")-1
+ oo=[ii(k):ii(k+1)-1]
+ vec=-ones(1,nblk);
+ vec(clkconnect(oo,3))=0
+ [r,ok]=newc_tree4(vec,outoin,outoinptr,typ_r)
+ m=size(r,1)
+ r=[clkconnect(ii(k),1)*ones(m,1),clkconnect(ii(k),2)*ones(m,1),r]
+ clkconnect=[clkconnect;r]
+ end
+ // temporary fix to take care of conditional blocks inherting from
+ // constants: make these blocks always active
+
+ ind=setdiff(find(typ_l),clkconnect(:,3))
+ ind=ind(:)
+ for k=ind'
+ clkconnect=[clkconnect;[all_out,ones(all_out)*[k,0;0,0]]]
+ end
+ // end of temoprary fix
+ if show_trace then mprintf("c_pass4446:\t%f\n", timer()),end
+endfunction
+
+function [r,ok]=tree4(vec,outoin,outoinptr,typ_r)
+ //compute blocks which inherit
+ ok=%t;
+ nb=size(vec,"*");
+ r=[];
+ for j=1:nb-1
+ fini=%t
+ for i=1:nb
+ if vec(i)==j-1 then
+ for k=outoinptr(i):outoinptr(i+1)-1
+ ii=outoin(k,1);
+ if (vec(ii)>-1)|typ_r(ii) then
+ fini=%f;
+ vec(ii)=j;
+ end
+ if typ_r(ii) then
+ r=[r;outoin(k,:)]
+ end
+ end
+ end
+ end
+ if fini then break;end
+ end
+endfunction
+
+function [bllst,inplnk,outlnk,clkptr,cliptr,inpptr,outptr,dep_u,dep_uptr,dep_t,..
+ typ_l,typ_r,typ_m,tblock,typ_cons,typ_zx,ok]=mini_extract_info(bllst,..
+ connectmat,clkconnect)
+ ok=%t
+ nbl=length(bllst)
+ clkptr=zeros(nbl+1,1);clkptr(1)=1
+ cliptr=clkptr;inpptr=cliptr;outptr=inpptr;
+ fff=ones(nbl,1)==1
+ typ_l=fff;typ_r=fff;typ_cons=fff;typ_m=fff;typ_zx=fff;
+ dep_t=ones(nbl,1)==1;
+ dep_u=[];dep_uptr=1;
+ tblock=fff
+ //tblock=[] // specifies blocks that must be connected to time event.
+ //
+ for i=1:nbl
+ ll=bllst(i)
+ if (ll.state==[]&ll.nzcross==0) then typ_zx(i)=%f;end
+ inpnum=ll.in;outnum=ll.out;cinpnum=ll.evtin;coutnum=ll.evtout;
+ //
+ if cinpnum==[] then
+ // this block inherits
+ //ok=%f
+
+ typ_r(i)=~ll.dep_ut($)
+ tblock(i)=ll.dep_ut($)
+ //if block depends on time but has no event input port
+ if ~ll.dep_ut($) then
+ //inherits from the inputs
+ cinpnum=ones(inpnum)
+ bllst(i).evtin=cinpnum //XXXXXXXXXXXXXXXXXXXXX
+ end
+ //
+ else
+ tblock(i)=ll.dep_ut($);typ_r(i)=%f
+ end
+ inpptr(i+1)=inpptr(i)+size(inpnum,"*")
+ outptr(i+1)=outptr(i)+size(outnum,"*")
+ cliptr(i+1)=cliptr(i)+size(cinpnum,"*")
+ clkptr(i+1)=clkptr(i)+size(coutnum,"*")
+ //
+
+ typ_l(i)=ll.blocktype=="l";typ_m(i)=ll.blocktype=="m";
+ typ_cons(i)=cinpnum==[]&inpnum==[]&~ll.dep_ut($)
+ //test of the dep_ut size
+ sizenin=size(ll.in,"*");
+ if (size(ll.dep_ut,"*") <> 2) then
+ if ( size(ll.dep_ut(1:$-1),"*") <> sizenin) then
+ messagebox(msprintf(_("the dep_ut size of the %s block is not correct.\n"+..
+ "It should be a colon vector of size %d."),..
+ ll.sim(1),sizenin+1),"modal","error");
+ ok=%f;
+ end
+ end
+
+ dep_t(i)=ll.dep_ut($);
+
+ if (size(ll.dep_ut,"*") == 2) then
+ if (sizenin == 1) then
+ dep_u($+1)=ll.dep_ut(1);
+ dep_uptr($+1)=dep_uptr($)+1;
+ elseif (sizenin > 1) then
+ dep_u=[dep_u;ones(sizenin,1)==1*ll.dep_ut(1)];
+ dep_uptr($+1)=dep_uptr($)+sizenin;
+ else
+ dep_uptr($+1)=dep_uptr($);
+ end
+ else
+ dep_u_i=ll.dep_ut(1:$-1);
+ dep_u=[dep_u;dep_u_i(:)];
+ dep_uptr($+1)=dep_uptr($)+sizenin;
+ end
+
+ //
+ end
+ if show_trace then mprintf("c_pass22222222:\t%f\n", timer()),end //'
+ nlnk=size(connectmat,1)
+ inplnk=zeros(inpptr($)-1,1);outlnk=zeros(outptr($)-1,1);ptlnk=1;
+
+ for jj=1:nlnk
+ ko=outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)
+ ki=inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)
+ if ko<>0 & ki<>0 then
+ if ko>ki then
+ outlnk(outlnk>ko)=outlnk(outlnk>ko)-1
+ outlnk(outlnk==ko)=ki
+ inplnk(inplnk>ko)=inplnk(inplnk>ko)-1
+ inplnk(inplnk==ko)=ki
+ ptlnk=-1+ptlnk
+ elseif ki>ko
+ outlnk(outlnk>ki)=outlnk(outlnk>ki)-1
+ outlnk(outlnk==ki)=ko
+ inplnk(inplnk>ki)=inplnk(inplnk>ki)-1
+ inplnk(inplnk==ki)=ko
+ ptlnk=-1+ptlnk
+ end
+ elseif ko<>0 then
+ inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)=ko
+ elseif ki<>0 then
+ outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)=ki
+ else
+ outlnk(outptr(connectmat(jj,1))+connectmat(jj,2)-1)=ptlnk
+ inplnk(inpptr(connectmat(jj,3))+connectmat(jj,4)-1)=ptlnk
+ ptlnk=1+ptlnk
+ end
+ end
+
+ //store unconnected outputs, if any, at the end of outtb
+ for unco=find(outlnk==0);
+ outlnk(unco)=max(outlnk)+1
+ end
+
+ //store unconnected inputs, if any, at the end of outtb
+ for unco=find(inplnk==0);
+ inplnk(unco)=max([inplnk;max(outlnk)])+1
+ end
+endfunction
+
+function [evoutoin,evoutoinptr]=synch_clkconnect(typ_l,clkconnect)
+ nblk=size(typ_l,"*")
+ evoutoin=[];evoutoinptr=1
+ for i=1:nblk
+ if typ_l(i) then
+ dd=clkconnect(clkconnect(:,1)==i,3)
+ else
+ dd=[]
+ end
+ evoutoin=[evoutoin;dd]
+ evoutoinptr=[evoutoinptr;evoutoinptr($)+size(dd,"*")]
+ end
+endfunction
+
+function clkconnect=cleanup(clkconnect)
+ mm=max(clkconnect)+1
+ cc=clkconnect(:,4)+mm*clkconnect(:,3)+clkconnect(:,2)*mm^2+..
+ clkconnect(:,1)*mm^3
+ [cc1,ind]=gsort(-cc)
+ clkconnect=clkconnect(ind,:)
+ ind=find(cc1(2:$)-cc1(1:$-1)==0)
+ clkconnect(ind,:)=[]
+endfunction
+
+//function mat=cleanup1(mat)
+// mm=max(mat)+1
+// cc=mat(:,1)*mm
+// [cc1,ind]=gsort(-cc)
+// mat=mat(ind,:)
+// ind=find(cc1(2:$)-cc1(1:$-1)==0)
+// mat(ind,:)=[]
+//endfunction
+
+function vec=intersection(vec1,vec2)
+ vec=[]
+ for i=1:size(vec1,1)
+ if find(vec1(i)==vec2)~=[] then
+ vec=[vec;vec1(i)]
+ end
+ end
+endfunction
+
+function [r,ok]=newc_tree2(vec,outoin,outoinptr,dep_u,dep_uptr)
+ dd=zeros(dep_u);dd(dep_u)=1;
+ [r,ok2]=ctree2(vec,outoin,outoinptr,dd,dep_uptr)
+ ok=ok2==1
+endfunction
+
+function [r,ok]=new_tree2(vec,outoin,outoinptr,dep_u,dep_uptr)
+ dd=zeros(dep_u);dd(dep_u)=1;
+ [r,ok2]=sci_tree2(vec,outoin,outoinptr,dd)
+ ok=ok2==1
+endfunction
+
+function [r,ok]=new_tree3(vec,dep_ut,typ_l)
+ dd=zeros(dep_ut);dd(dep_ut)=1;
+ [r2,ok2]=sci_tree3(vec,dd,typ_l,bexe,boptr,blnk,blptr)
+ r=r2'
+ ok=ok2==1
+endfunction
+
+function [r,ok]=newc_tree3(vec,dep_u,dep_uptr,typ_l)
+ dd=zeros(dep_u);dd(dep_u)=1;
+ [r2,ok2]=ctree3(vec,dd,dep_uptr,typ_l,bexe,boptr,blnk,blptr)
+ r=r2'
+ ok=ok2==1
+endfunction
+
+function [r,ok]=new_tree4(vec,outoin,outoinptr,typ_r)
+ nd=zeros(size(vec,"*"),(max(outoin(:,2))+1));
+ ddd=zeros(typ_r);ddd(typ_r)=1;
+ [r1,r2]=sci_tree4(vec,outoin,outoinptr,nd,ddd)
+ r=[r1',r2']
+ ok=%t
+endfunction
+
+function [r,ok]=newc_tree4(vec,outoin,outoinptr,typ_r)
+ nd=zeros(size(vec,"*"),(max(outoin(:,2))+1));
+ ddd=zeros(typ_r);ddd(typ_r)=1;
+ [r1,r2]=ctree4(vec,outoin,outoinptr,nd,ddd)
+ r=[r1',r2']
+ ok=%t
+endfunction
+
+function [critev]=critical_events(connectmat,clkconnect,dep_t,typ_r,..
+ typ_l,typ_zx,outoin,outoinptr,clkptr)
+
+ typ_c=typ_l<>typ_l;
+ typ_r=typ_r|dep_t
+
+ done1=%f
+ while ~done1
+ done1=%t
+ [clkr,clkc]=size(clkconnect);
+ mm=max(clkconnect)+1;
+
+ cll=clkconnect(:,1)*mm+clkconnect(:,2);
+ [cll,ind]=gsort(-cll);
+ clkconnect=clkconnect(ind,:);
+ cll=[-1;-cll;mm];
+ ii=find(cll(2:$)-cll(1:$-1)<>0)
+
+ for k=1:size(ii,"*")-1
+ oo=[ii(k):ii(k+1)-1]
+ vec=-ones(1,nblk);
+ vec(clkconnect(oo,3))=0
+ [r,ok]=newc_tree4(vec,outoin,outoinptr,typ_r)
+
+ m=size(r,1)
+ r=[clkconnect(ii(k),1)*ones(m,1),clkconnect(ii(k),2)*ones(m,1),r]
+ clkconnect=[clkconnect;r]
+ end
+
+ done=%f;
+ while ~done
+ done=%t;
+ for jj=find(typ_l&(~typ_c));
+ if ~or(jj==clkconnect(:,3)) then
+ typ_r(clkconnect(find(jj==clkconnect(:,1)),3))=%t
+ clkconnect(find(jj==clkconnect(:,1)),:)=[];
+ typ_c(jj)=%t;
+ done1=%f
+ done=%f
+ end
+ end
+ end
+ end
+ critev=zeros(clkptr($)-1,1);
+ for bb=1:size(clkptr,1)-1
+ for i=clkptr(bb):clkptr(bb+1)-1
+ if or(typ_zx(clkconnect(find((clkconnect(:,1)==bb)&..
+ (clkconnect(:,2)==i-clkptr(bb)+1)),3))) then
+ critev(i)=1
+ end
+ end
+ end
+endfunction
+
+// adjust_typ: It resolves positive and negative port types.
+// Its Algorithm is based on the algorithm of adjust_inout
+// Fady NASSIF: 14/06/2007
+
+function [ok,bllst]=adjust_typ(bllst,connectmat)
+
+ for i=1:length(bllst)
+ if size(bllst(i).in,"*")<>size(bllst(i).intyp,"*") then
+ bllst(i).intyp=bllst(i).intyp(1)*ones(bllst(i).in);
+ end
+ if size(bllst(i).out,"*")<>size(bllst(i).outtyp,"*") then
+ bllst(i).outtyp=bllst(i).outtyp(1)*ones(bllst(i).out);
+ end
+ end
+ nlnk=size(connectmat,1)
+ for hhjj=1:length(bllst)+1
+ for hh=1:length(bllst)+1
+ ok=%t
+ for jj=1:nlnk
+ nnout(1,1)=bllst(connectmat(jj,1)).out(connectmat(jj,2))
+ nnout(1,2)=bllst(connectmat(jj,1)).out2(connectmat(jj,2))
+ nnin(1,1)=bllst(connectmat(jj,3)).in(connectmat(jj,4))
+ nnin(1,2)=bllst(connectmat(jj,3)).in2(connectmat(jj,4))
+ outtyp = bllst(connectmat(jj,1)).outtyp(connectmat(jj,2))
+ intyp = bllst(connectmat(jj,3)).intyp(connectmat(jj,4))
+
+ //first case : types of source and
+ // target ports are explicitly informed
+ // with positive types
+ if (intyp>0 & outtyp>0) then
+ //if types of source and target port don't match and aren't double and complex
+ //then call bad_connection, set flag ok to false and exit
+
+ if intyp<>outtyp then
+ if (intyp==1 & outtyp==2) then
+ bllst(connectmat(jj,3)).intyp(connectmat(jj,4))=2;
+ elseif (intyp==2 & outtyp==1) then
+ bllst(connectmat(jj,1)).outtyp(connectmat(jj,2))=2;
+ else
+ bad_connection(corinv(connectmat(jj,1)),connectmat(jj,2),..
+ nnout,outtyp,..
+ corinv(connectmat(jj,3)),connectmat(jj,4),..
+ nnin,intyp,1)
+ ok=%f;
+ return
+ end
+ end
+
+ //second case : type of source port is
+ // positive and type of
+ // target port is negative
+ elseif(outtyp>0&intyp<0) then
+ //find vector of input ports of target block with
+ //type equal to intyp
+ //and assign it to outtyp
+ ww=find(bllst(connectmat(jj,3)).intyp==intyp)
+ bllst(connectmat(jj,3)).intyp(ww)=outtyp
+
+ //find vector of output ports of target block with
+ //type equal to intyp
+ //and assign it to outtyp
+ ww=find(bllst(connectmat(jj,3)).outtyp==intyp)
+ bllst(connectmat(jj,3)).outtyp(ww)=outtyp
+
+ //third case : type of source port is
+ // negative and type of
+ // target port is positive
+ elseif(outtyp<0&intyp>0) then
+ //find vector of output ports of source block with
+ //type equal to outtyp
+ //and assign it to intyp
+ ww=find(bllst(connectmat(jj,1)).outtyp==outtyp)
+ bllst(connectmat(jj,1)).outtyp(ww)=intyp
+
+ //find vector of input ports of source block with
+ //type equal to size outtyp
+ //and assign it to intyp
+ ww=find(bllst(connectmat(jj,1)).intyp==outtyp)
+ bllst(connectmat(jj,1)).intyp(ww)=intyp
+
+
+ //fourth (& last) case : type of both source
+ // and target port are negatives
+ else
+ ok=%f //set flag ok to false
+ end
+ end
+ if ok then return, end //if ok is set true then exit adjust_typ
+ end
+ //if failed then display message
+ messagebox(msprintf(_("Not enough information to find port type.\n"+..
+ "I will try to find the problem.")),"modal","info");
+ findflag=%f
+ for jj=1:nlnk
+ nouttyp=bllst(connectmat(jj,1)).outtyp(connectmat(jj,2))
+ nintyp=bllst(connectmat(jj,3)).intyp(connectmat(jj,4))
+
+ //loop on the two dimensions of source/target port
+ //only case : target and source ports are both
+ // negative or null
+ if nouttyp<=0 & nintyp<=0 then
+ findflag=%t;
+ //
+ inouttyp=under_connection(corinv(connectmat(jj,1)),connectmat(jj,2),nouttyp,..
+ corinv(connectmat(jj,3)),connectmat(jj,4),nintyp,2)
+ //
+ if inouttyp<1|inouttyp>8 then ok=%f;return;end
+ //
+ ww=find(bllst(connectmat(jj,1)).outtyp==nouttyp)
+ bllst(connectmat(jj,1)).outtyp(ww)=inouttyp
+
+ //
+ ww=find(bllst(connectmat(jj,1)).intyp==nouttyp)
+ bllst(connectmat(jj,1)).intyp(ww)=inouttyp
+
+ ww=find(bllst(connectmat(jj,3)).intyp==nintyp)
+ bllst(connectmat(jj,3)).intyp(ww)=inouttyp
+ //
+ ww=find(bllst(connectmat(jj,3)).outtyp==nintyp)
+ bllst(connectmat(jj,3)).outtyp(ww)=inouttyp
+
+ //
+ end
+ end
+ //if failed then display message
+ if ~findflag then
+ messagebox(msprintf(_("I cannot find a link with undetermined size.\n"+..
+ "My guess is that you have a block with unconnected \n"+..
+ "undetermined types.")),"modal","error");
+ ok=%f;return;
+ end
+ end
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/c_pass3.bin b/modules/scicos/macros/scicos_scicos/c_pass3.bin
new file mode 100755
index 000000000..b03dc50d1
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/c_pass3.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/c_pass3.sci b/modules/scicos/macros/scicos_scicos/c_pass3.sci
new file mode 100755
index 000000000..fb888b20f
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/c_pass3.sci
@@ -0,0 +1,257 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// - Massoud Najafi <massoud.najafi@inria.fr>
+// - Alan Layec <alan.layec@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [cpr,ok]=c_pass3(scs_m,cpr)
+
+ // reconstruct the block list structure
+
+ bllst=list();
+ corinv=cpr.corinv;
+ sim=cpr.sim;
+
+ for k=1:size(corinv)
+ if type(corinv(k))==1 then
+
+ if corinv(k)>size(%cpr.cor) then ok=%f;cpr=list();return;end
+
+ if size(corinv(k),"*")==1 then
+ bllst(k)=scs_m.objs(corinv(k)).model;
+ else
+ path=get_subobj_path(corinv(k));path($+1)="model";
+ bllst(k)=scs_m(path);
+ end
+ else
+
+ //-Alan/Masoud 19/12/06-
+
+ //We force here update of parameters for THE modelica block
+
+ if findinlistcmd(cpr.corinv,size(cpr.cor),">")<>list() then ok=%f;return; end
+
+ [%state0,state,sim]=modipar(corinv(k),%state0,cpr.state,sim,scs_m,cpr.cor);
+ cpr.state=state;
+ m=scicos_model();
+ //here it is assumed that modelica blocs have only scalar inputs/outputs
+
+ m.in=ones(sim.inpptr(k+1)-sim.inpptr(k),1);
+ m.out=ones(sim.outptr(k+1)-sim.outptr(k),1);
+ if sim.funtyp(k)<10000 then
+ n=(sim.xptr(k+1)-sim.xptr(k))
+ else
+ n=2*(sim.xptr(k+1)-sim.xptr(k))
+ end
+
+ m.state=cpr.state.x(sim.xptr(k)+(0:n-1));
+ m.dstate=cpr.state.z(sim.zptr(k):sim.zptr(k+1)-1);
+ m.rpar=sim.rpar(sim.rpptr(k):sim.rpptr(k+1)-1);
+ m.ipar=sim.ipar(sim.ipptr(k):sim.ipptr(k+1)-1);
+ m.label="";
+ m.sim=list(sim.funs(k),sim.funtyp(k));
+ //here it is assumed that modelica blocs does not have output events
+ bllst(k)=m;
+ end
+ end
+
+ //
+ [inpptr,outptr,inplnk,outlnk,clkptr]= sim(["inpptr","outptr","inplnk","outlnk","clkptr"])
+
+ // computes undetermined port sizes
+
+ [ok,bllst]=adjust(bllst,inpptr,outptr,inplnk,outlnk)
+
+ if ~ok then return; end
+
+ [lnksz,lnktyp]=lnkptrcomp(bllst,inpptr,outptr,inplnk,outlnk)
+
+ //
+ xptr=1;zptr=1;ozptr=1;rpptr=1;ipptr=1;opptr=1;
+ xc0=[];xcd0=[];xd0=[];oxd0=list();
+ rpar=[];ipar=[];opar=list();initexe=[];funtyp=[];labels=[];
+ funs=list();
+ //
+ for i=1:length(bllst)
+ ll=bllst(i)
+ labels=[labels;ll.label];
+ //fun and funtype
+ if type(ll.sim)==15 then
+ if ll.sim(1)<>"scifunc" then
+ funs(i)=ll.sim(1) // replace except for compiled scifunc
+ else
+ funs(i)=%cpr.sim.funs(i)
+ end
+ funtyp(i,1)=ll.sim(2);
+ else
+ funs(i)=ll.sim;
+ funtyp(i,1)=0;
+ end
+
+ //state
+ X0=ll.state(:)
+ if funtyp(i,1)<10000 then
+ xcd0=[xcd0;0*X0]
+ xc0=[xc0;X0]
+ xptr(i+1)=xptr(i)+size(ll.state,"*")
+ else
+ xcd0=[xcd0;X0($/2+1:$)]
+ xc0=[xc0;X0(1:$/2)]
+ xptr(i+1)=xptr(i)+size(ll.state,"*")/2
+ end
+
+ //discrete state
+ if (funtyp(i,1)==3 | funtyp(i,1)==5 | funtyp(i,1)==10005) then //sciblocks
+ if ll.dstate==[] then xd0k=[]; else xd0k=var2vec(ll.dstate);end
+ else
+ xd0k=ll.dstate(:)
+ end
+ xd0=[xd0;xd0k];
+ zptr=[zptr;zptr($)+size(xd0k,"*")]
+ //object discrete state
+ if type(ll.odstate)==15 then
+ if ((funtyp(i,1)==5) | (funtyp(i,1)==10005)) then //sciblocks : don't extract
+ if lstsize(ll.odstate)>0 then
+ oxd0($+1)=ll.odstate
+ ozptr=[ozptr;ozptr($)+1];
+ else
+ ozptr=[ozptr;ozptr($)];
+ end
+ elseif ((funtyp(i,1)==4) | (funtyp(i,1)==10004) | (funtyp(i,1)==2004)) //C blocks : extract
+ ozsz=lstsize(ll.odstate);
+ if ozsz>0 then
+ for j=1:ozsz, oxd0($+1)=ll.odstate(j), end;
+ ozptr=[ozptr;ozptr($)+ozsz];
+ else
+ ozptr=[ozptr;ozptr($)];
+ end
+ else
+ ozptr=[ozptr;ozptr($)];
+ end
+ else
+ //add an error message here please !
+ ozptr=[ozptr;ozptr($)];
+ end
+
+ //rpar
+ if (funtyp(i,1)==3 | funtyp(i,1)==5 | funtyp(i,1)==10005) then //sciblocks
+ if ll.rpar==[] then rpark=[]; else rpark=var2vec(ll.rpar);end
+ else
+ rpark=ll.rpar(:)
+ end
+ rpar=[rpar;rpark]
+ rpptr=[rpptr;rpptr($)+size(rpark,"*")]
+ //ipar
+ if type(ll.ipar)==1 then
+ ipar=[ipar;ll.ipar(:)]
+ ipptr=[ipptr;ipptr($)+size(ll.ipar,"*")]
+ else
+ ipptr=[ipptr;ipptr($)]
+ end
+
+ //opar
+ if type(ll.opar)==15 then
+ if ((funtyp(i,1)==5) | (funtyp(i,1)==10005)) then //sciblocks : don't extract
+ if lstsize(ll.opar)>0 then
+ opar($+1)=ll.opar
+ opptr=[opptr;opptr($)+1];
+ else
+ opptr=[opptr;opptr($)];
+ end
+ elseif ((funtyp(i,1)==4) | (funtyp(i,1)==10004) | (funtyp(i,1)==2004)) then //C blocks : extract
+ oparsz=lstsize(ll.opar);
+ if oparsz>0 then
+ for j=1:oparsz, opar($+1)=ll.opar(j), end;
+ opptr=[opptr;opptr($)+oparsz];
+ else
+ opptr=[opptr;opptr($)];
+ end
+ else
+ opptr=[opptr;opptr($)];
+ end
+ else
+ //add an error message here please !
+ opptr=[opptr;opptr($)];
+ end
+ //
+ if ll.evtout<>[] then
+ ll11=ll.firing
+ if type(ll11)==4 then
+ //this is for backward compatibility
+ prt=find(ll11);nprt=prod(size(prt))
+ initexe=[initexe;[i*ones(nprt,1),matrix(prt,nprt,1),zeros(nprt,1)]]
+ else
+ prt=find(ll11>=zeros(ll11));nprt=prod(size(prt))
+ initexe=[initexe;..
+ [i*ones(nprt,1),matrix(prt,nprt,1),matrix(ll11(prt),nprt,1)]];
+ end
+ end
+ end
+
+ //initialize agenda
+
+ [tevts,evtspt,pointi]=init_agenda(initexe,clkptr)
+
+ sim.funtyp=funtyp
+ sim.funs=funs
+ sim.xptr=xptr
+ sim.zptr=zptr
+ sim.ozptr=ozptr
+ sim.inpptr=inpptr
+ sim.outptr=outptr
+ sim.inplnk=inplnk
+ sim.outlnk=outlnk
+ sim.rpar=rpar
+ sim.rpptr=rpptr
+ sim.ipar=ipar
+ sim.ipptr=ipptr
+ sim.opar=opar
+ sim.opptr=opptr
+ sim.clkptr=clkptr
+ sim.labels=labels
+ cpr.sim=sim;
+ outtb=list();
+
+ outtb=buildouttb(lnksz,lnktyp);
+
+ if exists("%scicos_solver")==0 then %scicos_solver=0,end
+
+ if max(funtyp)>10000 &%scicos_solver<100 then
+ messagebox(["Diagram contains Implicit blocks,"
+ "Compiling for implicit Solver"],"modal")
+ %scicos_solver=100
+ end
+
+ if (or (%scicos_solver == [100 101 102])) then xc0=[xc0;xcd0],end
+
+ nb=size(clkptr,"*")-1;
+ iz0=zeros(nb,1);
+ state=cpr.state
+ state.x=xc0;
+ state.z=xd0;
+ state.oz=oxd0;
+ state.iz=iz0;
+ state.tevts=tevts;
+ state.evtspt=evtspt;
+ state.pointi=pointi;
+ state.outtb=outtb
+ cpr.state=state
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/check_io.bin b/modules/scicos/macros/scicos_scicos/check_io.bin
new file mode 100755
index 000000000..b752347ac
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/check_io.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/check_io.sci b/modules/scicos/macros/scicos_scicos/check_io.sci
new file mode 100755
index 000000000..e05ae58af
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/check_io.sci
@@ -0,0 +1,141 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [model,graphics,ok]=check_io(model,graphics,in,out,clkin,clkout,in_implicit,out_implicit)
+ // check_io first check if given number of ports agree with block connection
+ // and then changes block structure
+ //%parameters
+ // model : initial and resulting block model structure
+ // graphics: initial and resulting block graphics structure
+ // in : new input ports sizes
+ // nout : new output ports sizes
+ // nclkin : new event input ports sizes
+ // nclkout : new event output ports sizes
+ // in_impl : index of implicit input ports, the other ports are supposed to be explicit
+ // out_impl: index of implicit output ports , the other ports are supposed to be explicit
+ // ok : error flag
+ // ok==%f : some of input parameters are incorrects or
+ // attempt to add/delete ports when some are connected
+ // ok==%t : changes of block structure has been performed
+ //!
+ if argn(2)<=6 then in_implicit=[],out_implicit=[],end
+ // check_io first check if given number of ports agree with block connection
+ in=int(in(:));nin=size(in,1)
+
+ out=int(out(:));nout=size(out,1);
+
+ clkin=int(clkin(:));nclkin=size(clkin,1);
+ if nclkin>0 then
+ if min(clkin)<1 then
+ message("Event input ports sizes must be positive")
+ ok=%f
+ return
+ end
+ end
+
+
+ clkout=int(clkout(:));nclkout=size(clkout,1);
+ if nclkout>0 then
+ if min(clkout)<1 then
+ message("Event output ports sizes must be positive")
+ ok=%f
+ return
+ end
+ end
+
+
+ [label,ip1,op1,cip1,cop1]=(graphics.exprs,graphics.pin,graphics.pout,..
+ graphics.pein,graphics.peout)
+
+ [in1,out1,clkin1,clkout1]=(model.in,model.out,model.evtin,model.evtout)
+
+ n1=size(in1(:,1),"*");n=size(in(:,1),"*")
+ if n1>n then
+ ip1=ip1(1:n)
+ else
+ ip1=[ip1;zeros(n-n1,1)]
+ end
+
+ n1=size(out1,"*");n=size(out,"*")
+ if n1>n then
+ op1=op1(1:n)
+ else
+ op1=[op1;zeros(n-n1,1)]
+ end
+
+ n1=size(clkin1,"*");n=size(clkin,"*")
+ if n1>n then
+ cip1=cip1(1:n)
+ else
+ cip1=[cip1;zeros(n-n1,1)];
+ end
+
+ n1=size(clkout1,"*");n=size(clkout,"*")
+ if n1>n then
+ cop1=cop1(1:n);
+ else
+ cop1=[cop1;zeros(n-n1,1)];
+ end
+
+ I="E";
+
+
+ if ip1<>[] then
+ in_impl=I(ones(ip1)); in_impl(in_implicit)="I";
+ else
+ in_impl=[]
+ end
+
+
+ if op1<>[] then
+ out_impl=I(ones(op1)); out_impl(out_implicit)="I";
+ else
+ out_impl=[]
+ end
+
+ ok=%t
+
+ graphics.pin=ip1
+ graphics.pout=op1
+ graphics.pein=cip1
+ graphics.peout=cop1
+ graphics.in_implicit=in_impl
+ graphics.out_implicit=out_impl
+
+ if size(in1,2)<=1 then
+ model.in=in
+ elseif size(in1,2)==2 then //This appears not to be useful, retained if case of?
+ disp("check_io : unexpected case")
+ model.in=[in,2*ones(in)];
+ end
+
+ if size(out1,2)<=1 then
+ model.out=out
+ elseif size(out1,2)==2 then //This appears not to be useful, retained if case of?
+ disp("check_io : unexpected case")
+ model.out=[out,2*ones(out)];
+ end
+ model.evtin=clkin
+ model.evtout=clkout
+
+
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/check_mac.bin b/modules/scicos/macros/scicos_scicos/check_mac.bin
new file mode 100755
index 000000000..1c4a3ff7d
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/check_mac.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/check_mac.sci b/modules/scicos/macros/scicos_scicos/check_mac.sci
new file mode 100755
index 000000000..fb47f6401
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/check_mac.sci
@@ -0,0 +1,29 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function ok=check_mac(txt)
+ //errcatch doesnt work poperly
+ ok=%t
+ if execstr("comp(mac)","errcatch")<>0 then
+ messagebox(["Incorrect syntax: ";lasterror()],"modal")
+ ok=%f
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/color.tst b/modules/scicos/macros/scicos_scicos/color.tst
new file mode 100755
index 000000000..b5f1b0004
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/color.tst
@@ -0,0 +1,61 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+xsetech([0 0 1 1],[0 0 1 1])
+orig=[0 0]
+sz=[1 1]
+
+thick=xget('thickness');xset('thickness',2);
+xrect(orig(1)+sz(1)/10,orig(2)+(1-1/10)*sz(2),sz(1)*8/10,sz(2)*8/10);
+xx=[orig(1)+sz(1)/5,orig(1)+sz(1)/5;
+orig(1)+(1-1/5)*sz(1),orig(1)+sz(1)/5];
+yy=[orig(2)+sz(2)/5,orig(2)+sz(2)/5;
+orig(2)+sz(2)/5,orig(2)+(1-1/5)*sz(2)];
+xarrows(xx,yy);
+t=(0:0.3:2*%pi)'
+xx=orig(1)+(1/5+3*t/(10*%pi))*sz(1);
+yy=orig(2)+(1/4.3+(sin(t)+1)*3/10)*sz(2);
+xpoly(xx,yy,'lines');
+xset('thickness',thick)
+
+
+
+orig=[0.5 0.5]
+
+
+
+wd=xget('wdim').*[1.016,1.12];
+thick=xget('thickness');xset('thickness',2);
+p=wd(2)/wd(1);p=1;
+rx=sz(1)*p/2;ry=sz(2)/2;
+xarcs([orig(1)+0.05*sz(1);
+orig(2)+0.95*sz(2);
+ 0.9*sz(1)*p;
+ 0.9*sz(2);
+ 0;
+ 360*64],default_color(-1));
+xset('thickness',1);
+xx=[orig(1)+rx orig(1)+rx;
+ orig(1)+rx orig(1)+rx+0.6*rx*cos(%pi/6)];
+yy=[orig(2)+ry orig(2)+ry ;
+ orig(2)+1.8*ry orig(2)+ry+0.6*ry*sin(%pi/6)];
+xsegs(xx,yy,10);
+xset('thickness',thick);
diff --git a/modules/scicos/macros/scicos_scicos/compile_init_modelica.bin b/modules/scicos/macros/scicos_scicos/compile_init_modelica.bin
new file mode 100755
index 000000000..6a7d643fe
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/compile_init_modelica.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/compile_init_modelica.sci b/modules/scicos/macros/scicos_scicos/compile_init_modelica.sci
new file mode 100755
index 000000000..ec5587ccc
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/compile_init_modelica.sci
@@ -0,0 +1,140 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+// Compilation needed by the graphical interface for intitialization
+
+function [ok]=compile_init_modelica(xmlmodel,paremb,jaco)
+
+ if exists("%scicos_solver")==0 then
+ %scicos_solver = 0 ;
+ end
+
+ if ~exists("%scicos_debug_gr") then
+ %scicos_debug_gr = %f; //** debug mode : default is "%f"
+ end
+
+
+ MODELICAC_FILENAME = "modelicac";
+ if getos() == "Windows" then
+ MODELICAC_FILENAME = MODELICAC_FILENAME + ".exe";
+ end
+
+ // called by Initilization IHM
+ lines(0);
+ global icpr;
+
+ //set paths for generated files
+ outpath = pathconvert(TMPDIR,%t,%t);
+
+ // created files for initialization
+ xmlfile = outpath + xmlmodel + "_init.xml"; // file created by translator
+ namei = xmlmodel + "i";
+ Flati = outpath + xmlmodel + "i.mo";
+ FlatCi = outpath + xmlmodel + "i.c"; // computational C function associated to the flat model for initialization
+ incidencei = outpath + xmlmodel + "i_incidence_matrix.xml";
+ Flat_functions = outpath + xmlmodel + "_functions" + ".mo"; // file created by translator
+
+ //--------------------------------------------------------------------
+ ok = xml2modelica(xmlfile, Flati)
+ if ~ok then return,end
+
+ if jaco == "0" then
+ JAC = "";
+ else
+ JAC = " -jac "; // to generate the analytical jacobian
+ end
+
+ tmpdir = pathconvert(TMPDIR, %t, %t); //for error log and shell scripts
+
+ exe = """" + pathconvert(getmodelicacpath() + MODELICAC_FILENAME, %f, %t) + """";
+ Flati = " """ + Flati + """";
+
+ // generates the computational C function associated to the flat model
+ instr = exe + Flati + "" + JAC + " -with-init-in """ + strsubst(xmlfile,"\","/") + ..
+ """ -with-init-out """ + strsubst(xmlfile,"\","/") + """ -o """ + ..
+ FlatCi + """";
+
+
+ if getos() == "Windows" then
+ mputl(instr, tmpdir + "igenm.bat");
+ instr = tmpdir + "igenm.bat";
+ end
+
+ [rep,stat,err]=unix_g(instr);
+ if stat == 0 then
+ mprintf("%s"," Init C code : "+FlatCi);
+ mprintf("\n\r");
+
+ ok = Link_modelica_C(FlatCi);
+ [nipar, nrpar, nopar, nz, nx, nx_der, nx_ns, nin, nout, nm, ng, dep_u] = reading_incidence(incidencei);
+
+ if (~ok) then
+ return;
+ end
+
+ else
+ messagebox(err, _("Modelica compiler (flat2C)"), "error", "modal");
+ ok = %f;
+ return
+ end
+
+ //build model data structure of the block equivalent to the implicit
+ bllst = bllst;
+ nblock = length(bllst);
+ mdl = bllst(nblock);
+ mdl.sim = list(namei, 10004);
+ mdl.state = zeros(nx * 2, 1);
+ mdl.dstate = zeros(nz, 1);
+ mdl.nzcross = ng;
+ mdl.nmode = nm;
+ mdl.in = ones(nin, 1);
+ mdl.out = ones(nout, 1);
+ mdl.dep_ut = [dep_u, %t];
+ bllst(nblock) = mdl;
+ if size(connectmat, 2) == 6 then
+ connectmat = connectmat(:,[1 2 4 5]);
+ end
+ scs_m = null();
+
+ icpr = list();
+ if exists(%scicos_solver) == 0 | (exists(%scicos_solver) <> 0 & %scicos_solver < 100) then
+ %scicos_solver = 100;
+ end
+ icpr = c_pass2(bllst, connectmat, clkconnect, cor, corinv);
+
+ if icpr == list() then
+ ok = %f;
+ return,
+ end
+
+ // suppressing display blocks
+ Ignore=["bouncexy", "cscope", "cmscope", "canimxy", "canimxy3d", "cevscpe", "cfscope", "cscopexy", ..
+ "cscopexy3d", "cscopxy", "cscopxy3d", "cmatview", "cmat3d", "affich", "affich2", "BPLATFORM"];
+
+ for i = 1:length(icpr.sim.funs)
+ if type(icpr.sim.funs(i)) <> 13 then
+ if find(icpr.sim.funs(i)(1) == Ignore) <> [] then
+ icpr.sim.funs(i)(1) = "trash";
+ end
+ end
+ end
+endfunction
+//-----------------------------------------------------------------------------
+
diff --git a/modules/scicos/macros/scicos_scicos/compile_modelica.bin b/modules/scicos/macros/scicos_scicos/compile_modelica.bin
new file mode 100755
index 000000000..b28efcf0f
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/compile_modelica.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/compile_modelica.sci b/modules/scicos/macros/scicos_scicos/compile_modelica.sci
new file mode 100755
index 000000000..b0feda73b
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/compile_modelica.sci
@@ -0,0 +1,141 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// - Serge Steer <serge.steer@inria.fr> - 2003
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [ok,name,nipar,nrpar,nopar,nz,nx,nx_der,nx_ns,nin,nout,nm,ng,dep_u]=compile_modelica(filemo,Mblocks)
+
+ // Copyright INRIA
+ // Modelica_Init becomes true only in "Modelicainitialize_.sci"
+ if exists("%Modelica_Init")==0 then %Modelica_Init=%f;end
+ if exists("%Jacobian")==0 then %Jacobian=%t; end
+ if exists("%Modelica_ParEmb")==0 then %Modelica_ParEmb=%t; end
+
+ //Initialize lhs arguments in case of return on error
+ name="";
+ dep_u=%t; nipar=0;nrpar=0;nopar=0;
+ nz=0;nx=0;nx_der=0;nx_ns=0;nin=0;nout=0;nm=0;ng=0;
+
+ // modelica UI initialization is always ignored
+ running="off";
+
+ //set paths for generated files
+ outpath=pathconvert(TMPDIR,%t,%t);
+
+
+ name=basename(filemo)
+ namef=name+"f";
+
+
+ //Flat modelica file generated by translator
+ Flat=outpath+namef+".mo";// flat modelica file path
+
+ //xml files generated by translator and/or edited by Initialization GUI
+ xmlfile=outpath+namef+"_init.xml";// initialization XML
+ Relfile=outpath+namef+"_relations.xml";
+
+ //files generated by modelicac
+ Cfile=outpath+name+".c" //C code of the simulation function
+ incidence=outpath+name+"_incidence_matrix.xml" //incidence matrix
+
+ //files generated for the scicos simulation by translator
+ Flat_functions=outpath+namef+"_functions.mo";
+ xmlfileTMP=outpath+name+"Sim.xml";
+
+ //do not update C code if not required this allows C code
+ //modifications for debugging purposes
+ updateC=needcompile<>0|fileinfo(Cfile)==[]| %Modelica_Init
+
+ if updateC then
+
+ //Generate the flat model if it does not exist yet (It may have been
+ //generated by the initialization GUI
+ if ( %Modelica_Init ) then
+ if (fileinfo(xmlfile)==[]) then
+ overwrite=%t;//Yes
+ else
+ overwrite=messagebox([_("The initialization file already exists!");
+ _("Do you want to overwrite it?") ],..
+ "","question",[_("Yes"),_("No")],"modal")==1
+ end
+ else
+ // do not generate the flat file when it is already generated by
+ // the initialization GUI
+ overwrite=(running <>"1")
+ end
+
+ if overwrite then
+ // generate with filemo the Modelica flat model,the xml files,
+ // and files needed for the scicos simulation
+ [ok]=translator(filemo,Mblocks,modelica_libs,Flat)
+ if ~ok then dep_u=%t; return,end
+ end
+
+ // if the initialisation GUI is used
+ if (%Modelica_Init) then //---------------------------
+ mprintf("%s"," Init XML file : "+xmlfile); mprintf("\n\r");
+ mprintf("%s"," Init Rel file : "+Relfile); mprintf("\n\r");
+ name=Flat;
+ //<<ALERT dep_u of the initialization block is obtained only when the C
+ // code is generated.
+ dep_u=%t;
+ ok=%t,
+ return;
+ else
+ mprintf("%s\n"," Flat Modelica : "+Flat);
+ end
+
+ //Generate the C file with modelicac
+ //---------------------------------------------------------------------
+ ok=modelicac(Flat,Flat_functions,xmlfileTMP,%Jacobian,Cfile,running=="1")
+
+ if ~ok then return,end
+ mprintf(" Simulation C code :%s\n", Cfile);
+ //---------------------------------------------------------------------
+ end // if update
+
+ [nipar,nrpar,nopar,nz,nx,nx_der,nx_ns,nin,nout,nm,ng,dep_u]=reading_incidence(incidence)
+ depu(dep_u)="T"; depu(~dep_u)="F";depu=strcat(depu);
+
+ txt = [_("Modelica blocks are reduced to a block with:") ;
+ msprintf(_("Number of differential states: %d"),nx_der);
+ msprintf(_("Number of algebraic states: %d"),nx-nx_der);
+ msprintf(_("Number of discrete time states : %d"),nz);
+ msprintf(_("Number of zero-crossing surfaces: %d"),ng);
+ msprintf(_("Number of modes : %d"),nm);
+ msprintf(_("Number of inputs : %d"),nin);
+ msprintf(_("Number of outputs: %d"),nout);
+ msprintf(_("Input/output dependency:[%s]"),depu)
+ msprintf(_("Analytical Jacobian: enabled (%%Jacobian=%s)"),sci2exp(%Jacobian));
+ msprintf(_("Parameter embedding mode: enabled (%%Modelica_ParEmb=%s)"),sci2exp(%Modelica_ParEmb))
+ ""
+ msprintf(_("Generated files path: %s"),outpath)
+ ""];
+
+ if getscilabmode() <> "NWNI" then
+ messagebox(txt, "info");
+ else
+ disp(txt);
+ end
+
+ //compile and link the generated C file
+ ok=Link_modelica_C(Cfile)
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/context_evstr.bin b/modules/scicos/macros/scicos_scicos/context_evstr.bin
new file mode 100755
index 000000000..96227b567
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/context_evstr.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/context_evstr.sci b/modules/scicos/macros/scicos_scicos/context_evstr.sci
new file mode 100755
index 000000000..1a9178701
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/context_evstr.sci
@@ -0,0 +1,50 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [%vv_list,%ierr_vec,err_mess,%ok]=context_evstr(%str,%scicos_context,%typ)
+ // Copyright INRIA
+ // Evaluate Scicos Context utility function
+ %ok=%t
+ err_mess=[];lasterror();
+ %mm=getfield(1,%scicos_context)
+ for %mi=%mm(3:$)
+ if execstr(%mi+"=%scicos_context(%mi)","errcatch")<>0 then
+ err_mess=lasterror()
+ if err_mess==[] then err_mess="Error in evaluating "+%mi,end
+ %ok=%f
+ return
+ end
+ end
+ %nn=prod(size(%str))
+ %ierr_vec=zeros(%nn,1)
+ %vv_list=list()
+ for %kk=1:%nn
+ if %typ(2*%kk-1)(1)<>"str" then
+ [%vv_list(%kk),%ierr_vec(%kk)]=evstr(%str(%kk));
+ %err_mes=lasterror()
+ if %err_mes<>[] then
+ err_mess(%kk)=%err_mes;%ok=%f;
+ end
+ else
+ %vv_list(%kk)=%str(%kk);
+ end
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/cos2cosf.bin b/modules/scicos/macros/scicos_scicos/cos2cosf.bin
new file mode 100755
index 000000000..6836c82f9
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/cos2cosf.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/cos2cosf.sci b/modules/scicos/macros/scicos_scicos/cos2cosf.sci
new file mode 100755
index 000000000..bf795a666
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/cos2cosf.sci
@@ -0,0 +1,233 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function ierr = cos2cosf(u,scs_m,count)
+
+ //write scilab instructions whose evaluation
+ //returns the value of scicos data structure scs_m.
+ //in the opened file associated with logical unit u
+
+ [lhs,rhs]=argn(0)
+ ierr=0;
+ if rhs<3 then
+ count=0,
+ lname="scs_m"
+ else
+ count=count+1
+ lname="scs_m_"+string(count)
+ end
+
+ lmax=80;
+
+ //////////////////
+ txt=[];
+
+ //version
+ txt=[txt;"version="""+get_scicos_version()+""",.."];
+
+ //scicos_params
+ tt=[];
+ fields=getfield(1,scs_m.props);
+ for i=1:lstsize(scs_m.props)-1
+ field_nam=fields(i+1);
+ if field_nam=="title" then field_nam="Title", end
+ tt2=sci2exp(getfield(i+1,scs_m.props),lmax);
+ tt2(1)=field_nam+"="+tt2(1);
+ if i<>lstsize(scs_m.props)-1 then
+ tt2($)=tt2($)+",";
+ end
+ tt=[tt;tt2];
+ end
+
+ tt=my_strcat(tt);
+ txt=[txt;
+ "props=scicos_params(..";
+ " "+tt(1)];
+ for i=2:size(tt,1)
+ txt=[txt;" "+tt(i)];
+ end
+ txt($)=txt($)+")";
+
+ //scicos_diagram
+ txt=["scicos_diagram(..";txt];
+ txt($)=txt($)+")";
+
+ //final work
+ txt(1)=lname+"="+txt(1);
+ bl1=" ";
+ for i=2:size(txt,1)
+ txt(i)=part(bl1,1:length(lname)+1)+txt(i);
+ end
+ //////////////////
+
+ ierr=execstr("write(u,txt,''(a)'')","errcatch");
+ if ierr<>0 then return, end;
+
+ t=[];
+
+ for k=1:lstsize(scs_m.objs)
+
+ o=scs_m.objs(k)
+ if typeof(o)=="Block" then
+ lhs=lname+".objs("+string(k)+")="
+
+ if o.model.sim=="super"| o.model.sim=="csuper"| o.model.sim(1)=="asuper" then //Super blocks
+ cos2cosf(u,o.model.rpar,count);//model.rpar
+ end
+ //////////////////
+ txt=[];
+
+ //gui
+ tt=sci2exp(o.gui);
+ txt=[txt;"gui="+tt(1)];
+ for i=2:size(tt,1)
+ txt=[txt;" "+tt(i)];
+ end
+ txt($)=txt($)+",..";
+
+ //scicos_graphics
+ tt=[];
+ fields=getfield(1,o.graphics);
+ for i=1:lstsize(o.graphics)-1
+ field_nam=fields(i+1);
+ tt2=sci2exp(getfield(i+1,o.graphics),lmax);
+ tt2(1)=field_nam+"="+tt2(1);
+ if i<>lstsize(o.graphics)-1 then
+ tt2($)=tt2($)+",";
+ end
+ tt=[tt;tt2];
+ end
+
+ tt=my_strcat(tt);
+ txt=[txt;
+ "graphics=scicos_graphics(..";
+ " "+tt(1)];
+ for i=2:size(tt,1)
+ txt=[txt;" "+tt(i)];
+ end
+ txt($)=txt($)+"),..";
+
+ //scicos_model
+ tt=[];
+ fields=getfield(1,o.model);
+ for i=1:lstsize(o.model)-1
+ field_nam=fields(i+1);
+ if field_nam=="rpar"&(o.model.sim=="super"| o.model.sim=="csuper"| o.model.sim(1)=="asuper") then
+ tt2="scs_m_"+string(count+1);
+ else
+ tt2=sci2exp(getfield(i+1,o.model),lmax);
+ end
+ tt2(1)=field_nam+"="+tt2(1);
+ if i<>lstsize(o.model)-1 then
+ tt2($)=tt2($)+",";
+ end
+ tt=[tt;tt2];
+ end
+
+ tt=my_strcat(tt);
+ txt=[txt;
+ "model=scicos_model(..";
+ " "+tt(1)];
+ for i=2:size(tt,1)
+ txt=[txt;" "+tt(i)];
+ end
+ txt($)=txt($)+"),..";
+
+ //doc
+ tt=sci2exp(o.doc,50);
+ txt=[txt;"doc="+tt(1)];
+ for i=2:size(tt,1)
+ txt=[txt;" "+tt(i)];
+ end
+
+ //scicos_block
+ txt=["scicos_block(..";txt];
+ txt($)=txt($)+")";
+
+ //final work
+ txt(1)=lhs+txt(1);
+ bl1=" ";
+ for i=2:size(txt,1)
+ txt(i)=part(bl1,1:length(lhs))+txt(i);
+ end
+ write(u,txt,"(a)");
+ ///////////////
+ else //link
+ lhs=lname+".objs("+string(k)+")="
+ if typeof(o)=="Link" then
+ //scicos_link
+ tt=[];
+ txt=[];
+ fields=getfield(1,o);
+ for i=1:lstsize(o)-1
+ field_nam=fields(i+1);
+ tt2=sci2exp(getfield(i+1,o),lmax);
+ tt2(1)=field_nam+"="+tt2(1);
+ if i<>lstsize(o)-1 then
+ tt2($)=tt2($)+",";
+ end
+ tt=[tt;tt2];
+ end
+
+ tt=my_strcat(tt);
+ txt=[txt;
+ "scicos_link(..";
+ " "+tt(1)];
+ for i=2:size(tt,1)
+ txt=[txt;" "+tt(i)];
+ end
+ txt($)=txt($)+")";
+
+ //final work
+ txt(1)=lhs+txt(1);
+ bl1=" ";
+ for i=2:size(txt,1)
+ txt(i)=part(bl1,1:length(lhs))+txt(i);
+ end
+ write(u,txt,"(a)");
+
+ else // ??
+ // Alan : JESAISPASIYADAUTRESOBJS
+ // QUEDESBLOCKSETDESLINKSDANSSCICOS
+ // ALORSJELAISSELEVIEUCODE
+ t=[]
+ t1=sci2exp(o,lmax-length(lhs))
+ n1=size(t1,1)
+ bl1=" ";bl1=part(bl1,1:length(lhs))
+ t=[t;lhs+t1(1);bl1(ones(n1-1,1))+t1(2:$)]
+ write(u,t,"(a)");
+ end
+ end
+ end
+
+endfunction
+
+function txt_out=my_strcat(txt)
+ txt_out=[]
+ for i=1:size(txt,1)
+ txt_out(i)=txt(i);
+ if length(txt_out(i))<>0 then
+ if part(txt_out(i),length(txt_out(i)))=="," then
+ txt_out(i)=txt_out(i)+"..";
+ end
+ end
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/countblocks.bin b/modules/scicos/macros/scicos_scicos/countblocks.bin
new file mode 100755
index 000000000..36ea49561
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/countblocks.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/countblocks.sci b/modules/scicos/macros/scicos_scicos/countblocks.sci
new file mode 100755
index 000000000..d66309a03
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/countblocks.sci
@@ -0,0 +1,38 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function n=countblocks(scs_m)
+ // count number of blocks used in the scicos data structure scs_m
+
+ n=0
+ for o=scs_m.objs
+ x=getfield(1,o)
+ if x(1)=="Block" then
+ if o.model.sim=="super"|o.model.sim=="csuper" then
+ n=n+countblocks(o.model.rpar)
+ else
+ n=n+1
+ end
+ else
+ n=n+1
+ end
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/create_modelica.bin b/modules/scicos/macros/scicos_scicos/create_modelica.bin
new file mode 100755
index 000000000..00d39185c
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/create_modelica.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/create_modelica.sci b/modules/scicos/macros/scicos_scicos/create_modelica.sci
new file mode 100755
index 000000000..14eefad38
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/create_modelica.sci
@@ -0,0 +1,333 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [txt,rpar,ipar] = create_modelica(blklst,corinvm,cmat,NvM,name,scs_m)
+
+ if exists("%Modelica_Init")==0 then
+ // Modelica_Init becomes true only in "Modelicainitialize_.sci"
+ %Modelica_Init=%f;
+ end
+ if exists("%Modelica_ParEmb")==0 then
+ %Modelica_ParEmb=%t;
+ end
+
+ Parembed=%Modelica_ParEmb & ~%Modelica_Init;
+
+ txt=[];tab=ascii(9)
+ rpar=[];//will contain all parameters associated with the all modelica blocs
+ ipar=[];//will contain the "adress" of each block in rpar
+ models=[]//will contain the model declaration part
+ eqns=[]//will contain the modelica equations part
+ Pin=[]
+ Bnumbers=[]
+ Bnam=[]
+ Bnames=[]
+ nb=size(blklst)
+ Params=[];
+ for k=1:nb
+ ipar(k)=0
+ o=blklst(k);
+ //#########
+ //## Params
+ //#########
+ mo=o.equations;
+ np=size(mo.parameters(1),"*");
+ P=[];
+ //** mo.parameters have size=2
+ //** it only contains parameters
+ if np<>0 then
+ if lstsize(mo.parameters)==2 then
+ mo.parameters(3)=zeros(1,np)
+ end
+ end
+
+ for j=1:np
+ //## loop on number of param value
+ //## can be both scalar or array
+ Parj=mo.parameters(1)(j)
+ Parjv=mo.parameters(2)(j)
+ Parj_in=Parj+"_"+string(k)+string(j)
+
+ if type(Parjv)==1 then // if Real/Complex Integers are used with "fixed=true"
+ rpar=[rpar;matrix(Parjv,-1,1)]
+ ipar(k)=ipar(k)+size(Parjv,"*")
+ end
+ //======================================================
+ Params=[Params;construct_Pars(Parj_in,Parjv,Parembed)]
+ if mo.parameters(3)(j)==0 then
+ P=[P;Parj+"="+Parj_in]
+ elseif mo.parameters(3)(j)==1 then
+ //eParjv=construct_redeclar(Parjv)
+ P=[P;Parj+"(start="+Parj_in+")"];
+ elseif mo.parameters(3)(j)==2 then
+ //eParjv=construct_redeclar(Parjv)
+ P=[P;Parj+"(start="+Parj_in+",fixed=true)"];
+ end
+ //======================================================
+ end
+
+ //#########
+ //## models
+ //#########
+ Bnumbers=[Bnumbers k];
+
+ //## update list of names of modelica blocks
+ // Modelica compiler complains about ID containing dots
+ // So remove them Modelica.package.subpackage => Modelica_DOT_package_DOT_subpackage
+ Bnam = [Bnam, get_model_name(strsubst(mo.model, ".", "_DOT_"),Bnam)];
+ Bnames = [Bnames, Bnam($)]
+
+ if P==[] then
+ models=[models;
+ " "+mo.model+" "+tab+Bnames($)];
+ else
+ models=[models;
+ " "+mo.model+" "+tab+Bnames($)+"("+strcat(P,", ")+")"];
+ end
+
+ //## Add gr_i identification in comments of models
+ if mo.model<>"OutPutPort" & mo.model<>"InPutPort" then
+ //## retrieve the object in the scs_m structure
+ o_scsm = scs_m(scs_full_path(corinvm(k)));
+ //## get the structure graphics
+ o_gr = o_scsm.graphics;
+ //## get the identification field
+ id = stripblanks(o_gr.id)
+
+ if id<>"" then
+ models($)=models($)+" """+id+""";"
+ else
+ models($)=models($)+";"
+ end
+ else
+ models($)=models($)+";"
+ end
+
+ //rajouter les ports
+ end
+ ipar=cumsum([1;ipar(:)])
+
+ //links
+ for k=1:size(cmat,1)
+ from=cmat(k,1:3)
+ to=cmat(k,4:6)
+ if from(1)==0 then //input port
+ nb=nb+1
+ Bnumbers=[Bnumbers nb];
+ Bnames=[Bnames,"B"+string(nb)];
+ models=[models;" InPutPort"+" "+tab+"B"+string(nb)+";"];
+ n1="B"+string(nb)
+ elseif from(3)==1 then
+ p1=blklst(from(1)).equations.inputs(from(2))
+ n1=Bnames(find(Bnumbers==from(1)))
+ else
+ p1=blklst(from(1)).equations.outputs(from(2))
+ n1=Bnames(find(Bnumbers==from(1)))
+ end
+
+ if to(1)==0 then //output port
+ nb=nb+1
+ Bnumbers=[Bnumbers nb];
+ Bnames=[Bnames,"B"+string(nb)];
+ models=[models;" OutPutPort"+" "+tab+"B"+string(nb)+";"];
+ n1="B"+string(nb)
+ elseif to(3)==1 then
+ p2=blklst(to(1)).equations.inputs(to(2))
+ n2=Bnames(find(Bnumbers==to(1)))
+ else
+ if size(blklst(to(1)).equations.outputs,"*")<to(2) then pause,end
+ p2=blklst(to(1)).equations.outputs(to(2))
+ n2=Bnames(find(Bnumbers==to(1)))
+ end
+
+ if or(blklst(from(1)).equations.model==["InPutPort","OutPutPort"]) ...
+ | or(blklst(to(1)).equations.model==["InPutPort","OutPutPort"]) ...
+ | (k > (size(cmat,1) - NvM)) ...
+ then
+ eqns=[eqns
+ " "+n1+"."+p1+" = "+n2+"."+p2+";"]
+ else
+ eqns=[eqns
+ " connect ("+n1+"."+p1+","+n2+"."+p2+");"]
+ end
+ end
+
+ txt=[txt;
+ "model "+name
+ Params
+ models
+ "equation"
+ eqns
+ "end "+name+";"]
+endfunction
+
+function r=validvar_modelica(s)
+ r=validvar(s);
+
+ if r then
+ bad_char=["%" "#" "$"]
+ for j=1:size(bad_char,2)
+ if strindex(s,bad_char(j)) then
+ r=%f
+ return
+ end
+ end
+ end
+endfunction
+
+
+
+function r=write_nD_format(x)
+ sx=size(x)
+
+ if size(sx,"*")==2 then // Matrix/Vector
+ [nD1,nD2]=size(x)
+ if nD1==1 then // rows vector
+ r="{"+strcat(string(x),",")+"}"
+ r=strsubst(r,"D","e");
+ return r;
+ elseif nD2==1 then // column vector
+ N=nD1;
+ cmd=")"
+ else //matrix
+ N=sx(1);
+ cmd=",:)"
+ end
+ else // hypermatrix
+ // typeof(x)==hypermat
+ // xd=x.entries
+ // sdims=x.dims(2:$)
+ // N=x.dims(1)
+ // cmd=':)'
+ // n=size(sx,'c')
+ // for i=1:n-2;cmd=':,'+cmd;end;
+ // cmd=','+cmd;
+ end
+ r=[];
+ for i=1:N
+ cmdx="write_nD_format(x("+string(i)+cmd+")";
+ execstr("r(i)="+cmdx,"errcatch")
+ end
+ r="{"+strcat(r,",")+"}";
+endfunction
+
+// a 2x3 matrix {{xx,xx,xx},{xx,xx,xx}}
+// A[2] {xx,xx}
+// A[1,2] {{xx,xx}}
+// A[2,1] {{xx},{xx}}
+// A[1,1,2] {{{xx,xx}}}
+// a=rand(2,3)
+// a=[3,4];
+// a=[4;2];
+// a=rand(2,3);
+// a=rand(1,2,3,4,5);
+// a=[1 2 3 4 1 4];a(:,:,2)=[5 6 7 8 1 5] ;
+//if typeof(a)== 'hypermat' then
+// disp('not supported')
+//end
+//sa=write_nD_format(a)
+
+
+function Pari=construct_Pars(Pari,opari,Parembed)
+
+ if Pari==[] then
+ return " "
+ end
+ // Pars=' parameter Real '+Pars+'(fixed=false);'
+ [atemp]=format();
+ format(20);// writing in long format
+
+ //erpar=string(rpar); will put 1e-16 to zero in a vector containing
+ //big numbers
+
+ C=opari;
+ [a1,b1]=size(C);
+ npi=a1*b1;
+ if typeof(C)== "hypermat" then
+ messagebox(_("Hyper Matrix is not supported"),"error","modal")
+ return
+ end
+
+ if (type(C)==1) then
+ if isreal(C) then
+ par_type="Real"
+ else
+ par_type="Complex"
+ end
+ FIXED="false"
+ elseif (typeof(C)=="int32") | (typeof(C)=="int16") |...
+ (typeof(C)=="int8") |(typeof(C)=="uint32") |...
+ (typeof(C)=="uint16") | (typeof(C)=="uint8") then
+ par_type="Integer"
+ FIXED="true"
+ else
+ par_type="UnKnown_Type"
+ FIXED="???"
+ messagebox(_("Type not recognized"),"error","modal");ok=%f;
+ end
+
+ if ~Parembed then
+ FIXED="true"
+ end
+
+ if (npi==1) then,
+ eopari=strsubst(string(C),"D","e");
+ fixings="(fixed="+FIXED+") "
+ else
+ eopari=write_nD_format(C)
+ fixings="(each fixed="+FIXED+") ";
+ [d1,d2]=size(C);
+ if (d1==1) then
+ Pari=Pari+"["+string(d2)+"]"; //[d2]
+ else
+ Pari=Pari+"["+string(d1)+","+string(d2)+"]"; //[d1,d2]
+ end
+ end
+ Pari=" parameter "+par_type+" "+Pari+ fixings+"="+eopari+ " """+Pari+""""+";"
+ format(atemp(2))// restituing the format
+
+endfunction
+
+function eopari = construct_redeclar(opari)
+
+ [atemp]=format();
+ format(20);// writing in long format
+ C=opari;
+ npi=size(C,"*");
+
+ if typeof(C)== "hypermat" then
+ messagebox(_("Hyper Matrix is not supported"),"error","modal")
+ return
+ end
+ if ~isreal(C) then
+ messagebox(_("Complex Matrix is not supported"),"error","modal")
+ return
+ end
+
+ if (npi==1) then,
+ eopari=strsubst(string(C),"D","e");
+ else
+ eopari=write_nD_format(C)
+ end
+
+ format(atemp(2))// restituing the format
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/default_color.bin b/modules/scicos/macros/scicos_scicos/default_color.bin
new file mode 100755
index 000000000..ecef9edbb
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/default_color.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/default_color.sci b/modules/scicos/macros/scicos_scicos/default_color.sci
new file mode 100755
index 000000000..6cdbd363d
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/default_color.sci
@@ -0,0 +1,36 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function clr=default_color(typ)
+
+ if typ==-1 then //event links
+ clr=options("Link")(2),
+ elseif typ==0 then //text, block shape,
+ if size(options("Background"),"*")>=2 then //compatibility
+ clr=options("Background")(2),
+ else
+ clr=1
+ end
+ elseif typ==1 | typ==2 then //regular links
+
+ clr=options("Link")(1),
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/default_options.bin b/modules/scicos/macros/scicos_scicos/default_options.bin
new file mode 100755
index 000000000..50a93208a
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/default_options.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/default_options.sci b/modules/scicos/macros/scicos_scicos/default_options.sci
new file mode 100755
index 000000000..dfb76eafb
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/default_options.sci
@@ -0,0 +1,43 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function options = default_options()
+
+ options=scsoptlist()
+ col3d=[0.8 0.8 0.8]
+ //if xget('use color')==1 then //suppose always color screen
+ options("3D")=list(%t,33) // we add gray to color map
+ //else
+ // options('3D')=list(%f,0)
+ // col3d=[]
+ //end
+ options("Background")=[8 1] //white,black
+ options("Link")=[1,5] //black,red
+ options("ID")=list([4 1 10 1],[4 1 2 1])
+ options("Cmap")=col3d
+
+endfunction
+
+function options = scsoptlist(varargin)
+ lt = ["scsopt","3D","Background","Link","ID","Cmap"]
+ options = tlist(lt,varargin(:))
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/delete_unconnected.bin b/modules/scicos/macros/scicos_scicos/delete_unconnected.bin
new file mode 100755
index 000000000..c9fa824d5
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/delete_unconnected.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/delete_unconnected.sci b/modules/scicos/macros/scicos_scicos/delete_unconnected.sci
new file mode 100755
index 000000000..ce7c06d33
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/delete_unconnected.sci
@@ -0,0 +1,101 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function scs_m=delete_unconnected(scs_m);
+
+ n = lstsize(scs_m.objs);
+
+ if n==0 then
+ return
+ end ; //** exit point
+
+ DEL=[];
+ DELL=[]
+ finish=%f
+
+ while ~finish
+ finish = %t
+ for k=1:n //loop on scs_m objects
+ x = getfield(1,scs_m.objs(k))
+ if x(1)=="Block" then
+ if scs_m.objs(k).gui<>"SUM_f"&scs_m.objs(k).gui<>"SOM_f" then
+ if find(scs_m.objs(k).gui==["IFTHEL_f","ESELECT_f"]) then
+ kk=[find(scs_m.objs(k).graphics.pein==0),find(scs_m.objs(k).graphics.pin==0)]
+ if kk<> [] // a synchro block is not active, remove it
+ [scs_m,DEL1,DELL1]=do_delete1(scs_m,k,%f)
+ DEL=[DEL DEL1]
+ DELL=[DELL DELL1]
+ finish=%f
+ end
+ else
+ kk=[find(scs_m.objs(k).graphics.pin==0)]
+ if kk<>[] then // at least one input port is not connected delete the block
+ if or(getfield(1,scs_m.objs(k).graphics)=="in_implicit") then
+ if or(scs_m.objs(k).graphics.in_implicit(kk)<>"I") then
+ [scs_m,DEL1,DELL1]=do_delete1(scs_m,k,%f)
+ DEL=[DEL DEL1]
+ DELL=[DELL DELL1]
+ finish=%f
+ end
+ else
+ [scs_m,DEL1,DELL1]=do_delete1(scs_m,k,%f)
+ DEL=[DEL DEL1]
+ DELL=[DELL DELL1]
+ finish=%f
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+
+ //suppress rigth-most deleted elements
+ while getfield(1,scs_m.objs($))=="Deleted" then
+ scs_m.objs($)=null();
+ if lstsize(scs_m.objs)==0 then
+ break
+ end
+ end
+
+ // Notify by hiliting and message
+ if DEL<>[] then
+ // ind_del are deleted and not relinked blocks/links indexes of DEL
+ if DELL <> [] then
+ deleted = DEL(find(DEL<>DELL));
+ else
+ deleted = DEL;
+ end
+
+ // Store updated scs_m and retrieve the previous one
+ scs_save = scs_m;
+ scs_m = scs_m_s;
+
+ msg = gettext("Block is ignored because of undefined input(s).");
+ for del=deleted
+ hilite_path([path del], msg);
+ end
+
+ // Restore the updated scs_m
+ scs_m = scs_save;
+ end
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/dialog.bin b/modules/scicos/macros/scicos_scicos/dialog.bin
new file mode 100755
index 000000000..1230d4a61
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/dialog.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/dialog.sci b/modules/scicos/macros/scicos_scicos/dialog.sci
new file mode 100755
index 000000000..1f3d93c6b
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/dialog.sci
@@ -0,0 +1,25 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function result = dialog(labels,valueini)
+ // interface to x_dialog primitive to allow simple overloading for live demo
+ result = x_dialog(labels, valueini);
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/dig_bound_compound.bin b/modules/scicos/macros/scicos_scicos/dig_bound_compound.bin
new file mode 100755
index 000000000..1a7291650
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/dig_bound_compound.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/dig_bound_compound.sci b/modules/scicos/macros/scicos_scicos/dig_bound_compound.sci
new file mode 100755
index 000000000..416c2980b
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/dig_bound_compound.sci
@@ -0,0 +1,100 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+//** rotate compound : get dig_bound of a compound
+//**
+//** input : - blk the index of the compound (the i child of axe)
+//** -
+//** output : rect
+//**
+//** 25/11/08, Alan
+//** 22/06/09, Serge Steer INRIA
+// - input argument replaced by the compound handle
+// - removed the useless unglue + glue instruction using the compuound
+// children list
+// Copyright INRIA
+function [rect]=dig_bound_compound(gh_blk)
+ //gh_blk handle on a compound object
+
+ xmin = 100000;
+ xmax = -xmin;
+ ymin = xmin;
+ ymax = -xmin;
+ C=gh_blk.children
+ for i=1:size(C,"*")
+ select C(i).type
+ case "Rectangle" then
+ //disp('rectangle')
+
+ xmin=min(xmin,C(i).data(1));
+ ymin=min(ymin,C(i).data(2));
+ xmax=max(xmax,C(i).data(3)+C(i).data(1));
+ ymax=max(ymax,C(i).data(4)+C(i).data(2));
+
+ case "Text" then
+ //disp('text')
+
+ //** get bounding box of text with no rotation
+ rectstr = stringbox(C(i).text,C(i).data(1),...
+ C(i).data(2))
+
+ xmin=min(xmin,rectstr(1,1));
+ ymin=min(ymin,rectstr(2,1));
+ xmax=max(xmax,rectstr(1,3));
+ ymax=max(ymax,rectstr(2,3));
+
+ case "Polyline" then
+ //disp('polyline')
+
+ xmin=min(xmin,min(C(i).data(:,1)));
+ ymin=min(ymin,min(C(i).data(:,2)));
+ xmax=max(xmax,max(C(i).data(:,1)));
+ ymax=max(ymax,max(C(i).data(:,2)));
+
+ case "Compound" then
+ //disp('compound')
+
+ [rectcmpd]=dig_bound_compound(C(i))
+ xmin=min(xmin,rectcmpd(1,1));
+ ymin=min(ymin,rectcmpd(1,2));
+ xmax=max(xmax,rectcmpd(1,3));
+ ymax=max(ymax,rectcmpd(1,4));
+
+ case "Segs" then
+ //disp('Segs')
+
+ xmin=min(xmin,min(C(i).data(:,1)));
+ ymin=min(ymin,min(C(i).data(:,2)));
+ xmax=max(xmax,max(C(i).data(:,1)));
+ ymax=max(ymax,max(C(i).data(:,2)));
+
+ case "Arc" then
+ //disp('Arc')
+
+ xmin=min(xmin,C(i).data(1));
+ ymin=min(ymin,C(i).data(2));
+ xmax=max(xmax,C(i).data(3)+C(i).data(1));
+ ymax=max(ymax,C(i).data(4)+C(i).data(2));
+ end
+ end
+
+ rect=[xmin ymin xmax ymax]
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/do_compile.bin b/modules/scicos/macros/scicos_scicos/do_compile.bin
new file mode 100755
index 000000000..ab84f02d8
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_compile.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/do_compile.sci b/modules/scicos/macros/scicos_scicos/do_compile.sci
new file mode 100755
index 000000000..34b65b83e
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_compile.sci
@@ -0,0 +1,109 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [%cpr,ok] = do_compile(scs_m)
+ show_trace = %f //** tracing and profiling (probably by Alan L. )
+ if show_trace then
+ disp("c_pass0:"+string(timer()));
+ end
+
+ if exists("%scicos_solver")==0 then
+ %scicos_solver = 0 ;
+ end
+
+ par = scs_m.props;
+
+ if alreadyran then
+ // terminate current simulation
+ do_terminate();
+ end
+
+ timer() ; //** profiling timer
+
+ IN=[];OUT=[];
+ for i=1:lstsize(scs_m.objs)
+ if typeof(scs_m.objs(i))=="Block" then
+ if scs_m.objs(i).gui=="IN_f" then
+ scs_m.objs(i).gui="INPUTPORT";
+ scs_m.objs(i).model.sim="bidon"
+ IN=[IN scs_m.objs(i).model.ipar]
+ elseif scs_m.objs(i).gui=="OUT_f" then
+ scs_m.objs(i).gui="OUTPUTPORT";
+ scs_m.objs(i).model.sim="bidon"
+ OUT=[OUT scs_m.objs(i).model.ipar]
+ end
+ end
+ end
+
+ IN=-gsort(-IN);
+ if or(IN<>[1:size(IN,"*")]) then
+ ok=%f;%cpr=list()
+ messagebox("Input ports are not numbered properly.","modal")
+ return
+ end
+
+ OUT=-gsort(-OUT);
+ if or(OUT<>[1:size(OUT,"*")]) then
+ ok=%f;%cpr=list()
+ messagebox("Output ports are not numbered properly.","modal")
+ return
+ end
+
+ //** First PASSAGE
+ [bllst,connectmat,clkconnect,cor,corinv,ok] = c_pass1(scs_m);
+
+ if show_trace then
+ disp("c_pass1:"+string(timer()))
+ end
+
+ if ~ok then %cpr=list()
+ return ; //** incase of any error EXIT
+ end
+
+ if size(connectmat,2)==6 then
+ connectmat = connectmat(:,[1 2 4 5])
+ end
+
+
+ scs_m = null() ;
+
+ if ~ok then %cpr=list()
+ return
+ end
+
+ // newc_pass2 destroys the corinv component associated
+ // to the modelica blocks preserve it
+ // clast=corinv($)
+ // if type(clast)==15 then corinv($)=clast(1),klast=size(corinv),end
+ // %cpr=newc_pass2(bllst,connectmat,clkconnect,cor,corinv);
+ // newc_pass2 destroys the corinv component associated
+ // to the modelica blocks
+ // if type(clast)==15 then %cpr.corinv(klast)=clast,end
+
+
+ //** Second PASSAGE
+ %cpr = c_pass2(bllst,connectmat,clkconnect,cor,corinv);
+
+ if %cpr==list() then
+ ok = %f ;
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/do_compile_superblock42.bin b/modules/scicos/macros/scicos_scicos/do_compile_superblock42.bin
new file mode 100755
index 000000000..d2c4c6233
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_compile_superblock42.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/do_compile_superblock42.sci b/modules/scicos/macros/scicos_scicos/do_compile_superblock42.sci
new file mode 100755
index 000000000..9e8d1c478
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_compile_superblock42.sci
@@ -0,0 +1,6005 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// - Alan Layec <alan.layec@inria.fr>
+// - Ramine Nikoukhah <ramine.nikoukhah@inria.fr>
+// - Rachid Djenidi
+//
+// - Scilab 5 update by Simone Mannori
+//
+// Copyright (C) DIGITEO - 2010 - Allan CORNET
+// Copyright (C) Scilab Enterprises - 2012 - Bruno JOFRET
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+//**---------------------------------------------------------------------------------------------------------------------------------
+//
+//16/06/07 Author : ?, A. Layec
+//
+function [Code,actt,proto]=call_actuator(i)
+ nin=inpptr(i+1)-inpptr(i); //** number of input ports
+ nout=outptr(i+1)-outptr(i); //** number of output ports
+
+ if funtyp(i)==0 then
+ if nin==0 then
+ uk = 0;
+ nuk_1 = 0;
+ nuk_2 = 0;
+ uk_t = 1;
+ //Code($+1)=+' args[0]=(double *)outtbptr[0]);';
+ else
+ uk = inplnk(inpptr(i));
+ nuk_1 = size(outtb(uk),1);
+ nuk_2 = size(outtb(uk),2);
+ uk_t = mat2scs_c_nb(outtb(uk));
+ //Code($+1)=' args[0]=('+mat2scs_c_ptr(outtb(uk))+' *)outtbptr['+string(uk-1)+'];';
+ end
+ end
+ //pour la fonction gui ont a : num de bloc l'adresse dans
+ //nouveau z et la taille du port
+ actt=[i uk nuk_1 nuk_2 uk_t bllst(i).ipar]
+
+ Code($+1)="block_"+rdnom+"["+string(i-1)+"].nevprt=nevprt;"
+
+ Code=["/* Call of actuator (blk nb "+string(i)+") */"
+ Code;
+ "nport = "+string(nbact)+";";
+ rdnom+"_actuator(&flag, &nport, &block_"+rdnom+"["+string(i-1)+"].nevprt, told, "+..
+ "("+mat2scs_c_ptr(outtb(uk))+" *)outtbptr["+string(uk-1)+"], &nrd_"+string(nuk_1)+", &nrd_"+..
+ string(nuk_2)+", &nrd_"+string(uk_t)+",bbb);"];
+
+ proto="void "+rdnom+"_actuator("+..
+ "int *, int *, int *, double *, void *, int *, int *,int *,int);"
+ proto=cformatline(proto,70);
+endfunction
+
+//CallBlock : generate C calling sequence
+// of a scicos block
+//
+//inputs : bk : bloc index
+// pt : evt activation number
+// flag : flag
+//
+//output : txt :
+//
+//16/06/07 Authors : Alan Layec
+function txt=call_block42(bk,pt,flag)
+ txt=[]
+ //**
+ if flag==2 & ((zptr(bk+1)-zptr(bk))+..
+ (ozptr(bk+1)-ozptr(bk))+..
+ (xptr(bk+1)-xptr(bk)+..
+ with_work(bk))==0 |..
+ pt<=0) & ~(stalone & or(bk==actt(:,1))) then
+ return // block without state or continuously activated
+ end
+ if flag==0 & ((xptr(bk+1)-xptr(bk))==0) then
+ return // block without continuous state
+ end
+ if flag==9 & ((zcptr(bk+1)-zcptr(bk))==0) then
+ return // block without continuous state
+ end
+ if flag==3 & ((clkptr(bk+1)-clkptr(bk))==0) then
+ return
+ end
+
+ //** adjust pt
+ if ~(flag==3 & ((zcptr(bk+1)-zcptr(bk))<>0)) then
+ pt=abs(pt)
+ end
+
+ //** add comment
+ txt=[txt;
+ get_comment("call_blk",list(funs(bk),funtyp(bk),bk,labels(bk)));]
+
+ //** set nevprt and flag for called block
+ txt=[txt;
+ "block_"+rdnom+"["+string(bk-1)+"].nevprt = "+string(pt)+";"
+ "local_flag = "+string(flag)+";"]
+
+ //**see if its bidon, actuator or sensor
+ if funs(bk)=="bidon" then
+ txt=[];
+ return
+ elseif funs(bk)=="bidon2" then
+ txt=[];
+ return
+ elseif or(bk==actt(:,1)) then
+ ind=find(bk==actt(:,1))
+ uk=actt(ind,2)
+ nuk_1=actt(ind,3)
+ nuk_2=actt(ind,4)
+ uk_t=actt(ind,5)
+ txt = [txt;
+ "nport = "+string(ind)+";"]
+ txt = [txt;
+ rdnom+"_actuator(&local_flag, &nport, &block_"+rdnom+"["+string(bk-1)+"].nevprt, \"
+ get_blank(rdnom+"_actuator")+" &t, ("+mat2scs_c_ptr(outtb(uk))+" *)"+rdnom+"_block_outtbptr["+string(uk-1)+"], \"
+ get_blank(rdnom+"_actuator")+" &nrd_"+string(nuk_1)+", &nrd_"+string(nuk_2)+", &nrd_"+string(uk_t)+",bbb);"]
+ txt = [txt;
+ "if(local_flag < 0) return(5 - local_flag);"]
+ return
+ elseif or(bk==capt(:,1)) then
+ ind=find(bk==capt(:,1))
+ yk=capt(ind,2);
+ nyk_1=capt(ind,3);
+ nyk_2=capt(ind,4);
+ yk_t=capt(ind,5);
+ txt = [txt;
+ "nport = "+string(ind)+";"]
+ txt = [txt;
+ rdnom+"_sensor(&local_flag, &nport, &block_"+rdnom+"["+string(bk-1)+"].nevprt, \"
+ get_blank(rdnom+"_sensor")+" &t, ("+mat2scs_c_ptr(outtb(yk))+" *)"+rdnom+"_block_outtbptr["+string(yk-1)+"], \"
+ get_blank(rdnom+"_sensor")+" &nrd_"+string(nyk_1)+", &nrd_"+string(nyk_2)+", &nrd_"+string(yk_t)+",aaa);"]
+ txt = [txt;
+ "if(local_flag < 0) return(5 - local_flag);"]
+ return
+ end
+
+ //**
+ nx=xptr(bk+1)-xptr(bk);
+ nz=zptr(bk+1)-zptr(bk);
+ nrpar=rpptr(bk+1)-rpptr(bk);
+ nipar=ipptr(bk+1)-ipptr(bk);
+ nin=inpptr(bk+1)-inpptr(bk); //* number of input ports */
+ nout=outptr(bk+1)-outptr(bk); //* number of output ports */
+
+ //**
+ //l'adresse du pointeur de ipar
+ if nipar<>0 then ipar=ipptr(bk), else ipar=1;end
+ //l'adresse du pointeur de rpar
+ if nrpar<>0 then rpar=rpptr(bk), else rpar=1; end
+ //l'adresse du pointeur de z attention -1 pas sur
+ if nz<>0 then z=zptr(bk)-1, else z=0;end
+ //l'adresse du pointeur de x
+ if nx<>0 then x=xptr(bk)-1, else x=0;end
+
+ //**
+ ftyp=funtyp(bk)
+ if ftyp>2000 then ftyp=ftyp-2000,end
+ if ftyp>1000 then ftyp=ftyp-1000,end
+
+ //** check function type
+ if ftyp < 0 then //** ifthenelse eselect blocks
+ txt = [];
+ return;
+ else
+ if (ftyp<>0 & ftyp<>1 & ftyp<>2 & ftyp<>3 & ftyp<>4) then
+ disp("types other than 0,1,2,3 or 4 are not supported.")
+ txt = [];
+ return;
+ end
+ end
+
+ select ftyp
+
+ case 0 then
+ //**** input/output addresses definition ****//
+ if nin>1 then
+ for k=1:nin
+ uk=inplnk(inpptr(bk)-1+k);
+ nuk=size(outtb(uk),"*");
+ txt=[txt;
+ "rdouttb["+string(k-1)+"]=(double *)"+rdnom+"_block_outtbptr["+string(uk-1)+"];"]
+ end
+ txt=[txt;
+ "args[0]=&(rdouttb[0]);"]
+ elseif nin==0
+ uk=0;
+ nuk=0;
+ txt=[txt;
+ "args[0]=(double *)"+rdnom+"_block_outtbptr[0];"]
+ else
+ uk=inplnk(inpptr(bk));
+ nuk=size(outtb(uk),"*");
+ txt=[txt;
+ "args[0]=(double *)"+rdnom+"_block_outtbptr["+string(uk-1)+"];"]
+ end
+
+ if nout>1 then
+ for k=1:nout
+ yk=outlnk(outptr(bk)-1+k);
+ nyk=size(outtb(yk),"*");
+ txt=[txt;
+ "rdouttb["+string(k+nin-1)+"]=(double *)"+rdnom+"_block_outtbptr["+string(yk-1)+"];"];
+ end
+ txt=[txt;
+ "args[1]=&(rdouttb["+string(nin)+"]);"];
+ elseif nout==0
+ yk=0;
+ nyk=0;
+ txt=[txt;
+ "args[1]=(double *)"+rdnom+"_block_outtbptr[0];"];
+ else
+ yk=outlnk(outptr(bk));
+ nyk=size(outtb(yk),"*"),;
+ txt=[txt;
+ "args[1]=(double *)"+rdnom+"_block_outtbptr["+string(yk-1)+"];"];
+ end
+ //*******************************************//
+
+ //*********** call seq definition ***********//
+ txtc=["(&local_flag,&block_"+rdnom+"["+string(bk-1)+"].nevprt,&t,block_"+rdnom+"["+string(bk-1)+"].xd, \";
+ "block_"+rdnom+"["+string(bk-1)+"].x,&block_"+rdnom+"["+string(bk-1)+"].nx, \";
+ "block_"+rdnom+"["+string(bk-1)+"].z,&block_"+rdnom+"["+string(bk-1)+"].nz,block_"+rdnom+"["+string(bk-1)+"].evout, \";
+ "&block_"+rdnom+"["+string(bk-1)+"].nevout,block_"+rdnom+"["+string(bk-1)+"].rpar,&block_"+rdnom+"["+string(bk-1)+"].nrpar, \";
+ "block_"+rdnom+"["+string(bk-1)+"].ipar,&block_"+rdnom+"["+string(bk-1)+"].nipar, \";
+ "(double *)args[0],&nrd_"+string(nuk)+",(double *)args[1],&nrd_"+string(nyk)+");"];
+ if (funtyp(bk)>2000 & funtyp(bk)<3000)
+ blank = get_blank(funs(bk)+"( ");
+ txtc(1) = funs(bk)+txtc(1);
+ elseif (funtyp(bk)<2000)
+ txtc(1) = "C2F("+funs(bk)+")"+txtc(1);
+ blank = get_blank("C2F("+funs(bk)+") ");
+ end
+ txtc(2:$) = blank + txtc(2:$);
+ txt = [txt;txtc];
+ //*******************************************//
+
+
+ //**
+ case 1 then
+ //*********** call seq definition ***********//
+ txtc=["(&local_flag,&block_"+rdnom+"["+string(bk-1)+"].nevprt,&t,block_"+rdnom+"["+string(bk-1)+"].xd, \";
+ "block_"+rdnom+"["+string(bk-1)+"].x,&block_"+rdnom+"["+string(bk-1)+"].nx, \";
+ "block_"+rdnom+"["+string(bk-1)+"].z,&block_"+rdnom+"["+string(bk-1)+"].nz,block_"+rdnom+"["+string(bk-1)+"].evout, \";
+ "&block_"+rdnom+"["+string(bk-1)+"].nevout,block_"+rdnom+"["+string(bk-1)+"].rpar,&block_"+rdnom+"["+string(bk-1)+"].nrpar, \";
+ "block_"+rdnom+"["+string(bk-1)+"].ipar,&block_"+rdnom+"["+string(bk-1)+"].nipar"];
+ if (funtyp(bk)>2000 & funtyp(bk)<3000)
+ blank = get_blank(funs(bk)+"( ");
+ txtc(1) = funs(bk)+txtc(1);
+ elseif (funtyp(bk)<2000)
+ txtc(1) = "C2F("+funs(bk)+")"+txtc(1);
+ blank = get_blank("C2F("+funs(bk)+") ");
+ end
+ if nin>=1 | nout>=1 then
+ txtc($)=txtc($)+", \"
+ txtc=[txtc;""]
+ if nin>=1 then
+ for k=1:nin
+ uk=inplnk(inpptr(bk)-1+k);
+ nuk=size(outtb(uk),"*");
+ txtc($)=txtc($)+"(double *)"+rdnom+"_block_outtbptr["+string(uk-1)+"],&nrd_"+string(nuk)+",";
+ end
+ txtc($)=part(txtc($),1:length(txtc($))-1); //remove last ,
+ end
+ if nout>=1 then
+ if nin>=1 then
+ txtc($)=txtc($)+", \"
+ txtc=[txtc;""]
+ end
+ for k=1:nout
+ yk=outlnk(outptr(bk)-1+k);
+ nyk=size(outtb(yk),"*");
+ txtc($)=txtc($)+"(double *)"+rdnom+"_block_outtbptr["+string(yk-1)+"],&nrd_"+string(nyk)+",";
+ end
+ txtc($)=part(txtc($),1:length(txtc($))-1); //remove last ,
+ end
+ end
+
+ if ztyp(bk) then
+ txtc($)=txtc($)+", \"
+ txtc=[txtc;
+ "block_"+rdnom+"["+string(bk-1)+"].g,&block_"+rdnom+"["+string(bk-1)+"].ng);"]
+ else
+ txtc($)=txtc($)+");";
+ end
+
+ txtc(2:$) = blank + txtc(2:$);
+ txt = [txt;txtc];
+ //*******************************************//
+
+ //**
+ case 2 then
+
+ //*********** call seq definition ***********//
+ txtc=[funs(bk)+"(&local_flag,&block_"+rdnom+"["+string(bk-1)+"].nevprt,&t,block_"+rdnom+"["+string(bk-1)+"].xd, \";
+ "block_"+rdnom+"["+string(bk-1)+"].x,&block_"+rdnom+"["+string(bk-1)+"].nx, \";
+ "block_"+rdnom+"["+string(bk-1)+"].z,&block_"+rdnom+"["+string(bk-1)+"].nz,block_"+rdnom+"["+string(bk-1)+"].evout, \";
+ "&block_"+rdnom+"["+string(bk-1)+"].nevout,block_"+rdnom+"["+string(bk-1)+"].rpar,&block_"+rdnom+"["+string(bk-1)+"].nrpar, \";
+ "block_"+rdnom+"["+string(bk-1)+"].ipar,&block_"+rdnom+"["+string(bk-1)+"].nipar, \";
+ "(double **)block_"+rdnom+"["+string(bk-1)+"].inptr,block_"+rdnom+"["+string(bk-1)+"].insz,&block_"+rdnom+"["+string(bk-1)+"].nin, \";
+ "(double **)block_"+rdnom+"["+string(bk-1)+"].outptr,block_"+rdnom+"["+string(bk-1)+"].outsz, &block_"+rdnom+"["+string(bk-1)+"].nout"];
+ if ~ztyp(bk) then
+ txtc($)=txtc($)+");";
+ else
+ txtc($)=txtc($)+", \";
+ txtc=[txtc;
+ "block_"+rdnom+"["+string(bk-1)+"].g,&block_"+rdnom+"["+string(bk-1)+"].ng);"]
+ end
+ blank = get_blank(funs(bk)+"( ");
+ txtc(2:$) = blank + txtc(2:$);
+ txt = [txt;txtc];
+ //*******************************************//
+
+ //**
+ case 4 then
+ txt=[txt;
+ funs(bk)+"(&block_"+rdnom+"["+string(bk-1)+"],local_flag);"];
+
+ end
+
+ txt =[txt;"if(local_flag < 0) return(5 - local_flag);"]
+
+endfunction
+
+//CallBlock : generate C calling sequence
+// of a scicos block
+//
+//inputs : bk : bloc index
+// pt :
+// flag :block_'+rdnom+'[
+//
+//output : txt :
+//
+//16/06/07 Authors : R.Nikoukhah, A.Layec
+function txt=call_block4(bk)
+ // if flag==2 & ((zptr(bk+1)-zptr(bk))+(ozptr(bk+1)-ozptr(bk))==0 | pt<=0) then
+ // return // block without discrete state or continuously activated
+ // // If work allocated in the absence of z and oz, it does not work
+ // end
+
+ //**
+ nx=xptr(bk+1)-xptr(bk);
+ nz=zptr(bk+1)-zptr(bk);
+ nrpar=rpptr(bk+1)-rpptr(bk);
+ nipar=ipptr(bk+1)-ipptr(bk);
+ nin=inpptr(bk+1)-inpptr(bk); //* number of input ports */
+ nout=outptr(bk+1)-outptr(bk); //* number of output ports */
+
+ //**
+ //l'adresse du pointeur de ipar
+ if nipar<>0 then ipar=ipptr(bk), else ipar=1;end
+ //l'adresse du pointeur de rpar
+ if nrpar<>0 then rpar=rpptr(bk), else rpar=1; end
+ //l'adresse du pointeur de z attention -1 pas sur
+ if nz<>0 then z=zptr(bk)-1, else z=0;end
+ //l'adresse du pointeur de x
+ if nx<>0 then x=xptr(bk)-1, else x=0;end
+
+ //**
+ ftyp=funtyp(bk)
+ if ftyp>2000 then ftyp=ftyp-2000,end
+ if ftyp>1000 then ftyp=ftyp-1000,end
+
+ //** check function type
+ if ftyp < 0 then //** ifthenelse eselect blocks
+ txt = [];
+ return;
+ else
+ if (ftyp<>0 & ftyp<>1 & ftyp<>2 & ftyp<>3 & ftyp<>4) then
+ disp("types other than 0,1,2,3 or 4 are not supported.")
+ txt = [];
+ return;
+ end
+ end
+
+ //** add comment
+ txt=[get_comment("call_blk",list(funs(bk),funtyp(bk),bk,labels(bk)));]
+
+ //** write nevprt activation
+ // nclock=abs(pt);
+ txt=[txt;
+ "block_"+rdnom+"["+string(bk-1)+"].nevprt=nevprt;"]
+
+ select ftyp
+ //** zero funtyp
+ case 0 then
+ //**** input/output addresses definition ****//
+ if nin>1 then
+ for k=1:nin
+ uk=inplnk(inpptr(bk)-1+k);
+ nuk=size(outtb(uk),"*");
+ TYPE=mat2scs_c_ptr(outtb(uk));//scilab index start from 1
+ txt=[txt;
+ "rdouttb["+string(k-1)+"]=("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(uk-1)+"];"]
+ end
+ txt=[txt;
+ "args[0]=&(rdouttb[0]);"]
+ elseif nin==0
+ uk=0;
+ nuk=0;
+ txt=[txt;
+ "args[0]=(SCSREAL_COP *)"+rdnom+"_block_outtbptr[0];"]
+ else
+ uk=inplnk(inpptr(bk));
+ nuk=size(outtb(uk),"*");
+ TYPE=mat2scs_c_ptr(outtb(uk));//scilab index start from 1
+ txt=[txt;
+ "args[0]=("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(uk-1)+"];"]
+ end
+
+ if nout>1 then
+ for k=1:nout
+ yk=outlnk(outptr(bk)-1+k);
+ nyk=size(outtb(yk),"*");
+ TYPE=mat2scs_c_ptr(outtb(yk));//scilab index start from 1
+ txt=[txt;
+ "rdouttb["+string(k+nin-1)+"]=("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(yk-1)+"];"];
+ end
+ txt=[txt;
+ "args[1]=&(rdouttb["+string(nin)+"]);"];
+ elseif nout==0
+ yk=0;
+ nyk=0;
+ txt=[txt;
+ "args[1]=(SCSREAL_COP *)"+rdnom+"_block_outtbptr[0];"];
+ else
+ yk=outlnk(outptr(bk));
+ nyk=size(outtb(yk),"*"),;
+ TYPE=mat2scs_c_ptr(outtb(yk));//scilab index start from 1
+ txt=[txt;
+ "args[1]=("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(yk-1)+"];"];
+ end
+ //*******************************************//
+
+ //*********** call seq definition ***********//
+ txtc=["(&flag,&block_"+rdnom+"["+string(bk-1)+"].nevprt,told,block_"+rdnom+"["+string(bk-1)+"].xd, \";
+ "block_"+rdnom+"["+string(bk-1)+"].x,&block_"+rdnom+"["+string(bk-1)+"].nx, \";
+ "block_"+rdnom+"["+string(bk-1)+"].z,&block_"+rdnom+"["+string(bk-1)+"].nz,block_"+rdnom+"["+string(bk-1)+"].evout, \";
+ "&block_"+rdnom+"["+string(bk-1)+"].nevout,block_"+rdnom+"["+string(bk-1)+"].rpar,&block_"+rdnom+"["+string(bk-1)+"].nrpar, \";
+ "block_"+rdnom+"["+string(bk-1)+"].ipar,&block_"+rdnom+"["+string(bk-1)+"].nipar, \";
+ "(double *)args[0],&nrd_"+string(nuk)+",(double *)args[1],&nrd_"+string(nyk)+");"];
+ if (funtyp(bk)>2000 & funtyp(bk)<3000)
+ blank = get_blank(funs(bk)+"( ");
+ txtc(1) = funs(bk)+txtc(1);
+ elseif (funtyp(bk)<2000)
+ txtc(1) = "C2F("+funs(bk)+")"+txtc(1);
+ blank = get_blank("C2F("+funs(bk)+") ");
+ end
+ txtc(2:$) = blank + txtc(2:$);
+ txt = [txt;txtc];
+ //*******************************************//
+
+
+ //**
+ case 1 then
+ //**** input/output addresses definition ****//
+ // if nin>=1 then
+ // for k=1:nin
+ // uk=inplnk(inpptr(i)-1+k);
+ // nuk=size(outtb(uk),'*');
+ // end
+ // end
+ // if nout>=1 then
+ // for k=1:nout
+ // yk=outlnk(outptr(i)-1+k);
+ // nyk=size(outtb(yk),'*');
+ // end
+ // end
+ //*******************************************//
+
+ //*********** call seq definition ***********//
+ txtc=["(&flag,&block_"+rdnom+"["+string(bk-1)+"].nevprt,told,block_"+rdnom+"["+string(bk-1)+"].xd, \";
+ "block_"+rdnom+"["+string(bk-1)+"].x,&block_"+rdnom+"["+string(bk-1)+"].nx, \";
+ "block_"+rdnom+"["+string(bk-1)+"].z,&block_"+rdnom+"["+string(bk-1)+"].nz,block_"+rdnom+"["+string(bk-1)+"].evout, \";
+ "&block_"+rdnom+"["+string(bk-1)+"].nevout,block_"+rdnom+"["+string(bk-1)+"].rpar,&block_"+rdnom+"["+string(bk-1)+"].nrpar, \";
+ "block_"+rdnom+"["+string(bk-1)+"].ipar,&block_"+rdnom+"["+string(bk-1)+"].nipar"];
+ if (funtyp(bk)>2000 & funtyp(bk)<3000)
+ blank = get_blank(funs(bk)+"( ");
+ txtc(1) = funs(bk)+txtc(1);
+ elseif (funtyp(bk)<2000)
+ txtc(1) = "C2F("+funs(bk)+")"+txtc(1);
+ blank = get_blank("C2F("+funs(bk)+") ");
+ end
+ if nin>=1 | nout>=1 then
+ txtc($)=txtc($)+", \"
+ txtc=[txtc;""]
+ if nin>=1 then
+ for k=1:nin
+ uk=inplnk(inpptr(bk)-1+k);
+ nuk=size(outtb(uk),"*");
+ txtc($)=txtc($)+"(SCSREAL_COP *)"+rdnom+"_block_outtbptr["+string(uk-1)+"],&nrd_"+string(nuk)+",";
+ end
+ txtc($)=part(txtc($),1:length(txtc($))-1); //remove last ,
+ end
+ if nout>=1 then
+ if nin>=1 then
+ txtc($)=txtc($)+", \"
+ txtc=[txtc;""]
+ end
+ for k=1:nout
+ yk=outlnk(outptr(bk)-1+k);
+ nyk=size(outtb(yk),"*");
+ txtc($)=txtc($)+"(SCSREAL_COP *)"+rdnom+"_block_outtbptr["+string(yk-1)+"],&nrd_"+string(nyk)+",";
+ end
+ txtc($)=part(txtc($),1:length(txtc($))-1); //remove last ,
+ end
+ end
+
+ if ztyp(bk) then
+ txtc($)=txtc($)+", \"
+ txtc=[txtc;"w,&nrd_0);"];
+ else
+ txtc($)=txtc($)+");";
+ end
+
+ txtc(2:$) = blank + txtc(2:$);
+ txt = [txt;txtc];
+ //*******************************************//
+
+ //**
+ case 2 then
+
+ //*********** call seq definition ***********//
+ txtc=[funs(bk)+"(&flag,&block_"+rdnom+"["+string(bk-1)+"].nevprt,told,block_"+rdnom+"["+string(bk-1)+"].xd, \";
+ "block_"+rdnom+"["+string(bk-1)+"].x,&block_"+rdnom+"["+string(bk-1)+"].nx, \";
+ "block_"+rdnom+"["+string(bk-1)+"].z,&block_"+rdnom+"["+string(bk-1)+"].nz,block_"+rdnom+"["+string(bk-1)+"].evout, \";
+ "&block_"+rdnom+"["+string(bk-1)+"].nevout,block_"+rdnom+"["+string(bk-1)+"].rpar,&block_"+rdnom+"["+string(bk-1)+"].nrpar, \";
+ "block_"+rdnom+"["+string(bk-1)+"].ipar,&block_"+rdnom+"["+string(bk-1)+"].nipar, \";
+ "(double **)block_"+rdnom+"["+string(bk-1)+"].inptr,block_"+rdnom+"["+string(bk-1)+"].insz,&block_"+rdnom+"["+string(bk-1)+"].nin, \";
+ "(double **)block_"+rdnom+"["+string(bk-1)+"].outptr,block_"+rdnom+"["+string(bk-1)+"].outsz, &block_"+rdnom+"["+string(bk-1)+"].nout"];
+ if ~ztyp(bk) then
+ txtc($)=txtc($)+");";
+ else
+ txtc($)=txtc($)+", \";
+ txtc=[txtc;
+ "block_"+rdnom+"["+string(bk-1)+"].g,&block_"+rdnom+"["+string(bk-1)+"].ng);"]
+ end
+ blank = get_blank(funs(bk)+"( ");
+ txtc(2:$) = blank + txtc(2:$);
+ txt = [txt;txtc];
+ //*******************************************//
+
+ //**
+ case 4 then
+ txt=[txt;
+ funs(bk)+"(&block_"+rdnom+"["+string(bk-1)+"],flag);"];
+
+ end
+endfunction
+
+//
+//16/06/07 Author : ?, A. Layec
+//
+function [Code,capt,proto]=call_sensor(i)
+ nin=inpptr(i+1)-inpptr(i); ///* number of input ports */
+ nout=outptr(i+1)-outptr(i); ///* number of output ports */
+
+ //declaration des I/O des blocs de type 1
+ if funtyp(i)==0 then
+ if nout==0 then
+ yk = 0;
+ nyk_1 = 0;
+ nyk_2 = 0;
+ yk_t = 1;
+ //Code($+1)=+' args[1]=(double *)(outtbptr[0]);';
+ else
+ yk = outlnk(outptr(i));
+ nyk_1 = size(outtb(yk),1);
+ nyk_2 = size(outtb(yk),2);
+ yk_t = mat2scs_c_nb(outtb(yk));
+ //Code($+1)=' args[1]=('+mat2scs_c_ptr(outtb(yk))+' *)(outtbptr['+string(yk-1)+']);';
+ end
+
+ end
+ capt=[i yk nyk_1 nyk_2 yk_t bllst(i).ipar]
+ Code($+1)="block_"+rdnom+"["+string(i-1)+"].nevprt=nevprt;"
+ Code=["/* Call of sensor (blk nb "+string(i)+") */"
+ Code;
+ "nport = "+string(nbcap)+";";
+ rdnom+"_sensor(&flag, &nport, &block_"+rdnom+"["+string(i-1)+"].nevprt, "+..
+ "told, ("+mat2scs_c_ptr(outtb(yk))+" *)(outtbptr["+string(yk-1)+"]), &nrd_"+string(nyk_1)+..
+ ", &nrd_"+string(nyk_2)+", &nrd_"+string(yk_t)+",aaa);"];
+ proto="void "+rdnom+"_sensor("+..
+ "int *, int *, int *, double *,void *, int *, int *,int *, int);"
+ proto=cformatline(proto,70);
+endfunction
+
+//Generates Code for dynamically linked Fortran and C Blocks
+function [CCode,FCode]=gen_blocks()
+ CCode=[]
+ FCode=[]
+
+ kdyn=find(funtyp>1000) //dynamically linked blocs
+ //100X : Fortran blocks
+ //200X : C blocks
+
+ if (size(kdyn,"*") >1)
+ kfuns=[];
+ //get the block data structure in the initial scs_m structure
+ if size(corinv(kdyn(1)),"*")==1 then
+ O=scs_m.objs(corinv(kdyn(1)));
+ else
+ path=list("objs");
+ for l=corinv(kdyn(1))(1:$-1)
+ path($+1)=l;
+ path($+1)="model";
+ path($+1)="rpar";
+ path($+1)="objs";
+ end
+ path($+1)=corinv(kdyn(1))($);
+ O=scs_m(path);
+ end
+ if funtyp(kdyn(1))>2000 then
+ //C block
+ CCode=[CCode;O.graphics.exprs(2)]
+ else
+ FCode=[FCode;O.graphics.exprs(2)]
+ end
+ kfuns=funs(kdyn(1));
+ for i=2:size(kdyn,"*")
+ //get the block data structure in the initial scs_m structure
+ if size(corinv(kdyn(i)),"*")==1 then
+ O=scs_m.objs(corinv(kdyn(i)));
+ else
+ path=list("objs");
+ for l=corinv(kdyn(i))(1:$-1)
+ path($+1)=l;
+ path($+1)="model";
+ path($+1)="rpar";
+ path($+1)="objs";
+ end
+ path($+1)=corinv(kdyn(i))($);
+ O=scs_m(path);
+ end
+ if (find(kfuns==funs(kdyn(i))) == [])
+ kfuns=[kfuns;funs(kdyn(i))];
+ if funtyp(kdyn(i))>2000 then
+ //C block
+ CCode=[CCode;O.graphics.exprs(2)]
+ else
+ FCode=[FCode;O.graphics.exprs(2)]
+ end
+ end
+ end
+ elseif (size(kdyn,"*")==1)
+ //get the block data structure in the initial scs_m structure
+ if size(corinv(kdyn),"*")==1 then
+ O=scs_m.objs(corinv(kdyn));
+ else
+ path=list("objs");
+ for l=corinv(kdyn)(1:$-1)
+ path($+1)=l;
+ path($+1)="model";
+ path($+1)="rpar";
+ path($+1)="objs";
+ end
+ path($+1)=corinv(kdyn)($);
+ O=scs_m(path);
+ end
+ if funtyp(kdyn)>2000 then
+ //C block
+ CCode=[CCode;O.graphics.exprs(2)]
+ else
+ FCode=[FCode;O.graphics.exprs(2)]
+ end
+ end
+ if CCode==[]
+ CCode=["void no_ccode()"
+ "{"
+ " return;"
+ "}"]
+ end
+endfunction
+
+//** Generates the C code for new block simulation
+//
+//12/07/07 Alan Layec
+function ok=gen_ccode42();
+
+ //** Generate code for scicos block
+
+ ierr=execstr("make_computational42(rpat+''/''+rdnom+''.c'')","errcatch")
+ if ierr<>0 then
+ message(lasterror())
+ ok=%f
+ return
+ end
+
+ //** Generate files for dynamically linked scicos blocks
+ [CCode,FCode]=gen_blocks()
+ if FCode<>[] then
+ ierr=execstr("mputl(FCode,rpat+''/''+rdnom+''f.f'')","errcatch")
+ if ierr<>0 then
+ message(lasterror())
+ ok=%f
+ return
+ end
+ end
+ if CCode<>[] then
+ ierr=execstr("mputl(CCode,rpat+''/''+rdnom+''_Cblocks.c'')","errcatch")
+ if ierr<>0 then
+ message(lasterror())
+ ok=%f
+ return
+ end
+ end
+
+ //** Generate _void_io.c
+ try
+ fd = mopen(rpat+"/"+rdnom+"_void_io.c", "wt")
+
+ mputl(["/*";
+ "** Generated by Code_Generation toolbox of Xcos with "+getversion();
+ "** Date : "+date();
+ "*/"], fd);
+
+ if (readGlobal <> [] | writeGlobal <> [])
+ mputl([""
+ "#include ""scicos_block4.h"""], fd);
+ end
+
+ mputl([""
+ "/*---------------------------------------- Actuators */"
+ "void "+rdnom+"_actuator(int *flag, int *nport, int *nevprt, double *t, void *u, int *nu1, int *nu2, int *ut, int *flag1)"
+ "{"
+ " int k = 0,l = 0;"
+ "}"
+ "/*---------------------------------------- Sensor */"
+ "void "+rdnom+"_sensor(int *flag, int *nport, int *nevprt, double *t, void *y, int *ny1, int *ny2, int *yt, int *flag1)"
+ "{"
+ " int k = 0,l = 0;"
+ "}"], fd)
+
+ // Generate global data read <=> FromWorkspace.
+ if readGlobal <> []
+ for i = readGlobal
+ mputl(["/*---------------------------------------- Read variable "+i+" */"
+ "void readGlobal_"+i+"(scicos_block *block, int flag)"
+ "{"
+ " // Read a scilab Environment variable "+i
+ " fromws_c(block, flag);"
+ "}"
+ ], fd);
+ end
+ end
+
+ // Generate global data write <=> ToWorkspace.
+ if writeGlobal <> []
+ for i = writeGlobal
+ mputl(["/*---------------------------------------- Write variable "+i+" */"
+ "void writeGlobal_"+i+"(scicos_block *block, int flag)"
+ "{"
+ " // Write a scilab environment variable "+i
+ " // to a C one : global"+i
+ " tows_c(block, flag);"
+ "}"
+ ], fd);
+ end
+ end
+
+ mclose(fd);
+ catch
+ message(lasterror())
+ ok=%f
+ return
+ end
+
+ //** Generate _standalone.c
+
+ ierr=execstr("make_standalone42(rpat+''/''+rdnom+''_standalone.c'')","errcatch")
+ if ierr<>0 then
+ message(lasterror())
+ ok=%f
+ return
+ end
+
+ //** This copy is indispensable only for stand alone code generation
+ //** not supported in Scilab 5
+
+ //** copy source code of machine.h/scicos_block4.h
+ // in target path
+ // txt=mgetl(SCI+'/modules/core/includes/machine.h');
+ // ierr=execstr('mputl(txt,rpat+''/machine.h'')','errcatch')
+ // if ierr<>0 then
+ // message(lasterror())
+ // ok=%f
+ // return
+ // end
+ //
+ // txt=mgetl(SCI+'/modules/scicos_blocks/includes/scicos_block4.h');
+ // ierr=execstr('mputl(txt,rpat+''/scicos_block4.h'')','errcatch')
+ // if ierr<>0 then
+ // message(lasterror())
+ // ok=%f
+ // return
+ // end
+
+ //** Generate _act_sens_events.c
+ Code=["/*"
+ "** Generated by Code_Generation toolbox of Xcos with "+getversion()
+ "** Date :"+date()
+ "*/"
+ ""
+ "#include <stdio.h>"
+ "#include <stdlib.h>"
+ "#include <math.h>"
+ "#include <string.h>"
+ "extern void **"+rdnom+"_block_outtbptr;"
+ "extern char input[50],output[50];"
+ "FILE *fprr = NULL, *fprw = NULL;"
+ make_outevents()
+ make_actuator(%t)
+ make_sensor(%t)]
+
+ created=[];
+ reponse=[];
+
+ created=fileinfo(rpat+"/"+rdnom+"_act_sens_events.c")
+ if created~=[] then
+ reponse=messagebox(["File: """+rdnom+"_act_sens_events.c"" already exists,";
+ "do you want to replace it ?"],"modal","question",["Yes","No"]);
+ end
+
+ if reponse==1 | reponse==[] then
+ ierr=execstr("mputl(Code,rpat+''/''+rdnom+''_act_sens_events.c'')", ...
+ "errcatch")
+ if ierr<>0 then
+ message(lasterror())
+ ok=%f
+ return
+ end
+ end
+
+ try
+ if (readGlobal <> [] | writeGlobal <> [])
+ fd = mopen(rpat+"/"+rdnom+"_read_write_global.c", "wt")
+ mputl(["/*"
+ "** Generated by Code_Generation toolbox of Xcos with "+getversion()
+ "** Date :"+date()
+ "*/"
+ ""
+ "// Uncomment this to log each To Workspace variable update"
+ "//#define VERBOSE"
+ ""
+ "#ifdef VERBOSE"
+ "#include <stdio.h>"
+ "#endif"
+ "#include <stdlib.h>"
+ "#include <string.h>"
+ "#include ""scicos_block4.h"""
+ ""
+ "double get_scicos_time();"
+ ""
+ ], fd);
+ if writeGlobal <> []
+ // Generate global C variables
+ // #define global_XXX_Size
+ // static double **global_XXX
+ // static int global_XXX_Index (to manage buffer like variables)
+ for i = 1:size(writeGlobal, "*")
+ mputl(["/*---------------------------------------- Global Variable "+writeGlobal(i)+" */"
+ "#define global_"+writeGlobal(i)+"_Size "+string(writeGlobalSize(i))
+ "static double **global_"+writeGlobal(i)+";"
+ "static int global_"+writeGlobal(i)+"_Index = 0;"
+ ], fd);
+ end
+ end
+
+ if readGlobal <> []
+ // Generate global C variables
+ // #define global_XXX_Size
+ // #define global_XXX_Time_Size
+ // static double **global_XXX
+ // static double global_XXX_Time (manage time <-> values association)
+ for i = 1:size(readGlobal, "*")
+ mputl(["/*---------------------------------------- Global Variable "+readGlobal(i)+" */"
+ "#define global_"+readGlobal(i)+"_Size "+string(readGlobalSize(i))
+ "#define global_"+readGlobal(i)+"_Time_Size "+string(readGlobalTimeSize(i))
+ "static double **global_"+readGlobal(i)+";"
+ "static double *global_"+readGlobal(i)+"_Time = 0;"
+ ], fd);
+ end
+ end
+
+
+
+ if (readGlobal <> [])
+ for i = 1:size(readGlobal, "*")
+ mputl(["/*---------------------------------------- Read variable "+readGlobal(i)+" */"
+ "void readGlobal_"+readGlobal(i)+"(scicos_block *block, int flag)"
+ "{"
+ " int i = 0;"
+ " int j = 0;"
+ " double *y_d = NULL;"
+ ""
+ " /* Read a scilab Environment variable "+readGlobal(i)+" */"
+ " switch(flag)"
+ " {"
+ ], fd)
+ //
+ // Init case : allocate data / timetable
+ // Feal data/timetable with values from Scilab.
+ //
+ mputl([" case 4 : /* init */"
+ " {"
+ " // Allocate time table"
+ " global_"+readGlobal(i)+"_Time = (double *) malloc(global_"+readGlobal(i)+"_Time_Size * sizeof(double));"
+ " memset(global_"+readGlobal(i)+"_Time, 0x0, global_"+readGlobal(i)+"_Time_Size * sizeof(double));"
+ ""
+ " // Allocate data"
+ " global_"+readGlobal(i)+" = (double **) malloc(global_"+readGlobal(i)+"_Time_Size * sizeof(double *));"
+ " for (i = 0 ; i < global_"+readGlobal(i)+"_Time_Size ; ++i)"
+ " {"
+ " global_"+readGlobal(i)+"[i] = (double *) malloc( global_"+readGlobal(i)+"_Size * sizeof(double));"
+ " memset(global_"+readGlobal(i)+"[i], 0x0, global_"+readGlobal(i)+"_Size * sizeof(double));"
+ " }"
+ ""
+ ], fd);
+ // Save format
+ oldFormat = format();
+ format(25);
+
+ // Fead timetable
+ for (j = 1:readGlobalTimeSize(i))
+ mputl([" global_"+readGlobal(i)+"_Time["+string(j-1)+"] = " + ...
+ strsubst(string(evstr(readGlobal(i)+".time("+string(j)+")")), "D", "E")+";"
+ ], fd)
+ end
+ // Fead data
+ for (j = 1:readGlobalTimeSize(i))
+ for (k = 1:readGlobalSize(i))
+ mputl([" global_"+readGlobal(i)+"["+string(j-1)+"]["+string(k-1)+"] = " + ...
+ strsubst(string(evstr(readGlobal(i)+".values("+string(j)+", "+string(k)+")")), "D", "E")+";"
+ ], fd)
+
+ end
+ end
+
+ // Restore format
+ format(oldFormat(2), oldFormat(1));
+
+ mputl([""
+ " break;"
+ " }"
+ ],fd);
+ //
+ // Output update case :
+ //
+ mputl([" case 1 : /* output update */"
+ " {"
+ " j = 0;"
+ " while(get_scicos_time() > global_"+readGlobal(i)+"_Time[j] && j < global_"+readGlobal(i)+"_Time_Size)"
+ " {"
+ " j++;"
+ " }"
+ " y_d = GetRealOutPortPtrs(block,1);"
+ " if (j == global_"+readGlobal(i)+"_Time_Size)"
+ " {"
+ " memset(y_d, 0x0, global_"+readGlobal(i)+"_Size * sizeof(double));"
+ " }"
+ " else"
+ " {"
+ " memcpy(y_d, global_"+readGlobal(i)+"[j], global_"+readGlobal(i)+"_Size * sizeof(double));"
+ " }"
+ " break;"
+ " }"
+ ],fd);
+ //
+ // End, free memory.
+ //
+ mputl([" case 5 : /* END */"
+ " {"
+ " for (i = 0 ; i < global_"+readGlobal(i)+"_Time_Size ; ++i)"
+ " {"
+ " free(global_"+readGlobal(i)+"[i]);"
+ " }"
+ " free(global_"+readGlobal(i)+");"
+ " break;"
+ " }"
+ ],fd);
+ // Close switch + function declaration
+ mputl([" }"
+ "}"
+ ], fd);
+ end
+ end
+
+ if writeGlobal <> []
+ for i = 1:size(writeGlobal, "*")
+ mputl(["/*---------------------------------------- Write variable "+writeGlobal(i)+" */"
+ "void writeGlobal_"+writeGlobal(i)+"(scicos_block *block, int flag)"
+ "{"
+ " int i = 0;"
+ " int j = 0;"
+ " int nu = block->insz[0];"
+ " int nu2 = block->insz[1];"
+ ""
+ " /* Write a scilab environment variable "+writeGlobal(i)+" */"
+ " /* to a C one : global_"+writeGlobal(i)+" */"
+ " switch(flag)"
+ " {"
+ " case 4 : /* init */"
+ " {"
+ " global_"+writeGlobal(i)+" = (double **) malloc(global_"+writeGlobal(i)+"_Size * sizeof(double *));"
+ " for (i = 0 ; i < global_"+writeGlobal(i)+"_Size ; ++i)"
+ " {"
+ " global_"+writeGlobal(i)+"[i] = (double *) malloc(nu * nu2 * sizeof(double));"
+ " memset(global_"+writeGlobal(i)+"[i], 0x0, nu * nu2 * sizeof(double));"
+ " }"
+ " global_"+writeGlobal(i)+"_Index = -1;"
+ "#ifdef VERBOSE"
+ " printf(""C_"+writeGlobal(i)+".values = zeros(%d, %d, %d)\n"", global_"+writeGlobal(i)+"_Size, nu, nu2);"
+ " printf(""C_"+writeGlobal(i)+".time = -%%inf * ones(%d, 1)\n"", global_"+writeGlobal(i)+"_Size);"
+ "#endif"
+ " break;"
+ " }"
+ " case 2 : /* state update */"
+ " {"
+ " global_"+writeGlobal(i)+"_Index = (global_"+writeGlobal(i)+"_Index + 1) % global_"+writeGlobal(i)+"_Size;"
+ " memcpy(global_"+writeGlobal(i)+"[global_"+writeGlobal(i)+"_Index], block->inptr[i], nu * nu2 * sizeof(double));"
+ "#ifdef VERBOSE"
+ " printf(""C_"+writeGlobal(i)+".time(%d) = %.25E;\n"", global_"+writeGlobal(i)+"_Index + 1, get_scicos_time());"
+ " for (j = 0 ; j < nu * nu2 ; ++j)"
+ " {"
+ " printf(""C_"+writeGlobal(i)+".values(%d, %d) = %.25E;\n"", global_"+writeGlobal(i)+"_Index + 1, j + 1, global_"+writeGlobal(i)+"[global_"+writeGlobal(i)+"_Index][j]);"
+ " }"
+ "#endif /* !VERBOSE */"
+ " break;"
+ " }"
+ " case 5 : /* end */"
+ " {"
+ "#ifdef VERBOSE"
+ " //reshape to fit scilab behaviour"
+ " printf(""C_"+writeGlobal(i)+".time = C_"+writeGlobal(i)+".time(C_"+writeGlobal(i)+".time <> -%%inf);\n"");"
+ " printf(""C_"+writeGlobal(i)+".values = C_"+writeGlobal(i)+".values(1:size(C_"+writeGlobal(i)+".time, ''*''), :);\n"");"
+ "#endif"
+ " for (i = 0 ; i < global_"+writeGlobal(i)+"_Size ; ++i)"
+ " {"
+ " free(global_"+writeGlobal(i)+"[i]);"
+ " }"
+ " free(global_"+writeGlobal(i)+");"
+ " break;"
+ " }"
+ " }"
+ "}"
+ ], fd);
+ end
+ end
+
+ mclose(fd);
+ end
+ catch
+ message(lasterror())
+ ok=%f
+ return
+ end
+
+endfunction
+
+//creates the Scicos GUI function associated with the new block
+//
+//Author : Rachid Djenidi, A.Layec
+//
+//20/06/07, A.Layec : update with in2,out2,intyp,outtyp
+//27/06/07, A.Layec : update opar,oz
+//
+function ok=gen_gui42();
+ clkinput=ones(clkIN)';
+ clkoutput=ones(clkOUT)';
+ for i=1:length(bllst)
+ deput=[%t,%f]
+ if (bllst(i).dep_ut(2) == %t) then
+ deput(1,2)=%t;
+ break;
+ end
+ end
+ Code=["function [sciblk, s1, s2] = "+rdnom+"_c(job,sciblk,e1)"
+ "// Interfacing function of generated Xcos block "+rdnom
+ "// Generated by the Xcos Code_Generation tool with "+getversion();
+ "// Date : "+date();
+ "//"
+ " s1= []; s2 = [];"
+ " select job";
+ " case ""set"" then";
+ " case ""define"" then"
+ " "+sci2exp(capt(:,3),"in",70); //input ports sizes 1
+ " "+sci2exp(capt(:,4),"in2",70); //input ports sizes 2
+ " "+sci2exp(scs_c_nb2scs_nb(capt(:,5)),"intyp",70); //input ports type
+ " "+sci2exp(actt(:,3),"out",70); //output ports sizes 1
+ " "+sci2exp(actt(:,4),"out2",70); //output ports sizes 2
+ " "+sci2exp(scs_c_nb2scs_nb(actt(:,5)),"outtyp",70); //output ports type
+ " "+sci2exp(cpr.state.x,"x",70); //initial continuous state
+ " "+sci2exp(cpr.state.z,"z",70); //initial discrete state
+ " work=zeros("+string(nblk)+",1)";
+ " Z=[z;work]";
+ " "+sci2exp(lstcat(cpr.state.oz,cpr.state.outtb),"odstate",70);
+ " "+sci2exp(cpr.sim.rpar,"rpar",70); //real parameters
+ " "+sci2exp(cpr.sim.ipar,"ipar",70); //integer parameters
+ " "+sci2exp(cpr.sim.opar,"opar",70); //object parameters
+ " "+sci2exp(clkinput,"clkinput",70);
+ " "+sci2exp(clkoutput,"clkoutput",70);
+ " "+sci2exp(FIRING,"firing",70);
+ " nzcross="+string(sum(cpr.sim.zcptr(2:$)-cpr.sim.zcptr(1:$-1)))';
+ " nmode="+string(sum(cpr.sim.modptr(2:$)-cpr.sim.modptr(1:$-1)))';
+ " "+sci2exp(deput,"dep_ut",70);
+ " model=scicos_model(sim=list(''"+rdnom+"'',4),...";
+ " in=in,..."
+ " in2=in2,..."
+ " intyp=intyp,..."
+ " out=out,..."
+ " out2=out2,..."
+ " outtyp=outtyp,..."
+ " evtin=clkinput,..."
+ " evtout=clkoutput,..."
+ " firing=firing,..."
+ " state=x,..."
+ " dstate=Z,..."
+ " odstate=odstate,..."
+ " rpar=rpar,..."
+ " ipar=ipar,..."
+ " opar=opar,..."
+ " blocktype=''c'',..."
+ " dep_ut=dep_ut,..."
+ " nzcross=nzcross,..."
+ " nmode=nmode)";
+ " gr_i=""xstringb(orig(1),orig(2),"""""+rdnom+""""",sz(1),sz(2),""""fill"""")""";
+ " sciblk = standard_define([2 2],model,[],gr_i);";
+ " style_properties = [""blockWithLabel"";";
+ " ""verticalLabelPosition=middle"";";
+ " ""verticalAlign=middle"";";
+ " ""displayedLabel="+rdnom+"""];";
+ " sciblk.graphics.style = strcat(style_properties,"";"");";
+ " end"
+ "endfunction"];
+ //Create file
+ ierr=execstr("mputl(Code,rpat+""/""+rdnom+""_c.sci"")","errcatch")
+ if ierr<>0 then
+ message(lasterror())
+ ok=%f
+ end
+endfunction
+
+function [ok,XX,alreadyran,flgcdgen,szclkINTemp,freof] = do_compile_superblock42(XX,all_scs_m,numk,alreadyran)
+ // Transforms a given Scicos discrete and continuous SuperBlock into a C defined Block
+
+ scs_m=XX.model.rpar
+ par=scs_m.props;
+ if alreadyran then
+ //terminate current simulation
+ do_terminate()
+ alreadyran=%f
+ end
+ hname=scs_m.props.title(1) //superblock name
+ //***********************************************************
+ //Check blocks properties and adapt them if necessary
+ //***********************************************************
+
+ IN=[];
+ OUT=[];
+ clkIN=[];
+ clkOUT=[];
+ numa=[];
+ numc=[];
+ writeGlobal = [];
+ writeGlobalSize = [];
+ readGlobal = [];
+ readGlobalTimeSize = [];
+ readGlobalSize = [];
+
+ for i=1:size(scs_m.objs)
+ if typeof(scs_m.objs(i))=="Block" then
+ if scs_m.objs(i).gui=="CLKOUT_f" then
+ ok=%f;%cpr=list();
+ message("Superblock should not have any activation output port.")
+ return
+ elseif scs_m.objs(i).gui=="IN_f" then
+ //replace input ports by sensor blocks
+ numc=numc+1
+ scs_m.objs(i).gui="INPUTPORTEVTS";
+ scs_m.objs(i).model.evtin=1
+ scs_m.objs(i).model.sim(1)="capteur"+string(numc)
+ IN=[IN scs_m.objs(i).model.ipar]
+ elseif scs_m.objs(i).gui=="OUT_f" then
+ //replace output ports by actuator blocks
+ numa=numa+1
+ scs_m.objs(i).gui="OUTPUTPORTEVTS";
+ scs_m.objs(i).model.sim(1)="actionneur"+string(numa)
+ OUT=[OUT scs_m.objs(i).model.ipar]
+ elseif scs_m.objs(i).gui=="CLKINV_f" then
+ //replace event input ports by fictious block
+ scs_m.objs(i).gui="EVTGEN_f";
+ scs_m.objs(i).model.sim(1)="bidon"
+ clkIN=[clkIN scs_m.objs(i).model.ipar];
+ //elseif scs_m.objs(i).model.dep_ut(2)==%t then
+ //check for time dependency PAS IICI
+ //ok=%f;%cpr=list()
+ //message('a block have time dependence.')
+ //return
+ elseif scs_m.objs(i).gui=="CLKOUTV_f" then
+ scs_m.objs(i).gui="EVTOUT_f";
+ scs_m.objs(i).model.sim(1)="bidon2"
+ clkOUT=[clkOUT scs_m.objs(i).model.ipar];
+ end
+ end
+ end
+
+ //Check if input/output ports are numered properly
+ IN=-gsort(-IN);
+ if or(IN<>[1:size(IN,"*")]) then
+ ok=%f;%cpr=list()
+ message("Input ports are not numbered properly.")
+ return
+ end
+ OUT=-gsort(-OUT);
+ if or(OUT<>[1:size(OUT,"*")]) then
+ ok=%f;%cpr=list()
+ message("Output ports are not numbered properly.")
+ return
+ end
+ clkIN=-gsort(-clkIN);
+ if or(clkIN<>[1:size(clkIN,"*")]) then
+ ok=%f;%cpr=list()
+ message("Event input ports are not numbered properly.")
+ return
+ end
+ clkOUT=-gsort(-clkOUT);
+ if or(clkOUT<>[1:size(clkOUT,"*")]) then
+ ok=%f;%cpr=list()
+ message("Event output ports are not numbered properly.")
+ return
+ end
+
+ //Check if there is more than one clock in the diagram
+ szclkIN=size(clkIN,2);
+ if szclkIN==0 then
+ szclkIN=[]
+ end
+ flgcdgen=szclkIN;
+ [bllst,connectmat,clkconnect,cor,corinv,ok,scs_m,flgcdgen,freof]=c_pass1(scs_m,flgcdgen);
+
+ // Check for any To Workspace/FromWorkspace block
+ for i = 1:size(bllst)
+ if bllst(i).sim(1) == "tows_c" then
+ // Explore scs_m to find original block
+ towsObjIndex = corinv(i);
+ towsObj = scs_m.objs(towsObjIndex(1));
+ for j = 2:size(towsObjIndex, "*")
+ towsObj = towsObj.model.rpar.objs(towsObjIndex(j));
+ end
+ bllst(i).sim(1) = "writeGlobal_" + ...
+ towsObj.graphics.exprs(2);
+ // Force state to enable case 2 call
+ // on generated code
+ bllst(i).dstate = 0;
+ writeGlobal = [writeGlobal towsObj.graphics.exprs(2)];
+ writeGlobalSize = [writeGlobalSize bllst(i).ipar(1)];
+ elseif bllst(i).sim(1) == "fromws_c" then
+ fromwsObjIndex = corinv(i);
+ fromwsObj = scs_m.objs(fromwsObjIndex(1));
+ for j = 2:size(fromwsObjIndex, "*")
+ fromwsObj = fromwsObj.model.rpar.objs(fromwsObjIndex(j));
+ end
+ bllst(i).sim(1) = "readGlobal_" + fromwsObj.graphics.exprs(1);
+ readGlobal = [readGlobal fromwsObj.graphics.exprs(1)];
+ readGlobalTimeSize = [readGlobalTimeSize evstr("size(" + fromwsObj.graphics.exprs(1) + ".time, ""*"")")]
+ readGlobalSize = [readGlobalSize evstr("size(" + fromwsObj.graphics.exprs(1) + ".values(1, :), ""*"")")]
+ end
+ end
+
+ if flgcdgen<> szclkIN
+ clkIN=[clkIN flgcdgen]
+ end
+ szclkINTemp=szclkIN;
+ szclkIN=flgcdgen;
+ // [bllst,connectmat,clkconnect,cor,corinv,ok]=c_pass1(scs_m);
+
+ //Test for ALWAYS_ACTIVE sblock (RN -25/06/07)
+ ALWAYS_ACTIVE=%f;
+ for blki=bllst
+ if blki.dep_ut($) then
+ ALWAYS_ACTIVE=%t;
+ break;
+ end
+ end
+ if ALWAYS_ACTIVE then
+ CAPTEURS=[];
+ for Ii=1:length(bllst)
+ if part(bllst(Ii).sim(1),1:7)=="capteur" then
+ bllst(Ii).dep_ut($)=%t
+ // elseif part(bllst(Ii).sim(1),1:10)=='actionneur' then
+ // bllst(Ii).dep_ut($)=%t
+ end
+ end
+ end
+
+ if ~ok then
+ message("Sorry: problem in the pre-compilation step.")
+ return
+ end
+ a=[];
+ b=[];
+ tt=[];
+ howclk=[];
+ allhowclk=[];
+ allhowclk2=[];
+ cap=[];
+ act=[];
+
+ ///**********************************
+ for i=1:size(bllst)
+ // check for a scilab function block
+ if type(bllst(i).sim(1)) == 13 then
+ ok=%f;
+ %cpr=list();
+ message(_("Superblock should not contains any Scilab function block."))
+ return
+ end
+
+ for j=1:size(bllst)
+ if (bllst(i).sim(1)=="actionneur"+string(j)) then
+ if tt<>i then
+ act=[act;i];
+ tt=i;
+ end
+ elseif (bllst(i).sim(1)=="capteur"+string(j)) then
+ if tt<>i then
+ cap=[cap;i];
+ tt=i;
+ end
+ elseif (bllst(i).sim(1)=="bidon") then
+ if tt<>i then
+ allhowclk=[allhowclk;i];
+ tt=i;
+ end
+ elseif (bllst(i).sim(1)=="bidon2") then
+ if tt<>i then
+ allhowclk2=[allhowclk2;i];
+ tt=i;
+ end
+ end
+ end
+ end
+ ///**********************************
+ if szclkIN>1 then
+ //replace the N Event inputs by a fictious block with 2^N as many event
+ //outputs
+ output=ones((2^szclkIN)-1,1)
+ bllst($+1)=scicos_model(sim=list("bidon",1),evtout=output,..
+ blocktype="d",..
+ firing=-output',dep_ut=[%f %f])
+ corinv(size(bllst))=size(bllst)+1;
+ howclk=size(bllst)
+ // adjust the links accordingly
+ for i=1:(2^szclkIN)-1
+ vec=codebinaire(i,szclkIN)
+ for j=1:szclkIN
+ if vec(j)*allhowclk(j)>=1 then
+ for k=1:size(clkconnect,1)
+ if clkconnect(k,1)==allhowclk(j) then
+ clkconnect=[clkconnect;[howclk i clkconnect(k,3:4)]]
+ end
+ end
+ end
+ end
+ end
+ elseif szclkIN==[]&~ALWAYS_ACTIVE then
+ //superblock has no Event input, add a fictious clock
+ output=ones((2^(size(cap,"*")))-1,1)
+ if (output == []) then
+ output=0;
+ end
+ bllst($+1)=scicos_model(sim=list("bidon",1),evtout=output,..
+ firing=-output,blocktype="d",dep_ut=[%f %f])
+ corinv(size(bllst))=size(bllst)+1;
+ howclk=size(bllst);
+ elseif szclkIN==1 then
+ howclk=allhowclk;
+ end
+
+ //mise en ordre de clkconnect
+ if szclkIN>1 then
+ newclkconnect=clkconnect;
+ clkconnect=[];
+ for i=1:size(newclkconnect,1)-1
+ if or(newclkconnect(i,:)<>newclkconnect(i+1,:)) then
+ clkconnect=[clkconnect;newclkconnect(i,:)]
+ end
+ end
+ if or(newclkconnect($-1,:)<>newclkconnect($,:)) then
+ clkconnect=[clkconnect;newclkconnect($,:)]
+ end
+
+ //suppression des blocs bidons
+ newclkconnect=clkconnect;nkt=[];
+ for i=1:szclkIN
+ for k=1:size(newclkconnect,1)
+ if newclkconnect(k,1)~=allhowclk(i) then
+ nkt=[nkt;newclkconnect(k,:)];
+ end
+ end
+ newclkconnect=nkt;
+ nkt=[];
+ end
+ clkconnect=newclkconnect;
+ end
+
+ //**************************************************
+ // nouveau clkconnect avec liaisons sur les capteurs
+ //**************************************************
+
+ //
+ // Generate block activation fo C code
+ //
+ n=size(cap,1)
+ if ~(szclkIN==[]) then
+ // Activate sensors on each clock pulse.
+ generatedConnection = [];
+ for i=1:n
+ if szclkIN>1 then
+ for j=1:(2^szclkIN)-1
+ generatedConnection = [generatedConnection ; [howclk j cap(i) 1]];
+ end
+ elseif szclkIN==1 then
+ generatedConnection = [generatedConnection ; [howclk 1 cap(i) 1]];
+ end
+ end
+ clkconnect = [clkconnect ; generatedConnection]
+ elseif ~ALWAYS_ACTIVE then
+ // Generate all possible activations for sensors, based on number of blocks.
+ //codage de l'activation des capteurs dans le cas de l'heritage
+ generatedConnection = [];
+ for i=1:2^n-1
+ vec=codebinaire(i,n);
+ for j=1:n
+ if (vec(j)==1) then
+ generatedConnection = [generatedConnection ; [howclk i cap(j) 1]];
+ end
+ end
+ end
+ clkconnect = [clkconnect ; generatedConnection]
+ end
+
+ FIRING=[]
+ for i=1:size(allhowclk2,1)
+ j = find(clkconnect(:,3)==allhowclk2(i))
+ if j<>[] then
+ FIRING=[FIRING;bllst(clkconnect(j,1)).firing(clkconnect(j,2))]
+ end
+ end
+
+ Code_gene_run=[];
+
+ //** OLD GRAPHICS
+ //** %windo=xget('window')
+
+ cpr=c_pass2(bllst,connectmat,clkconnect,cor,corinv)
+
+ if cpr==list() then ok=%f,return, end
+
+ //** Alan's patch 5/07/07: try to solve
+ // which blocks use work
+ funs_save=cpr.sim.funs;
+ funtyp_save=cpr.sim.funtyp;
+ with_work = zeros(cpr.sim.nblk,1)
+ for i=1:lstsize(cpr.sim.funs)
+ if part(cpr.sim.funs(i),1:10)=="actionneur" then
+ cpr.sim.funs(i) ="bidon"
+ cpr.sim.funtyp(i) = 1
+ elseif part(cpr.sim.funs(i),1:7)=="capteur" then
+ cpr.sim.funs(i) ="bidon"
+ cpr.sim.funtyp(i) = 1
+ end
+ end
+
+ //**
+ //** retrieve all open Scilab windows with winsid()
+ //**
+
+ BeforeCG_WinList = winsid();
+
+ ierr=execstr("[state,t]=scicosim(cpr.state,0,0,cpr.sim,"+..
+ "''start'',scs_m.props.tol)","errcatch")
+ if ierr==0 then
+ for i=1:cpr.sim.nblk
+ if state.iz(i)<>0 then
+ with_work(i)=%t
+ end
+ end
+ ierr=execstr("[state,t]=scicosim(state,0,0,cpr.sim,"+..
+ "''finish'',scs_m.props.tol)","errcatch")
+ end
+
+ //**
+ //** retrieve all open Scilab windows with winsid
+ //** and close the additional windows open since first
+ //**
+
+ //** This code does not cover 100% of the possible situations because the user can
+ //** destroy one or more Scicos wins manually during this intermediate phase
+ //** This code is 100% functional if the user does not close manually any win.
+ //** TO BE updated in Scilab 5.0
+
+ AfterCG_WinList = winsid();
+
+ AfterCG_size = size(AfterCG_WinList); //** matrix
+ AfterCG_size = AfterCG_size(2) ; //** vector length
+
+ BeforeCG_size = size(BeforeCG_WinList); //** matrix
+ BeforeCG_size = BeforeCG_size(2) ; //** vector length
+
+ if (or(AfterCG_WinList<>BeforeCG_WinList)) & (AfterCG_size>BeforeCG_size) then
+ //** means that a scope or other scicos object has created some
+ //** output window
+
+ DiffCG_Winlist = AfterCG_WinList<>BeforeCG_WinList ; //** T/F mismatch
+ DiffCG_Index = find(DiffCG_Winlist); //** recover the mismatched indexes only
+
+ for win_idx = DiffCG_Index
+ delete( scf( AfterCG_WinList(win_idx) ) ) ; //** clear the spurious windows
+ end
+
+ end
+ //**------------- end of windows cleaning ----------------------------------------
+
+ cpr.sim.funs=funs_save;
+ cpr.sim.funtyp=funtyp_save;
+
+ //** OLD GRAPHICS
+ //** xset('window',%windo)
+
+ ///////////////////
+ //les pointeurs de cpr :
+ x=cpr.state.x;
+ z=cpr.state.z;
+ outtb=cpr.state.outtb;
+
+ //RN
+ zcptr=cpr.sim.zcptr;
+ ozptr=cpr.sim.ozptr;
+ rpptr=cpr.sim.rpptr;
+ ipptr=cpr.sim.ipptr;
+ opptr=cpr.sim.opptr;
+ funs=cpr.sim.funs;
+ xptr=cpr.sim.xptr;
+ zptr=cpr.sim.zptr;
+ inpptr=cpr.sim.inpptr;
+ inplnk=cpr.sim.inplnk;
+ outptr=cpr.sim.outptr;
+ outlnk=cpr.sim.outlnk;
+ //@l@n lnkptr=cpr.sim.lnkptr;
+ ordclk=cpr.sim.ordclk;
+ funtyp=cpr.sim.funtyp;
+ cord=cpr.sim.cord;
+ ncord=size(cord,1);
+ nblk=cpr.sim.nb;
+ ztyp=cpr.sim.ztyp;
+ clkptr=cpr.sim.clkptr
+ labels=cpr.sim.labels;
+ //taille totale de z : nztotal
+ nztotal=size(z,1);
+
+ //*******************************
+ //Checking if superblock is valid
+ //*******************************
+ msg=[]
+ for i=1:length(funs)-1
+ if funtyp(i)==3 then
+ msg=[msg;"Type 3 block''s not allowed"]
+ break;
+ end
+ if msg<>[] then message(msg),ok=%f,return,end
+ end
+
+ //********************************************************
+ // Change logical units for readf and writef blocks if any ???
+ //********************************************************
+ lunit=0
+ for d=1:length(funs)
+ if funs(d)=="readf" then
+ z(zptr(d)+2)=lunit
+ lunit=lunit+1;
+ elseif funs(d)=="writef"
+ z(zptr(d)+1)=lunit
+ lunit=lunit+1;
+ end
+ end
+
+ //***********************************
+ // Get the name of the file
+ //***********************************
+ foo=3;
+ okk=%f;
+ rdnom="foo";
+ rpat=pwd();
+ [x,ierr] = fileinfo(rpat);
+ S_IWRITE = 128; // mask write permission
+ if (ierr <> 0 | bitand(x(2), S_IWRITE) == 0) then
+ rpat = TMPDIR;
+ end
+
+ libs="";
+ label1=[hname;rpat+"/"+hname;""];
+
+ while %t do
+ ok=%t // to avoid infinite loop
+ [okk,..
+ rdnom,..
+ rpat,..
+ libs,..
+ label1]=scicos_getvalue("Set code generator parameters :",..
+ ["New block''s name :";
+ "Created files Path :";
+ "Other object files to link with (if any)"],..
+ list("str",1,"str",1,"str",1),label1);
+ if okk==%f then
+ ok=%f
+ return
+ end
+ rpat=stripblanks(rpat);
+
+ //** 1/07/06 Alan trying to solve multiple libraries during week-end
+ if strindex(libs,"''")<>[] | strindex(libs,"""")<>[] then
+ ierr=execstr("libs=evstr(libs)","errcatch")
+ if ierr<>0 then
+ message(["Can''t solve other files to link"])
+ ok=%f;
+ return
+ end
+ end
+
+ //** Alan, I put a warning here in order to inform the user
+ //** that the name of the superblock will change
+ //** because the space char in name isn't allowed.
+ if grep(rdnom," ")<>[] then
+ message(["Superblock name cannot contains space characters.";
+ "space chars will be automatically substituted by ""_"" "])
+ end
+ rdnom = strsubst(rdnom," ","_");
+
+ //** Put a warning here in order to inform the user
+ //** that the name of the superblock will change
+ //** because the "-" char could generate GCC problems
+ //** (the C functions contains the name of the superblock).
+ if grep(rdnom,"-")<>[] then
+ message(["For full C compiler compatibility ";
+ "Superblock name cannot contains ""-"" characters";
+ """-"" chars will be automatically substituted by ""_"" "])
+ end
+ rdnom = strsubst(rdnom,"-","_");
+
+ dirinfo=fileinfo(rpat)
+
+ if dirinfo==[] then
+ [pathrp,fnamerp,extensionrp]=fileparts(rpat)
+ ok=mkdir(pathrp,fnamerp+extensionrp)
+ if ~ok then
+ messagebox("Directory "+rpat+" cannot be created","modal","info");
+ end
+ elseif filetype(dirinfo(2))<>"Directory" then
+ ok=%f;
+ messagebox(rpat+" is not a directory","modal","error");
+ end
+
+ if stripblanks(rdnom)==emptystr() then
+ ok=%f;
+ messagebox("sorry C file name not defined","modal","error");
+ end
+ if ok then break,end
+ end
+
+ //////////////////////////////////////////////////
+ maxnrpar=max(rpptr(2:$)-rpptr(1:$-1))
+ maxnipar=max(ipptr(2:$)-ipptr(1:$-1))
+ maxnx=max(xptr(2:$)-xptr(1:$-1))
+ maxnz=max(zptr(2:$)-zptr(1:$-1))
+ maxnin=max(inpptr(2:$)-inpptr(1:$-1))
+ maxnout=max(outptr(2:$)-outptr(1:$-1))
+ maxdim=[];
+ for i=1:lstsize(cpr.state.outtb)
+ maxdim=max(size(cpr.state.outtb(i)))
+ end
+ maxtotal=max([maxnrpar;maxnipar;maxnx;maxnz;maxnin;maxnout;maxdim]);
+
+ //************************************************************************
+ //generate the call to the blocks and blocs simulation function prototypes
+ //************************************************************************
+ wfunclist=list();
+ nbcap=0;nbact=0;capt=[];actt=[];Protostalone=[];Protos=[];
+ dfuns=[]
+ for i=1:length(funs)
+ if or(i==act) then //block is an actuator
+ nbact=nbact+1;
+ [Code,actti,protoi]=call_actuator(i)
+ wfunclist($+1)=[Code;"if(flag < 0 ) return(5 - flag);"]
+ if nbact==1 then Protostalone=[Protostalone;"";protoi],end
+ actt=[actt;actti]
+ elseif or(i==cap) then //block is a sensor
+ nbcap=nbcap+1;
+ [Code,capti,protoi]=call_sensor(i)
+ wfunclist($+1)=[Code;"if(flag < 0 ) return(5 - flag);"]
+ if nbcap==1 then Protostalone=[Protostalone;"";protoi] ,end
+ capt=[capt;capti]
+ elseif funs(i)=="bidon"
+ wfunclist($+1)=" "
+ elseif funs(i)=="bidon2"
+ wfunclist($+1)=" "
+ else
+ ki=find(funs(i)==dfuns)
+ dfuns=[dfuns;funs(i)]
+ //[Code,protoi]=call_block(i)
+ [Code]=call_block4(i)
+ if Code<>[] then
+ wfunclist($+1)=[Code;"if(flag < 0 ) return(5 - flag);"]
+ else
+ wfunclist($+1)=" ";
+ end
+ if ki==[] then
+ Protos=[Protos;"";BlockProto(i)];
+ Protostalone=[Protostalone;"";BlockProto(i)];
+ end
+ end
+ end
+
+ //**************************************
+ //on prend en compte l'ordre des numerotation graphique des
+ //capteur et des actionneur
+ [junk,index]=gsort(-actt(:,$));
+ actt=actt(index,1:$) ;
+ [junk,index]=gsort(-capt(:,$));
+ capt=capt(index,1:$) ;
+
+ //***************************************************
+ //Compute the initial state and outtb (links) values
+ //***************************************************
+ //petite modification pour uniformiser les fichiers capteurs
+ //et actionneurs ???
+ rdcpr=cpr.sim.funs;
+ for r=1:length(cap),rdcpr(cap(r))="bidon";end
+ for r=1:length(act),rdcpr(act(r))="bidon";end
+ Total_rdcpr=cpr.sim;Total_rdcpr.funs=rdcpr;
+ //
+ tcur=0;
+ tf=scs_m.props.tf;
+ tolerances=scs_m.props.tol;
+ //[state,t]=scicosim(cpr.state,tcur,tf,Total_rdcpr,'start',tolerances);
+ //cpr.state=state;
+ z=cpr.state.z;
+ outtb=cpr.state.outtb;
+ //[junk_state,t]=scicosim(cpr.state,tcur,tf,Total_rdcpr,'finish',tolerances);
+
+ //***********************************
+ // Scilab and C files generation
+ //***********************************
+
+ //** generate scilab interfacing function
+ // of the generated scicos block
+ ok=gen_gui42();
+
+
+ //** generate C files
+ // of the generated scicos block
+ if ok then
+ ok=gen_ccode42()
+ end
+
+ //** Generates Makefile, loader
+ // and compile and link C files
+
+ //** def files to build
+ files=[rdnom rdnom+"_void_io" rdnom+"_Cblocks"]
+
+ //** def files to build for standalone
+ filestan=[rdnom+"_standalone" rdnom+"_act_sens_events" rdnom+"_Cblocks"]
+
+ if ok then
+ ok = buildnewblock(rdnom,files,filestan,rpat,libs,"","")
+ end
+
+ //**
+ //if ok then ok=gen_loader(),end
+
+ if ok then
+ //load the gui function
+ exec(rpat+"/"+rdnom+"_c.sci");
+ //Change diagram superblock to new generated block
+ XX=update_block(XX);
+ execstr(rdnom+"_c=resume("+rdnom+"_c)")
+ else
+ message([_("Generated block cannot be linked with Scilab.")])
+ end
+
+endfunction
+
+//BlockProto : generate prototype
+// of a scicos block
+//
+//inputs : bk : bloc index
+//
+//output : txt :
+//
+//16/06/07 Author : A.Layec
+function [txt]=BlockProto(bk)
+
+ nin=inpptr(bk+1)-inpptr(bk); //* number of input ports */
+ nout=outptr(bk+1)-outptr(bk); //* number of output ports */
+
+ //**
+ ftyp=funtyp(bk)
+ if ftyp>2000 then ftyp=ftyp-2000,end
+ if ftyp>1000 then ftyp=ftyp-1000,end
+
+ //** check function type
+ if ftyp < 0 then //** ifthenelse eselect blocks
+ txt = [];
+ return;
+ else
+ if (ftyp<>0 & ftyp<>1 & ftyp<>2 & ftyp<>3 & ftyp<>4) then
+ disp("types other than 0,1,2,3 or 4 are not yet supported.")
+ txt = [];
+ return;
+ end
+ end
+
+ //** add comment
+ txt=[get_comment("proto_blk",list(funs(bk),funtyp(bk),bk,labels(bk)));]
+
+ select ftyp
+ //** zero funtyp
+ case 0 then
+
+ //*********** prototype definition ***********//
+ txtp=["(int *, int *, double *, double *, double *, int *, double *, \";
+ " int *, double *, int *, double *, int *,int *, int *, \";
+ " double *, int *, double *, int *);"];
+ if (funtyp(bk)>2000 & funtyp(bk)<3000)
+ blank = get_blank("void "+funs(bk)+"(");
+ txtp(1) = "void "+funs(bk)+txtp(1);
+ elseif (funtyp(bk)<2000)
+ txtp(1) = "void C2F("+funs(bk)+")"+txtp(1);
+ blank = get_blank("void C2F("+funs(bk)+")");
+ end
+ txtp(2:$) = blank + txtp(2:$);
+ txt = [txt;txtp];
+ //*******************************************//
+
+
+ //**
+ case 1 then
+
+ //*********** prototype definition ***********//
+ txtp=["(int *, int *, double *, double *, double *, int *, double *, \";
+ " int *, double *, int *, double *, int *,int *, int *";]
+ if (funtyp(bk)>2000 & funtyp(bk)<3000)
+ blank = get_blank("void "+funs(bk)+"(");
+ txtp(1) = "void "+funs(bk)+txtp(1);
+ elseif (funtyp(bk)<2000)
+ txtp(1) = "void C2F("+funs(bk)+")"+txtp(1);
+ blank = get_blank("void C2F("+funs(bk)+")");
+ end
+ if nin>=1 | nout>=1 then
+ txtp($)=txtp($)+", \"
+ txtp=[txtp;""]
+ if nin>=1 then
+ for k=1:nin
+ txtp($)=txtp($)+" double *, int * ,"
+ end
+ txtp($)=part(txtp($),1:length(txtp($))-1); //remove last ,
+ end
+ if nout>=1 then
+ if nin>=1 then
+ txtp($)=txtp($)+", \"
+ txtp=[txtp;""]
+ end
+ for k=1:nout
+ txtp($)=txtp($)+" double *, int * ,"
+ end
+ txtp($)=part(txtp($),1:length(txtp($))-1); //remove last ,
+ end
+ end
+
+ if ztyp(bk) then
+ txtp($)=txtp($)+", \"
+ txtp=[txtp;" double *,int *);"];
+ else
+ txtp($)=txtp($)+");";
+ end
+
+ txtp(2:$) = blank + txtp(2:$);
+ txt = [txt;txtp];
+ //*******************************************//
+
+ //**
+ case 2 then
+
+ //*********** prototype definition ***********//
+
+ txtp=["void "+funs(bk)+...
+ "(int *, int *, double *, double *, double *, int *, double *, \";
+ " int *, double *, int *, double *, int *, int *, int *, \"
+ " double **, int *, int *, double **,int *, int *"];
+ if ~ztyp(bk) then
+ txtp($)=txtp($)+");";
+ else
+ txtp($)=txtp($)+", \";
+ txtp=[txtp;
+ " double *,int *);"]
+ end
+ blank = get_blank("void "+funs(bk));
+ txtp(2:$) = blank + txtp(2:$);
+ txt = [txt;txtp];
+ //********************************************//
+
+ //**
+ case 4 then
+ txt=[txt;
+ "void "+funs(bk)+"(scicos_block *, int );"];
+
+ end
+endfunction
+
+//Generating the routine for actuators interfacing
+//
+//
+//Authors : R. Djenid, R. Nikoukhah, A. Layec
+//
+//actt=[i uk nuk_1 nuk_2 uk_t bllst(i).ipar]
+function Code=make_actuator(standalone)
+ Call=["/*"
+ "** Generated by Code_Generation toolbox of Xcos with "+getversion()
+ "** Date : "+date()
+ "*/"
+ ""
+ "/*"+part("-",ones(1,40))+" Actuators */";
+ "void "+rdnom+"_actuator(int *flag, int *nport, int *nevprt, double *t, void *u, int *nu1, int *nu2, int *ut, int flag1)"]
+
+ comments=[" /*"
+ " * To be customized for standalone execution";
+ " * flag : specifies the action to be done"
+ " * nport : specifies the index of the Super Bloc"
+ " * regular input (The input ports are numbered"
+ " * from the top to the bottom )"
+ " * nevprt: indicates if an activation had been received"
+ " * 0 = no activation"
+ " * 1 = activation"
+ " * t : the current time value"
+ " * u : the vector inputs value"
+ " * nu1 : the input size 1"
+ " * nu2 : the input size 2"
+ " * ut : the input type"
+ " * flag1 : learn mode (0 from terminal,1 from input file"
+ " */"]
+
+ dcl=["{"
+ " int j,k,l;"];
+
+ if standalone then
+ a_actuator=[" /* skeleton to be customized */"
+ " switch (*flag) {"
+ " /* OutputUpdate (*flag==1) will be called on each iteration */"
+ " case 1 :"
+ " /*if(*nevprt>0) { get the input value */"
+ " switch (*ut) {"
+ " case 10 :"
+ " for (l=0;l<*nu2;l++) {"
+ " for (k=0;k<*nu1;k++) {"
+ " printf(""Actuator: time=%f, "+...
+ "u(%d,%d) of actuator %d is %f "+...
+ "\n"", \"
+ " *t, k, l, *nport,"+...
+ "*((double *) u+(k+l*(*nu1))));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 11 :"
+ " for (l=0;l<*nu2;l++) {"
+ " for (k=0;k<*nu1;k++) {"
+ " printf(""Actuator: time=%f, "+...
+ "u(%d,%d) of actuator %d is %f,%f "+...
+ "\n"", \"
+ " *t, k, l, *nport,"+...
+ "*((double *) u+(k+l*(*nu1))),"+...
+ "*((double *) u+((*nu1)*(*nu2)+k+l*(*nu1))));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 81 :"
+ " for (l=0;l<*nu2;l++) {"
+ " for (k=0;k<*nu1;k++) {"
+ " printf(""Actuator: time=%f, "+...
+ "u(%d,%d) of actuator %d is %i "+...
+ "\n"", \"
+ " *t, k, l, *nport,"+...
+ "*((char *) u+(k+l*(*nu1))));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 82 :"
+ " for (l=0;l<*nu2;l++) {"
+ " for (k=0;k<*nu1;k++) {"
+ " printf(""Actuator: time=%f, "+...
+ "u(%d,%d) of actuator %d is %hd "+...
+ "\n"", \"
+ " *t, k, l, *nport,"+...
+ "*((short *) u+(k+l*(*nu1))));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 84 :"
+ " for (l=0;l<*nu2;l++) {"
+ " for (k=0;k<*nu1;k++) {"
+ " printf(""Actuator: time=%f, "+...
+ "u(%d,%d) of actuator %d is %ld "+...
+ "\n"", \"
+ " *t, k, l, *nport,"+...
+ "*((long *) u+(k+l*(*nu1))));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 811 :"
+ " for (l=0;l<*nu2;l++) {"
+ " for (k=0;k<*nu1;k++) {"
+ " printf(""Actuator: time=%f, "+...
+ "u(%d,%d) of actuator %d is %d "+...
+ "\n"", \"
+ " *t, k, l, *nport,"+...
+ "*((unsigned char *) u+(k+l*(*nu1))));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 812 :"
+ " for (l=0;l<*nu2;l++) {"
+ " for (k=0;k<*nu1;k++) {"
+ " printf(""Actuator: time=%f, "+...
+ "u(%d,%d) of actuator %d is %hu "+...
+ "\n"", \"
+ " *t, k, l, *nport,"+...
+ "*((unsigned short *) u+(k+l*(*nu1))));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 814 :"
+ " for (l=0;l<*nu2;l++) {"
+ " for (k=0;k<*nu1;k++) {"
+ " printf(""Actuator: time=%f, "+...
+ "u(%d,%d) of actuator %d is %lu "+...
+ "\n"", \"
+ " *t, k, l, *nport,"+...
+ "*((unsigned long *) u+(k+l*(*nu1))));"
+ " }"
+ " }"
+ " break;"
+ " }"
+ " /*} */"
+ " break;"
+ " case 4 : /* actuator initialisation */"
+ " /* do whatever you want to initialize the actuator */"
+ " break;"
+ " case 5 : /* actuator ending */"
+ " /* do whatever you want to end the actuator */"
+ " break;"
+ " }"]
+ else
+ a_actuator=[]
+ end
+
+ // pour fprintf
+ nc=size(act,"*") // Alan : d'o? viens act ?????
+ // reponse : de do_compile_superblock!
+ typ=["""%f "]; //time
+ for i=1:nc
+ typ($)=typ($)+""" \"
+ typ=[typ;""""];
+ for j=1:sum(actt(i,3)*actt(i,4))
+ //typ=typ+'%f ';
+ typ($)=typ($)+scs_c_n2c_fmt(actt(i,5))+" ";
+ end
+ end
+ typ($)=typ($)+"\n"", \"
+ typ(1)=" fprintf(fprw,"+typ(1);
+ bl =" ";
+ if size(typ,1) <> 1 then
+ typ(2:$) = bl+typ(2:$);
+ end
+ //Code1=' fprintf(fprw, '"'+typ+' \n'",*t'
+ Code1=[typ;bl+"*t"];
+ //actt=[i uk nuk_1 nuk_2 uk_t bllst(i).ipar]
+ for i=1:size(actt,1)
+ ni=actt(i,3)*actt(i,4) // dimension of ith output
+ Code1($)=Code1($)+","
+ Code1=[Code1;bl];
+ for j=1:ni
+ if actt(i,5)<>11 then
+ Code1($)=Code1($)+...
+ "*((("+scs_c_n2c_typ(actt(i,5))+" *)("+...
+ rdnom+"_block_outtbptr+"+string(actt(i,2)-1)+"))"+...
+ "+"+string(j-1)+")";
+ else //CAS CMPLX
+ Code1($)=Code1($)+...
+ "*((("+scs_c_n2c_typ(actt(i,5))+" *)("+...
+ rdnom+"_block_outtbptr+"+string(actt(i,2)-1)+"))"+...
+ "+"+string((j-1))+"), "+...
+ "*((("+scs_c_n2c_typ(actt(i,5))+" *)("+...
+ rdnom+"_block_outtbptr+"+string(actt(i,2)-1)+"))"+...
+ "+"+string(ni+(j-1))+")";
+ end
+ if j<>ni then
+ Code1($)=Code1($)+", ";
+ end
+ end
+ end
+ Code1($)=Code1($)+");"
+
+ Code=[]
+
+ if nc==1|~standalone then
+ Code=[Call
+ comments
+ dcl
+ " if (flag1 == 0) {"
+ a_actuator
+ " }"
+ " else if (flag1 == 1) {"
+ " if (*flag == 4 && *nport == 1) {"
+ " fprw=fopen(output,'"wt'");"
+ " if( fprw == NULL )"
+ " {"
+ " printf('"Error opening file: %s\n'", output);"
+ " return;"
+ " }"
+ " }else if (*flag == 2 /* && *nevprt>0 */) {"
+ Code1
+ " }else if (*flag == 5 && *nport == 1) {"
+ " fclose(fprw);"
+ " }"
+ " }"
+ "}"]
+ elseif nc>1 then
+ S=" switch (*nport) {"
+ for k=1:nc
+ S=[S;
+ " case "+string(k)+" :/* Port number "+string(k)+" ----------*/"
+ " "+a_actuator
+ " break;"]
+ end
+ S=[S;" }"]
+
+ Code=[Code
+ Call
+ comments
+ dcl
+ " if (flag1 == 0){"
+ S
+ " }"
+ " else if (flag1 == 1) {"
+ " if (*flag == 4 && *nport == 1) {"
+ " fprw=fopen(output,'"wt'");"
+ " if( fprw == NULL ) {"
+ " printf('"Error opening file: %s\n'", output);"
+ " return;"
+ " }"
+ " }"
+ " else if (*flag == 2 /*&& *nevprt>0*/ ) {"
+ Code1
+ " }"
+ " else if (*flag == 5 && *nport == 1) {"
+ " fclose(fprw);"
+ " }"
+ " }"
+ "}"]
+ end
+endfunction
+
+//** Generates the scicos computational function
+// associated with the block
+//12/07/07 Alan Layec
+function make_computational42(filename)
+ z=cpr.state.z;
+ oz=cpr.state.oz;
+ outtb=cpr.state.outtb;
+ tevts=cpr.state.tevts;
+ evtspt=cpr.state.evtspt;
+ outptr=cpr.sim.outptr;
+ funtyp=cpr.sim.funtyp;
+ clkptr=cpr.sim.clkptr;
+ ordptr=cpr.sim.ordptr;
+ pointi=cpr.state.pointi;
+ ztyp=cpr.sim.ztyp;
+ zcptr=cpr.sim.zcptr;
+ zptr=cpr.sim.zptr;
+ ozptr=cpr.sim.ozptr;
+ opptr=cpr.sim.opptr;
+ opar=cpr.sim.opar;
+ rpptr=cpr.sim.rpptr;
+ ipptr=cpr.sim.ipptr;
+ inpptr=cpr.sim.inpptr;
+ funs=cpr.sim.funs;
+ xptr=cpr.sim.xptr;
+ modptr=cpr.sim.modptr;
+ inplnk=cpr.sim.inplnk;
+ nblk=cpr.sim.nb;
+ outlnk=cpr.sim.outlnk;
+ oord=cpr.sim.oord;
+ zord=cpr.sim.zord;
+ iord=cpr.sim.iord;
+ noord=size(cpr.sim.oord,1);
+ nzord=size(cpr.sim.zord,1);
+ niord=size(cpr.sim.iord,1);
+
+ Indent=" ";
+ Indent2=Indent+Indent;
+ BigIndent=" ";
+
+ nZ=size(z,"*"); //** index of work in z
+ nO=lstsize(oz); //** index of outtb in oz
+
+ stalone=%f
+
+ // Open file to write in
+ fd = mopen(filename, "wt");
+
+ mputl(["/*"
+ "** SCILAB Computational function"
+ "** Generated by Code_Generation toolbox of Xcos with "+getversion()
+ "** Date : "+date()
+ "*/"
+ ""
+ "/* ---- Headers ---- */"
+ "#include <stdio.h>"
+ "#include <stdlib.h>"
+ "#include <memory.h>"
+ "#include <string.h>"
+ "#include ""machine.h"" "
+ "#include ""scicos.h"" "
+ "#include ""scicos_malloc.h"" "
+ "#include ""scicos_free.h"" "
+ "#ifndef max"
+ "#define max(a,b) ((a) >= (b) ? (a) : (b))"
+ "#endif"
+ "#ifndef min"
+ "#define min(a,b) ((a) <= (b) ? (a) : (b))"
+ "#endif"], fd);
+
+ mputl([Protos ; ""], fd);
+
+ mputl(["/* Table of constant values */"
+ "static int nrd_"+string(0:maxtotal)'+" = "+string(0:maxtotal)'+";"], fd);
+
+ if maxtotal<10 then
+ mputl("static int nrd_10 = 10;", fd);
+ end
+ if maxtotal<11 then
+ mputl("static int nrd_11 = 11;", fd);
+ end
+
+ if maxtotal<81 then
+ mputl("static int nrd_81 = 81;", fd);
+ end
+ if maxtotal<82 then
+ mputl("static int nrd_82 = 82;", fd);
+ end
+ if maxtotal<84 then
+ mputl("static int nrd_84 = 84;", fd);
+ end
+ if maxtotal<811 then
+ mputl("static int nrd_811 = 811;", fd);
+ end
+ if maxtotal<812 then
+ mputl("static int nrd_812 = 812;", fd);
+ end
+ if maxtotal<814 then
+ mputl("static int nrd_814 = 814;", fd);
+ end
+
+ mputl([""
+ "/* Some general static variables */"
+ "static double zero=0;"
+ "static double w[1];"
+ "static int aaa=0, bbb=0;"], fd);
+
+ mputl([""
+ "/*"+part("-",ones(1,40))+" Block Computational function */ ";
+ "int "+rdnom+"(scicos_block *block, int flag)"
+ "{"
+ " /* declaration of local variables for that block struct */"
+ " double* z = block->z;"
+ " void **ozptr = block->ozptr;"
+ " void **oparptr = block->oparptr;"
+ " int nopar = block->nopar;"
+ " double* x = block->x;"
+ " double* xd = block->xd;"
+ " double* res = block->res;"
+ " void** u = block->inptr;"
+ " void** y = block->outptr;"
+ " int nevprt = block->nevprt;"
+ " double* rpar = block->rpar;"
+ " int nrpar = block->nrpar;"
+ " int* ipar = block->ipar;"
+ " int nipar = block->nipar;"
+ " double* g = block->g;"
+ " int* mode = block->mode;"
+ " void **work = block->work;"
+ ""
+ " double t = get_scicos_time();"
+ " int phase = get_phase_simulation();"
+ ""
+ " int kf = 0;"
+ " int i = 0;"
+ " int* reentryflag = NULL;"
+ ""
+ " double *args[100];"
+ " int local_flag;"
+ " int nport;"
+ " void **"+rdnom+"_block_outtbptr;"
+ " scicos_block *block_"+rdnom+";"
+ ""
+ " /* work of blocks are catenated at the end of z */"
+ " work = (void **)(z+"+string(nZ)+");"
+ ""
+ " /* "+rdnom+"_block_outtbptr is catenated at the end of oz */"
+ " "+rdnom+"_block_outtbptr = (void **)(ozptr+"+string(nO)+");"
+ ""
+ " /* struct of all blocks are stored in work of that block struct */"
+ " block_"+rdnom+"=(scicos_block*) *block->work;"
+ ""
+ " /* Copy inputs in the block outtb */"], fd);
+
+
+ for i=1:size(capt,1)
+ ni=capt(i,3)*capt(i,4); //** dimension of ith input
+ if capt(i,5)<>11 then
+ mputl([" memcpy(*("+rdnom+"_block_outtbptr+"+string(capt(i,2)-1)+"),"+...
+ "*(u+"+string(capt(i,6)-1)+"),"+...
+ string(ni)+"*sizeof("+mat2c_typ(capt(i,5))+"));"], fd);
+ else //** Cas cmplx
+ mputl([" memcpy(*("+rdnom+"_block_outtbptr+"+string(capt(i,2)-1)+"),"+...
+ "*(u+"+string(capt(i,6)-1)+"),"+...
+ string(2*ni)+"*sizeof("+mat2c_typ(capt(i,5))+"));"], fd);
+ end
+ end
+
+ mputl([""
+ " if (flag != 4 && flag != 6 && flag != 5){"
+ " reentryflag=(int*) ((scicos_block *)(*block->work)+"+string(nblk)+");"
+ " if (*reentryflag==0){"
+ " *reentryflag=1;"], fd);
+
+ for kf=1:nblk
+ nin=inpptr(kf+1)-inpptr(kf); //** number of input ports
+ nout=outptr(kf+1)-outptr(kf); //** number of output ports
+ nx=xptr(kf+1)-xptr(kf);
+ ng=zcptr(kf+1)-zcptr(kf);
+ nmode=modptr(kf+1)-modptr(kf);
+
+ //** add comment
+ mputl([""
+ " "+get_comment("set_blk",list(funs(kf),funtyp(kf),kf,labels(kf)));], fd);
+
+ for k=1:nin
+ lprt=inplnk(inpptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].inptr["+string(k-1)+"] = "+...
+ rdnom+"_block_outtbptr["+string(lprt-1)+"];"], fd);
+ end
+ for k=1:nout
+ lprt=outlnk(outptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].outptr["+string(k-1)+"] = "+...
+ rdnom+"_block_outtbptr["+string(lprt-1)+"];"], fd);
+ end
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].z = &(z["+...
+ string(zptr(kf)-1)+"]);"], fd);
+ if nx <> 0 then
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].x = &(x["+...
+ string(xptr(kf)-1)+"]);"], fd);
+ else
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].x = &(zero);"
+ " block_"+rdnom+"["+string(kf-1)+"].xd = w;"], fd);
+ end
+ if ng <> 0 then
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].g = &(g["+...
+ string(zcptr(kf)-1)+"]);"], fd);
+ else
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].g = &(zero);";], fd);
+ end
+ if nmode <> 0 then
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].mode = &(mode["+...
+ string(modptr(kf)-1)+"]);"], fd);
+ end
+ if (part(funs(kf),1:7) ~= "capteur" &...
+ part(funs(kf),1:10) ~= "actionneur" &...
+ funs(kf) ~= "bidon" &...
+ funs(kf) ~= "bidon2") then
+ //** rpar **//
+ if (rpptr(kf+1)-rpptr(kf)>0) then
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].rpar = &(rpar["+...
+ string(rpptr(kf)-1)+"]);"], fd);
+ end
+ //** ipar **//
+ if (ipptr(kf+1)-ipptr(kf)>0) then
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].ipar = &(ipar["+...
+ string(ipptr(kf)-1)+"]);"], fd);
+ end
+ //** opar **//
+ if (opptr(kf+1)-opptr(kf)>0) then
+ nopar = opptr(kf+1)-opptr(kf);
+ for k=1:nopar
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].oparptr["+string(k-1)+...
+ "] = oparptr["+string(opptr(kf)-1+k-1)+"];"], fd);
+ end
+ end
+ //** oz **//
+ if (ozptr(kf+1)-ozptr(kf)>0) then
+ noz = ozptr(kf+1)-ozptr(kf);
+ for k=1:noz
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].ozptr["+string(k-1)+...
+ "] = ozptr["+string(ozptr(kf)-1+k-1)+"];"], fd);
+ end
+ end
+ end
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].work ="+...
+ " (void **)(((double *)work)+"+string(kf-1)+");"], fd);
+ end
+
+ mputl([" }"
+ " }"
+ ""
+ ], fd);
+
+ /////////////////////////////////////////////
+
+
+ //** find activation number
+ blks=find(funtyp>-1);
+ evs=[];
+
+ for blk=blks
+ for ev=clkptr(blk):clkptr(blk+1)-1
+ if funs(blk)=="bidon" then
+ if ev > clkptr(howclk) -1
+ evs=[evs,ev];
+ end
+ end
+ end
+ end
+
+ //** flag 0
+ flag = 0;
+
+ block_has_output=%f
+ txt = [];
+ txt22 = [];
+
+ for kf=1:nblk
+ nx=xptr(kf+1)-xptr(kf);
+ if nx <> 0 then
+ txt=[txt;
+ " block_"+rdnom+"["+string(kf-1)+"].xd=&(xd["+...
+ string(xptr(kf)-1)+"]);"]
+ end
+ if part(funs(kf),1:10) == "actionneur" then
+ block_has_output=%t
+ end
+ end
+ if txt<>[] then
+ txt22=[txt22;
+ " "+get_comment("update_xd",list())
+ txt
+ ""
+ ]
+ end
+ txt22=[txt22;
+ write_code_odoit(1) //** first pass
+ write_code_odoit(0) //** second pass
+ ]
+
+ if txt22<>[] then
+ mputl([" if (flag == 0) { "+get_comment("flag",list(flag))
+ txt22
+ " }"], fd);
+ end
+
+ //** flag 1,2,3
+ for flag=[1,2,3]
+
+ txt3=[]
+
+ //** continuous time blocks must be activated
+ //** for flag 1
+ if flag==1 then
+ txt = write_code_cdoit(flag);
+
+ if txt <> [] then
+ txt3=[txt3;
+ Indent+" switch (nevprt) {"
+ ];
+ txt3=[txt3;
+ Indent2+" case "+string(0)+" : "+...
+ get_comment("ev",list(0))
+ " "+txt;
+ ];
+ txt3=[txt3;" break;";""]
+ end
+ else
+ txt=[];
+ end
+
+ //** blocks with input discrete event must be activated
+ //** for flag 1, 2 and 3
+ if size(evs,2)>=1 then
+ txt4=[]
+ //**
+ for ev=evs
+ txt2=write_code_doit(ev,flag);
+ if txt2<>[] then
+ //** adjust event number because of bidon block
+ new_ev=ev-(clkptr(howclk)-1)
+ //**
+ txt4=[txt4;
+ Indent2+[" case "+string(new_ev)+" : "+...
+ get_comment("ev",list(new_ev))
+ txt2];
+ " break;";""]
+ end
+ end
+
+ //**
+ if txt == [] then
+ if txt4 <> [] then
+ txt3=[txt3;
+ Indent+" switch (nevprt) {"
+ txt4
+ " }"];
+ end
+ else
+ txt3=[txt3;
+ txt4]
+ end
+ end
+
+ //**
+ if txt <> [] then
+ txt3=[txt3;
+ " }"];
+ end
+
+ //**
+ if txt3<>[] then
+ if flag==1 & txt22==[] then
+ mputl([" if (flag == "+string(flag)+") { "+...
+ get_comment("flag",list(flag))
+ txt3
+ " }"], fd);
+ else
+ mputl([" else if (flag == "+string(flag)+") { "+...
+ get_comment("flag",list(flag))
+ txt3
+ " }"], fd);
+ end
+ end
+ end
+
+ //** flag 9
+ ng=zcptr($)-1;
+ if (ng ~= 0) then
+ flag = 9;
+ mputl([" else if (flag == "+string(flag)+") { "+...
+ get_comment("flag",list(flag))], fd);
+
+ txt=[]
+ for kf=1:nblk
+ if zcptr(kf+1)-zcptr(kf) <> 0 then
+ txt=[txt;
+ " block_"+rdnom+"["+string(kf-1)+"].g="+...
+ "&(g["+string(zcptr(kf)-1)+"]);"]
+ end
+ end
+
+ mputl([" "+get_comment("update_g",list())
+ txt
+ ""
+ write_code_zdoit()
+ ], fd);
+
+ mputl([" }"], fd);
+ end
+
+ //** flag 4
+ mputl([" else if (flag == 4) { "+get_comment("flag",list(4))
+ " if ((*block->work=scicos_malloc(sizeof(scicos_block)*"+...
+ string(nblk)+"+sizeof(int)))== NULL) return 0;";
+ " reentryflag=(int*) ((scicos_block *)(*block->work)+"+string(nblk)+");"
+ " *reentryflag=0;"
+ " block_"+rdnom+"=(scicos_block*) *block->work;"], fd);
+
+ for kf=1:nblk
+ nin=inpptr(kf+1)-inpptr(kf); //* number of input ports */
+ nout=outptr(kf+1)-outptr(kf); //* number of output ports */
+ nx=xptr(kf+1)-xptr(kf);
+ ng=zcptr(kf+1)-zcptr(kf);
+ nmode=modptr(kf+1)-modptr(kf);
+
+ //** add comment
+ mputl([""
+ " "+get_comment("set_blk",list(funs(kf),funtyp(kf),kf,labels(kf)));], fd);
+
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].type = "+...
+ string(funtyp(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].ztyp = "+...
+ string(ztyp(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].ng = "+...
+ string(zcptr(kf+1)-zcptr(kf))+";"], fd);
+
+ if nx <> 0 then
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].nx = "+...
+ string(nx)+";";
+ " block_"+rdnom+"["+string(kf-1)+"].x = &(x["+...
+ string(xptr(kf)-1)+"]);"], fd);
+ else
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].nx = 0;";
+ " block_"+rdnom+"["+string(kf-1)+"].x = &(zero);"
+ " block_"+rdnom+"["+string(kf-1)+"].xd = w;"], fd);
+ end
+
+ if ng <> 0 then
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].g = &(g["+...
+ string(zcptr(kf)-1)+"]);"], fd);
+ else
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].g = &(zero);";], fd);
+ end
+ if nmode <> 0 then
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].mode = &(mode["+...
+ string(modptr(kf)-1)+"]);"], fd);
+ end
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].nz = "+...
+ string(zptr(kf+1)-zptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].noz = "+...
+ string(ozptr(kf+1)-ozptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].nrpar = "+...
+ string(rpptr(kf+1)-rpptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].nopar = "+...
+ string(opptr(kf+1)-opptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].nipar = "+...
+ string(ipptr(kf+1)-ipptr(kf))+";"
+ " block_"+rdnom+"["+string(kf-1)+"].nin = "+...
+ string(inpptr(kf+1)-inpptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].nout = "+...
+ string(outptr(kf+1)-outptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].nevout = "+...
+ string(clkptr(kf+1)-clkptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].nmode = "+...
+ string(modptr(kf+1)-modptr(kf))+";"], fd);
+
+ mputl([" if ((block_"+rdnom+"["+string(kf-1)+"].evout = "+...
+ "calloc(block_"+rdnom+"["+string(kf-1)+"].nevout,sizeof(double)))== NULL) return 0;"], fd);
+
+ //***************************** input port *****************************//
+ //** alloc insz/inptr **//
+ mputl([" if ((block_"+rdnom+"["+string(kf-1)+"].insz = "+...
+ "malloc(3*sizeof(int)*block_"+rdnom+"["+string(kf-1)+"].nin))== NULL) return 0;";
+ " if ((block_"+rdnom+"["+string(kf-1)+"].inptr = "+...
+ "malloc(sizeof(void *)*block_"+rdnom+"["+string(kf-1)+"].nin))== NULL) return 0;"], fd);
+
+ //** inptr **//
+ for k=1:nin
+ lprt=inplnk(inpptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].inptr["+string(k-1)+"] = "+...
+ rdnom+"_block_outtbptr["+string(lprt-1)+"];"], fd);
+ end
+
+ //** 1st dim **//
+ for k=1:nin
+ lprt=inplnk(inpptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].insz["+string((k-1))+"] = "+...
+ string(size(outtb(lprt),1))+";"], fd);
+ end
+
+ //** 2dn dim **//
+ for k=1:nin
+ lprt=inplnk(inpptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].insz["+string((k-1)+nin)+"] = "+...
+ string(size(outtb(lprt),2))+";"], fd);
+ end
+
+ //** typ **//
+ for k=1:nin
+ lprt=inplnk(inpptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].insz["+string((k-1)+2*nin)+"] = "+...
+ mat2scs_c_typ(outtb(lprt))+";"], fd);
+ end
+ //**********************************************************************//
+
+ //***************************** output port *****************************//
+ //** alloc outsz/outptr **//
+ mputl([" if ((block_"+rdnom+"["+string(kf-1)+"].outsz = "+...
+ "malloc(3*sizeof(int)*block_"+rdnom+"["+string(kf-1)+"].nout))== NULL) return 0;";
+ " if ((block_"+rdnom+"["+string(kf-1)+"].outptr = "+...
+ "malloc(sizeof(void*)*block_"+rdnom+"["+string(kf-1)+"].nout))== NULL) return 0;"], fd);
+
+ //** outptr **//
+ for k=1:nout
+ lprt=outlnk(outptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].outptr["+string(k-1)+"] = "+...
+ rdnom+"_block_outtbptr["+string(lprt-1)+"];"], fd);
+ end
+
+ //** 1st dim **//
+ for k=1:nout
+ lprt=outlnk(outptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].outsz["+string((k-1))+...
+ "] = "+string(size(outtb(lprt),1))+";"], fd);
+ end
+
+ //** 2dn dim **//
+ for k=1:nout
+ lprt=outlnk(outptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].outsz["+string((k-1)+nout)+...
+ "] = "+string(size(outtb(lprt),2))+";"], fd)
+ end
+
+ //** typ **//
+ for k=1:nout
+ lprt=outlnk(outptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].outsz["+string((k-1)+2*nout)+...
+ "] = "+mat2scs_c_typ(outtb(lprt))+";"], fd);
+ end
+ //**********************************************************************//
+
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].z = &(z["+...
+ string(zptr(kf)-1)+"]);"], fd);
+
+ //***************************** object state *****************************//
+ if (ozptr(kf+1)-ozptr(kf)>0) then
+ noz = ozptr(kf+1)-ozptr(kf);
+ mputl([" if ((block_"+rdnom+"["+string(kf-1)+"].ozptr = "+...
+ "malloc(sizeof(void *)*block_"+rdnom+"["+string(kf-1)+"].noz))== NULL) return 0;";
+ " if ((block_"+rdnom+"["+string(kf-1)+"].ozsz = "+...
+ "malloc(2*sizeof(int)*block_"+rdnom+"["+string(kf-1)+"].noz))== NULL) return 0;";
+ " if ((block_"+rdnom+"["+string(kf-1)+"].oztyp = "+...
+ "malloc(sizeof(int)*block_"+rdnom+"["+string(kf-1)+"].noz))== NULL) return 0;";], fd);
+
+ //** ozptr **//
+ for k=1:noz
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].ozptr["+string(k-1)+...
+ "] = ozptr["+string(ozptr(kf)-1+k-1)+"];"], fd);
+ end
+
+ //** 1st dim **//
+ for k=1:noz
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].ozsz["+string(k-1)+...
+ "] = "+string(size(oz(ozptr(kf)-1+k),1))+";"], fd);
+ end
+
+ //** 2nd dim **//
+ for k=1:noz
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].ozsz["+string(k-1)+...
+ "] = "+string(size(oz(ozptr(kf)-1+k),2))+";"], fd);
+ end
+
+ //** typ **//
+ for k=1:noz
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].oztyp["+string(k-1)+...
+ "] = "+mat2scs_c_typ(oz(ozptr(kf)-1+k))+";"], fd);
+ end
+ end
+ //************************************************************************//
+
+ if (part(funs(kf),1:7) ~= "capteur" &...
+ part(funs(kf),1:10) ~= "actionneur" &...
+ funs(kf) ~= "bidon" &...
+ funs(kf) ~= "bidon2") then
+ if (rpptr(kf+1)-rpptr(kf)>0) then
+ mputl([" block_"+rdnom+"["+string(kf-1)+...
+ "].rpar = &(rpar["+string(rpptr(kf)-1)+"]);"], fd);
+ end
+ if (ipptr(kf+1)-ipptr(kf)>0) then
+ mputl([" block_"+rdnom+"["+string(kf-1)+...
+ "].ipar = &(ipar["+string(ipptr(kf)-1)+"]);"], fd);
+ end
+ //** opar
+ if (opptr(kf+1)-opptr(kf)>0) then
+ mputl([" if ((block_"+rdnom+"["+string(kf-1)+"].oparptr = "+...
+ "malloc(sizeof(void *)*block_"+rdnom+"["+string(kf-1)+"].nopar))== NULL) return 0;";
+ " if ((block_"+rdnom+"["+string(kf-1)+"].oparsz = "+...
+ "malloc(2*sizeof(int)*block_"+rdnom+"["+string(kf-1)+"].nopar))== NULL) return 0;";
+ " if ((block_"+rdnom+"["+string(kf-1)+"].opartyp = "+...
+ "malloc(sizeof(int)*block_"+rdnom+"["+string(kf-1)+"].nopar))== NULL) return 0;";
+ ], fd);
+ nopar = opptr(kf+1)-opptr(kf);
+ //** oparptr **//
+ for k=1:nopar
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].oparptr["+string(k-1)+...
+ "] = oparptr["+string(opptr(kf)-1+k-1)+"];"], fd);
+ end
+ //** 1st dim **//
+ for k=1:nopar
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].oparsz["+string(k-1)+...
+ "] = "+string(size(opar(opptr(kf)-1+k),1))+";"], fd);
+ end
+ //** 2dn dim **//
+ for k=1:nopar
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].oparsz["+string(nopar+(k-1))+...
+ "] = "+string(size(opar(opptr(kf)-1+k),2))+";"], fd)
+ end
+ //** typ **//
+ for k=1:nopar
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].opartyp["+string(k-1)+...
+ "] = "+mat2scs_c_typ(opar(opptr(kf)-1+k))+";"], fd)
+ end
+ end
+ end
+
+ mputl([" block_"+rdnom+"["+string(kf-1)+...
+ "].work = (void **)(((double *)work)+"+string(kf-1)+");"
+ " block_"+rdnom+"["+string(kf-1)+...
+ "].nevprt = nevprt;"], fd);
+
+ end //for kf=1:nblk
+
+ //** init
+ for kf=1:nblk
+ // if or(kf==act) | or(kf==cap) then
+ // if stalone then
+ // txt = call_block42(kf,0,4);
+ // if txt <> [] then
+ // Code=[Code;
+ // '';
+ // ' '+txt];
+ // end
+ // end
+ // else
+ txt = call_block42(kf,0,4);
+ if txt <> [] then
+ mputl(["";
+ " "+txt], fd);
+ end
+ // end
+ end
+
+ //** cst blocks and it's dep
+ txt=write_code_idoit()
+
+ if txt<>[] then
+ mputl([""
+ " /* initial blocks must be called with flag 1 */"
+ txt], fd);
+ end
+ // for kf=iord(:,1)'
+ // // if or(kf==act) then
+ // // if stalone then
+ // // txt = call_block42(kf,0,1);
+ // // if txt <> [] then
+ // // Code=[Code;
+ // // '';
+ // // ' '+txt];
+ // // end
+ // // end
+ // // else
+ // txt = call_block42(kf,0,1);
+ // if txt <> [] then
+ // Code=[Code;
+ // '';
+ // ' '+txt];
+ // end
+ // // end
+ // end
+
+ mputl([" }"], fd);
+
+ //** flag 5
+ mputl([" else if (flag == 5) { "+get_comment("flag",list(5))
+ " block_"+rdnom+"=*block->work;"], fd);
+
+ for kf=1:nblk
+ nin=inpptr(kf+1)-inpptr(kf); //* number of input ports */
+ nout=outptr(kf+1)-outptr(kf); //* number of output ports */
+
+ //** add comment
+ txt=mputl([""
+ " "+get_comment("set_blk",list(funs(kf),funtyp(kf),kf,labels(kf)));], fd);
+
+ for k=1:nin
+ lprt=inplnk(inpptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].inptr["+string(k-1)+...
+ "] = "+rdnom+"_block_outtbptr["+string(lprt-1)+"];"], fd);
+ end
+ for k=1:nout
+ lprt=outlnk(outptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].outptr["+string(k-1)+...
+ "] = "+rdnom+"_block_outtbptr["+string(lprt-1)+"];"], fd);
+ end
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].z=&(z["+...
+ string(zptr(kf)-1)+"]);"], fd);
+ if (part(funs(kf),1:7) ~= "capteur" &...
+ part(funs(kf),1:10) ~= "actionneur" &...
+ funs(kf) ~= "bidon" &...
+ funs(kf) ~= "bidon2") then
+ //** rpar **//
+ if (rpptr(kf+1)-rpptr(kf)>0) then
+ mputl([" block_"+rdnom+"["+string(kf-1)+...
+ "].rpar=&(rpar["+string(rpptr(kf)-1)+"]);"], fd);
+ end
+ //** ipar **//
+ if (ipptr(kf+1)-ipptr(kf)>0) then
+ mputl([" block_"+rdnom+"["+string(kf-1)+...
+ "].ipar=&(ipar["+string(ipptr(kf)-1)+"]);"], fd);
+ end
+ //** opar **//
+ if (opptr(kf+1)-opptr(kf)>0) then
+ nopar = opptr(kf+1)-opptr(kf);
+ for k=1:nopar
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].oparptr["+string(k-1)+...
+ "] = oparptr["+string(opptr(kf)-1+k-1)+"];"], fd);
+ end
+ end
+ //** oz **//
+ if (ozptr(kf+1)-ozptr(kf)>0) then
+ noz = ozptr(kf+1)-ozptr(kf);
+ for k=1:noz
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].ozptr["+string(k-1)+...
+ "] = ozptr["+string(ozptr(kf)-1+k-1)+"];"], fd);
+ end
+ end
+ end
+
+ mputl([" block_"+rdnom+"["+string(kf-1)+...
+ "].work=(void **)(((double *)work)+"+string(kf-1)+");"], fd)
+ end
+
+ for kf=1:nblk
+ // if or(kf==act) | or(kf==cap) then
+ // if stalone then
+ // txt = call_block42(kf,0,5);
+ // if txt <> [] then
+ // Code=[Code;
+ // '';
+ // ' '+txt];
+ // end
+ // end
+ // else
+ txt = call_block42(kf,0,5);
+ if txt <> [] then
+ mputl(["";
+ " "+txt], fd);
+ end
+ // end
+ end
+
+ mputl([""
+ " for (kf = 0; kf < "+string(nblk)+"; ++kf) {"
+ " if (block_"+rdnom+"[kf].insz!=NULL) {"
+ " free(block_"+rdnom+"[kf].insz);"
+ " }else {"
+ " break;"
+ " }"
+ " if (block_"+rdnom+"[kf].outsz!=NULL){"
+ " free(block_"+rdnom+"[kf].outsz);"
+ " }else {"
+ " break;"
+ " }"
+ " if (block_"+rdnom+"[kf].nopar!=0){"
+ " if (block_"+rdnom+"[kf].oparptr!=NULL){"
+ " free(block_"+rdnom+"[kf].oparptr);"
+ " }else {"
+ " break;"
+ " }"
+ " if (block_"+rdnom+"[kf].oparsz!=NULL){"
+ " free(block_"+rdnom+"[kf].oparsz);"
+ " }else {"
+ " break;"
+ " }"
+ " if (block_"+rdnom+"[kf].opartyp!=NULL){"
+ " free(block_"+rdnom+"[kf].opartyp);"
+ " }else {"
+ " break;"
+ " }"
+ " }"
+ " if (block_"+rdnom+"[kf].noz!=0){"
+ " if (block_"+rdnom+"[kf].ozptr!=NULL){"
+ " free(block_"+rdnom+"[kf].ozptr);"
+ " }else {"
+ " break;"
+ " }"
+ " if (block_"+rdnom+"[kf].ozsz!=NULL){"
+ " free(block_"+rdnom+"[kf].ozsz);"
+ " }else {"
+ " break;"
+ " }"
+ " if (block_"+rdnom+"[kf].oztyp!=NULL){"
+ " free(block_"+rdnom+"[kf].oztyp);"
+ " }else {"
+ " break;"
+ " }"
+ " }"
+ " if (block_"+rdnom+"[kf].evout!=NULL){"
+ " free(block_"+rdnom+"[kf].evout);"
+ " }else {"
+ " break;"
+ " }"
+ " }"
+ " scicos_free(block_"+rdnom+");"
+ " }"
+ ""], fd);
+
+ for i=1:size(actt,1)
+ ni=actt(i,3)*actt(i,4); // dimension of ith input
+ if actt(i,5)<>11 then
+ mputl([" memcpy(*(y+"+string(actt(i,6)-1)+"),"+...
+ "*("+rdnom+"_block_outtbptr+"+string(actt(i,2)-1)+"),"+...
+ string(ni)+"*sizeof("+mat2c_typ(actt(i,5))+"));"], fd);
+ else //** Cas cmplx
+ mputl([" memcpy(*(y+"+string(actt(i,6)-1)+"),"+...
+ "*("+rdnom+"_block_outtbptr+"+string(actt(i,2)-1)+"),"+...
+ string(2*ni)+"*sizeof("+mat2c_typ(actt(i,5))+"));"], fd);
+ end
+ end
+
+ //**
+ mputl([" return 0;"
+ ""
+ "} /* "+rdnom+" */"], fd);
+
+ mclose(fd);
+
+endfunction
+
+//generates skeleton of external world events handling function
+function Code=make_outevents()
+ z="0"
+ if szclkIN==[] then
+ newszclkIN=0;
+ else
+ newszclkIN=szclkIN;
+ end
+
+ Code=[ "/*"+part("-",ones(1,40))+" External events handling function */";
+ "void "+rdnom+"_events(int *nevprt,double *t)";
+ "{"
+ "/* set next event time and associated events ports"
+ " * nevprt has binary expression b1..b"+string(newszclkIN)+" where bi is a bit"
+ " * bi is set to 1 if an activation is received by port i. Note that"
+ " * more than one activation can be received simultaneously"
+ " * Caution: at least one bi should be equal to one */"
+ ""]
+
+ if (newszclkIN <> 0) then
+ Code=[Code;
+ " int i,p,b[]={"+strcat(z(ones(1,newszclkIN)),",")+"};"
+ ""
+ "/* this is an example for the activation of events ports */"
+ " b[0]=1;"]
+
+ if newszclkIN>1 then
+ for bb=2:newszclkIN
+ Code($+1)=" b["+string(bb-1)+"]=1;"
+ end
+ end
+
+ Code=[Code;
+ ""
+ "/* definition of the step time */"
+ " *t = *t + 0.1;"
+ ""
+ "/* External events handling process */"
+ " *nevprt=0;p=1;"
+ " for (i=0;i<"+string(newszclkIN)+";i++) {"
+ " *nevprt=*nevprt+b[i]*p;"
+ " p=p*2;"
+ " }"
+ "}"]
+ else
+ Code=[Code;
+ "";
+ "/* definition of the step time */"
+ " *t = *t + 0.1;"
+ "}"]
+ end
+endfunction
+
+//Generating the routine for sensors interfacing
+//
+//
+//Author : R. Djenidi, R. Nikoukhah, A. Layec
+//
+function Code=make_sensor(standalone)
+ Call=["/*"+part("-",ones(1,40))+" Sensor */";
+ "void "+rdnom+"_sensor(int *flag, int *nport, int *nevprt, double *t, void *y, int *ny1, int *ny2, int *yt, int *flag1)"]
+
+ comments=[" /*"
+ " * To be customized for standalone execution";
+ " * flag : specifies the action to be done"
+ " * nport : specifies the index of the Super Bloc"
+ " * regular input (The input ports are numbered"
+ " * from the top to the bottom )"
+ " * nevprt: indicates if an activation had been received"
+ " * 0 = no activation"
+ " * 1 = activation"
+ " * t : the current time value"
+ " * y : the vector outputs value"
+ " * ny1 : the output size 1"
+ " * ny2 : the output size 2"
+ " * yt : the output type"
+ " * flag1 : learn mode (0 from terminal,1 from input file"
+ " */"]
+
+ dcl=["{"
+ " int j,k,l;"
+ " double temps;"]
+
+ if standalone then
+
+ a_sensor=[" switch (*flag) {"
+ " case 1 : /* set the output value */"
+ " printf(""Require outputs of sensor number %d\n"", *nport);"
+ " printf(""time is: %f\n"", *t);"
+ " printf(""sizes of the sensor output is: %d,%d\n"", *ny1,*ny2);"
+ " switch (*yt) {"
+ " case 10 :"
+ " printf(""type of the sensor output is: %d (double) \n"", *yt);"
+ " puts(""Please set the sensor output values"");"
+ " for (l=0;l<*ny2;l++) {"
+ " for (k=0;k<*ny1;k++) {"
+ " printf(""y(%d,%d) : "",k,l);"
+ " scanf(""%lf"", (double *) y+(k+l*(*ny1)));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 11 :"
+ " printf(""type of the sensor output is: %d (complex) \n"", *yt);"
+ " puts(""Please set the sensor output values"");"
+ " for (l=0;l<*ny2;l++) {"
+ " for (k=0;k<*ny1;k++) {"
+ " printf(""y(%d,%d) real part : "",k,l);"
+ " scanf(""%lf"", (double *) y+(k+l*(*ny1)));"
+ " printf(""y(%d,%d) imag part : "",k,l);"
+ " scanf(""%lf"", (double *) y+((*ny1)*(*ny2)+k+l*(*ny1)));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 81 :"
+ " printf(""type of the sensor output is: %d (char) \n"", *yt);"
+ " puts(""Please set the sensor output values"");"
+ " for (l=0;l<*ny2;l++) {"
+ " for (k=0;k<*ny1;k++) {"
+ " printf(""y(%d,%d) : "",k,l);"
+ " scanf(""%i"", (char *) y+(k+l*(*ny1)));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 82 :"
+ " printf(""type of the sensor output is: %d (char) \n"", *yt);"
+ " puts(""Please set the sensor output values"");"
+ " for (l=0;l<*ny2;l++) {"
+ " for (k=0;k<*ny1;k++) {"
+ " printf(""y(%d,%d) : "",k,l);"
+ " scanf(""%hd"", (short *) y+(k+l*(*ny1)));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 84 :"
+ " printf(""type of the sensor output is: %d (long) \n"", *yt);"
+ " puts(""Please set the sensor output values"");"
+ " for (l=0;l<*ny2;l++) {"
+ " for (k=0;k<*ny1;k++) {"
+ " printf(""y(%d,%d) : "",k,l);"
+ " scanf(""%ld"", (long *) y+(k+l*(*ny1)));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 811 :"
+ " printf(""type of the sensor output is: %d (unsigned char) \n"", *yt);"
+ " puts(""Please set the sensor output values"");"
+ " for (l=0;l<*ny2;l++) {"
+ " for (k=0;k<*ny1;k++) {"
+ " printf(""y(%d,%d) : "",k,l);"
+ " scanf(""%d"", (unsigned char *) y+(k+l*(*ny1)));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 812 :"
+ " printf(""type of the sensor output is: %d (unsigned short) \n"", *yt);"
+ " puts(""Please set the sensor output values"");"
+ " for (l=0;l<*ny2;l++) {"
+ " for (k=0;k<*ny1;k++) {"
+ " printf(""y(%d,%d) : "",k,l);"
+ " scanf(""%hu"", (unsigned short *) y+(k+l*(*ny1)));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " case 814 :"
+ " printf(""type of the sensor output is: %d (unsigned long) \n"", *yt);"
+ " puts(""Please set the sensor output values"");"
+ " for (l=0;l<*ny2;l++) {"
+ " for (k=0;k<*ny1;k++) {"
+ " printf(""y(%d,%d) : "",k,l);"
+ " scanf(""%lu"", (unsigned long *) y+(k+l*(*ny1)));"
+ " }"
+ " }"
+ " break;"
+ ""
+ " }"
+ " break;"
+ " case 4 : /* sensor initialisation */"
+ " /* do whatever you want to initialize the sensor */"
+ " break;"
+ " case 5 : /* sensor ending */"
+ " /* do whatever you want to end the sensor */"
+ " break;"
+ " }"]
+ else
+ a_sensor=[]
+ end
+
+ nc=size(cap,"*")
+
+ // pour fscanf
+ typ=["""%lf "]; //temps
+ for i=1:nc
+ typ($)=typ($)+""" \"
+ typ=[typ;""""];
+ for j=1:sum(capt(i,3)*capt(i,4))
+ //typ=typ+'%f ';
+ typ($)=typ($)+scs_c_n2c_fmt(capt(i,5))+" ";
+ end
+ end
+ typ($)=typ($)+"\n"", \"
+ typ=strsubst(typ,"%f","%lf");
+ typ(1)=" fscanf(fprr,"+typ(1);
+ bl =" ";
+ if size(typ,1) <> 1 then
+ typ(2:$) = bl+typ(2:$);
+ end
+ //Code1=[' fscanf( fprr, '"'+typ+' \n'",&temps']
+ Code1=[typ;bl+"&temps"];
+ for i=1:size(capt,1)
+ ni=capt(i,3)*capt(i,4); // dimension of ith input
+ Code1($)=Code1($)+",";
+ Code1=[Code1;bl];
+ for j=1:ni
+ if capt(i,5)<>11 then
+ Code1($)=Code1($)+...
+ "("+scs_c_n2c_typ(capt(i,5))+" *)("+...
+ rdnom+"_block_outtbptr+"+string(capt(i,2)-1)+")"+...
+ "+"+string(j-1)+"";
+ else //CAS CMPLX
+ Code1($)=Code1($)+...
+ "("+scs_c_n2c_typ(capt(i,5))+" *)("+...
+ rdnom+"_block_outtbptr+"+string(capt(i,2)-1)+")"+...
+ "+"+string((j-1))+", "+...
+ "("+scs_c_n2c_typ(capt(i,5))+" *)("+...
+ rdnom+"_block_outtbptr+"+string(capt(i,2)-1)+")"+...
+ "+"+string(ni+(j-1))+"";
+ end
+ if j<>ni then
+ Code1($)=Code1($)+", ";
+ end
+ end
+ end
+ Code1($)=Code1($)+");"
+
+ Code=[]
+ if nc==1|~standalone then
+ Code=[Code;
+ Call
+ comments
+ dcl
+ " if (flag1 == 0) {"
+ a_sensor;
+ " } "
+ " else if (flag1 == 1) {"
+ " if (*flag == 4 && *nport == 1) {"
+ " fprr=fopen(input,'"r'");"
+ " if( fprr == NULL ) {"
+ " printf('"Error opening file: %s\n'", input);"
+ " return;"
+ " }"
+ " }"
+ " else if (*flag == 1) {"
+ Code1
+ " }"
+ " else if (*flag == 5 && *nport == 1) {"
+ " fclose(fprr);"
+ " }"
+ " }"
+ "}"];
+
+ elseif nc>1 then
+ S=" switch (*nport) {"
+ for k=1:nc
+ S=[S;
+ " case "+string(k)+" : /* Port number "+string(k)+" ----------*/"
+ " "+a_sensor
+ " break;"]
+ end
+ S=[S;" }"]
+
+ Code=[Code
+ Call
+ comments
+ dcl
+ " if (flag1 == 0) {"
+ S
+ " }"
+ " else if (flag1 == 1){"
+ " if (*flag == 4 && *nport == 1) {"
+ " fprr=fopen(input,'"r'");"
+ " if( fprr == NULL ) {"
+ " printf('"Error opening file: %s\n'", input);"
+ " return ;"
+ " }"
+ " }"
+ " else if (*flag == 1) {"
+ Code1
+ " }"
+ " else if (*flag == 5 && *nport == 1) {"
+ " fclose(fprr);"
+ " }"
+ " }"
+ "}"]
+ end
+endfunction
+
+//generates code of the standalone simulation procedure
+//
+//
+// rmq : La fonction zdoit n'est pas utilis?e pour le moment
+function make_standalone42(filename)
+
+ x=cpr.state.x;
+ modptr=cpr.sim.modptr;
+ rpptr=cpr.sim.rpptr;
+ ipptr=cpr.sim.ipptr;
+ opptr=cpr.sim.opptr;
+ rpar=cpr.sim.rpar;
+ ipar=cpr.sim.ipar;
+ opar=cpr.sim.opar;
+ oz=cpr.state.oz;
+ ordptr=cpr.sim.ordptr;
+ oord=cpr.sim.oord;
+ zord=cpr.sim.zord;
+ iord=cpr.sim.iord;
+ tevts=cpr.state.tevts;
+ evtspt=cpr.state.evtspt;
+ zptr=cpr.sim.zptr;
+ clkptr=cpr.sim.clkptr;
+ ordptr=cpr.sim.ordptr;
+ pointi=cpr.state.pointi;
+ funs=cpr.sim.funs;
+ noord=size(cpr.sim.oord,1);
+ nzord=size(cpr.sim.zord,1);
+ niord=size(cpr.sim.iord,1);
+
+ Indent=" ";
+ Indent2=Indent+Indent;
+ BigIndent=" ";
+
+ work=zeros(nblk,1)
+ Z=[z;zeros(lstsize(outtb),1);work]';
+ nX=size(x,"*");
+ nztotal=size(z,1);
+
+ stalone = %t;
+
+ fd = mopen(filename, "wt");
+
+ mputl(["/*"
+ "** Code prototype for standalone use"
+ "** Generated by Code_Generation toolbox of Xcos with "+getversion()
+ "** Date : "+date()
+ "*/"
+ ""
+ "/* To learn how to use the standalone code, type '"./standalone -h'" */"
+ ""
+ "/* ---- Headers ---- */"
+ "#include <stdio.h>"
+ "#include <stdlib.h>"
+ "#include <math.h>"
+ "#include <string.h>"
+ "#include <memory.h>"
+ "#include '"scicos_block4.h'""
+ "#include '"machine.h'""
+ "#ifndef max"
+ "#define max(a,b) ((a) >= (b) ? (a) : (b))"
+ "#endif"
+ "#ifndef min"
+ "#define min(a,b) ((a) <= (b) ? (a) : (b))"
+ "#endif"
+ ""
+ "/* ---- Internals functions declaration ---- */"
+ "int "+rdnom+"_sim(double, double, double, int);"
+ Protostalone
+ ""], fd);
+
+
+
+ if x<>[] then
+ mputl(["/* Code prototype for standalone use */"
+ "int C2F("+rdnom+"simblk)(double , double *, double *);"
+ "int dset(int *n, double *dx, double *dy, int *incy);"
+ "int ode1();"
+ "int ode2();"
+ "int ode4();"
+ ""], fd);
+ end
+
+ mputl(["/* Table of constant values */"
+ "static int nrd_"+string(0:maxtotal)'+" = "+string(0:maxtotal)'+";"], fd);
+
+ if maxtotal<10 then
+ mputl(["static int nrd_10 = 10;"], fd);
+ end
+ if maxtotal<11 then
+ mputl(["static int nrd_11 = 11;"], fd)
+ end
+
+ if maxtotal<81 then
+ mputl(["static int nrd_81 = 81;"], fd);
+ end
+ if maxtotal<82 then
+ mputl(["static int nrd_82 = 82;"], fd);
+ end
+ if maxtotal<84 then
+ mputl(["static int nrd_84 = 84;"], fd);
+ end
+ if maxtotal<811 then
+ mputl(["static int nrd_811 = 811;"], fd);
+ end
+ if maxtotal<812 then
+ mputl(["static int nrd_812 = 812;"], fd);
+ end
+ if maxtotal<814 then
+ mputl(["static int nrd_814 = 814;"], fd);
+ end
+
+ mputl([""
+ "/* Some general static variables */"
+ "static double zero=0;"
+ "static double w[1];"
+ "static int aaa=0, bbb=0;"
+ "void **"+rdnom+"_block_outtbptr;"], fd); //** !!
+
+ mputl([make_static_standalone42()], fd);
+
+ mputl(["static void usage();"
+ ""
+ "/* Main program */"
+ "int main(int argc, char *argv[])"
+ "{"
+ " double tf=30;" // FIXME : Add current simulation tf.
+ " double dt=0.1;" // FIXME : Try to figure out what is the given Simulation step.
+ " double h=0.001;"
+ " int solver=3;"
+ " char * progname = argv[0];"
+ " int c;"
+ " strcpy(input,'"'");"
+ " strcpy(output,'"'");"
+ " while ((c = getopt(argc , argv, '"i:o:d:t:e:s:hv'")) != -1)"
+ " switch (c) {"
+ " case ''i'':"
+ " strcpy(input,argv[optind-1]);"
+ " break;"
+ " case ''o'':"
+ " strcpy(output,argv[optind-1]);"
+ " break;"
+ " case ''d'':"
+ " strcpy(s,argv[optind-1]);"
+ " dt=strtod(s,p);"
+ " break;"
+ " case ''t'':"
+ " strcpy(sf,argv[optind-1]);"
+ " tf=strtod(sf,p);"
+ " break;"
+ " case ''e'':"
+ " strcpy(se,argv[optind-1]);"
+ " h=strtod(se,p);"
+ " break;"
+ " case ''s'':"
+ " strcpy(ss,argv[optind-1]);"
+ " solver=(int) strtod(ss,p);"
+ " break;"
+ " case ''h'':"
+ " usage(progname);"
+ " printf(""Options : \n'");"
+ " printf("" -h for the help \n"");"
+ " printf("" -v for printing the Scilab Version \n"");"
+ " printf("" -i for input file name, by default is Terminal \n"");"
+ " printf("" -o for output file name, by default is Terminal \n"");"
+ " printf("" -d for the clock period, by default is 0.1 \n"");"
+ " printf("" -t for the final time, by default is 30 \n"");"
+ " printf("" -e for the solvers step size, by default is 0.001 \n"");"
+ " printf("" -s integer parameter for select the numerical solver : \n"");"
+ " printf("" 1 for Euler''s method \n"");"
+ " printf("" 2 for Heun''s method \n"");"
+ " printf("" 3 (default value) for the Fourth-Order Runge-Kutta"+...
+ " (RK4) Formula \n"");"
+ " return 0;"
+ " break;"
+ " case ''v'':"
+ " printf(""Generated by Code_Generation toolbox of Xcos """
+ " ""with "+getversion()+" version \n"");"
+ " return 0;"
+ " break;"
+ " case ''?'':"
+ " errflg++;"
+ " break;"
+ " }"
+ " if (errflg){"
+ " usage(progname);"
+ " return 0;"
+ " }"
+ " "
+ " "+rdnom+"_sim(tf,dt,h,solver);"
+ " return 0;"
+ "}"
+ ""
+ "static void usage(prog)"
+ " char *prog;"
+ "{"
+ " fprintf(stderr, ""Usage: %s [-h] [-v] [-i arg] [-o arg] """
+ " ""[-d arg] [-t arg] [-e arg] [-s arg]\n"", prog);"
+ "}"
+ ""], fd);
+
+ mputl(["/*"+part("-",ones(1,40))+" External simulation function */"
+ "int "+rdnom+"_sim(tf,dt,h,solver)"
+ ""
+ " double tf,dt,h;"
+ " int solver;"
+ "{"
+ " double t;"
+ " int nevprt=1;"
+ " int local_flag;"
+ " int nport;"
+ " int i;"
+ " double *args[100];"
+ ""], fd);
+
+ if (x <> []) then
+ mputl([" double tout;"
+ " double he=0.1;"
+ ""], fd);
+ end
+
+ mputl([" /* Initial values */"
+ ""
+ " /* Note that z[]=[z_initial_condition;outtbptr;work]"
+ cformatline(" z_initial_condition={"+...
+ strcat(string(z),",")+"};",70)
+ cformatline(" outtbptr={"+...
+ strcat(string(zeros(lstsize(outtb),1)),"," )+"};",70)
+ cformatline(" work= {"+...
+ strcat(string(work),"," )+"};",70)
+ " */"
+ ""
+ cformatline(" double z[]={"+strcat(string(Z),",")+"};",70)], fd);
+
+ if size(z,1) <> 0 then
+ for i=1:(length(zptr)-1)
+ if zptr(i+1)-zptr(i)>0 then
+ if size(corinv(i),"*")==1 then
+ OO=scs_m.objs(corinv(i))
+ else
+ path=list("objs")
+ for l=cpr.corinv(i)(1:$-1)
+ path($+1)=l;path($+1)="model"
+ path($+1)="rpar"
+ path($+1)="objs"
+ end
+ path($+1)=cpr.corinv(i)($)
+ OO=scs_m(path)
+ end
+ aaa=OO.gui
+ bbb=emptystr(3,1);
+ if and(aaa+bbb~=["INPUTPORTEVTS";"OUTPUTPORTEVTS";"EVTGEN_f"]) then
+ mputl(["";
+ " /* Routine name of block: "+strcat(string(cpr.sim.funs(i)));
+ " Gui name of block: "+strcat(string(OO.gui));
+ //'/* Name block: '+strcat(string(cpr.sim.funs(i)));
+ //'Object number in diagram: '+strcat(string(cpr.corinv(i)));
+ " Compiled structure index: "+strcat(string(i));], fd);
+ if stripblanks(OO.model.label)~=emptystr() then
+ mputl([cformatline(" Label: "+strcat(string(OO.model.label)),70)], fd);
+ end
+ if stripblanks(OO.graphics.exprs(1))~=emptystr() then
+ mputl([cformatline(" Exprs: "+strcat(OO.graphics.exprs(1),","),70)], fd);
+ end
+ if stripblanks(OO.graphics.id)~=emptystr() then
+ mputl([cformatline(" Identification: "+..
+ strcat(string(OO.graphics.id)),70)], fd);
+ end
+ mputl([cformatline(" z={"+...
+ strcat(string(z(zptr(i):zptr(i+1)-1)),",")+"};",70)
+ " */"], fd);
+ end
+ end
+ end
+ end
+
+ //** declaration of oz
+ Code_oz = [];
+ for i=1:lstsize(oz)
+ if mat2scs_c_nb(oz(i)) <> 11 then
+ Code_oz=[Code_oz;
+ cformatline(" "+mat2c_typ(oz(i))+...
+ " oz_"+string(i)+"[]={"+...
+ strcat(string(oz(i)(:)),",")+"};",70)]
+ else //** cmplx test
+ Code_oz=[Code_oz;
+ cformatline(" "+mat2c_typ(oz(i))+...
+ " oz_"+string(i)+"[]={"+...
+ strcat(string([real(oz(i)(:));
+ imag(oz(i)(:))]),",")+"};",70)]
+ end
+ end
+
+ if Code_oz <> [] then
+ mputl([" /* oz declaration */"
+ Code_oz], fd);
+ end
+
+ //** declaration of outtb
+ Code_outtb = [];
+ for i=1:lstsize(outtb)
+ if mat2scs_c_nb(outtb(i)) <> 11 then
+ Code_outtb=[Code_outtb;
+ cformatline(" "+mat2c_typ(outtb(i))+...
+ " outtb_"+string(i)+"[]={"+...
+ strcat(string(outtb(i)(:)),",")+"};",70)]
+ else //** cmplx test
+ Code_outtb=[Code_outtb;
+ cformatline(" "+mat2c_typ(outtb(i))+...
+ " outtb_"+string(i)+"[]={"+...
+ strcat(string([real(outtb(i)(:));
+ imag(outtb(i)(:))]),",")+"};",70)]
+ end
+ end
+
+ if Code_outtb<>[] then
+ mputl([""
+ " /* outtb declaration */"
+ Code_outtb
+ ""], fd);
+ end
+
+ Code_outtbptr=[];
+ for i=1:lstsize(outtb)
+ Code_outtbptr=[Code_outtbptr;
+ " "+rdnom+"_block_outtbptr["+...
+ string(i-1)+"] = (void *) outtb_"+string(i)+";"];
+ end
+
+ //** declaration of work
+ mputl([" /* work ptr declaration */"
+ " void **work;"
+ ""
+ //## affectation of work
+ " /* Get work ptr of blocks */"
+ " work = (void **)(z+"+string(size(z,"*")+lstsize(outtb))+");"
+ ""], fd);
+
+ //## affection of outtbptr
+ if Code_outtb<>[] then
+ mputl([" /* Get outtbptr ptr of blocks */"
+ " "+rdnom+"_block_outtbptr = (void **)(z+"+string(nztotal)+");"
+ ""], fd);
+ end
+ if Code_outtbptr<>[] then
+ mputl([Code_outtbptr
+ ""], fd);
+ end
+
+ for kf=1:nblk
+ nx=xptr(kf+1)-xptr(kf); //** number of continuous state
+ nin=inpptr(kf+1)-inpptr(kf); //** number of input ports
+ nout=outptr(kf+1)-outptr(kf); //** number of output ports
+
+ //** add comment
+ mputl([""
+ " "+get_comment("set_blk",list(funs(kf),funtyp(kf),kf,labels(kf)));], fd);
+
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].type = "+string(funtyp(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].ztyp = "+string(ztyp(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].ng = "+string(zcptr(kf+1)-zcptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].nz = "+string(zptr(kf+1)-zptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].noz = "+string(ozptr(kf+1)-ozptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].nrpar = "+string(rpptr(kf+1)-rpptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].nopar = "+string(opptr(kf+1)-opptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].nipar = "+string(ipptr(kf+1)-ipptr(kf))+";"
+ " block_"+rdnom+"["+string(kf-1)+"].nin = "+string(inpptr(kf+1)-inpptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].nout = "+string(outptr(kf+1)-outptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].nevout = "+string(clkptr(kf+1)-clkptr(kf))+";";
+ " block_"+rdnom+"["+string(kf-1)+"].nmode = "+string(modptr(kf+1)-modptr(kf))+";";], fd);
+
+ if nx <> 0 then
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].nx = "+string(nx)+";";
+ " block_"+rdnom+"["+string(kf-1)+"].x = &(x["+string(xptr(kf)-1)+"]);"
+ " block_"+rdnom+"["+string(kf-1)+"].xd = &(xd["+string(xptr(kf)-1)+"]);"], fd);
+ end
+
+ mputl([" if ((block_"+rdnom+"["+string(kf-1)+"].evout = "+...
+ "calloc(block_"+rdnom+"["+string(kf-1)+"].nevout,sizeof(double)))== NULL) return 0;"], fd);
+
+ //***************************** input port *****************************//
+ //** alloc insz/inptr **//
+ mputl([" if ((block_"+rdnom+"["+string(kf-1)+"].inptr = "+...
+ "malloc(sizeof(double*)*block_"+rdnom+"["+string(kf-1)+"].nin))== NULL) return 0;";
+ " if ((block_"+rdnom+"["+string(kf-1)+"].insz = "+...
+ "malloc(3*sizeof(int)*block_"+rdnom+"["+string(kf-1)+"].nin))== NULL) return 0;"], fd);
+
+ //** inptr **//
+ for k=1:nin
+ lprt=inplnk(inpptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].inptr["+string(k-1)+...
+ "] = "+rdnom+"_block_outtbptr["+string(lprt-1)+"];"], fd);
+ end
+
+ //** 1st dim **//
+ for k=1:nin
+ lprt=inplnk(inpptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].insz["+string((k-1))+...
+ "] = "+string(size(outtb(lprt),1))+";"], fd);
+ end
+
+ //** 2dn dim **//
+ for k=1:nin
+ lprt=inplnk(inpptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].insz["+string((k-1)+nin)+...
+ "] = "+string(size(outtb(lprt),2))+";"], fd);
+ end
+
+ //** typ **//
+ for k=1:nin
+ lprt=inplnk(inpptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].insz["+string((k-1)+2*nin)+...
+ "] = "+mat2scs_c_typ(outtb(lprt))+";"], fd);
+ end
+ //**********************************************************************//
+
+ //***************************** output port *****************************//
+ //** alloc outsz/outptr **//
+ mputl([" if ((block_"+rdnom+"["+string(kf-1)+"].outsz = "+...
+ "malloc(3*sizeof(int)*block_"+rdnom+"["+string(kf-1)+"].nout))== NULL) return 0;";
+ " if ((block_"+rdnom+"["+string(kf-1)+"].outptr = "+...
+ "malloc(sizeof(double*)*block_"+rdnom+"["+string(kf-1)+"].nout))== NULL) return 0;"], fd);
+
+ //** outptr **//
+ for k=1:nout
+ lprt=outlnk(outptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].outptr["+string(k-1)+...
+ "] = "+rdnom+"_block_outtbptr["+string(lprt-1)+"];"], fd);
+ end
+
+ //** 1st dim **//
+ for k=1:nout
+ lprt=outlnk(outptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].outsz["+string((k-1))+...
+ "] = "+string(size(outtb(lprt),1))+";"], fd);
+ end
+
+ //** 2dn dim **//
+ for k=1:nout
+ lprt=outlnk(outptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].outsz["+string((k-1)+nout)+...
+ "] = "+string(size(outtb(lprt),2))+";"], fd);
+ end
+
+ //** typ **//
+ for k=1:nout
+ lprt=outlnk(outptr(kf)-1+k);
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].outsz["+string((k-1)+2*nout)+...
+ "] = "+mat2scs_c_typ(outtb(lprt))+";"], fd);
+ end
+ //**********************************************************************//
+
+ mputl([" block_"+rdnom+"["+string(kf-1)+...
+ "].z = &(z["+string(zptr(kf)-1)+"]);"], fd);
+
+ if (part(funs(kf),1:7) ~= "capteur" &...
+ part(funs(kf),1:10) ~= "actionneur" &...
+ funs(kf) ~= "bidon") then
+ //** rpar **//
+ if (rpptr(kf+1)-rpptr(kf)>0) then
+ mputl([ " block_"+rdnom+"["+string(kf-1)+...
+ "].rpar=&(RPAR1["+string(rpptr(kf)-1)+"]);"], fd);
+ end
+ //** ipar **//
+ if (ipptr(kf+1)-ipptr(kf)>0) then
+ mputl([" block_"+rdnom+"["+string(kf-1)+...
+ "].ipar=&(IPAR1["+string(ipptr(kf)-1)+"]);"], fd);
+ end
+ //** opar **//
+ if (opptr(kf+1)-opptr(kf)>0) then
+ mputl([" if ((block_"+rdnom+"["+string(kf-1)+"].oparptr = "+...
+ "malloc(sizeof(void *)*block_"+rdnom+"["+string(kf-1)+"].nopar))== NULL ) return 0;";
+ " if ((block_"+rdnom+"["+string(kf-1)+"].oparsz = "+...
+ "malloc(2*sizeof(int)*block_"+rdnom+"["+string(kf-1)+"].nopar))== NULL ) return 0;";
+ " if ((block_"+rdnom+"["+string(kf-1)+"].opartyp = "+...
+ "malloc(sizeof(int)*block_"+rdnom+"["+string(kf-1)+"].nopar))== NULL ) return 0;";
+ ], fd);
+ nopar = opptr(kf+1)-opptr(kf);
+ //** oparptr **//
+ for k=1:nopar
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].oparptr["+string(k-1)+...
+ "] = (void *) OPAR_"+string(opptr(kf)-1+k)+";"], fd);
+ end
+ //** 1st dim **//
+ for k=1:nopar
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].oparsz["+string(k-1)+...
+ "] = "+string(size(opar(opptr(kf)-1+k),1))+";"], fd);
+ end
+ //** 2dn dim **//
+ for k=1:nopar
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].oparsz["+string(nopar+(k-1))+...
+ "] = "+string(size(opar(opptr(kf)-1+k),2))+";"], fd);
+ end
+ //** typ **//
+ for k=1:nopar
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].opartyp["+string(k-1)+...
+ "] = "+mat2scs_c_typ(opar(opptr(kf)-1+k))+";"], fd);
+ end
+ end
+ //** oz **//
+ if (ozptr(kf+1)-ozptr(kf)>0) then
+ noz = ozptr(kf+1)-ozptr(kf);
+ mputl([" if ((block_"+rdnom+"["+string(kf-1)+"].ozptr = "+...
+ "malloc(sizeof(void *)*block_"+rdnom+"["+string(kf-1)+"].noz))== NULL) return 0;";
+ " if ((block_"+rdnom+"["+string(kf-1)+"].ozsz = "+...
+ "malloc(2*sizeof(int)*block_"+rdnom+"["+string(kf-1)+"].noz))== NULL) return 0;";
+ " if ((block_"+rdnom+"["+string(kf-1)+"].oztyp = "+...
+ "malloc(sizeof(int)*block_"+rdnom+"["+string(kf-1)+"].noz))== NULL) return 0;";], fd);
+ //** ozptr **//
+ for k=1:noz
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].ozptr["+string(k-1)+...
+ "] = (void *) oz_"+string(ozptr(kf)-1+k)+";"], fd);
+ end
+ //** 1st dim **//
+ for k=1:noz
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].ozsz["+string(k-1)+...
+ "] = "+string(size(oz(ozptr(kf)-1+k),1))+";"], fd);
+ end
+ //** 2nd dim **//
+ for k=1:noz
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].ozsz["+string(noz+(k-1))+...
+ "] = "+string(size(oz(ozptr(kf)-1+k),2))+";"], fd);
+ end
+ //** typ **//
+ for k=1:noz
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].oztyp["+string(k-1)+...
+ "] = "+mat2scs_c_typ(oz(ozptr(kf)-1+k))+";"], fd);
+ end
+ end
+ end
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].work = "+...
+ "(void **)(((double *)work)+"+string(kf-1)+");"], fd);
+ end
+
+ mputl([" if (strlen(input) > 0)"
+ " aaa=1;"
+ " if (strlen(output)> 0)"
+ " bbb=1;"
+ ""
+ " /* set initial time */"
+ " t=0.0;"
+ ""], fd);
+
+ //** init
+ mputl([" "+get_comment("flag",list(4))], fd);
+
+ for kf=1:nblk
+ if or(kf==act) | or(kf==cap) then
+ txt = call_block42(kf,0,4);
+ if txt <> [] then
+ mputl(["";
+ " "+txt], fd);
+ end
+ else
+ txt = call_block42(kf,0,4);
+ if txt <> [] then
+ mputl(["";
+ " "+txt], fd);
+ end
+ end
+ end
+
+ //** cst blocks and it's dep
+ txt=write_code_idoit()
+
+ if txt<>[] then
+ mputl([""
+ " /* Initial blocks must be called with flag 1 */"
+ txt], fd);
+ end
+
+ //** begin input main loop on time
+ mputl([""
+ " while (t < tf) {";
+ " /* */"
+ " sci_time=t;"
+ ""], fd);
+
+ //** find source activation number
+ blks=find(funtyp>-1);
+ evs=[];
+
+ for blk=blks
+ for ev=clkptr(blk):clkptr(blk+1)-1
+ if funs(blk)=="bidon" then
+ if ev > clkptr(howclk) -1
+ evs=[evs,ev];
+ end
+ end
+ end
+ end
+
+ //** flag 1,2,3
+ for flag=[1,2,3]
+
+ txt3=[]
+
+ //** continuous time blocks must be activated
+ //** for flag 1
+ if flag==1 then
+ txt = write_code_cdoit(flag);
+
+ if txt <> [] then
+ txt3=[""
+ " "+get_comment("ev",list(0))
+ txt;
+ ];
+ end
+ end
+
+ //** blocks with input discrete event must be activated
+ //** for flag 1, 2 and 3
+ if size(evs,2)>=1 then
+ txt4=[]
+ //**
+ for ev=evs
+ txt2=write_code_doit(ev,flag);
+ if txt2<>[] then
+ //** adjust event number because of bidon block
+ new_ev=ev-(clkptr(howclk)-1)
+ //**
+ txt4=[txt4;
+ Indent2+[" case "+string(new_ev)+" : "+...
+ get_comment("ev",list(new_ev))
+ txt2];
+ " break;";""]
+ end
+ end
+
+ //**
+ if txt4 <> [] then
+ txt3=[txt3;
+ Indent+" /* Discrete activations */"
+ Indent+" switch (nevprt) {"
+ txt4
+ " }"];
+ end
+ end
+
+ //**
+ if txt3<>[] then
+ mputl([" "+get_comment("flag",list(flag))
+ txt3], fd);
+ end
+ end
+
+ if x<>[] then
+ mputl([""
+ " tout=t;"
+ ""
+ " /* integrate until the cumulative add of the integration"
+ " * time step doesn''t cross the sample time step"
+ " */"
+ " while (tout+h<t+dt){"
+ " switch (solver) {"
+ " case 1:"
+ " ode1(C2F("+rdnom+"simblk),tout,h);"
+ " break;"
+ " case 2:"
+ " ode2(C2F("+rdnom+"simblk),tout,h);"
+ " break;"
+ " case 3:"
+ " ode4(C2F("+rdnom+"simblk),tout,h);"
+ " break;"
+ " default :"
+ " ode4(C2F("+rdnom+"simblk),tout,h);"
+ " break;"
+ " }"
+ " tout=tout+h;"
+ " }"
+ ""
+ " /* integration for the remainder piece of time */"
+ " he=t+dt-tout;"
+ " switch (solver) {"
+ " case 1:"
+ " ode1(C2F("+rdnom+"simblk),tout,he);"
+ " break;"
+ " case 2:"
+ " ode2(C2F("+rdnom+"simblk),tout,he);"
+ " break;"
+ " case 3:"
+ " ode4(C2F("+rdnom+"simblk),tout,he);"
+ " break;"
+ " default :"
+ " ode4(C2F("+rdnom+"simblk),tout,he);"
+ " break;"
+ " }"], fd);
+ end
+
+ //** fix bug provided by Roberto Bucher
+ //** Alan, 13/10/07
+ if nX <> 0 then
+ mputl([""
+ " /* update ptrs of continuous array */"], fd);
+ for kf=1:nblk
+ nx=xptr(kf+1)-xptr(kf); //** number of continuous state
+ if nx<>0 then
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].nx = "+...
+ string(nx)+";";
+ " block_"+rdnom+"["+string(kf-1)+"].x = "+...
+ "&(x["+string(xptr(kf)-1)+"]);"
+ " block_"+rdnom+"["+string(kf-1)+"].xd = "+...
+ "&(xd["+string(xptr(kf)-1)+"]);"], fd);
+ end
+ end
+ end
+
+ mputl([""
+ " /* update current time */"
+ " t=t+dt;"
+ " }"
+ //** flag 5
+ ""
+ " sci_time = tf;"
+ ""
+ " "+get_comment("flag",list(5))], fd);
+
+ for kf=1:nblk
+ if or(kf==act) | or(kf==cap) then
+ txt = call_block42(kf,0,5);
+ if txt <> [] then
+ mputl(["";
+ " "+txt], fd);
+ end
+ else
+ txt = call_block42(kf,0,5);
+ if txt <> [] then
+ mputl(["";
+ " "+txt], fd);
+ end
+ end
+ end
+
+ mputl([""
+ " return 0;"
+ "}"
+ ""
+ "/*"+part("-",ones(1,40))+" Lapack messag function */";
+ "void C2F(xerbla)(char *SRNAME,int *INFO,long int L)"
+ "{"
+ " printf(""** On entry to %s, parameter number %d"""
+ " "" had an illegal value\n"",SRNAME,*INFO);"
+ "}"
+ ""
+ "void set_block_error(int err)"
+ "{"
+ " return;"
+ "}"
+ ""
+ "int get_phase_simulation()"
+ "{"
+ " return 1;"
+ "}"
+ ""
+ "void * scicos_malloc(size_t size)"
+ "{"
+ " return malloc(size);"
+ "}"
+ ""
+ "void scicos_free(void *p)"
+ "{"
+ " free(p);"
+ "}"
+ ""
+ "double get_scicos_time()"
+ "{"
+ " return sci_time;"
+ "}"
+ ""
+ "void do_cold_restart()"
+ "{"
+ " return;"
+ "}"
+ ""
+ "void sciprint (char *fmt)"
+ "{"
+ " return;"
+ "}"
+ ""
+ "int getopt (int argc, char *argv[], char *optstring)"
+ "{"
+ " char *group, option, *sopt;"
+ " int len;"
+ " option = -1;"
+ " optarg = NULL;"
+ " while ( optind < argc )"
+ " { "
+ " group = argv[optind];"
+ " if ( *group != ''-'' )"
+ " {"
+ " option = -1;"
+ " optarg = group;"
+ " optind++;"
+ " break;"
+ " }"
+ " len = strlen (group);"
+ " group = group + offset;"
+ " if ( *group == ''-'' )"
+ " {"
+ " group++;"
+ " offset += 2;"
+ " }"
+ " else"
+ " offset++ ;"
+ " option = *group ;"
+ " sopt = strchr ( optstring, option ) ;"
+ " if ( sopt != NULL )"
+ " {"
+ " sopt++ ;"
+ " if ( *sopt == '':'' )"
+ " {"
+ " optarg = group + 1;"
+ " if ( *optarg == ''\0'' )"
+ " optarg = argv[++optind];"
+ " if ( *optarg == ''-'' )"
+ " {"
+ " fprintf ( stderr, '"\n%s: illegal option -- %c'","
+ " argv[0], option );"
+ " option = ''?'';"
+ " break;"
+ " }"
+ " else"
+ " {"
+ " optind++;"
+ " offset = 0;"
+ " break;"
+ " }"
+ " }"
+ " if ( offset >= len )"
+ " {"
+ " optind++;"
+ " offset = 0;"
+ " }"
+ " break;"
+ " }"
+ " else"
+ " {"
+ " fprintf ( stderr, '"\n%s: illegal option -- %c'", argv[0], option );"
+ " option = ''?'';"
+ " break;"
+ " }"
+ " }"
+ " return ( option );"
+ "}"
+ ""], fd);
+
+ if (x <> []) then
+ mputl(["int C2F("+rdnom+"simblk)(t, x, xd)"
+ ""
+ " double t, *x, *xd;"
+ ""
+ " /*"
+ " * !purpose"
+ " * compute state derivative of the continuous part"
+ " * !calling sequence"
+ " * neq : integer the size of the continuous state"
+ " * t : current time"
+ " * x : double precision vector whose contains the continuous state"
+ " * xd : double precision vector, contain the computed derivative"
+ " * of the state"
+ " */"
+ "{"
+ " int phase=2;"
+ " int local_flag;"
+ " int nport;"
+ " int nevprt=1;"
+ " double *args[100];"
+ " dset(&neq, &c_b14,xd , &c__1);"
+ ""
+ " "+get_comment("update_xd",list())], fd);
+
+ for kf=1:nblk
+ if (xptr(kf+1)-xptr(kf)) > 0 then
+ mputl([" block_"+rdnom+"["+string(kf-1)+"].x="+...
+ "&(x["+string(xptr(kf)-1)+"]);"
+ " block_"+rdnom+"["+string(kf-1)+"].xd="+...
+ "&(xd["+string(xptr(kf)-1)+"]);"], fd);
+ end
+ end
+
+ mputl([""
+ write_code_odoit(1)
+ write_code_odoit(0)
+ ""
+ " return 0;"
+ "}"
+ ""
+ "int dset(int *n, double *dx, double *dy, int *incy)"
+ "{"
+ " int iMax = 0;"
+ " int i = 0, iy = 0;"
+ " --dy;"
+ " if (*n <= 0) return 0;"
+ " iy = 1;"
+ " if (*incy < 0)"
+ " {"
+ " iy = (-(*n) + 1) * *incy + 1;"
+ " }"
+ " iMax = *n;"
+ " for (i = 1; i <= iMax; ++i)"
+ " {"
+ " dy[iy] = *dx;"
+ " iy += *incy;"
+ " }"
+ " return 0;"
+ "}"
+ ""
+ "/* Euler''s Method */"
+ "int ode1(f,t,h)"
+ " int (*f) ();"
+ " double t, h;"
+ "{"
+ " int i;"
+ ""
+ " /**/"
+ " (*f)(t,x, xd);"
+ ""
+ " for (i=0;i<neq;i++) {"
+ " x[i]=x[i]+h*xd[i];"
+ " }"
+ ""
+ " return 0;"
+ "}"
+ ""
+ "/* Heun''s Method */"
+ "int ode2(f,t,h)"
+ " int (*f) ();"
+ " double t, h;"
+ "{"
+ " int i;"
+ " double y["+string(nX)+"],yh["+string(nX)+"],temp,f0["+string(nX)+"],th;"
+ ""
+ " /**/"
+ " memcpy(y,x,neq*sizeof(double));"
+ " memcpy(f0,xd,neq*sizeof(double));"
+ ""
+ " /**/"
+ " (*f)(t,y, f0);"
+ ""
+ " /**/"
+ " for (i=0;i<neq;i++) {"
+ " x[i]=y[i]+h*f0[i];"
+ " }"
+ " th=t+h;"
+ " for (i=0;i<neq;i++) {"
+ " yh[i]=y[i]+h*f0[i];"
+ " }"
+ " (*f)(th,yh, xd);"
+ ""
+ " /**/"
+ " temp=0.5*h;"
+ " for (i=0;i<neq;i++) {"
+ " x[i]=y[i]+temp*(f0[i]+xd[i]);"
+ " }"
+ ""
+ " return 0;"
+ "}"
+ ""
+ "/* Fourth-Order Runge-Kutta (RK4) Formula */"
+ "int ode4(f,t,h)"
+ " int (*f) ();"
+ " double t, h;"
+ "{"
+ " int i;"
+ " double y["+string(nX)+"],yh["+string(nX)+"],"+...
+ "temp,f0["+string(nX)+"],th,th2,"+...
+ "f1["+string(nX)+"],f2["+string(nX)+"];"
+ ""
+ " /**/"
+ " memcpy(y,x,neq*sizeof(double));"
+ " memcpy(f0,xd,neq*sizeof(double));"
+ ""
+ " /**/"
+ " (*f)(t,y, f0);"
+ ""
+ " /**/"
+ " for (i=0;i<neq;i++) {"
+ " x[i]=y[i]+h*f0[i];"
+ " }"
+ " th2=t+h/2;"
+ " for (i=0;i<neq;i++) {"
+ " yh[i]=y[i]+(h/2)*f0[i];"
+ " }"
+ " (*f)(th2,yh, f1);"
+ ""
+ " /**/"
+ " temp=0.5*h;"
+ " for (i=0;i<neq;i++) {"
+ " x[i]=y[i]+temp*f1[i];"
+ " }"
+ " for (i=0;i<neq;i++) {"
+ " yh[i]=y[i]+(h/2)*f1[i];"
+ " }"
+ " (*f)(th2,yh, f2);"
+ ""
+ " /**/"
+ " for (i=0;i<neq;i++) {"
+ " x[i]=y[i]+h*f2[i];"
+ " }"
+ " th=t+h;"
+ " for (i=0;i<neq;i++) {"
+ " yh[i]=y[i]+h*f2[i];"
+ " }"
+ " (*f)(th2,yh, xd);"
+ ""
+ " /**/"
+ " temp=h/6;"
+ " for (i=0;i<neq;i++) {"
+ " x[i]=y[i]+temp*(f0[i]+2.0*f1[i]+2.0*f2[i]+xd[i]);"
+ " }"
+ ""
+ "return 0;"
+ "}"], fd);
+ end
+
+ mclose(fd);
+endfunction
+
+//generates static table definitions
+//
+//Author : Rachid Djenidi, Alan Layec
+function txt=make_static_standalone42()
+ oldFormat = format();
+ format(25);
+ txt=[];
+
+ //*** Continuous state ***//
+ if x <> [] then
+ txt=[txt;
+ "/* def continuous state */"
+ cformatline("double x[]={"+strcat(string(x),",")+"};",70)
+ cformatline("double xd[]={"+strcat(string(x),",")+"};",70)
+ "static int c__1 = 1;"
+ "static double c_b14 = 0.;"
+ "static int neq="+string(nX)+";"
+ ""]
+ end
+ //************************//
+
+ txt=[txt;
+ "char input[50], output[50],s[1],sf[1],se[1],ss[1],**p;"
+ "static double sci_time;"
+ "static int errflg = 0;"
+ "static char *optarg = NULL ;"
+ "static int optind = 1, offset = 0 ;"
+ "scicos_block block_"+rdnom+"["+string(nblk)+"];"
+ ""];
+
+ //*** Real parameters ***//
+ if size(rpar,1) <> 0 then
+ txt=[txt;
+ "/* def real parameters */"
+ "static double RPAR1[ ] = {"];
+
+ for i=1:(length(rpptr)-1)
+ if rpptr(i+1)-rpptr(i)>0 then
+
+ if size(corinv(i),"*")==1 then
+ OO=scs_m.objs(corinv(i));
+ else
+ path=list("objs");
+ for l=cpr.corinv(i)(1:$-1)
+ path($+1)=l;
+ path($+1)="model";
+ path($+1)="rpar";
+ path($+1)="objs";
+ end
+ path($+1)=cpr.corinv(i)($);
+ OO=scs_m(path);
+ end
+
+ //** Add comments **//
+ txt($+1)="/* Routine name of block: "+strcat(string(cpr.sim.funs(i)));
+ txt($+1)=" * Gui name of block: "+strcat(string(OO.gui));
+ txt($+1)=" * Compiled structure index: "+strcat(string(i));
+
+ if stripblanks(OO.model.label)~=emptystr() then
+ txt=[txt;cformatline(" * Label: "+strcat(string(OO.model.label)),70)];
+ end
+ if stripblanks(OO.graphics.exprs(1))~=emptystr() then
+ txt=[txt;cformatline(" * Exprs: "+strcat(OO.graphics.exprs(1),","),70)];
+ end
+ if stripblanks(OO.graphics.id)~=emptystr() then
+ txt=[txt;
+ cformatline(" * Identification: "+strcat(string(OO.graphics.id)),70)];
+ end
+ txt=[txt;" * rpar="];
+ txt($+1)=" */";
+ //******************//
+
+ txt=[txt;
+ cformatline(strcat(msprintf("%.25E,\n",rpar(rpptr(i):rpptr(i+1)-1))),70);
+ ""]
+
+ end
+ end
+ txt=[txt;
+ "};"
+ ""]
+
+ else
+ txt($+1)="static double RPAR1[1];";
+ end
+ //***********************//
+
+ //*** Integer parameters ***//
+ if size(ipar,1) <> 0 then
+ txt=[txt;
+ "/* def integer parameters */"
+ "static int IPAR1[ ] = {"];
+
+ for i=1:(length(ipptr)-1)
+ if ipptr(i+1)-ipptr(i)>0 then
+ if size(corinv(i),"*")==1 then
+ OO=scs_m.objs(corinv(i));
+ else
+ path=list("objs");
+ for l=cpr.corinv(i)(1:$-1)
+ path($+1)=l
+ path($+1)="model"
+ path($+1)="rpar"
+ path($+1)="objs"
+ end
+ path($+1)=cpr.corinv(i)($);
+ OO=scs_m(path);
+ end
+
+ //** Add comments **//
+ txt($+1)="/* Routine name of block: "+strcat(string(cpr.sim.funs(i)));
+ txt($+1)=" * Gui name of block: "+strcat(string(OO.gui));
+ txt($+1)=" * Compiled structure index: "+strcat(string(i));
+ if stripblanks(OO.model.label)~=emptystr() then
+ txt=[txt;cformatline(" * Label: "+strcat(string(OO.model.label)),70)];
+ end
+
+ if stripblanks(OO.graphics.exprs(1))~=emptystr() then
+ txt=[txt;
+ cformatline(" * Exprs: "+strcat(OO.graphics.exprs(1),","),70)];
+ end
+ if stripblanks(OO.graphics.id)~=emptystr() then
+ txt=[txt;
+ cformatline(" * Identification: "+strcat(string(OO.graphics.id)),70)];
+ end
+ txt=[txt;
+ cformatline(" * ipar= {"+strcat(string(ipar(ipptr(i):ipptr(i+1)-1)),",")+"};",70)];
+ txt($+1)=" */";
+ //******************//
+
+ txt=[txt;cformatline(strcat(string(ipar(ipptr(i):ipptr(i+1)-1))+","),70)];
+ txt($+1)="";
+ end
+ end
+ txt=[txt;
+ "};"
+ ""]
+ else
+ txt($+1)="static int IPAR1[1];";
+ end
+ //**************************//
+
+ //Alan added opar (27/06/07)
+ //*** Object parameters ***//
+ if lstsize(opar)<>0 then
+ txt=[txt;
+ "/* def object parameters */"]
+ for i=1:(length(opptr)-1)
+ if opptr(i+1)-opptr(i)>0 then
+
+ if size(corinv(i),"*")==1 then
+ OO=scs_m.objs(corinv(i));
+ else
+ path=list("objs");
+ for l=cpr.corinv(i)(1:$-1)
+ path($+1)=l;
+ path($+1)="model";
+ path($+1)="rpar";
+ path($+1)="objs";
+ end
+ path($+1)=cpr.corinv(i)($);
+ OO=scs_m(path);
+ end
+
+ //** Add comments **//
+ txt($+1)="";
+ txt($+1)="/* Routine name of block: "+strcat(string(cpr.sim.funs(i)));
+ txt($+1)=" * Gui name of block: "+strcat(string(OO.gui));
+ txt($+1)=" * Compiled structure index: "+strcat(string(i));
+ if stripblanks(OO.model.label)~=emptystr() then
+ txt=[txt;cformatline(" * Label: "+strcat(string(OO.model.label)),70)];
+ end
+ if stripblanks(OO.graphics.id)~=emptystr() then
+ txt=[txt;
+ cformatline(" * Identification: "+strcat(string(OO.graphics.id)),70)];
+ end
+ txt($+1)=" */";
+ //******************//
+
+
+ for j=1:opptr(i+1)-opptr(i)
+ txt =[txt;
+ cformatline("static "+mat2c_typ(opar(opptr(i)+j-1)) +...
+ " OPAR_"+string(opptr(i)+j-1) + "[] = {"+...
+ strcat(string(opar(opptr(i)+j-1)),",")+"};",70)]
+ end
+ end
+ end
+ end
+ //*************************//
+
+ txt=[txt;
+ ""]
+ format(oldFormat(2), oldFormat(1));
+endfunction
+
+//utilitary fonction used to format long C instruction
+//t : a string containing a C instruction
+//l : max line length allowed
+
+//Author : Rachid Djenidi
+function t1=cformatline(t ,l)
+ // Force format to avoid precision loss
+ oldFormat = format();
+ format(25);
+
+ sep=[",","+"]
+ l1=l-2
+ t1=[]
+ kw=strindex(t," ")
+ nw=0
+ if kw<>[] then
+ if kw(1)==1 then // there is leading blanks
+ k1=find(kw(2:$)-kw(1:$-1)<>1)
+ if k1==[] then // there is a single blank
+ nw=1
+ else
+ nw=kw(k1(1))
+ end
+ end
+ end
+ t=part(t,nw+1:length(t));
+ bl=part(" ",ones(1,nw))
+ l1=l-nw;first=%t
+ while %t
+ if length(t)<=l then
+ t1=[t1;bl+t]
+ break
+ end
+ k=strindex(t,sep);
+ if k==[] then
+ t1=[t1;bl+t]
+ break
+ end
+ k($+1)=length(t)+1 // positions of the commas
+ i=find(k(1:$-1)<=l&k(2:$)>l) //nearest left comma (reltively to l)
+ if i==[] then
+ i=1
+ end
+ t1=[t1;bl+part(t,1:k(i))]
+ t=part(t,k(i)+1:length(t))
+ if first then
+ l1=l1-2;bl=bl+" ";
+ first=%f;
+ end
+ end
+
+ format(oldFormat(2), oldFormat(1));
+endfunction
+
+//
+// Generate Matrix of all binary code from
+// 1 to 2^n-1
+//
+function vec = binaryTable(n)
+ n = int(n);
+ vec = [];
+ for i = 1:n
+ accu = [];
+ for j = 1:2^(n-i-1)
+ accu = [accu ; zeros(2^(i-1),1) ; ones(2^(i-1),1)]
+ end
+ vec = [accu, vec]
+ end
+ vec=vec(2:$, :); // Remove first line [ 0 --- 0 ]
+endfunction
+
+//used in do_compile_superblock
+function vec=codebinaire(v,szclkIN)
+ vec=zeros(1,szclkIN)
+ for i=1:szclkIN
+ w=v/2;
+ vec(i)=v-2*int(w);
+ v=int(w);
+ end
+endfunction
+
+function t=filetype(m)
+ m=int32(m)
+ filetypes=["Directory","Character device","Block device",...
+ "Regular file","FIFO","Symbolic link","Socket"]
+ bits=[16384,8192,24576,32768,4096,40960,49152]
+ m=int32(m)&int32(61440)
+ t=filetypes(find(m==int32(bits)))
+endfunction
+
+//get_blank : return blanks with a length
+// of the given input string
+//
+//input : str : a string
+//
+//output : txt : blanks
+//
+//16/06/07 Author : A.Layec
+function [txt] = get_blank(str)
+ txt="";
+ for i=1:length(str)
+ txt=txt+" ";
+ end
+endfunction
+
+// get_comment : return a C comment
+// for generated code
+//
+//input : typ : a string
+// param : a list
+//
+//output : a C comment
+//
+//16/06/07 Author : A.Layec
+function [txt]=get_comment(typ,param)
+ txt = [];
+ select typ
+ //** main flag
+ case "flag" then
+ select param(1)
+ case 0 then
+ txt = "/* Continuous state computation */"
+ case 1 then
+ txt = "/* Output computation */"
+ case 2 then
+ txt = "/* Discrete state computation */"
+ case 3 then
+ txt = "/* Output Event computation */"
+ case 4 then
+ txt = "/* Initialization */"
+ case 5 then
+ txt = "/* Ending */"
+ case 9 then
+ txt = "/* Update zero crossing surfaces */"
+ end
+ //** blocks activated on event number
+ case "ev" then
+ txt = "/* Blocks activated on the event number "+string(param(1))+" */"
+
+ //** blk calling sequence
+ case "call_blk" then
+ txt = ["/* Call of ''"+param(1) + ...
+ "'' (type "+string(param(2))+" - blk nb "+...
+ string(param(3))+" - uid "+param(4)];
+ if ztyp(param(3)) then
+ txt=txt+" - with zcross) */";
+ else
+ txt=txt+") */";
+ end
+ //** proto calling sequence
+ case "proto_blk" then
+ txt = ["/* prototype of ''"+param(1) + ...
+ "'' (type "+string(param(2))];
+ if ztyp(param(3)) then
+ txt=txt+" - with zcross) */";
+ else
+ txt=txt+") */";
+ end
+ //** ifthenelse calling sequence
+ case "ifthenelse_blk" then
+ txt = ["/* Call of ''if-then-else'' blk (blk nb "+...
+ string(param(1))+") */"]
+ //** eventselect calling sequence
+ case "evtselect_blk" then
+ txt = ["/* Call of ''event-select'' blk (blk nb "+...
+ string(param(1))+") */"]
+ //** set block structure
+ case "set_blk" then
+ txt = ["/* set blk struc. of ''"+param(1) + ...
+ "'' (type "+string(param(2))+" - blk nb "+...
+ string(param(3))++" - uid "+param(4)+") */"];
+ //** Update xd vector ptr
+ case "update_xd" then
+ txt = ["/* Update xd vector ptr */"];
+ //** Update g vector ptr
+ case "update_g" then
+ txt = ["/* Update g vector ptr */"];
+ else
+ break;
+ end
+endfunction
+
+//mat2c_typ : matrix to C type
+//sci2c_ttyp : get the C string of a scicos type
+//
+//input : outtb : a matrix
+//
+//output : txt : the string of the C scicos type
+// of the data of outtb
+//
+//16/06/07 Author : A.Layec
+function [txt]=mat2c_typ(outtb)
+ select type(outtb)
+ //real matrix
+ case 1 then
+ if isreal(outtb) then
+ txt = "double"
+ else
+ txt = "double"
+ end
+ //integer matrix
+ case 8 then
+ select typeof(outtb)
+ case "int32" then
+ txt = "long"
+ case "int16" then
+ txt = "short"
+ case "int8" then
+ txt = "char"
+ case "uint32" then
+ txt = "unsigned long"
+ case "uint16" then
+ txt = "unsigned short"
+ case "uint8" then
+ txt = "unsigned char"
+ end
+ else
+ break;
+ end
+endfunction
+
+//mat2scs_c_nb matrix to scicos C number (sci2sci_n)
+//
+//input : outtb : a matrix
+//
+//output : c_nb : the scicos C number
+//
+//16/06/07 Author : A.Layec
+function [c_nb]=mat2scs_c_nb(outtb)
+ select type(outtb)
+ //real matrix
+ case 1 then
+ if isreal(outtb) then
+ c_nb = 10
+ else
+ c_nb = 11
+ end
+ //integer matrix
+ case 8 then
+ select typeof(outtb)
+ case "int32" then
+ c_nb = 84
+ case "int16" then
+ c_nb = 82
+ case "int8" then
+ c_nb = 81
+ case "uint32" then
+ c_nb = 814
+ case "uint16" then
+ c_nb = 812
+ case "uint8" then
+ c_nb = 811
+ end
+ else
+ break;
+ end
+endfunction
+
+//mat2scs_c_ptr matrix to scicos C ptr (sci2c_typ)
+//
+//input : outtb : a matrix
+//
+//output : txt : the string of the C scicos type
+// of the data of outtb
+//
+//16/06/07 Author : A.Layec
+function [txt]=mat2scs_c_ptr(outtb)
+ select type(outtb)
+ //real matrix
+ case 1 then
+ if isreal(outtb) then
+ txt = "SCSREAL_COP"
+ else
+ txt = "SCSCOMPLEX_COP"
+ end
+ //integer matrix
+ case 8 then
+ select typeof(outtb)
+ case "int32" then
+ txt = "SCSINT32_COP"
+ case "int16" then
+ txt = "SCSINT16_COP"
+ case "int8" then
+ txt = "SCSINT8_COP"
+ case "uint32" then
+ txt = "SCSUINT32_COP"
+ case "uint16" then
+ txt = "SCSUINT16_COP"
+ case "uint8" then
+ txt = "SCSUINT8_COP"
+ end
+ else
+ break;
+ end
+endfunction
+
+//mat2scs_c_typ matrix to scicos C type
+//
+//input : outtb : a matrix
+//
+//output : txt : the string of the C scicos type
+// of the data of outtb
+//
+//16/06/07 Author : A.Layec
+function [txt]=mat2scs_c_typ(outtb)
+ select type(outtb)
+ //real matrix
+ case 1 then
+ if isreal(outtb) then
+ txt = "SCSREAL_N"
+ else
+ txt = "SCSCOMPLEX_N"
+ end
+ //integer matrix
+ case 8 then
+ select typeof(outtb)
+ case "int32" then
+ txt = "SCSINT32_N"
+ case "int16" then
+ txt = "SCSINT16_N"
+ case "int8" then
+ txt = "SCSINT8_N"
+ case "uint32" then
+ txt = "SCSUINT32_N"
+ case "uint16" then
+ txt = "SCSUINT16_N"
+ case "uint8" then
+ txt = "SCSUINT8_N"
+ end
+ else
+ break;
+ end
+endfunction
+
+//scs_c_n2c_fmt : scicos C number to C format
+//
+//input : c_nb : a C scicos type
+//
+//output : txt : the string of the C format string
+// of the data of outtb
+//
+//16/06/07 Author : A.Layec
+function [txt]=scs_c_n2c_fmt(c_nb)
+ select c_nb
+ //real matrix
+ case 10 then
+ txt = "%f";
+ //complex matrix
+ case 11 then
+ txt = "%f,%f";
+ //int8 matrix
+ case 81 then
+ txt = "%d";
+ //int16 matrix
+ case 82 then
+ txt = "%d";
+ //int32 matrix
+ case 84 then
+ txt = "%d";
+ //uint8 matrix
+ case 811 then
+ txt = "%d";
+ //uint16 matrix
+ case 812 then
+ txt = "%d";
+ //uint32 matrix
+ case 814 then
+ txt = "%d";
+ else
+ txt="%f"
+ break;
+ end
+endfunction
+
+//scs_c_n2c_typ scicos C number to C type
+//
+//input : c_nb : a C scicos number
+//
+//output : txt : the string of the C format string
+// of the data of outtb
+//
+//16/06/07 Author : A.Layec
+function [txt]=scs_c_n2c_typ(c_nb)
+ select c_nb
+ //real matrix
+ case 10 then
+ txt = "double";
+ //complex matrix
+ case 11 then
+ txt = "double";
+ //int8 matrix
+ case 81 then
+ txt = "char";
+ //int16 matrix
+ case 82 then
+ txt = "short";
+ //int32 matrix
+ case 84 then
+ txt = "long";
+ //uint8 matrix
+ case 811 then
+ txt = "unsigned char";
+ //uint16 matrix
+ case 812 then
+ txt = "unsigned short";
+ //uint32 matrix
+ case 814 then
+ txt = "unsigned long";
+ else
+ txt="double"
+ break;
+ end
+endfunction
+
+//scs_c_nb2scs_nb : scicos C number to scicos number
+//
+//input : c_nb : the scicos C number type
+//
+//output : scs_nb : the scilab number type
+//
+//16/06/07 Author : A.Layec
+function [scs_nb]=scs_c_nb2scs_nb(c_nb)
+ scs_nb=zeros(size(c_nb,1),size(c_nb,2));
+ for i=1:size(c_nb,1)
+ for j=1:size(c_nb,2)
+ select (c_nb(i,j))
+ case 10 then
+ scs_nb(i,j) = 1
+ case 11 then
+ scs_nb(i,j) = 2
+ case 81 then
+ scs_nb(i,j) = 5
+ case 82 then
+ scs_nb(i,j) = 4
+ case 84 then
+ scs_nb(i,j) = 3
+ case 811 then
+ scs_nb(i,j) = 8
+ case 812 then
+ scs_nb(i,j) = 7
+ case 814 then
+ scs_nb(i,j) = 6
+ else
+ scs_nb(i,j) = 1
+ end
+ end
+ end
+endfunction
+
+//used in do_compile_superblock
+function XX=update_block(XX)
+ execstr("o="+rdnom+"_c(''define'')")
+ XX.model=o.model
+ XX.gui=rdnom+"_c";
+ XX.graphics.gr_i=o.graphics.gr_i
+endfunction
+
+//write_code_cdoit : generate body of the code for
+// for all time dependant blocks
+//
+//input : flag : flag number for block's call
+//
+//output : txt for cord blocks
+//
+//12/07/07 Alan Layec
+function [txt]=write_code_cdoit(flag)
+ txt=[];
+
+ for j=1:ncord
+ bk=cord(j,1);
+ pt=cord(j,2);
+ //** blk
+ if funtyp(bk)>-1 then
+ if or(bk==act) | or(bk==cap) then
+ if stalone then
+ txt2=call_block42(bk,pt,flag);
+ if txt2<>[] then
+ txt=[txt;
+ " "+txt2
+ ""];
+ end
+ end
+ else
+ txt2=call_block42(bk,pt,flag);
+ if txt2<>[] then
+ txt=[txt;
+ " "+txt2
+ ""];
+ end
+ end
+ //** ifthenelse blk
+ elseif funtyp(bk)==-1 then
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ thentxt=write_code_doit(clkptr(bk),flag);
+ elsetxt=write_code_doit(clkptr(bk)+1,flag);
+ if thentxt<>[] | elsetxt<>[] then
+ txt=[txt;
+ " "+get_comment("ifthenelse_blk",list(bk));]
+ //** C **//
+ tmp_="*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ txt=[txt;
+ " if("+tmp_+">0) {"]
+ //*******//
+ txt=[txt;
+ Indent+thentxt];
+ if elsetxt<>[] then
+ //** C **//
+ txt=[txt;
+ " }";
+ " else {";]
+ //*******//
+ txt=[txt;
+ Indent+elsetxt];
+ end
+ //** C **//
+ txt=[txt;
+ " }"]
+ //*******//
+ end
+ //** eventselect blk
+ elseif funtyp(bk)==-2 then
+ Noutport=clkptr(bk+1)-clkptr(bk);
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ II=[];
+ switchtxt=list()
+ for i=1: Noutport
+ switchtxt(i)=write_code_doit(clkptr(bk)+i-1,flag);
+ if switchtxt(i)<>[] then II=[II i];end
+ end
+ if II<>[] then
+ txt=[txt;
+ " "+get_comment("evtselect_blk",list(bk));]
+ //** C **//
+ tmp_="*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ txt=[txt;
+ " i=max(min((int) "+...
+ tmp_+",block_"+rdnom+"["+string(bk-1)+"].evout),1);"
+ " switch(i)"
+ " {"]
+ //*******//
+ for i=II
+ //** C **//
+ txt=[txt;
+ " case "+string(i)+" :";]
+ //*******//
+ txt=[txt;
+ BigIndent+write_code_doit(clkptr(bk)+i-1,flag);]
+ //** C **//
+ txt=[txt;
+ BigIndent+"break;"]
+ //*******//
+ end
+ //** C **//
+ txt=[txt;
+ " }"];
+ //*******//
+ end
+ //** Unknown block
+ else
+ error("Unknown block type "+string(bk));
+ end
+ end
+
+endfunction
+
+//write_code_doit : generate body of the code for
+// ordering calls of blocks during
+// flag 1,2 & flag 3
+//
+//input : ev : evt number for block's call
+// flag : flag number for block's call
+//
+//output : txt for flag 1 or 2, or flag 3
+//
+//12/07/07 Alan Layec
+function [txt]=write_code_doit(ev,flag)
+ txt=[];
+
+ for j=ordptr(ev):ordptr(ev+1)-1
+ bk=ordclk(j,1);
+ pt=ordclk(j,2);
+ //** blk
+ if funtyp(bk)>-1 then
+ if or(bk==act) | or(bk==cap) then
+ if stalone then
+ txt2=call_block42(bk,pt,flag);
+ if txt2<>[] then
+ txt=[txt;
+ " "+txt2
+ ""];
+ end
+ end
+ else
+ txt2=call_block42(bk,pt,flag);
+ if txt2<>[] then
+ txt=[txt;
+ " "+txt2
+ ""];
+ end
+ end
+ //** ifthenelse blk
+ elseif funtyp(bk)==-1 then
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ thentxt=write_code_doit(clkptr(bk),flag);
+ elsetxt=write_code_doit(clkptr(bk)+1,flag);
+ if thentxt<>[] | elsetxt<>[] then
+ txt=[txt;
+ " "+get_comment("ifthenelse_blk",list(bk));]
+ //** C **//
+ tmp_ = "*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ txt=[txt;
+ " if("+tmp_+">0) {"]
+ //*******//
+ txt=[txt;
+ Indent+thentxt]
+ if elsetxt<>[] then
+ //** C **//
+ txt=[txt;
+ " }";
+ " else {";]
+ //*******//
+ txt=[txt;
+ Indent+elsetxt];
+ end
+ //** C **//
+ txt=[txt;
+ " }"]
+ //*******//
+ end
+ //** eventselect blk
+ elseif funtyp(bk)==-2 then
+ Noutport=clkptr(bk+1)-clkptr(bk);
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ II=[];
+ switchtxt=list()
+ for i=1: Noutport
+ switchtxt(i)=write_code_doit(clkptr(bk)+i-1,flag);
+ if switchtxt(i)<>[] then II=[II i];end
+ end
+ if II<>[] then
+ txt=[txt;
+ " "+get_comment("evtselect_blk",list(bk));]
+ tmp_="*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ //** C **//
+ txt=[txt;
+ " i=max(min((int) "+...
+ tmp_+",block_"+rdnom+"["+string(bk-1)+"].evout),1);"
+ " switch(i)"
+ " {"]
+ //*******//
+ for i=II
+ //** C **//
+ txt=[txt;
+ " case "+string(i)+" :";]
+ //*******//
+ txt=[txt;
+ BigIndent+write_code_doit(clkptr(bk)+i-1,flag);]
+ //** C **//
+ txt=[txt;
+ BigIndent+"break;"]
+ //*******//
+ end
+ //** C **//
+ txt=[txt;
+ " }"]
+ //*******//
+ end
+ //** Unknown block
+ else
+ error("Unknown block type "+string(bk));
+ end
+ end
+
+endfunction
+
+//write_code_idoit : generate body of the code for
+// ordering calls of initial
+// called blocks
+//
+//input : nothing (blocks are called with flag 1)
+//
+//output : txt for iord
+//
+//15/07/07 Alan Layec
+function [txt]=write_code_idoit()
+ txt=[];
+
+ for j=1:niord
+ bk=iord(j,1);
+ pt=iord(j,2);
+ //** blk
+ if funtyp(bk)>-1 then
+ if or(bk==act) then
+ if stalone then
+ txt2=call_block42(bk,pt,1);
+ if txt2<>[] then
+ txt=[txt;
+ " "+txt2
+ ""];
+ end
+ end
+ else
+ txt2=call_block42(bk,pt,1);
+ if txt2<>[] then
+ txt=[txt;
+ " "+txt2
+ ""];
+ end
+ end
+ //** ifthenelse blk
+ elseif funtyp(bk)==-1 then
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ thentxt=write_code_doit(clkptr(bk),1);
+ elsetxt=write_code_doit(clkptr(bk)+1,1);
+ if thentxt<>[] | elsetxt<>[] then
+ txt=[txt;
+ " "+get_comment("ifthenelse_blk",list(bk));]
+ //** C **//
+ tmp_ = "*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ txt=[txt;
+ " if("+tmp_+">0) {"]
+ //*******//
+ txt=[txt;
+ Indent+thentxt];
+ if elsetxt<>[] then
+ //** C **//
+ txt=[txt;
+ " }";
+ " else {";]
+ //*******//
+ txt=[txt;
+ Indent+elsetxt];
+ end
+ //** C **//
+ txt=[txt;
+ " }"]
+ //*******//
+ end
+ //** eventselect blk
+ elseif funtyp(bk)==-2 then
+ Noutport=clkptr(bk+1)-clkptr(bk);
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ II=[];
+ switchtxt=list()
+ for i=1: Noutport
+ switchtxt(i)=write_code_doit(clkptr(bk)+i-1,1);
+ if switchtxt(i)<>[] then II=[II i];end
+ end
+ if II<>[] then
+ txt=[txt;
+ " "+get_comment("evtselect_blk",list(bk));]
+ //** C **//
+ tmp_="*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ txt=[txt;
+ " i=max(min((int) "+...
+ tmp_+",block_"+rdnom+"["+string(bk-1)+"].evout),1);"]
+ txt=[txt;
+ " switch(i)"
+ " {"]
+ //*******//
+ for i=II
+ //** C **//
+ txt=[txt;
+ " case "+string(i)+" :";]
+ //*******//
+ txt=[txt;
+ BigIndent+write_code_doit(clkptr(bk)+i-1,1);]
+ //** C **//
+ txt=[txt;
+ BigIndent+"break;"]
+ //*******//
+ end
+ //** C **//
+ txt=[txt;
+ " }"];
+ //*******//
+ end
+ //** Unknown block
+ else
+ error("Unknown block type "+string(bk));
+ end
+ end
+
+endfunction
+
+//write_code_odoit : generate body of the code for
+// ordering calls of blocks before
+// continuous time integration
+//
+//input : flag : flag number for block's call
+//
+//output : txt for flag 0
+//
+//12/07/07 Alan Layec
+function [txt]=write_code_odoit(flag)
+ txt=[];
+
+ for j=1:noord
+ bk=oord(j,1);
+ pt=oord(j,2);
+ //** blk
+ if funtyp(bk)>-1 then
+ txt2=call_block42(bk,pt,flag);
+ if txt2<>[] then
+ txt=[txt;
+ " "+txt2
+ ""];
+ end
+ //** ifthenelse blk
+ elseif funtyp(bk)==-1 then
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ thentxt=write_code_ozdoit(clkptr(bk),flag);
+ elsetxt=write_code_ozdoit(clkptr(bk)+1,flag);
+ if thentxt<>[] | elsetxt<>[] then
+ txt=[txt;
+ " "+get_comment("ifthenelse_blk",list(bk));]
+ //** C **//
+ tmp_="*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ txt=[txt;
+ " if ((block_"+rdnom+"["+string(bk-1)+"].nmode<0"+...
+ " && "+tmp_+">0)"+...
+ " || \"
+ " (block_"+rdnom+"["+string(bk-1)+"].nmode>0"+...
+ " && block_"+rdnom+"["+string(bk-1)+"].mode[0]==1)) {"]
+ //*******//
+ txt=[txt;
+ Indent+thentxt]
+ //** C **//
+ txt=[txt;
+ " }"];
+ //*******//
+ if elsetxt<>[] then
+ //** C **//
+ txt=[txt;
+ " else if ((block_"+rdnom+"["+string(bk-1)+"].nmode<0"+...
+ " && "+tmp_+"<=0)"+...
+ " || \"
+ " (block_"+rdnom+"["+string(bk-1)+"].nmode>0"+...
+ " && block_"+rdnom+"["+string(bk-1)+"].mode[0]==2)) {";]
+ //*******//
+ txt=[txt;
+ Indent+elsetxt]
+ //** C **//
+ txt=[txt;
+ " }"];
+ //*******//
+ end
+ end
+ //** eventselect blk
+ elseif funtyp(bk)==-2 then
+ Noutport=clkptr(bk+1)-clkptr(bk);
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ II=[];
+ switchtxt=list()
+ for i=1: Noutport
+ switchtxt(i)=write_code_ozdoit(clkptr(bk)+i-1,flag);
+ if switchtxt(i)<>[] then II=[II i];end
+ end
+ if II<>[] then
+ txt=[txt;
+ " "+get_comment("evtselect_blk",list(bk));]
+ //** C **//
+ tmp_="*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ txt=[txt;
+ " if (block_"+rdnom+"["+string(bk-1)+"].nmode<0) {";
+ " i=max(min((int) "+...
+ tmp_+",block_"+rdnom+"["+string(bk-1)+"].evout),1);"
+ " }"
+ " else {"
+ " i=block_"+rdnom+"["+string(bk-1)+"].mode[0];"
+ " }"]
+ txt=[txt;
+ " switch(i)"
+ " {"];
+ //*******//
+ for i=II
+ //** C **//
+ txt=[txt;
+ " case "+string(i)+" :";]
+ //*******//
+ txt=[txt;
+ BigIndent+write_code_ozdoit(clkptr(bk)+i-1,flag);]
+ //** C **//
+ txt=[txt;
+ BigIndent+"break;"]
+ //*******//
+ end
+ //** C **//
+ txt=[txt;
+ " }"];
+ //*******//
+ end
+ //** Unknown block
+ else
+ error("Unknown block type "+string(bk));
+ end
+ end
+
+endfunction
+
+//write_code_ozdoit : generate body of the code for both
+// flag 0 & flag 9
+//
+//input: ev : evt number for block's call
+// flag : flag number for block's call
+//
+//output : txt for flag 0 or flag 9
+//
+//12/07/07 Alan Layec
+function [txt]=write_code_ozdoit(ev,flag)
+ txt=[];
+
+ for j=ordptr(ev):ordptr(ev+1)-1
+ bk=ordclk(j,1);
+ pt=ordclk(j,2);
+ //** blk
+ if funtyp(bk)>-1 then
+ if (or(bk==act) | or(bk==cap)) & (flag==1) then
+ if stalone then
+ txt=[txt;
+ " "+call_block42(bk,pt,flag)
+ ""];
+ end
+ else
+ txt2=call_block42(bk,pt,flag);
+ if txt2<>[] then
+ txt=[txt;
+ " "+txt2
+ ""];
+ end
+ end
+ //** ifthenelse blk
+ elseif funtyp(bk)==-1 then
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ thentxt=write_code_ozdoit(clkptr(bk),flag);
+ elsetxt=write_code_ozdoit(clkptr(bk)+1,flag);
+ if thentxt<>[] | elsetxt<>[] then
+ txt=[txt;
+ " "+get_comment("ifthenelse_blk",list(bk));]
+ //** C **//
+ tmp_ = "*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ txt=[txt;
+ " if (((phase==1"+...
+ " || block_"+rdnom+"["+string(bk-1)+"].nmode==0)"+...
+ " && "+tmp_+">0)"+...
+ " || \"
+ " ((phase!=1"+...
+ " && block_"+rdnom+"["+string(bk-1)+"].nmode!=0)"+...
+ " && block_"+rdnom+"["+string(bk-1)+"].mode[0]==1)) {"]
+ //*******//
+ txt=[txt;
+ Indent+thentxt]
+ //** C **//
+ txt=[txt;
+ " }"];
+ //*******//
+ if elsetxt<>[] then
+ //** C **//
+ txt=[txt;
+ " else if (((phase==1"+...
+ " || block_"+rdnom+"["+string(bk-1)+"].nmode==0)"+...
+ " && "+tmp_+"<=0)"+...
+ " || \"
+ " ((phase!=1"+...
+ " && block_"+rdnom+"["+string(bk-1)+"].nmode!=0)"+...
+ " && block_"+rdnom+"["+string(bk-1)+"].mode[0]==2)) {";]
+ //*******//
+ txt=[txt;
+ Indent+elsetxt]
+ //** C **//
+ txt=[txt;
+ " }"];
+ //*******//
+ end
+ end
+ //** eventselect blk
+ elseif funtyp(bk)==-2 then
+ Noutport=clkptr(bk+1)-clkptr(bk);
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ II=[];
+ switchtxt=list()
+ for i=1: Noutport
+ switchtxt(i)=write_code_ozdoit(clkptr(bk)+i-1,flag);
+ if switchtxt(i)<>[] then II=[II i];end
+ end
+ if II<>[] then
+ txt=[txt;
+ " "+get_comment("evtselect_blk",list(bk));]
+ //** C **//
+ tmp_="*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ txt=[txt;
+ " if (phase==1 || block_"+rdnom+"["+string(bk-1)+"].nmode==0) {";
+ " i=max(min((int) "+...
+ tmp_+",block_"+rdnom+"["+string(bk-1)+"].evout),1);"
+ " }"
+ " else {"
+ " i=block_"+rdnom+"["+string(bk-1)+"].mode[0];"
+ " }"]
+ txt=[txt;
+ " switch(i)"
+ " {"];
+ //*******//
+ for i=II
+ //** C **//
+ txt=[txt;
+ " case "+string(i)+" :";]
+ //*******//
+ txt=[txt;
+ BigIndent+write_code_ozdoit(clkptr(bk)+i-1,flag);]
+ //** C **//
+ txt=[txt;
+ BigIndent+"break;"]
+ //*******//
+ end
+ //** C **//
+ txt=[txt;
+ " }"];
+ //*******//
+ end
+ //** Unknown block
+ else
+ error("Unknown block type "+string(bk));
+ end
+ end
+
+endfunction
+
+//write_code_zdoit : generate body of the code for
+// ordering calls of blocks before
+// continuous time zero crossing
+// detection
+//
+//input : noting
+//
+//output : txt for flag 9
+//
+//12/07/07 Alan Layec
+function [txt]=write_code_zdoit()
+ txt=[];
+
+ //** first pass (flag 1)
+ for j=1:nzord
+ bk=zord(j,1);
+ pt=zord(j,2);
+ //** blk
+ if funtyp(bk)>-1 then
+ if or(bk==act) | or(bk==cap) then
+ if stalone then
+ txt=[txt;
+ " "+call_block42(bk,pt,1)
+ ""];
+ end
+ else
+ txt2=call_block42(bk,pt,1);
+ if txt2<>[] then
+ txt=[txt;
+ " "+txt2
+ ""];
+ end
+ end
+ //** ifthenelse blk
+ elseif funtyp(bk)==-1 then
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ thentxt=write_code_ozdoit(clkptr(bk),1);
+ elsetxt=write_code_ozdoit(clkptr(bk)+1,1);
+ if thentxt<>[] | elsetxt<>[] then
+ txt=[txt;
+ " "+get_comment("ifthenelse_blk",list(bk));]
+ //** C **//
+ tmp_ = "*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ txt=[txt;
+ " if (((phase==1"+...
+ " || block_"+rdnom+"["+string(bk-1)+"].nmode==0)"+...
+ " && "+tmp_+">0)"+...
+ " || \"
+ " ((phase!=1"+...
+ " && block_"+rdnom+"["+string(bk-1)+"].nmode!=0)"+...
+ " && block_"+rdnom+"["+string(bk-1)+"].mode[0]==1)) {"]
+ //*******//
+ txt=[txt;
+ Indent+thentxt]
+ //** C **//
+ txt=[txt;
+ " }"];
+ //*******//
+ if elsetxt<>[] then
+ //** C **//
+ txt=[txt;
+ " else if (((phase==1"+...
+ " || block_"+rdnom+"["+string(bk-1)+"].nmode==0)"+...
+ " && "+tmp_+"<=0)"+...
+ " || \"
+ " ((phase!=1"+...
+ " && block_"+rdnom+"["+string(bk-1)+"].nmode!=0)"+...
+ " && block_"+rdnom+"["+string(bk-1)+"].mode[0]==2)) {";]
+ //*******//
+ txt=[txt;
+ Indent+elsetxt]
+ //** C **//
+ txt=[txt;
+ " }"];
+ //*******//
+ end
+ end
+ //** eventselect blk
+ elseif funtyp(bk)==-2 then
+ Noutport=clkptr(bk+1)-clkptr(bk);
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ II=[];
+ switchtxt=list()
+ for i=1: Noutport
+ switchtxt(i)=write_code_ozdoit(clkptr(bk)+i-1,1);
+ if switchtxt(i)<>[] then II=[II i];end
+ end
+ if II<>[] then
+ txt=[txt;
+ " "+get_comment("evtselect_blk",list(bk));]
+ //** C **//
+ tmp_="*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ txt=[txt;
+ " if (phase==1 || block_"+rdnom+"["+string(bk-1)+"].nmode==0){";
+ " i=max(min((int) "+...
+ tmp_+",block_"+rdnom+"["+string(bk-1)+"].evout),1);"
+ " else {"
+ " i=block_"+rdnom+"["+string(bk-1)+"].mode[0];"
+ " }"]
+ txt=[txt;
+ " switch(i)"
+ " {"];
+ //*******//
+ for i=II
+ //** C **//
+ txt=[txt;
+ " case "+string(i)+" :";]
+ //*******//
+ txt=[txt;
+ BigIndent+write_code_ozdoit(clkptr(bk)+i-1,1);]
+ //** C **//
+ txt=[txt;
+ BigIndent+"break;"]
+ //*******//
+ end
+ //** C **//
+ txt=[txt;
+ " }"];
+ //*******//
+ end
+ //** Unknown block
+ else
+ error("Unknown block type "+string(bk));
+ end
+ end
+
+ //** second pass (flag 9)
+ for j=1:nzord
+ bk=zord(j,1);
+ pt=zord(j,2);
+ //** blk
+ if funtyp(bk)>-1 then
+ if or(bk==act) | or(bk==cap) then
+ if stalone then
+ txt=[txt;
+ " "+call_block42(bk,pt,9)
+ ""];
+ end
+ else
+ txt2=call_block42(bk,pt,9);
+ if txt2<>[] then
+ txt=[txt;
+ " "+txt2
+ ""];
+ end
+ end
+
+ //** ifthenelse blk
+ elseif funtyp(bk)==-1 then
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ //** C **//
+ tmp_="*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ //*******//
+ thentxt=write_code_zzdoit(clkptr(bk),9);
+ elsetxt=write_code_zzdoit(clkptr(bk)+1,9);
+ txt=[txt;
+ " "+get_comment("ifthenelse_blk",list(bk));]
+ //** C **//
+ txt=[txt;
+ " g["+string(zcptr(bk)-1)+"]=(double)"+tmp_+";"]
+ //*******//
+ if thentxt<>[] | elsetxt<>[] then
+ //** C **//
+ txt=[txt;
+ " if (g["+string(zcptr(bk)-1)+"] > 0.){"]
+ //*******//
+ txt=[txt;
+ Indent+thentxt]
+ //** C **//
+ txt=[txt;
+ " }"]
+ //*******//
+ if elsetxt <> [] then
+ //** C **//
+ txt=[txt;
+ " else {"]
+ //*******//
+ txt=[txt;
+ Indent+elsetxt]
+ //** C **//
+ txt=[txt;
+ " }"]
+ //*******//
+ end
+ end
+ //** C **//
+ txt=[txt;
+ " if(phase==1 && block_"+rdnom+"["+string(bk-1)+"].nmode > 0){"
+ " if (g["+string(zcptr(bk)-1)+"] > 0.){"
+ " block_"+rdnom+"["+string(bk-1)+"].mode[0] = 1;"
+ " }"
+ " else {"
+ " block_"+rdnom+"["+string(bk-1)+"].mode[0] = 2;"
+ " }"
+ " }"]
+ //*******//
+ //** eventselect blk
+ elseif funtyp(bk)==-2 then
+ Noutport=clkptr(bk+1)-clkptr(bk);
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ //** C **//
+ tmp_="*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ //*******//
+ II=[];
+ switchtxt=list()
+ for i=1:Noutport
+ switchtxt(i)=write_code_zzdoit(clkptr(bk)+i-1,9);
+ if switchtxt(i)<>[] then II=[II i];end
+ end
+ txt=[txt;
+ " "+get_comment("evtselect_blk",list(bk));]
+ if II<>[] then
+ //** C **//
+ txt=[txt;
+ " j=max(min((int) "+...
+ tmp_+",block_"+rdnom+"["+string(bk-1)+"].nevout),1);"]
+ txt=[txt;
+ " switch(j)"
+ " {"];
+ //*******//
+ for i=II
+ //** C **//
+ txt=[txt;
+ " case "+string(j)+" :";]
+ //*******//
+ txt=[txt;
+ BigIndent+write_code_zzdoit(clkptr(bk)+i-1,9);]
+ //** C **//
+ txt=[txt;
+ BigIndent+"break;"]
+ //*******//
+ end
+ //** C **//
+ txt=[txt;
+ " }"];
+ //*******//
+ end
+ //** C **//
+ txt=[txt;
+ " for (jj=0;jj<block_"+rdnom+"["+string(fun-1)+"].nevout-1;++jj) {"
+ " g["+string(zcptr(bk)-1)+"+jj]=(double)"+tmp_+"-(double)(jj+2);"
+ " }"
+ " if(phase==1 && block_"+rdnom+"["+string(bk-1)+"].nmode>0){"
+ " j=max(min((int) "+tmp_+","
+ " block_"+rdnom+"["+string(bk-1)+"].nevout),1);"
+ " block_"+rdnom+"["+string(bk-1)+"].mode[0]= j;"
+ " }"]
+ //*******//
+ //** Unknown block
+ else
+ error("Unknown block type "+string(bk));
+ end
+ end
+
+endfunction
+
+//write_code_zzdoit : generate body of the code for
+// flag 9
+//
+//input: ev : evt number for block's call
+// flag : flag number for block's call
+//
+//output : txt for flag 9
+//
+//12/07/07 Alan Layec
+function [txt]=write_code_zzdoit(ev,flag)
+ txt=[];
+
+ for j=ordptr(ev):ordptr(ev+1)-1
+ bk=ordclk(j,1);
+ pt=ordclk(j,2);
+ //** blk
+ if funtyp(bk)>-1 then
+ if or(bk==act) | or(bk==cap) then
+ if stalone then
+ txt=[txt;
+ " "+call_block42(bk,pt,flag)
+ ""];
+ end
+ else
+ txt2=call_block42(bk,pt,flag);
+ if txt2<>[] then
+ txt=[txt;
+ " "+txt2
+ ""];
+ end
+ end
+ //** ifthenelse blk
+ elseif funtyp(bk)==-1 then
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ //** C **//
+ tmp_="*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ //*******//
+ thentxt=write_code_zzdoit(clkptr(bk),9);
+ elsetxt=write_code_zzdoit(clkptr(bk)+1,9);
+ txt=[txt;
+ " "+get_comment("ifthenelse_blk",list(bk));]
+ //** C **//
+ txt=[txt;
+ " g["+string(zcptr(bk)-1)+"]=(double)"+tmp_+";"]
+ //*******//
+ if thentxt<>[] | elsetxt<>[] then
+ //** C **//
+ txt=[txt;
+ " if (g["+string(zcptr(bk)-1)+"] > 0.){"]
+ //*******//
+ txt=[txt;
+ Indent+thentxt]
+ //** C **//
+ txt=[txt;
+ " }"]
+ //*******//
+ if elsetxt <> [] then
+ //** C **//
+ txt=[txt;
+ " else {"]
+ //*******//
+ txt=[txt;
+ Indent+elsetxt]
+ //** C **//
+ txt=[txt;
+ " }"]
+ //*******//
+ end
+ end
+ //** C **//
+ txt=[txt;
+ " if(phase==1 && block_"+rdnom+"["+string(bk-1)+"].nmode > 0){"
+ " if (g["+string(zcptr(bk)-1)+"] > 0.){"
+ " block_"+rdnom+"["+string(bk-1)+"].mode[0] = 1;"
+ " }"
+ " else {"
+ " block_"+rdnom+"["+string(bk-1)+"].mode[0] = 2;"
+ " }"
+ " }"]
+ //*******//
+
+ //** eventselect blk
+ elseif funtyp(bk)==-2 then
+ Noutport=clkptr(bk+1)-clkptr(bk);
+ ix=-1+inplnk(inpptr(bk));
+ TYPE=mat2c_typ(outtb(ix+1)); //** scilab index start from 1
+ //** C **//
+ tmp_="*(("+TYPE+" *)"+rdnom+"_block_outtbptr["+string(ix)+"])"
+ //*******//
+ II=[];
+ switchtxt=list()
+ for i=1:Noutport
+ switchtxt(i)=write_code_zzdoit(clkptr(bk)+i-1,9);
+ if switchtxt(i)<>[] then II=[II i];end
+ end
+ txt=[txt;
+ " "+get_comment("evtselect_blk",list(bk));]
+ if II<>[] then
+ //** C **//
+ txt=[txt;
+ " j=max(min((int) "+...
+ tmp_+",block_"+rdnom+"["+string(bk-1)+"].nevout),1);"]
+ txt=[txt;
+ " switch(j)"
+ " {"];
+ //*******//
+ for i=II
+ //** C **//
+ txt=[txt;
+ " case "+string(j)+" :";]
+ //*******//
+ txt=[txt;
+ BigIndent+write_code_zzdoit(clkptr(bk)+i-1,9);]
+ //** C **//
+ txt=[txt;
+ BigIndent+"break;"]
+ //*******//
+ end
+ //** C **//
+ txt=[txt;
+ " }"];
+ //*******//
+ end
+ //** C **//
+ txt=[txt;
+ " for (jj=0;jj<block_"+rdnom+"["+string(fun-1)+"].nevout-1;++jj) {"
+ " g["+string(zcptr(bk)-1)+"+jj]=(double)"+tmp_+"-(double)(jj+2);"
+ " }"
+ " if(phase==1 && block_"+rdnom+"["+string(bk-1)+"].nmode>0){"
+ " j=max(min((int) "+tmp_+","
+ " block_"+rdnom+"["+string(bk-1)+"].nevout),1);"
+ " block_"+rdnom+"["+string(bk-1)+"].mode[0]= j;"
+ " }"]
+ //*******//
+
+ //** Unknown block
+ else
+ error("Unknown block type "+string(bk));
+ end
+ end
+
+endfunction
+
+
diff --git a/modules/scicos/macros/scicos_scicos/do_delete1.bin b/modules/scicos/macros/scicos_scicos/do_delete1.bin
new file mode 100755
index 000000000..7f05da707
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_delete1.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/do_delete1.sci b/modules/scicos/macros/scicos_scicos/do_delete1.sci
new file mode 100755
index 000000000..c678ae673
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_delete1.sci
@@ -0,0 +1,253 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [scs_m,DEL,DELL]=do_delete1(scs_m,K,gr)
+ //!
+ //
+ //** 30 August 2007 :
+ //** BEWARE: this code is BUGGED : see the residual split after delete
+ //** this bug is older than Simone (see scilab 3.1.1)
+ //**
+ //** 22 June 2006 : New Graphics Interface update
+ //
+ // Perform deletion of scs_m object whose index are given in the vector
+ // K and all other relevant objects (link, splits,..)
+ //
+ // deleted objects:
+ // - are replaced by the value : mlist('Deleted')
+ // - not to change the indexing: use do_purge to suppress them and to renumber objects
+ //
+ //** Perform deletion of [scs_m] object whose index are given in the vector
+ //** [K] and all other relevant objects (link, splits,..) in recursive way
+ //
+ //** Deleted objects are replaced by the value : mlist('Deleted')
+ //** ---> not to change the indexing:
+ //** ---> use [do_purge] to suppress them and to renumber objects
+ //** Similar strategy is used for the ghraphics object: to mantain the coherency
+ //** from the grphics object "gh_curwin.children.children(gr_k)" [Compund] list and the
+ //** scs_o.objs(k) data structure with the equation
+ //**
+ //** gr_k = get_gri(k, o_size(1))
+ //**
+ //** where
+ //**
+ //** o_size = size(gh_curwin.children.children); // o_size(1) => length o_size(2) => 1
+ //**
+ //** the graphics "Compound" object are NOT deleted BUT set to "invisible" with the propriety
+ //**
+ //** gh_object.visible = "off" // You can't see me, by John Cena :) ... ask enrico.mannori
+ //**
+ //** OK: ...looks simple... until you begin to fight with the code ...
+ //**
+
+ DEL = [] // table of deleted objects
+ DELL= [] // table of redefined links
+ outin = ["out","in"]
+
+ //** Delete object until "K" is empty
+ //** ----------------------------------------------------------------------------------------------
+ while K<>[] do
+
+ k = K(1); K(1) = [] ;
+
+ o = scs_m.objs(k);
+
+ if find(DEL==k)==[] then
+ typ = typeof(o);
+ else
+ typ = "Deleted"
+ end
+
+ DEL=[DEL k]
+
+ //**----------------------------------- Link -------------------------------------------
+ if typ=="Link" then
+
+ [ct,from,to]=(o.ct,o.from,o.to)
+
+ // free connected ports
+ if ct(2)==2 then //Implicit link
+
+ if or(scs_m.objs(from(1)).graphics.pin==k) & from(3)==1 then
+ scs_m.objs(from(1))=mark_prt(scs_m.objs(from(1)),from(2),"in",ct(2),0)
+ else //or(scs_m.objs(from(1)).graphics.pout==k) then
+ scs_m.objs(from(1))=mark_prt(scs_m.objs(from(1)),from(2),"out",ct(2),0)
+ end
+
+ if or(scs_m.objs(to(1)).graphics.pin==k) & to(3)==1 then
+ scs_m.objs(to(1))=mark_prt(scs_m.objs(to(1)),to(2),"in",ct(2),0)
+ else // or(scs_m.objs(to(1)).graphics.pout==k) then
+ scs_m.objs(to(1))=mark_prt(scs_m.objs(to(1)),to(2),"out",ct(2),0)
+ end
+
+ else
+ scs_m.objs(from(1))=mark_prt(scs_m.objs(from(1)),from(2),"out",ct(2),0)
+ scs_m.objs(to(1))=mark_prt(scs_m.objs(to(1)),to(2),"in",ct(2),0)
+ end
+
+ fromblock=scs_m.objs(from(1));
+ toblock=scs_m.objs(to(1));
+
+ if or(fromblock.gui==["SPLIT_f" "CLKSPLIT_f" "IMPSPLIT_f"]) then
+ //user kills a split output link:
+
+ //get links connected to the split block
+ connected=get_connected(scs_m,from(1))
+ if size(setdiff(connected,K),"*")==2 then
+ //RN: 22-7-2004 setdiff added above
+ //create a unique link with the split input and remaining
+ //output link and suppress the split block
+ if find(connected(2)==DEL)<>[] then // delete split
+ K = [from(1) K]
+ else
+ ksplit=from(1)
+ DEL=[DEL ksplit] //suppress split block
+ o1=scs_m.objs(connected(1));from1=o1.to;
+ o2=scs_m.objs(connected(2));
+
+ //create a unique link
+ if o1.from(1)==ksplit&o2.from(1)==ksplit then
+ //the two links come from the split: invert o1
+ w=o1.to;o1.to=o1.from;o1.from=w;
+ o1.xx=o1.xx($:-1:1);o1.yy=o1.yy($:-1:1);
+ elseif o1.to(1)==ksplit(1)&o2.to(1)==ksplit then
+ //the two links go from the split: invert o2
+ w=o2.to;o2.to=o2.from;o2.from=w;
+ o2.xx=o2.xx($:-1:1);o2.yy=o2.yy($:-1:1);
+ elseif o1.to(1)<>ksplit then
+ //o1 comes from the split while o2 goes to the split,
+ //switch o1 and o2
+ [o1,o2]=(o2,o1),
+ connected=connected([2 1]);
+ end
+
+ //now we can assume that o1 goes to the split and o2 comes
+ //from the split
+ from1=o1.to;to2=o2.to;ct2=o2.ct
+ //the links comes from connected(1) block and
+ //goes to connected(2) block
+ x1=o1.xx;y1=o1.yy
+ if x1($-1)==x1($)&o2.xx(1)==o2.xx(2)|.. // both segs are vertical
+ y1($-1)==y1($)&o2.yy(1)==o2.yy(2) then //both segs are horiz
+ o1.xx=[x1(1:$-1);o2.xx(2:$)];
+ o1.yy=[y1(1:$-1);o2.yy(2:$)];
+ else
+ o1.xx=[x1(1:$-1);o2.xx];
+ o1.yy=[y1(1:$-1);o2.yy];
+ end
+ o1.to=o2.to;
+
+ DEL = [DEL connected(1)] // suppress one link
+ DELL=[DELL connected(1)]
+ scs_m.objs(connected(2))=o1 //change link
+
+ scs_m.objs(to2(1))=mark_prt(scs_m.objs(to2(1)),to2(2),outin(to2(3)+1),ct2(2),..
+ connected(2))
+ scs_m.objs(o1.from(1))=mark_prt(scs_m.objs(o1.from(1)),o1.from(2),..
+ outin(o1.from(3)+1),o1.ct(2),connected(2))
+
+ end // delete split
+ end //get links connected to the split block
+ end // erase and delete link
+
+ if toblock.gui=="SPLIT_f"|toblock.gui=="CLKSPLIT_f" then //
+ //user kills a split input link
+ //ask for split deletion
+ K=[K to(1)]
+ elseif toblock.gui=="IMPSPLIT_f" then
+ //user kills a IMPsplit link:
+
+ //get links connected to the split block
+ connected=get_connected(scs_m,to(1))
+ if size(connected,"*")==2 then
+ //create a unique link with the split input and remaining
+ //output link and suppress the split block
+ if find(connected(2)==DEL)<>[] then // delete split
+ K=[to(1) K]
+ else
+
+ DEL=[DEL to(1)] //suppress split block
+
+ o1=scs_m.objs(connected(1));
+ o2=scs_m.objs(connected(2));
+ //o1 and o2 are the links that comes from the split
+
+ //create a unique link
+ to1=o1.to; //number of block at the boundary of link o1
+ to2=o2.to; //number of block at the boundary of link o2
+ if (o1.xx(1)==o1.xx(2)& o2.xx(1)==o2.xx(2))| ..
+ (o1.yy(1)==o1.yy(2)& o2.yy(1)==o2.yy(2)) then
+ o1.xx=o1.xx(2:$);o1.yy=o1.yy(2:$)
+ end
+ o1.xx=[o1.xx($:-1:1);o2.xx]
+ o1.yy=[o1.yy($:-1:1);o2.yy]
+ o1.from=o1.to
+ o1.to=o2.to;
+
+
+ DEL=[DEL connected(1)] // suppress one link
+ DELL=[DELL connected(1)]
+ scs_m.objs(connected(2))=o1 //change link
+
+ scs_m.objs(to1(1))=mark_prt(scs_m.objs(to1(1)),..
+ to1(2),outin(to1(3)+1),o1.ct(2),connected(2))
+ scs_m.objs(to2(1))=mark_prt(scs_m.objs(to2(1)),to2(2),..
+ outin(to2(3)+1),ct(2), ...
+ connected(2))
+ end //if find(connected(2)==DEL)<>[]
+
+ end //if size(connected,'*')==2
+
+ end //elseif toblock.gui=='IMPSPLIT_f'
+
+ //** -------------------------------------- Block ---------------------------------------
+ elseif typ=="Block" then
+
+ // get connected links
+ connected=get_connected(scs_m,k)
+ //ask for connected links deletion
+ K=[K connected]
+
+
+ //**--------------------------------------- Text ----------------------------------------
+ elseif typ=="Text" then
+ //** do nothing :)
+
+ //** ---------------------------- already "Deleted" object :) ----------------------------
+ elseif typ=="Deleted" then
+ //** do nothing :)
+
+ //** --------------------------- in all the other possibles cases -----------------------
+ else
+
+ messagebox("This object can''t be deleted","modal");
+
+ end //** link / Block / Text / Deleted / other...
+
+ end //** ... end of while ()
+ //**---------------------------------- end of main while() loop ---------------------------
+
+
+ //** Scan all the deleted elements and update the graphics datastrucure
+ for k = DEL
+ scs_m.objs(k) = mlist("Deleted"); //** mark the object as "Deleted"
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/do_edit_pal.bug b/modules/scicos/macros/scicos_scicos/do_edit_pal.bug
new file mode 100755
index 000000000..95457ed66
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_edit_pal.bug
@@ -0,0 +1,32 @@
+function [scicos_palnew]=do_edit_pal(scicos_pal)
+// Copyright INRIA
+scicos_palnew=[]
+load('.scicos_pal')
+ txt=scicos_pal(:,2);
+txtnew=txt
+ld=%f
+while ld=%f
+ txtnew=x_dialog('Edit the list of palettes below',txtnew)
+ if txtnew==[]|txt==txtnew then scicos_palnew=[];return;end
+ scicos_palnew=[]
+ for i=1:size(txtnew,1)
+ txtnew(i)=stripblanks(txtnew(i))
+ l=length(txtnew(i))
+ if l<>0 then
+ k=strindex(txtnew(i),'/');if k=[] then k=0;end
+ h=strindex(txtnew(i),'\');if h=[] then h=0;end
+ m=max(k,h);
+ n=strindex(txtnew(i),'.cosf')
+ if n=[] then n=strindex(txtnew(i),'.cos');end
+ if n=[] then
+ messagebox('All files must end with .cos or .cosf','modal')
+ scicos_palnew=[]
+ ld=%f;break
+ end
+ a=part(txtnew(i),m+1:n);
+ scicos_palnew=[scicos_palnew;[a,txtnew(i)]];
+ ld=%t
+ end
+ end
+end
+
diff --git a/modules/scicos/macros/scicos_scicos/do_eval.bin b/modules/scicos/macros/scicos_scicos/do_eval.bin
new file mode 100755
index 000000000..479ac7189
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_eval.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/do_eval.sci b/modules/scicos/macros/scicos_scicos/do_eval.sci
new file mode 100755
index 000000000..e26bc94db
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_eval.sci
@@ -0,0 +1,207 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// Copyright (C) DIGITEO - 2010 - Jérôme PICARD
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [scs_m,cpr,needcompile,ok]=do_eval(scs_m,cpr,%scicos_context)
+ // This function (re)-evaluates blocks in the scicos data structure scs_m
+
+ ok=%t
+ needcompile1=max(2,needcompile)
+ %mprt=funcprot()
+ funcprot(0)
+ scicos_getvalue=setvalue;
+ getvalue=setvalue;
+
+ function scicosmessage(txt)
+ messagebox(["In block " + o.gui + ": ";
+ txt;
+ "current parameter value kept"],"Warning","modal");
+ %scicos_prob = resume(%t)
+ endfunction
+
+ // overload message
+ // This function is used to alert the user on setvalue
+ // (invalid exprs we keep the previous parameters)
+ function message(str)
+ if length(arg1.doc) >= 1 then
+ uid = arg1.doc(1);
+ uid = [full_uids uid];
+
+ html = "<html><body>";
+ html = html + "<em>" + gettext("Evaluation problem: value not updated from context.") + "</em><br/>";
+ html = html + strcat(str, "<br/>") + "<br/>";
+ html = html + "</body></html>";
+ warnBlockByUID(uid, html);
+ else
+ txt = gettext("Evaluation problem: value not updated from context.");
+ txt = [txt ; str];
+ disp(txt);
+ end
+
+ %scicos_prob = resume(%t)
+ endfunction
+
+ // path on do_eval hierarchy loop
+ if ~isdef("full_uids") then
+ full_uids = [];
+ end
+
+ global %scicos_prob
+ %scicos_prob=%f
+
+ //## overload some functions used in GUI
+ deff("[ok,tt] = FORTR(funam,tt,i,o)","ok=%t")
+ deff("[ok,tt,cancel] = CFORTR2(funam,tt,i,o)","ok=%t,cancel=%f")
+ deff("[ok,tt,cancel] = CC4(funam,tt,i,o)","ok=%t,cancel=%f")
+ deff("[ok,tt] = CFORTR(funam,tt,i,o)","ok=%t")
+ deff("[x,y,ok,gc] = edit_curv(x,y,job,tit,gc)","ok=%t")
+ deff("[ok,tt,dep_ut] = genfunc1(tt,ni,no,nci,nco,nx,nz,nrp,type_)",..
+ "dep_ut=model.dep_ut;ok=%t")
+ deff("result = dialog(labels,valueini)","result=valueini")
+ deff("[result,Quit] = scstxtedit(valueini,v2)","result=valueini,Quit=0")
+ deff("[ok,tt] = MODCOM(funam,tt,vinp,vout,vparam,vparamv,vpprop)",..
+ "[dirF, nameF, extF] = fileparts(funam);..
+ [modelica_path, modelica_directory] = getModelicaPath();..
+ funam1 = []; ..
+ if (extF == """") then, ..
+ funam1 = modelica_directory + nameF + "".mo""; ..
+ elseif fileinfo(funam) == [] then, ..
+ funam1 = funam; ..
+ end; ..
+ if funam1 <> [] then, ..
+ mputl(tt, funam1); ..
+ end");
+ %nx=lstsize(scs_m.objs)
+ funcprot(%mprt)
+ for %kk=1:%nx
+ o=scs_m.objs(%kk)
+ if typeof(o)=="Block" then
+ model=o.model
+ if model.sim=="super"| (model.sim=="csuper"& ~isequal(model.ipar,1)) then //exclude mask
+ sblock=model.rpar
+ context=sblock.props.context
+ [scicos_context1,ierr]=script2var(context,%scicos_context)
+ if ierr <>0 then
+ %now_win=xget("window")
+ scicosmessage(["Cannot evaluate a context";lasterror()])
+ xset("window",%now_win)
+ else
+ previous_full_uids = full_uids;
+ if length(o.doc) >= 1 then
+ full_uids = [full_uids o.doc(1)];
+ end
+ [sblock,%w,needcompile2,ok]=do_eval(sblock,list(),scicos_context1)
+ needcompile1=max(needcompile1,needcompile2)
+ full_uids = previous_full_uids;
+ if ok then
+ scs_m.objs(%kk).model.rpar=sblock
+ else
+ return
+ end
+ end
+ elseif o.model.sim(1)=="asuper" then
+ else
+ model=o.model
+ if ~isdef(o.gui) | ~or(type(evstr(o.gui) == [13 11])) then
+ if length(o.doc) >= 1 then
+ uid = [full_uids o.doc(1)];
+
+ html = "<html><body>";
+ html = html + "<em>" + gettext("Evaluation problem: Unknown block") + "</em><br/>";
+ html = html + "</body></html>";
+ warnBlockByUID(uid, html);
+ else
+ error("do_eval: " + gettext("Evaluation problem: Unknown block") + " " + o.gui);
+ end
+ end
+
+ %scicos_prob=%f
+ ier=execstr("o="+o.gui+"(''set'',o)","errcatch", "m")
+ if ier==0& %scicos_prob==%f then
+ needcompile1=max(needcompile1,needcompile) // for scifunc_block
+ model_n=o.model
+ if or(model.blocktype<>model_n.blocktype)|.. // type 'c','d','z','l'
+ or(model.dep_ut<>model_n.dep_ut)|..
+ (model.nzcross<>model_n.nzcross)|..
+ (model.nmode<>model_n.nmode) then
+ needcompile1=4
+ end
+ if (size(model.in,"*")<>size(model_n.in,"*"))|..
+ (size(model.out,"*")<>size(model_n.out,"*"))|..
+ (size(model.evtin,"*")<>size(model_n.evtin,"*")) then
+ // number of input (evt or regular ) or output changed
+ needcompile1=4
+ end
+ if model.sim=="input"|model.sim=="output" then
+ if model.ipar<>model_n.ipar then
+ needcompile1=4
+ end
+ end
+
+ itisanMBLOCK=%f
+ if prod(size(model.sim))>1 then
+ if (model.sim(2)==30004) then
+ itisanMBLOCK=%t
+ end
+ end
+
+ if (prod(size(model.sim))==1 & ~model.equations==list()) | itisanMBLOCK then
+ if ~isequal(model.equations.parameters,model_n.equations.parameters) then
+ param_name = model.equations.parameters(1);
+ param_name_n = model_n.equations.parameters(1);
+ if ~isequal(param_name,param_name_n) then
+ needcompile1=4
+ else
+ for i=1:length(model.equations.parameters(2))
+ if or((model.equations.parameters(2)(i))<>(model_n.equations.parameters(2)(i))) then
+ needcompile=0
+
+ // the initialization XML files is re-created by translator if needed
+ // XML=TMPDIR+'/'+stripblanks(scs_m.props.title(1))+'_imf_init.xml';
+ // if ~deletefile(XML) then
+ // messagebox(msprintf(_('Unable to delete the file: %s'),XML),'error','modal');
+ // end
+
+ // the XML simulation is no more created with Xcos
+ // XMLTMP=TMPDIR+'/'+stripblanks(scs_m.props.title(1))+'_imSim.xml'
+ // if ~deletefile(XMLTMP) then
+ // messagebox(msprintf(_('Unable to delete the file: %s'),XMLTMP),'error','modal');
+ // end
+
+ break;
+ end
+ end
+ end
+ end
+ end
+
+ scs_m.objs(%kk)=o
+ else
+ error(msprintf(gettext("%s: Error while calling block %s [uid=''%s'']: invalid parameter (ier=%f, %%scicos_prob=%%%s).\n"), "do_eval", o.gui, o.model.uid, ier, string(%scicos_prob)));
+ ok=%f
+ return
+ end
+ end
+ end
+ end
+ needcompile=needcompile1
+ if needcompile==4 then cpr=list(),end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/do_purge.bin b/modules/scicos/macros/scicos_scicos/do_purge.bin
new file mode 100755
index 000000000..37514e974
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_purge.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/do_purge.sci b/modules/scicos/macros/scicos_scicos/do_purge.sci
new file mode 100755
index 000000000..b9edaf4f9
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_purge.sci
@@ -0,0 +1,78 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function scs_m_new = do_purge(scs_m)
+
+ // suppress deleted elements in a scicos data structure
+ nx = lstsize(scs_m.objs);
+
+ // get index of deleted blocks
+ deleted=[];
+ for k=1:nx
+ typ = typeof(scs_m.objs(k));
+ if typ=="Deleted" then
+ deleted = [deleted,k];
+ elseif typ=="Block" then
+ if scs_m.objs(k).model.sim=="super" then
+ scs_m.objs(k).model.rpar = do_purge(scs_m.objs(k).model.rpar)
+ end
+ end
+
+ end
+
+ if deleted==[] then // nothing has to be done
+ scs_m_new = scs_m
+ return ; //** EXIT point
+ end
+
+ retained = 1:nx;
+ retained(deleted)=[];
+
+ // compute index cross table
+ old_to_new = ones(1,nx);
+ old_to_new(deleted) = 0*deleted;
+ old_to_new = rtitr(1,%z-1,old_to_new)';
+
+ scs_m_new = scicos_diagram( version=get_scicos_version() );
+ scs_m_new.props = scs_m.props
+ for k=1:size(retained,"*")
+ o = scs_m.objs(retained(k))
+ if typeof(o)=="Block" then
+ if o.graphics.pin<>[] then
+ o.graphics.pin = old_to_new(o.graphics.pin+1);
+ end
+ if o.graphics.pout<>[] then
+ o.graphics.pout = old_to_new(o.graphics.pout+1);
+ end
+ if o.graphics.pein<>[] then
+ o.graphics.pein = old_to_new(o.graphics.pein+1);
+ end
+ if o.graphics.peout<>[] then
+ o.graphics.peout = old_to_new(o.graphics.peout+1);
+ end
+ elseif typeof(o)=="Link" then
+ o.from(1) = old_to_new(o.from(1)+1);
+ o.to(1) = old_to_new(o.to(1)+1);
+ end
+ scs_m_new.objs(k)=o;
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/do_terminate.bin b/modules/scicos/macros/scicos_scicos/do_terminate.bin
new file mode 100755
index 000000000..a1d1e3989
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_terminate.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/do_terminate.sci b/modules/scicos/macros/scicos_scicos/do_terminate.sci
new file mode 100755
index 000000000..b4763945d
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_terminate.sci
@@ -0,0 +1,104 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [alreadyran,%cpr] = do_terminate(scs_m,%cpr)
+ // Terminate the current simulation
+ // Ne rend pas la main à l'utilisateur en cas d'erreur
+
+
+ //** if sim or and state is not in %cpr
+ if prod(size(%cpr))<2 then
+ alreadyran = %f ;
+ return ; //** EXIT
+ end
+
+ par = scs_m.props ;
+
+ //** if the simulation have already ran
+ //** and is not finished
+ if alreadyran then
+ alreadyran = %f ;
+ state=%cpr.state;
+
+ //** win = xget('window');
+ gh_win = gcf();
+
+ //** run scicosim via 'finish' flag
+ ierr = execstr("[state,t]=scicosim(%cpr.state,par.tf,par.tf,%cpr.sim,"+..
+ "''finish'',par.tol)","errcatch")
+
+ //** xset('window',win)
+ scf(gh_win);
+
+ %cpr ; //get write access at the variable
+ %cpr.state = state ;//not always called with second arg
+
+ //**----------------------------------
+ if ierr<>0 then
+ str_err=split_lasterror(lasterror());
+ title_err="End problem."
+
+ kfun = curblock() ;
+ corinv = %cpr.corinv
+ if kfun<>0 then //** block error
+ path = corinv(kfun)
+
+ if type(path)==15 then //** modelica block
+ spec_err="The modelica block returns the error :";
+ messagebox([title_err;spec_err;str_err],"modal");
+
+ else //** all other type of blocks
+ obj_path=path(1:$-1)
+ spec_err="block"
+ blk=path($)
+ scs_m_n=scs_m;
+ //** check if we can open a window
+ //** Alan: we can improve that piece of code
+ //** to also returns the name of the comput. func.
+ for i=1:size(path,"*")
+ if scs_m_n.objs(path(i)).model.sim=="super" then
+ scs_m_n=scs_m_n.objs(path(i)).model.rpar;
+ elseif scs_m_n.objs(path(i)).model.sim=="csuper" then
+ obj_path=path(1:i-1);
+ blk=path(i);
+ //spec_err='csuper block (block '+string(path(i+1))+')'
+ spec_err="csuper block"
+ break;
+ end
+ end
+ spec_err="The highlighted "+spec_err+" returns the error :";
+ //**
+ scf(curwin)
+ //** call bad_connection
+ bad_connection(path,...
+ [title_err;spec_err;str_err],0,1,0,-1,0,1)
+ end
+ else//** simulateur error
+ messagebox(["End problem:";str_err],"modal")
+ end
+ end
+ //**---------------------------------
+
+ //** xset('window',curwin)
+ scf(curwin);
+
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/do_update.bin b/modules/scicos/macros/scicos_scicos/do_update.bin
new file mode 100755
index 000000000..b22f72182
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_update.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/do_update.sci b/modules/scicos/macros/scicos_scicos/do_update.sci
new file mode 100755
index 000000000..1b31dc026
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_update.sci
@@ -0,0 +1,124 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [%cpr,%state0,needcompile,alreadyran,ok]=do_update(%cpr,%state0,needcompile)
+ //Update an already compiled scicos diagram compilation result according to
+ //parameter changes
+ //!
+ ok=%t
+ select needcompile
+ case 0 then // only parameter changes
+ if size(newparameters)<>0 then
+ cor=%cpr.cor
+ [%state0,state,sim,ok]=modipar(newparameters,%state0,%cpr.state,%cpr.sim)
+ if ~ok then
+ alreadyran=do_terminate();
+ disp("Partial compilation failed. Attempting a full compilation.");
+ needcompile=4
+ [%cpr,ok]=do_compile(scs_m)
+ if ok then
+ %state0=%cpr.state
+ needcompile=0
+ return;
+ end
+ end
+ %cpr.state=state,%cpr.sim=sim
+ end
+ case 1 then // parameter changes and/or port sizes change
+ if size(newparameters)<>0 then
+ // update parameters or states
+ cor=%cpr.cor
+ [%state0,state,sim,ok]=modipar(newparameters,%state0,%cpr.state,%cpr.sim)
+ if (~ok| findinlistcmd(%cpr.corinv,size(cor),">")<>list() ) then
+ alreadyran=do_terminate()
+ disp("Partial compilation failed. Attempting a full compilation.");
+ needcompile=4
+ [%cpr,ok]=do_compile(scs_m)
+ if ok then
+ %state0=%cpr.state
+ needcompile=0
+ end
+ return;
+ end
+ %cpr.state=state,%cpr.sim=sim
+ end
+ //update port sizes.
+ // NB: if modelica part block size has been changed, the diagram is recompiled
+ bllst=list();
+ corinv=%cpr.corinv
+ sim=%cpr.sim
+ for k=1:size(corinv)
+ if type(corinv(k))==1 then //dont take care of modelica blocks
+ if size(corinv(k),"*")==1 then
+ bllst(k)=scs_m.objs(corinv(k)).model;
+ else
+ path=list("objs");
+ for l=corinv(k)(1:$-1),
+ path($+1)=l;
+ path($+1)="model";
+ path($+1)="rpar";path($+1)="objs";
+ end
+ path($+1)=corinv(k)($);
+ path($+1)="model";
+ bllst(k)=scs_m(path);
+ end
+ else // modelica block
+ //build a fake bllst(k) only for in and out fields
+ m=scicos_model();
+ m.in=ones(sim.inpptr(k+1)-sim.inpptr(k),1)
+ m.out=ones(sim.outptr(k+1)-sim.outptr(k),1)
+ bllst(k)=m;
+ end
+ end
+ [ok,bllst]=adjust(bllst,sim("inpptr"),sim("outptr"),sim("inplnk"),..
+ sim("outlnk"))
+ if ok then
+ [lnksz,lnktyp]=lnkptrcomp(bllst,sim("inpptr"),sim("outptr"),...
+ sim("inplnk"),sim("outlnk"))
+ %cpr.state("outtb")=buildouttb(lnksz,lnktyp)
+ %state0("outtb")=buildouttb(lnksz,lnktyp)
+ needcompile=0
+ end
+
+ case 2 then // partial recompilation
+ alreadyran=do_terminate()
+ [%cpr,ok]=c_pass3(scs_m,%cpr)
+ if ok then
+ %state0=%cpr.state
+ needcompile=0;
+ return;
+ end
+ disp("Partial compilation failed. Attempting a full compilation.");
+ [%cpr,ok]=do_compile(scs_m)
+ if ok then
+ %state0=%cpr.state
+ needcompile=0
+ end
+ case 4 then // full compilation
+ alreadyran=do_terminate()
+ [%cpr,ok]=do_compile(scs_m)
+ if ok then
+ %state0=%cpr.state
+ needcompile=0
+ end
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/do_version.bin b/modules/scicos/macros/scicos_scicos/do_version.bin
new file mode 100755
index 000000000..0da93bce3
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_version.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/do_version.sci b/modules/scicos/macros/scicos_scicos/do_version.sci
new file mode 100755
index 000000000..8042e0ce1
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/do_version.sci
@@ -0,0 +1,2328 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// Copyright (C) DIGITEO - 2010 - Jérôme PICARD
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function scs_m=do_version(scs_m,version)
+
+ // available versions of Scicos
+ availableVersions = [ ..
+ "scicos2.2"; ..
+ "scicos2.3"; ..
+ "scicos2.3.1"; ..
+ "scicos2.4"; ..
+ "scicos2.5.1"; ..
+ "scicos2.7"; ..
+ "scicos2.7.1"; ..
+ "scicos2.7.2"; ..
+ "scicos2.7.3"; ..
+ "scicos4"; ..
+ "scicos4.0.1"; ..
+ "scicos4.0.2"; ..
+ "scicos4.2"; ..
+ "scicos4.0.1"; ..
+ "scicos4.0.2"; ..
+ "scicos4.2"; ..
+ "scicos4.3"; ..
+ "scicos4.4"];
+
+ if ~or(version==availableVersions) then
+ error("No version update defined to "+version+" version")
+ end
+
+ if version=="scicos2.2" then scs_m=do_version22(scs_m);version="scicos2.3";end
+ if version=="scicos2.3" then scs_m=do_version23(scs_m);version="scicos2.3.1";end
+ if version=="scicos2.3.1" then scs_m=do_version231(scs_m); version="scicos2.4";end
+ if version=="scicos2.4" then scs_m=do_version251(scs_m),version="scicos2.5.1";end
+ if version=="scicos2.5.1" then
+ ncl=lines()
+ lines(0)
+ disp("This is an old scicos diagram. I have to translate.")
+ scs_m=do_versionxx(scs_m);scs_m=do_version27(scs_m);version="scicos2.7";
+ disp("I am now going to clean your diagram. Block numbers may change.")
+ scs_m=do_purge(scs_m);
+ disp("Save the diagram (under a different name just in case)")
+ lines(ncl(2))
+ end
+ if version=="scicos2.7" then
+ disp("This is an old scicos diagram. I have to translate. Be patient.")
+ scs_m=do_version271(scs_m),
+ version="scicos2.7.1";
+ end
+ if version=="scicos2.7.1" then scs_m=do_version272(scs_m),version="scicos2.7.2";end
+ if version=="scicos2.7.2" then scs_m=do_version273(scs_m),version="scicos2.7.3";end
+ if version=="scicos2.7.3" | version=="scicos4" |...
+ version=="scicos4.0.1" | version=="scicos4.0.2" then
+ version="scicos4.2";
+ //*** do certification ***//
+ scs_m=update_scs_m(scs_m,version);
+ //*** update scope ***//
+ scs_m=do_version42(scs_m);
+ //*********************************//
+ end
+ if version=="scicos4.2" then
+ ncl=lines(); lines(0);
+ version="scicos4.3";
+ //*** do certification ***//
+ scs_m=update_scs_m(scs_m,version);
+ scs_m=do_version43(scs_m);
+ lines(ncl(2))
+ end
+
+ if or(version==["scicos4.3";"scicos4.4"]) then
+ ncl=lines(); lines(0);
+ version="scicos4.3";
+ scs_m=update_scs_m(scs_m,version);
+ scs_m=do_version43(scs_m);
+ scs_m.version = version;
+ lines(ncl(2))
+ end
+endfunction
+
+function scs_m_new=do_version43(scs_m)
+ //disp('do_version43');
+ scs_m_new=scs_m;
+
+ //@@ adjust ID.fonts
+ scs_m_new.props.options.ID(1)=[scs_m.props.options.ID(1)(1),scs_m.props.options.ID(1)(2),2,1];
+ scs_m_new.props.options.ID(2)=[scs_m.props.options.ID(2)(1),scs_m.props.options.ID(2)(2),10,1];
+
+ n=size(scs_m.objs);
+ for j=1:n //loop on objects
+ o=scs_m.objs(j);
+ if typeof(o)=="Block" then
+ omod=o.model;
+
+ // Clear the doc fields if it contains a function pointer
+ if type(o.doc) == 15 & size(o.doc) > 1 & (type(o.doc(1)) == 11 | type(o.doc(1)) == 13) then
+ scs_m_new.objs(j).doc = list();
+ end
+
+ //@@ sbloc
+ if omod.sim=="super"|omod.sim=="csuper"|omod.sim(1)=="asuper" then
+ rpar=do_version43(omod.rpar)
+ scs_m_new.objs(j).model.rpar=rpar
+ end
+
+ //@@ Change gr_i of MUX if needed
+ if o.gui=="MUX" then
+ gr_i=["txt=''Mux'';"
+ "style=5;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"
+ "e.font_style=style;"]
+ id=o.graphics.id
+ if id=="Mux" then id="",end
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == " " then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i == " " then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of DEMUX if needed
+ elseif o.gui=="DEMUX" then
+ gr_i=["txt=''Demux'';"
+ "style=5;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"
+ "e.font_style=style;"]
+ id=o.graphics.id
+ if id=="Demux" then id="",end
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == "" then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i == "" then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of FROMWSB
+ elseif o.gui=="FROMWSB" then
+ gr_i=["xstringb(orig(1),orig(2),''From workspace'',sz(1),sz(2),''fill'')"
+ "txt=varnam;"
+ "style=5;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"
+ "e.font_style=style;"]
+ id=""
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ else
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+
+ //@@ Change gr_i of TOWS_c
+ elseif o.gui=="TOWS_c" then
+ gr_i=["xstringb(orig(1),orig(2),''To workspace'',sz(1),sz(2),''fill'')"
+ "txt=varnam;"
+ "style=5;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"
+ "e.font_style=style;"]
+ id=""
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ else
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+
+ //@@ Change gr_i of INTEGRAL_m if needed
+ elseif o.gui=="INTEGRAL_m" | o.gui=="INTEGRAL" then
+ gr_i=["thick=xget(''thickness'')"
+ "pat=xget(''pattern'')"
+ "fnt=xget(''font'')"
+ "xpoly(orig(1)+[0.7;0.62;0.549;0.44;0.364;0.291]*sz(1),orig(2)+[0.947;0.947;0.884;0.321;0.255;0.255]*sz(2),"'lines"')"
+ "txt=''1/s'';"
+ "style=5;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"
+ "e.font_style=style;"
+ "xset(''thickness'',thick)"
+ "xset(''pattern'',pat)"
+ "xset(''font'',fnt(1),fnt(2))"]
+ old_gri=["thick=xget(''thickness'')"
+ "pat=xget(''pattern'')"
+ "fnt=xget(''font'')"
+ "xpoly(orig(1)+[0.7;0.62;0.549;0.44;0.364;0.291]*sz(1),orig(2)+[0.947;0.947;0.884;0.321;0.255;0.255]*sz(2),"'lines"')"
+ "xset(''thickness'',thick)"
+ "xset(''pattern'',pat)"
+ "xset(''font'',fnt(1),fnt(2))"
+ ]
+ id=o.graphics.id
+ if id=="1/s" then id="",end
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of PRODUCT if needed
+ elseif o.gui=="PRODUCT" then
+ gr_i=["[x,y,typ]=standard_inputs(o) ";
+ "dd=sz(1)/8,de=0,"
+ "if ~arg1.graphics.flip then dd=6*sz(1)/8,de=-sz(1)/8,end"
+ "for k=1:size(x,''*'')";
+ "if size(sgn,1)>1 then"
+ " if sgn(k)>0 then";
+ " xstring(orig(1)+dd,y(k)-4,''*'')";
+ " else";
+ " xstring(orig(1)+dd,y(k)-4,''/'')";
+ " end";
+ "end";
+ "end";
+ "xx=sz(1)*[.8 .8 .4 .4]+orig(1)+de";
+ "yy=sz(2)*[.2 .8 .8 .2]+orig(2)";
+ "xpoly(xx,yy,''lines'')"
+ "txt=''Product'';"
+ "style=5;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"
+ "e.font_style=style;"]
+ old_gri=["[x,y,typ]=standard_inputs(o) ";
+ "dd=sz(1)/8,de=0,"
+ "if ~arg1.graphics.flip then dd=6*sz(1)/8,de=-sz(1)/8,end"
+ "for k=1:size(x,''*'')";
+ "if size(sgn,1)>1 then"
+ " if sgn(k)>0 then";
+ " xstring(orig(1)+dd,y(k)-4,''*'')";
+ " else";
+ " xstring(orig(1)+dd,y(k)-4,''/'')";
+ " end";
+ "end";
+ "end";
+ "xx=sz(1)*[.8 .8 .4 .4]+orig(1)+de";
+ "yy=sz(2)*[.2 .8 .8 .2]+orig(2)";
+ "xpoly(xx,yy,''lines'')"]
+ id=o.graphics.id
+ if id=="1/s" then id="",end
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of DERIV if needed
+ elseif o.gui=="DERIV" then
+ gr_i=["xstringb(orig(1),orig(2),'' du/dt '',sz(1),sz(2),''fill'');"
+ "txt=''s'';"
+ "style=5;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"
+ "e.font_style=style;"]
+ old_gri=["xstringb(orig(1),orig(2),'' du/dt '',sz(1),sz(2),''fill'');"]
+ id=o.graphics.id
+ if id=="s" then id="",end
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of JKFLIPFLOP if needed
+ elseif o.gui=="JKFLIPFLOP" then
+ gr_i=["[x,y,typ]=standard_inputs(o) ";
+ "dd=sz(1)/8,de=5.5*sz(1)/8";
+ "txt=''J'';"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "rectstr=stringbox(txt,orig(1)+dd,y(1)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+dd,y(1)-4,txt,w,h,''fill'')";
+ "txt=''clk'';"
+ "rectstr=stringbox(txt,orig(1)+dd,y(2)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+dd,y(2)-4,txt,w,h,''fill'')";
+ "txt=''K'';"
+ "rectstr=stringbox(txt,orig(1)+dd,y(3)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+dd,y(3)-4,txt,w,h,''fill'')";
+ "[x,y,typ]=standard_outputs(o) ";
+ "txt=''Q'';"
+ "rectstr=stringbox(txt,orig(1)+de,y(1)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+de,y(1)-4,txt,w,h,''fill'')";
+ "txt=''!Q'';"
+ "rectstr=stringbox(txt,orig(1)+4.5*dd,y(2)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+4.5*dd,y(2)-4,txt,w,h,''fill'')";
+ "txt=''JK FLIP-FLOP'';"
+ "style=5;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"
+ "e.font_style=style;"]
+ old_gri=["[x,y,typ]=standard_inputs(o) ";
+ "dd=sz(1)/8,de=6*sz(1)/8";
+ "xstring(orig(1)+dd,y(1)-4,''J'')";
+ "xstring(orig(1)+dd,y(2)-4,''clk'')";
+ "xstring(orig(1)+dd,y(3)-4,''K'')";
+ "[x,y,typ]=standard_outputs(o) ";
+ "xstring(orig(1)+de,y(1)-4,''Q'')";
+ "xstring(orig(1)+5*dd,y(2)-4,''!Q'')"]
+ id=o.graphics.id
+ if id=="JK FLIP-FLOP" then id="",end
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of SRFLIPFLOP if needed
+ elseif o.gui=="SRFLIPFLOP" then
+ gr_i=["[x,y,typ]=standard_inputs(o) ";
+ "dd=sz(1)/8,de=5.5*sz(1)/8";
+ "txt=''S'';"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "rectstr=stringbox(txt,orig(1)+dd,y(1)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+dd,y(1)-4,txt,w,h,''fill'')";
+ "txt=''R'';"
+ "rectstr=stringbox(txt,orig(1)+dd,y(2)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+dd,y(2)-4,txt,w,h,''fill'')";
+ "[x,y,typ]=standard_outputs(o) ";
+ "txt=''Q'';"
+ "rectstr=stringbox(txt,orig(1)+de,y(1)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+de,y(1)-4,txt,w,h,''fill'')";
+ "txt=''!Q'';"
+ "rectstr=stringbox(txt,orig(1)+4.5*dd,y(2)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+4.5*dd,y(2)-4,txt,w,h,''fill'')";
+ "txt=''SR FLIP-FLOP'';"
+ "style=5;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"
+ "e.font_style=style;"]
+ old_gri=["[x,y,typ]=standard_inputs(o) ";
+ "dd=sz(1)/8,de=6*sz(1)/8";
+ "xstring(orig(1)+dd,y(1)-4,''S'')";
+ "xstring(orig(1)+dd,y(2)-4,''R'')";
+ "[x,y,typ]=standard_outputs(o) ";
+ "xstring(orig(1)+de,y(1)-4,''Q'')";
+ "xstring(orig(1)+5*dd,y(2)-4,''!Q'')"]
+ id=o.graphics.id
+ if id=="SR FLIP-FLOP" then id="",end
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of DLATCH if needed
+ elseif o.gui=="DLATCH" then
+ gr_i=["[x,y,typ]=standard_inputs(o) ";
+ "dd=sz(1)/8,de=5.5*sz(1)/8";
+ "txt=''D'';"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "rectstr=stringbox(txt,orig(1)+dd,y(1)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+dd,y(1)-4,txt,w,h,''fill'')";
+ "txt=''C'';"
+ "rectstr=stringbox(txt,orig(1)+dd,y(2)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+dd,y(2)-4,txt,w,h,''fill'')";
+ "txt=''Q'';"
+ "rectstr=stringbox(txt,orig(1)+de,y(1)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+de,y(1)-4,txt,w,h,''fill'')";
+ "txt=''!Q'';"
+ "rectstr=stringbox(txt,orig(1)+4.5*dd,y(2)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+4.5*dd,y(2)-4,txt,w,h,''fill'')";
+ "txt=''DLATCH'';"
+ "style=5;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"
+ "e.font_style=style;"]
+ old_gri=["[x,y,typ]=standard_inputs(o) ";
+ "dd=sz(1)/8,de=6*sz(1)/8";
+ "xstring(orig(1)+dd,y(1)-4,''D'')";
+ "xstring(orig(1)+dd,y(2)-4,''C'')";
+ "xstring(orig(1)+de,y(1)-4,''Q'')";
+ "xstring(orig(1)+5*dd,y(2)-4,''!Q'')"]
+ id=o.graphics.id
+ if id=="DLATCH" then id="",end
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of DFLIPFLOP if needed
+ elseif o.gui=="DFLIPFLOP" then
+ gr_i=["[x,y,typ]=standard_inputs(o) ";
+ "dd=sz(1)/8,de=5.5*sz(1)/8";
+ "txt=''D'';"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "rectstr=stringbox(txt,orig(1)+dd,y(1)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+dd,y(1)-4,txt,w,h,''fill'')";
+ "txt=''clk'';"
+ "rectstr=stringbox(txt,orig(1)+dd,y(2)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+dd,y(2)-4,txt,w,h,''fill'')";
+ "txt=''en'';"
+ "rectstr=stringbox(txt,orig(1)+dd,y(3)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+dd,y(3)-4,txt,w,h,''fill'')";
+ "[x,y,typ]=standard_outputs(o) ";
+ "txt=''Q'';"
+ "rectstr=stringbox(txt,orig(1)+de,y(1)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+de,y(1)-4,txt,w,h,''fill'')";
+ "txt=''!Q'';"
+ "rectstr=stringbox(txt,orig(1)+4.5*dd,y(2)-4,0,1,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+4.5*dd,y(2)-4,txt,w,h,''fill'')";
+ "txt=''D FLIP-FLOP'';"
+ "style=5;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"
+ "e.font_style=style;"]
+ old_gri=["[x,y,typ]=standard_inputs(o) ";
+ "dd=sz(1)/8,de=6*sz(1)/8";
+ "xstring(orig(1)+dd,y(1)-4,''D'')";
+ "xstring(orig(1)+dd,y(2)-4,''clk'')";
+ "xstring(orig(1)+dd,y(3)-4,''en'')";
+ "[x,y,typ]=standard_outputs(o) ";
+ "xstring(orig(1)+de,y(1)-4,''Q'')";
+ "xstring(orig(1)+5*dd,y(2)-4,''!Q'')"]
+ id=o.graphics.id
+ if id=="D FLIP-FLOP" then id="",end
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of CLKGotoTagVisibility if needed
+ elseif o.gui=="CLKGotoTagVisibility" then
+ gr_i=["xstringb(orig(1),orig(2),[''{''+arg1.graphics.exprs(1)+''}''],sz(1),sz(2),''fill'');";
+ "wd=xget(''wdim'').*[1.016,1.12];";
+ "thick=xget(''thickness'');xset(''thickness'',2);";
+ "p=wd(2)/wd(1);p=1;";
+ "xarcs([orig(1)+0.05*sz(1);";
+ "orig(2)+0.95*sz(2);";
+ "0.9*sz(1)*p;";
+ "0.9*sz(2);";
+ "0;";
+ "360*64],scs_color(5));";
+ "txt=[''Goto Tag'';''Visibility'' ];"
+ "style=5;"
+ "gh_axes = gca();"
+ "axes_font_style = gh_axes.font_style ;"
+ "axes_font_size = gh_axes.font_size ;"
+ "gh_axes.font_style = 5;"
+ "gh_axes.font_size = 1;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-5,txt,w,h,''fill'');"
+ "gh_axes.font_style = axes_font_style ;"
+ "gh_axes.font_size = axes_font_size ;"
+ "xset(''thickness'',thick)"]
+ old_gri=["xstringb(orig(1),orig(2),[''{''+arg1.graphics.exprs(1)+''}''],sz(1),sz(2),''fill'');";
+ "wd=xget(''wdim'').*[1.016,1.12];";
+ "thick=xget(''thickness'');xset(''thickness'',2);";
+ "p=wd(2)/wd(1);p=1;";
+ "xarcs([orig(1)+0.05*sz(1);";
+ "orig(2)+0.95*sz(2);";
+ "0.9*sz(1)*p;";
+ "0.9*sz(2);";
+ "0;";
+ "360*64],scs_color(5));";
+ "xset(''thickness'',thick)"]
+ id=o.graphics.id
+ if id==["Goto Tag";"Visibility"] then id="",end
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of GotoTagVisibilityMO if needed
+ elseif o.gui=="GotoTagVisibilityMO" then
+ gr_i=["xstringb(orig(1),orig(2),[''{''+arg1.graphics.exprs(1)+''}''],sz(1),sz(2),''fill'');";
+ "wd=xget(''wdim'').*[1.016,1.12];";
+ "thick=xget(''thickness'');xset(''thickness'',2);";
+ "p=wd(2)/wd(1);p=1;";
+ "xarcs([orig(1)+0.05*sz(1);";
+ "orig(2)+0.95*sz(2);";
+ "0.9*sz(1)*p;";
+ "0.9*sz(2);";
+ "0;";
+ "360*64],scs_color(3));";
+ "txt=[''Goto Tag'';''Visibility'' ];"
+ "style=5;"
+ "gh_axes = gca();"
+ "axes_font_style = gh_axes.font_style ;"
+ "axes_font_size = gh_axes.font_size ;"
+ "gh_axes.font_style = 5;"
+ "gh_axes.font_size = 1;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-5,txt,w,h,''fill'');"
+ "gh_axes.font_style = axes_font_style ;"
+ "gh_axes.font_size = axes_font_size ;"
+ "xset(''thickness'',thick)"]
+ old_gri=["xstringb(orig(1),orig(2),[''{''+arg1.graphics.exprs(1)+''}''],sz(1),sz(2),''fill'');";
+ "wd=xget(''wdim'').*[1.016,1.12];";
+ "thick=xget(''thickness'');xset(''thickness'',2);";
+ "p=wd(2)/wd(1);p=1;";
+ "xarcs([orig(1)+0.05*sz(1);";
+ "orig(2)+0.95*sz(2);";
+ "0.9*sz(1)*p;";
+ "0.9*sz(2);";
+ "0;";
+ "360*64],scs_color(3));";
+ "xset(''thickness'',thick)"]
+ id=o.graphics.id
+ if id==["Goto Tag";"Visibility"] then id="",end
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of GotoTagVisibility if needed
+ elseif o.gui=="GotoTagVisibility" then
+ gr_i=["xstringb(orig(1),orig(2),[''{''+arg1.graphics.exprs(1)+''}''],sz(1),sz(2),''fill'');"
+ "txt=[''Goto Tag'';''Visibility'' ];"
+ "style=5;"
+ "gh_axes = gca();"
+ "axes_font_style = gh_axes.font_style ;"
+ "axes_font_size = gh_axes.font_size ;"
+ "gh_axes.font_style = 5;"
+ "gh_axes.font_size = 1;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-5,txt,w,h,''fill'');"
+ "gh_axes.font_style = axes_font_style ;"
+ "gh_axes.font_size = axes_font_size ;"]
+ old_gri=["xstringb(orig(1),orig(2),[''{''+arg1.graphics.exprs(1)+''}''],sz(1),sz(2),''fill'');"]
+ id=o.graphics.id
+ if id==["Goto Tag";"Visibility"] then id="",end
+ scs_m_new.objs(j).graphics.id=id
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of Inductor if needed
+ elseif o.gui=="Inductor" then
+ gr_i=["tt=linspace(0.04,0.96,100)'';"
+ "xpoly(tt*sz(1)+orig(1),+orig(2)+abs(sin(18*(tt-0.04)))*sz(2),""lines"");";
+ "xx=orig(1)+[0 0.04 0.04 0.04 0]*sz(1);";
+ "yy=orig(2)+[1/2 1/2 0 1/2 1/2]*sz(2);";
+ "xpoly(xx,yy) ";
+ "xx=orig(1)+[0.96 0.96 1 0.96 0.96 ]*sz(1);";
+ "yy=orig(2)+[abs(sin(18*0.92)) 1/2 1/2 1/2 abs(sin(18*0.92))]*sz(2);";
+ "xpoly(xx,yy) ";
+ "txt=''L= ''+L;"
+ "style=2;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"]
+ old_gri=["tt=linspace(0.04,0.96,100)'';"
+ "xpoly(tt*sz(1)+orig(1),+orig(2)+abs(sin(18*(tt-0.04)))*sz(2),""lines"");";
+ "xx=orig(1)+[0 0.04 0.04 0.04 0]*sz(1);";
+ "yy=orig(2)+[1/2 1/2 0 1/2 1/2]*sz(2);";
+ "xpoly(xx,yy) ";
+ "xx=orig(1)+[0.96 0.96 1 0.96 0.96 ]*sz(1);";
+ "yy=orig(2)+[abs(sin(18*0.92)) 1/2 1/2 1/2 abs(sin(18*0.92))]*sz(2);";
+ "xpoly(xx,yy) ";
+ "rect=xstringl(0,0,''L=''+L)"
+ "xstring(orig(1)+(sz(1)-rect(3))/2,orig(2)-rect(4)*1.2,''L=''+L)"]
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of Capacitor if needed
+ elseif o.gui=="Capacitor" then
+ gr_i=["xset(''thickness'',2)"
+ "xx=orig(1)+[0 1/3 1/3 1/3 ]*sz(1);";
+ "yy=orig(2)+[1/2 1/2 1 0]*sz(2);";
+ "xpoly(xx,yy);"
+ "xsegs(orig(1)+ sz(1)*2/3*[1 1 1 3/2],orig(2)+(sz(2)*1/2)*[2 0 1 1],0);";
+ "if orient then"
+ " xrects([orig(1)+sz(1)*1/2;orig(2)+sz(2);sz(1)*1/6;sz(2)],scs_color(33));"
+ " xstring(orig(1)+sz(1)*1/12,orig(2)+sz(2)*3/4,''+'');";
+ " xstring(orig(1)+sz(1)*7/8,orig(2)+sz(2)*3/4,''-'');";
+ "else"
+ " xrects([orig(1)+sz(1)*1/3;orig(2)+sz(2);sz(1)*1/6;sz(2)],scs_color(33));"
+ " xstring(orig(1)+sz(1)*1/12,orig(2)+sz(2)*3/4,''-'');";
+ " xstring(orig(1)+sz(1)*7/8,orig(2)+sz(2)*3/4,''+'');";
+ "end"
+ "txt=''C= ''+C;"
+ "style=2;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"
+ "e.font_style=style;"]
+ old_gri=["xset(''thickness'',2)"
+ "xx=orig(1)+[0 1/3 1/3 1/3 ]*sz(1);";
+ "yy=orig(2)+[1/2 1/2 1 0]*sz(2);";
+ "xpoly(xx,yy);"
+ "xsegs(orig(1)+ sz(1)*2/3*[1 1 1 3/2],orig(2)+(sz(2)*1/2)*[2 0 1 1],0);";
+ "if orient then"
+ " xrects([orig(1)+sz(1)*1/2;orig(2)+sz(2);sz(1)*1/6;sz(2)],scs_color(33));"
+ " xstring(orig(1)+sz(1)*1/12,orig(2)+sz(2)*3/4,''+'');";
+ " xstring(orig(1)+sz(1)*7/8,orig(2)+sz(2)*3/4,''-'');";
+ "else"
+ " xrects([orig(1)+sz(1)*1/3;orig(2)+sz(2);sz(1)*1/6;sz(2)],scs_color(33));"
+ " xstring(orig(1)+sz(1)*1/12,orig(2)+sz(2)*3/4,''-'');";
+ " xstring(orig(1)+sz(1)*7/8,orig(2)+sz(2)*3/4,''+'');";
+ "end"
+ "rect=xstringl(0,0,''C=''+C)"
+ "xstring(orig(1)+(sz(1)-rect(3))/2,orig(2)-rect(4)*1.2,''C= ''+C);"]
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ //@@ Change gr_i of Resistor if needed
+ elseif o.gui=="Resistor" then
+ gr_i=["xx=[0,1,1,7,7,8,7,7,1,1]/8;";
+ "yy=[1,1,0,0,1,1,1,2,2,1]/2;";
+ "xpoly(orig(1)+xx*sz(1),orig(2)+yy*sz(2)); "
+ "txt=''R= ''+R;"
+ "style=2;"
+ "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
+ "if ~exists(''%zoom'') then %zoom=1, end;"
+ "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
+ "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
+ "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
+ "e=gce();"]
+ old_gri=["xx=[0,1,1,7,7,8,7,7,1,1]/8;";
+ "yy=[1,1,0,0,1,1,1,2,2,1]/2;";
+ "xpoly(orig(1)+xx*sz(1),orig(2)+yy*sz(2)); "
+ "rect=xstringl(0,0,''R=''+R)"
+ "xstring(orig(1)+(sz(1)-rect(3))/2,orig(2)-rect(4)*1.2,''R=''+R);"]
+ if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
+ end
+ else
+ if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
+ scs_m_new.objs(j).graphics.gr_i=gr_i
+ end
+ end
+
+ end
+ end
+ end
+endfunction
+
+
+//*** update scope ***//
+function scs_m_new=do_version42(scs_m)
+ scs_m_new=scs_m
+ n=size(scs_m.objs);
+ for j=1:n //loop on objects
+ o=scs_m.objs(j);
+ if typeof(o)=="Block" then
+ omod=o.model;
+ //SUPER BLOCK
+ if omod.sim=="super"|omod.sim=="csuper" then
+ rpar=do_version42(omod.rpar)
+ scs_m_new.objs(j).model.rpar=rpar
+ //name of gui and sim list change
+ elseif o.gui=="SCOPE_f" then
+ scs_m_new.objs(j).gui="CSCOPE"
+ scs_m_new.objs(j).model.dstate=[]
+ //Alan's patch 01/10/07 : remove the last parameter
+ // (inheritance not used in cscope)
+ ipar = scs_m_new.objs(j).model.ipar(:);
+ scs_m_new.objs(j).model.ipar = ipar(1:$-1);
+ scs_m_new.objs(j).model.sim=list("cscope", 4)
+ in = scs_m_new.objs(j).model.in(:);
+ a = size(in,1);
+ in2 = ones(a,1);
+ scs_m_new.objs(j).model.in2 = in2;
+ scs_m_new.objs(j).model.intyp = in2;
+ //Alan's patch 04/10/07 : update exprs
+ exprs = scs_m.objs(j).graphics.exprs;
+ if size(exprs)<9 then exprs(9)="0",end // compatibility
+ if size(exprs)<10 then exprs(10)=emptystr(),end // compatibility
+ scs_m_new.objs(j).graphics.exprs=exprs;
+ elseif o.gui=="CSCOPE" then
+ //Alan's patch 04/10/07 : update exprs
+ exprs = scs_m.objs(j).graphics.exprs;
+ if size(exprs)<10 then exprs(10)=emptystr(),end // compatibility
+ scs_m_new.objs(j).graphics.exprs=exprs;
+ elseif o.gui=="BOUNCEXY" then
+ in = scs_m_new.objs(j).model.in(:);
+ a = size(in,1);
+ in2 = ones(a,1);
+ scs_m_new.objs(j).model.in2 = in2;
+ scs_m_new.objs(j).model.intyp = in2;
+ elseif o.gui=="MSCOPE_f" then
+ //Alan's patch 04/10/07 : update exprs
+ exprs = scs_m.objs(j).graphics.exprs;
+ if size(exprs)<10 then exprs(10)="0",end // compatibility
+ if size(exprs)<11 then exprs(11)=emptystr(),end // compatibility
+ scs_m_new.objs(j).graphics.exprs=exprs;
+ scs_m_new.objs(j).gui="CMSCOPE"
+ scs_m_new.objs(j).model.dstate=[]
+ scs_m_new.objs(j).model.sim=list("cmscope", 4)
+ in = scs_m_new.objs(j).model.in(:);
+ a = size(in,1);
+ B=stripblanks(scs_m.objs(j).graphics.exprs(8));
+ B(1:a)=B;
+ B = strcat(B', " ");
+ scs_m_new.objs(j).graphics.exprs(8) = B;
+ rpar=scs_m_new.objs(j).model.rpar(:);
+ N=scs_m_new.objs(j).model.ipar(2);
+ period = [];
+ for i=1:N
+ period(i)=rpar(2);
+ end
+ scs_m_new.objs(j).model.rpar = [rpar(1);period(:);rpar(3:size(rpar,1))]
+ in2 = ones(a,1);
+ scs_m_new.objs(j).model.in2 = in2;
+ scs_m_new.objs(j).model.intyp = in2;
+ elseif o.gui=="ANIMXY_f" then
+ scs_m_new.objs(j).gui="CANIMXY"
+ scs_m_new.objs(j).model.dstate=[]
+ scs_m_new.objs(j).model.sim=list("canimxy", 4)
+ in = scs_m_new.objs(j).model.in(:);
+ a = size(in,1);
+ in2 = ones(a,1);
+ scs_m_new.objs(j).model.in2 = in2;
+ scs_m_new.objs(j).model.intyp = in2;
+ scs_m_new.objs(j).graphics.exprs = [string(1);scs_m_new.objs(j).graphics.exprs(:)]
+ scs_m_new.objs(j).model.ipar = [scs_m_new.objs(j).model.ipar(:);1]
+ //Alan's patch 04/10/07 : update exprs
+ exprs = scs_m_new.objs(j).graphics.exprs(:)
+ if size(exprs,"*")==8 then exprs=[1;exprs(1:3);"[]";"[]";exprs(4:8)],end
+ scs_m_new.objs(j).graphics.exprs=exprs;
+ elseif o.gui=="EVENTSCOPE_f" then
+ scs_m_new.objs(j).gui="CEVENTSCOPE"
+ scs_m_new.objs(j).model.dstate=[]
+ scs_m_new.objs(j).model.sim=list("cevscpe", 4)
+ in = scs_m_new.objs(j).model.in(:);
+ a = size(in,1);
+ in2 = ones(a,1);
+ scs_m_new.objs(j).model.in2 = in2;
+ scs_m_new.objs(j).model.intyp = in2;
+ elseif o.gui=="FSCOPE_f" then
+ scs_m_new.objs(j).gui="CFSCOPE"
+ scs_m_new.objs(j).model.dstate=[]
+ scs_m_new.objs(j).model.sim=list("cfscope", 4)
+ in = scs_m_new.objs(j).model.in(:);
+ a = size(in,1);
+ in2 = ones(a,1);
+ scs_m_new.objs(j).model.in2 = in2;
+ scs_m_new.objs(j).model.intyp = in2;
+ //Alan's patch 04/10/07 : update exprs
+ exprs = scs_m.objs(j).graphics.exprs;
+ if size(exprs)<9 then exprs(9)="0",end // compatibility
+ scs_m_new.objs(j).graphics.exprs=exprs;
+ elseif o.gui=="SCOPXY_f" then
+ scs_m_new.objs(j).gui="CSCOPXY"
+ scs_m_new.objs(j).model.dstate=[]
+ scs_m_new.objs(j).model.sim=list("cscopxy", 4)
+ in = scs_m_new.objs(j).model.in(:);
+ a = size(in,1);
+ in2 = ones(a,1);
+ scs_m_new.objs(j).model.in2 = in2;
+ scs_m_new.objs(j).model.intyp = in2;
+ scs_m_new.objs(j).graphics.exprs = [string(1);scs_m_new.objs(j).graphics.exprs(:)]
+ scs_m_new.objs(j).model.ipar = [scs_m_new.objs(j).model.ipar(:);1]
+ elseif o.gui=="CMSCOPE" then
+ //Alan's patch 04/10/07 : update exprs
+ exprs = scs_m.objs(j).graphics.exprs;
+ if size(exprs)<11 then exprs(11)=emptystr(),end // compatibility
+ scs_m_new.objs(j).graphics.exprs=exprs;
+ scs_m_new.objs(j).model.dstate=[]
+ in = scs_m_new.objs(j).model.in(:);
+ a = size(in,1);
+ B=stripblanks(scs_m.objs(j).graphics.exprs(8));
+ B(1:a)=B;
+ B = strcat(B', " ");
+ scs_m_new.objs(j).graphics.exprs(8)=B;
+ rpar=scs_m_new.objs(j).model.rpar(:);
+ N=scs_m_new.objs(j).model.ipar(2);
+ period = [];
+ for i=1:N
+ period(i)=rpar(2);
+ end
+ scs_m_new.objs(j).model.rpar = [rpar(1);period(:);rpar(3:size(rpar,1))]
+ in2 = ones(a,1);
+ scs_m_new.objs(j).model.in2 = in2;
+ scs_m_new.objs(j).model.intyp = in2;
+ elseif o.gui=="IN_f" then
+ scs_m_new.objs(j).model.out = -1;
+ scs_m_new.objs(j).model.out2 = -2;
+ scs_m_new.objs(j).model.outtyp = -1;
+ elseif o.gui=="OUT_f" then
+ scs_m_new.objs(j).model.in = -1;
+ scs_m_new.objs(j).model.in2 = -2;
+ scs_m_new.objs(j).model.intyp = -1;
+ elseif o.gui=="INIMPL_f" then
+ scs_m_new.objs(j).model.out = -1;
+ scs_m_new.objs(j).model.out2 = 1;
+ scs_m_new.objs(j).model.outtyp = -1;
+ elseif o.gui=="OUTIMPL_f" then
+ scs_m_new.objs(j).model.in = -1;
+ scs_m_new.objs(j).model.in2 = 1;
+ scs_m_new.objs(j).model.intyp = -1;
+ end
+ end
+ end
+endfunction
+
+function scs_m_new=do_version273(scs_m)
+ scs_m_new=scs_m;
+ n=size(scs_m.objs);
+ for i=1:n //loop on objects
+ o=scs_m.objs(i);
+ if typeof(o)=="Block" then
+ omod=o.model;
+ T=getfield(1,omod)
+ if T($)<>"equations" then
+ T($+1)="equations"
+ setfield(1,T,omod)
+ setfield($+1,list(),omod)
+ end
+ if omod.sim=="super"|omod.sim=="csuper" then
+ rpar=do_version273(omod.rpar)
+ setfield($+1,getfield($,omod),omod)
+ setfield($-1,0,omod)
+ omod.rpar=rpar
+ elseif omod.sim(1)=="ifthel" then // |omod.sim(1)=='eselect' then
+ setfield($+1,getfield($,omod),omod)
+ setfield($-1,1,omod)
+ setfield($-2,1,omod)
+ else
+ setfield($+1,getfield($,omod),omod)
+ setfield($-1,0,omod)
+ end
+ xx=getfield(1,omod);
+ yy=xx($);
+ xx($)="nmode"
+ xx($+1)=yy;
+ setfield(1,xx,omod)
+ o.model= omod
+ scs_m_new.objs(i)=o
+ elseif typeof(o)=="Link" then
+ if size(o.from,"*")==2 then o.from(3)=0;end
+ if size(o.to,"*")==2 then o.to(3)=1;end
+ scs_m_new.objs(i)=o
+ end
+ end
+endfunction
+
+
+function scs_m_new=do_version272(scs_m)
+
+ scs_m_new=scs_m
+ for i=1:lstsize(scs_m.objs)
+
+ if typeof(scs_m.objs(i))=="Block" then
+ grphic=scs_m.objs(i).graphics
+ chmps=size(getfield(1,grphic))
+ if or(getfield(1,grphic)=="in_implicit")&..
+ size(grphic.in_implicit,"*")==size(grphic.pin,"*") then
+ in_implicit=grphic.in_implicit
+ else
+ I="E";
+ in_implicit=I(ones(grphic.pin(:)));
+ end
+
+ if or(getfield(1,grphic)=="out_implicit")&..
+ size(grphic.out_implicit,"*")==size(grphic.pout,"*") then
+ out_implicit=grphic.out_implicit
+ else
+ I="E";
+ out_implicit=I(ones(grphic.pout(:)));
+ end
+
+ scs_m_new.objs(i).graphics=mlist(["graphics","orig","sz","flip","exprs","pin",..
+ "pout","pein","peout","gr_i","id","in_implicit","out_implicit"],..
+ grphic.orig,grphic.sz,grphic.flip,grphic.exprs,grphic.pin,..
+ grphic.pout,grphic.pein,grphic.peout,grphic.gr_i,grphic.id,..
+ in_implicit,out_implicit)
+
+ if or(scs_m_new.objs(i).model.sim==["super","csuper"]) then
+ rpar=do_version272(scs_m_new.objs(i).model.rpar)
+ scs_m_new.objs(i).model.rpar=rpar
+ end
+ end
+ end
+endfunction
+
+function scs_m_new=do_version271(scs_m)
+ scs_m_new=scs_m;
+ n=size(scs_m.objs);
+ for i=1:n //loop on objects
+ o=scs_m.objs(i);
+ if typeof(o)=="Block" then
+ omod=o.model;
+ if omod.sim=="super"|omod.sim=="csuper" then
+ rpar=do_version271(omod.rpar)
+ setfield($+1,0,omod)
+ omod.rpar=rpar
+ elseif omod.sim=="zcross" then
+ setfield($+1,omod.in,omod)
+ omod.sim=list(omod.sim,1)
+ elseif omod.sim=="lusat" then
+ setfield($+1,2*omod.in,omod)
+ omod.sim=list(omod.sim,1)
+ else
+ setfield($+1,0,omod)
+ end
+ setfield(1,[getfield(1,omod),"nzcross"],omod)
+ o.model= omod
+ scs_m_new.objs(i)=o
+ end
+ end
+endfunction
+
+function scs_m=do_version251(scs_m)
+ nx=size(scs_m)
+ obsolete=%f
+ for k=2:nx
+ o=scs_m(k)
+ if o(1)=="Block" then
+ model=o(3)
+ if model(1)=="super"|model(1)=="csuper" then
+ model(8)=do_version251(model(8))
+ o(3)=model
+ scs_m(k)=o
+ elseif o(5)=="SOM_f" then
+ if and(model(8)==1) then
+ model(8)=[]
+ model(1)=list("plusblk",2)
+ scs_m(k)(3)=model
+ scs_m(k)(5)="SUM_f"
+ else
+ scs_m(k)(3)(1)=list("sum",2)
+ obsolete=%t
+ end
+ elseif o(5)=="AFFICH_f" then
+ scs_m(k)(3)(7)=[0;-1;0;0;1;1]
+ scs_m(k)(2)(9)=["xset(''font'',ipar(1),ipar(2))";
+ "str='' ''+part(''0'',ones(1,ipar(5)-ipar(6)-2))+''.''+part(''0'',ones(1,ipar(6)))"
+ "rr=xstringl(orig(1),orig(2),str)"
+ "xstring(orig(1)+max(0,(sz(1)-rr(3))/2),orig(2)+max(0,(sz(2)-rr(4))/2),str)"]
+ elseif o(5)=="c_block" then
+ model(1)(2)=model(1)(2)-int(model(1)(2)/1000)*1000+2000
+ scs_m(k)(3)=model
+ tt=scs_m(k)(2)(4)(2)
+ ii=grep(tt,"machine.h")
+ if size(ii,"*")==1 then
+ tt(ii)="#include <machine.h>",
+ scs_m(k)(2)(4)(2)=tt
+ end
+ end
+ elseif o(1)=="Link" then
+ if size(o(2),"*")==1 then
+ o(2)=o(2)*[1;1];o(3)=o(3)*[1;1];
+ scs_m(k)=o
+ end
+ end
+ end
+ if obsolete then
+ messagebox(["Diagram contains obsolete signed blocks sum"
+ "They are drawn in brown, they work as before but,"
+ "please replace them with the new block sum"],"modal")
+ end
+
+endfunction
+function scs_m=do_version231(scs_m)
+ //2.3.1 to 2.4 version
+ if size(scs_m(1))<5 then scs_m(1)(5)=" ",end //compatibility
+ if type(scs_m(1)(5))<>10 then scs_m(1)(5)=" ",end //compatibility
+ if size(scs_m(1))<6 then //compatibility
+ wpar=scs_m(1)
+ wpar(6)=list()
+ wpar(7)=list(%t,[0.8 0.8 0.8])
+ wpar(8)=[]
+ wpar(9)=[]
+ wpar(10)=[]
+ scs_m(1)=wpar
+ end
+
+ if size(scs_m(1)(1),"*") <4 then scs_m(1)(1)=[scs_m(1)(1),0,0],end //compatibility
+
+
+ scs_m(1)(1)(2)=max(scs_m(1)(1)(2),450)
+ if size(scs_m(1))<6 then
+ options=default_options()
+ doc=list() //documentation structure
+ wpar=scs_m(1)
+ wpar(6)=list()
+ wpar(7)=options
+ wpar(8)=[]
+ wpar(9)=[]
+ wpar(10)=doc
+ scs_m(1)=wpar
+ end
+ wsiz=scs_m(1)(1)
+ if size(wsiz,"*")<6 then //compatibility
+ if size(wsiz,"*")<4 then wsiz(3)=0;wsiz(4)=0;end
+ wsiz(5)=wsiz(1);wsiz(6)=wsiz(2);
+ scs_m(1)(1)=wsiz;
+ end
+ if type(scs_m(1)(7))==15 then //options
+ old_opt=scs_m(1)(7)
+ options=default_options()
+ options("3D")(1)=old_opt(1)
+ options("Cmap")=old_opt(2)
+ scs_m(1)(7)=options
+ end
+
+ nx=size(scs_m)
+ for k=2:nx
+ o=scs_m(k)
+ if o(1)=="Block" then
+ model=o(3)
+ if model(1)=="super"|model(1)=="csuper" then
+ model(8)=do_version231(model(8))
+ o(3)=model
+ scs_m(k)=o
+ elseif model(1)(1)=="ifthel" then
+ model(1)=list("ifthel",-1)
+ scs_m(k)(3)=model
+ elseif model(1)(1)=="eselect" then
+ model(1)=list("eselect",-1)
+ scs_m(k)(3)=model
+ end
+ end
+ end
+
+
+endfunction
+function x_new=do_version23(scs_m)
+ //2.3 to 2.3.1
+ x_new=list()
+ x_new(1)=scs_m(1)
+ nx=size(scs_m)
+ for k=2:nx
+ o=scs_m(k)
+ if o(1)=="Link" then
+ elseif o(1)=="Block" then
+ model=o(3)
+ if model(1)=="super"|model(1)=="csuper" then
+ model(8)=do_version23(model(8))
+ o(3)=model
+ o=block2_version(o)
+ scs_m(k)=o
+ else
+ o=block2_version(o)
+ end
+ end
+ x_new(k)=o;
+ end
+
+
+endfunction
+function o=block2_version(o)
+ if o(3)(6)<>[] then o(3)(12)(2)=%t;end
+
+endfunction
+
+
+function o=block_version(o)
+ [graphics,model]=o(2:3)
+ for k=2:5, model(k)=ones(model(k),1),end
+ blocktype=o(5)
+ ok=%t
+ label=" "
+ gr_i=" "
+ select blocktype
+ case "ABSBLK_f" then
+ model(2)=-1
+ model(3)=-1
+ label=" "
+ gr_i="xstringb(orig(1),orig(2),''abs'',sz(1),sz(2),''fill'')"
+ case "ANIMXY_f" then
+ [rpar,ipar]=model([8:9])
+ model(9)=[model(9);0;[-1;-1];[-1;-1]]
+ win=ipar(1);N=ipar(3);clrs=ipar(4);siz=ipar(5)
+ xmin=rpar(1);xmax=rpar(2);ymin=rpar(3);ymax=rpar(4)
+ label=[string(clrs);
+ string(siz);
+ string(win);
+ "[]";
+ "[]";
+ string(xmin);
+ string(xmax);
+ string(ymin);
+ string(ymax);
+ string(N)]
+ gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
+ "t=(0:0.3:2*%pi)'';";
+ "xx=orig(1)+(1/5+(cos(2.2*t)+1)*3/10)*sz(1);";
+ "yy=orig(2)+(1/4.3+(sin(t)+1)*3/10)*sz(2);";
+ "xpoly(xx,yy,''lines'');"
+ "xset(''thickness'',thick);"]
+ case "BOUND_f" then
+ rpar=model(8);in=model(2);nin=sum(in)
+ if nin<>1 then
+ write(%io(2),["Pb with BOUND_f block";
+ "previously block has more than one input port";
+ "It is better to change it with the new block version";
+ "preceded by a multiplexer"])
+ end
+ thresh=rpar(1:nin),v=rpar(nin+1:2*nin)
+ label=[strcat(sci2exp(thresh));
+ strcat(sci2exp(v))]
+ gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
+ "xx=orig(1)+[1/5;1/2;1/2;1-1/5]*sz(1);";
+ "yy=orig(2)+[1/2;1/2;1-1/5;1-1/5]*sz(2);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',1);";
+ "xpoly(orig(1)+[1/9;1/5]*sz(1),orig(2)+[1/2;1/2]*sz(2),''lines'');";
+ "xpoly(orig(1)+[1/2;1-1/9]*sz(1),orig(2)+[1/2;1/2]*sz(2),''lines'');";
+ "xpoly(orig(1)+[1/2;1/2]*sz(1),orig(2)+[1/9;1/2]*sz(2),''lines'');";
+ "xpoly(orig(1)+[1/2;1/2]*sz(1),orig(2)+[1-1/5;1-1/9]*sz(2),''lines'');";
+ "xset(''thickness'',thick);"]
+ case "CLINDUMMY_f" then
+ label=[]
+ gr_i=["xstringb(orig(1),orig(2),[''DUMMY'';''CLSS''],sz(1),sz(2),''fill'');"]
+ case "CLKIN_f" then
+ prt=model(9);
+ label=string(prt)
+ gr_i=[]
+ case "CLKOUT_f" then
+ prt=model(9);
+ label=string(prt)
+ gr_i=[]
+ case "CLKSPLIT_f" then
+ label=[]
+ gr_i=[]
+ case "CLKSOM_f" then
+ label=[]
+ gr_i=[]
+ case "CLOCK_f" then
+ orig=o(2)(1)
+ sz=o(2)(2)
+ oo=o(3)(8)
+ dt=0.1
+ for ko=2:size(oo)
+ if oo(ko)(3)(1)=="evtdly" then
+ dt=oo(ko)(3)(8)
+ break
+ end
+ end
+ o = list("Block",..
+ list([0,0],[2,2],%t,[],[],[],[],0,..
+ list(..
+ ["wd=xget(''wdim'').*[1.016,1.12];";
+ "thick=xget(''thickness'');xset(''thickness'',2);";
+ "p=wd(2)/wd(1);p=1;";
+ "rx=sz(1)*p/2;ry=sz(2)/2;";
+ "xarcs([orig(1)+0.05*sz(1);";
+ "orig(2)+0.95*sz(2);";
+ " 0.9*sz(1)*p;";
+ " 0.9*sz(2);";
+ " 0;";
+ " 360*64],scs_color(5));";
+ "xset(''thickness'',1);";
+ "xx=[orig(1)+rx orig(1)+rx;";
+ " orig(1)+rx orig(1)+rx+0.6*rx*cos(%pi/6)];";
+ "yy=[orig(2)+ry orig(2)+ry ;";
+ " orig(2)+1.8*ry orig(2)+ry+0.6*ry*sin(%pi/6)];";
+ "xsegs(xx,yy,scs_color(10));";
+ "xset(''thickness'',thick);"],[])),..
+ list("csuper",[],[],[],1,[]," ",..
+ list(list([600,400,0,0],"foo",[],[]),..
+ list("Block",list([399,162],[20,20],%t,"1",[],[],6,[],[]),..
+ list("output",[],[],1,[],[],[],[],1,"d",[],[%f,%f]," ",list())," ","CLKOUT_f"),..
+ list("Block",list([320,232],[40,40],%t,["0.1";"0.1"],[],[],7,4,..
+ ["dt=model(8);";
+ "txt=[''Delay'';string(dt)];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]),..
+ list("evtdly",[],[],1,1,[],[],0.1,[],"d",0.1,[%f,%f]," ",list())," ","EVTDLY_f"),..
+ list("Link",[340;340;380.71066],[226.28571;172;172],"drawlink"," ",[0,0],[5,-1],[3,1],..
+ [5,1]),..
+ list("Block",list([380.71066;172],[1,1],%t," ",[],[],4,[6;7]),..
+ list("lsplit",[],[],1,[1;1],[],[],[],[],"d",[-1,-1],[%t,%f]," ",list())," ","CLKSPLIT_f"),..
+ list("Link",[380.71066;399],[172;172],"drawlink"," ",[0,0],[5,-1],[5,1],[2,1]),..
+ list("Link",[380.71066;380.71066;340;340],[172;301.9943;301.9943;277.71429],"drawlink"," ",..
+ [0,0],[5,-1],[5,2],[3,1])),[],"h",[],[%f,%f])," ","CLOCK_f")
+
+ o(2)(1)=orig
+ o(2)(2)=sz
+ xx=o(3)(8)(3)
+ xx(2)(4)=string([dt;dt])
+ xx(3)(11)=dt
+ xx(3)(8)=dt
+ o(3)(8)(3)=xx
+ model=o(3)
+ else
+ ok=%f
+ end
+
+ if ok then
+ graphics(4)=label
+ graphics(9)=gr_i
+ o(2)=graphics
+ model(13)=" ";model(14)=list()
+ o(3)=model
+ o=replace_firing(o)
+ return
+ end
+
+ ok=%t
+ select blocktype
+ case "CLR_f" then
+ ipar=model(9);model(9)=[]
+ ns=size(model(6),"*");nin=1;nout=1;
+ rpar=model(8);
+ A=matrix(rpar(1:ns*ns),ns,ns);
+ B=matrix(rpar(ns*ns+1:ns*(ns+nin)),ns,nin);
+ C=matrix(rpar(ns*(ns+nin)+1:ns*(ns+nin+nout)),nout,ns);
+ D=rpar(ns*(ns+nin+nout)+1);
+ H=ss2tf(syslin("c",A,B,C,D));
+ H=clean(H);
+ if type(H)==16 then
+ num=H(2);den=H(3)
+ else
+ num=H,den=1
+ end
+ label=[sci2exp(num);sci2exp(den)]
+ gr_i=["xstringb(orig(1),orig(2),[''Num(s)'';''-----'';''Den(s)''],sz(1),sz(2),''fill'');"]
+ case "CLSS_f" then
+ in=model(2);out=model(3)
+ nin=sum(in)
+ nout=sum(out)
+ x0=model(6),
+ rpar=model(8)
+ ns=prod(size(x0))
+ A=matrix(rpar(1:ns*ns),ns,ns)
+ B=matrix(rpar(ns*ns+1:ns*(ns+nin)),ns,nin)
+ C=matrix(rpar(ns*(ns+nin)+1:ns*(ns+nin+nout)),nout,ns)
+ D=matrix(rpar(ns*(ns+nin+nout)+1:ns*(ns+nin+nout)+(nin*nout)),nout,nin)
+ label=[ strcat(sci2exp(A));
+ strcat(sci2exp(B));
+ strcat(sci2exp(C));
+ strcat(sci2exp(D));
+ strcat(sci2exp(x0))]
+ gr_i=["txt=[''xd=Ax+Bu'';''y=Cx+Du''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
+ model(2)=nin;model(3)=nout
+ case "CONST_f" then
+ C=model(8);model(3)=sum(model(3))
+ label=[strcat(sci2exp(C))]
+ gr_i=["model=arg1(3);C=model(8);";
+ "dx=sz(1)/5;dy=sz(2)/10;";
+ "w=sz(1)-2*dx;h=sz(2)-2*dy;";
+ "xstringb(orig(1)+dx,orig(2)+dy,string(C),w,h,''fill'');"]
+ case "COSBLK_f" then
+ in=model(2);nin=sum(in)
+ if nin<>1 then
+ write(%io(2),["Pb with COSBLK_f block";
+ "previously block has more than one input port";
+ "It is better to change it with the new block version";
+ "preceded by a multiplexer and followed by a demultiplxer"])
+ end
+ label=" "
+ gr_i=["xstringb(orig(1),orig(2),[''cos''],sz(1),sz(2),''fill'');"]
+ case "CURV_f" then
+ label=[]
+ gr_i=["model=arg1(3);rpar=model(8);ipar=model(9);n=ipar(1);";
+ "thick=xget(''thickness'');xset(''thickness'',2);";
+ "xx=rpar(1:n);yy=rpar(n+1:2*n);";
+ "rect=rpar(2*n+1:2*n+4);";
+ "mxx=rect(3)-rect(1);";
+ "mxy=rect(4)-rect(2);";
+ "xx=orig(1)+sz(1)*(1/10+(4/5)*((xx-rect(1))/mxx));";
+ "yy=orig(2)+sz(2)*(1/10+(4/5)*((yy-rect(2))/mxy));";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick);"]
+ case "DELAY_f" then
+ orig=o(2)(1)
+ sz=o(2)(2)
+ oo=o(3)(8)
+ dt=[];z0=[]
+ for ko=2:size(oo)
+ if oo(ko)(3)(1)=="evtdly" then
+ dt=oo(ko)(3)(8)
+ elseif oo(ko)(3)(1)=="register" then
+ z0=oo(ko)(3)(7)
+ end
+ end
+ if dt==[]|z0==[] then
+ write(%io(2), "Pb with DELAY_f block dt or z0 not found")
+ pause
+ end
+ o=DELAY_f("define")
+ o(2)(1)=orig
+ o(2)(2)=sz
+ o(3)(8)(4)(2)(4)=sci2exp(z0)
+ o(3)(8)(5)(2)(4)=sci2exp(dt)
+ o(3)(8)(5)(3)(8)=dt
+ o(3)(8)(5)(3)(11)=0
+ o(3)(8)(4)(3)(7)=z0(:)
+ model=o(3)
+ label=[]
+ gr_i=["b1=xstringl(0,0,''e'');";
+ "b2=xstringl(0,0,''-Ts'');";
+ "h=-b1(2)+max(0,sz(2)-0.5*b1(4)+b2(4))/2;";
+ "w=max(0,sz(1)-b1(3)-b1(4))/2;";
+ "xstring(orig(1)+w,orig(2)+h,''e'');";
+ "xstring(orig(1)+w+b1(3)/2,orig(2)+h+b1(4)*0.5,''-Ts'');"]
+ case "DLRADAPT_f" then
+ [dstate,rpar,ipar]=model(7:9)
+ m=ipar(1);
+ n=ipar(2)
+ npt=ipar(3)
+ p=rpar(1:npt)
+
+ rn=matrix(rpar(npt+1:npt+m*npt)+%i*rpar(npt+m*npt+1:npt+2*m*npt),npt,m)
+ rd=matrix(rpar(npt+2*m*npt+1:npt+(2*m+n)*npt)+..
+ %i*rpar(npt+(2*m+n)*npt+1:npt+2*(m+n)*npt),npt,n)
+ g=rpar(npt+2*(m+n)*npt+1:npt+2*(m+n)*npt+npt)
+ last_u=dstate(1:m);last_y=dstate(m+1:m+n)
+ label=[sci2exp(p);
+ sci2exp(rn);
+ sci2exp(rd);
+ sci2exp(g);
+ sci2exp(last_u);
+ sci2exp(last_y)]
+ gr_i=["txt=[''N(z,p)'';''-----'';''D(z,p)''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
+ case "DLR_f" then
+ model(9)=[];model(10)="d"
+ ns=size(model(7),"*");nin=1;nout=1;
+ rpar=model(8);
+ A=matrix(rpar(1:ns*ns),ns,ns);
+ B=matrix(rpar(ns*ns+1:ns*(ns+nin)),ns,nin);
+ C=matrix(rpar(ns*(ns+nin)+1:ns*(ns+nin+nout)),nout,ns);
+ D=rpar(ns*(ns+nin+nout)+1);
+ H=ss2tf(syslin("d",A,B,C,D));
+ H=clean(H);
+ if type(H)==16 then
+ num=H(2);den=H(3)
+ else
+ num=H,den=1
+ end
+ label=[sci2exp(num);sci2exp(den)]
+ gr_i=["txt=[''Num(z)'';''-----'';''Den(z)''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
+ case "DLSS_f" then
+ in=model(2);out=model(3)
+ nin=sum(in)
+ nout=sum(out)
+ x0=model(6),rpar=model(8)
+ ns=prod(size(x0))
+ A=matrix(rpar(1:ns*ns),ns,ns)
+ B=matrix(rpar(ns*ns+1:ns*(ns+nin)),ns,nin)
+ C=matrix(rpar(ns*(ns+nin)+1:ns*(ns+nin+nout)),nout,ns)
+ D=matrix(rpar(ns*(ns+nin+nout)+1:ns*(ns+nin+nout)+(nin*nout)),nout,nin)
+
+ label=[ strcat(sci2exp(A));
+ strcat(sci2exp(B));
+ strcat(sci2exp(C));
+ strcat(sci2exp(D));
+ strcat(sci2exp(x0))]
+ gr_i=["txt=[''x+=Ax+Bu'';''y=Cx+Du''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
+ case "EVENTSCOPE_f" then
+ [nclock,rpar,ipar]=model([4 8 9])
+ win=ipar(1);
+ per=rpar(1);
+ wdim=[-1;-1]
+ wpos=[-1;-1]
+ clrs=[1;3;5;7;9;11;13;15];
+ model(9)=[win;1;clrs;wpos(:);wdim(:)]
+ label=[sci2exp(nclock);
+ strcat(sci2exp(clrs)," ");
+ string(win);
+ sci2exp([]);
+ sci2exp([]);
+ string(per)]
+ gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
+ "xrect(orig(1)+sz(1)/10,orig(2)+(1-1/10)*sz(2),sz(1)*8/10,sz(2)*8/10);";
+ "xx=[orig(1)+sz(1)/5,orig(1)+sz(1)/5;";
+ "orig(1)+(1-1/5)*sz(1),orig(1)+sz(1)/5];";
+ "yy=[orig(2)+sz(2)/5,orig(2)+sz(2)/5;";
+ "orig(2)+sz(2)/5,orig(2)+(1-1/5)*sz(2)];";
+ "xarrows(xx,yy);";
+ "t=(0:0.3:2*%pi)'';";
+ "xx=orig(1)+(1/5+3*t/(10*%pi))*sz(1);";
+ "yy=orig(2)+(1/4.3+(sin(t)+1)*3/10)*sz(2);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick);"]
+ case "EVTDLY_f" then
+ dt=model(8);
+ if model(11) then ff=0; else ff=-1; end
+ model(11)=ff
+ label=[string(dt);string(ff)]
+ gr_i=["dt=model(8);";
+ "txt=[''Delay'';string(dt)];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
+ case "EVTGEN_f" then
+ tt=model(11);
+ label=string(tt)
+ gr_i=["xstringb(orig(1),orig(2),''Event'',sz(1),sz(2),''fill'');"]
+ case "FOR_f" then
+ write(%io(2),"FOR block nor more exist")
+ else
+ ok=%f
+ end
+ if ok then
+ graphics(4)=label
+ graphics(9)=gr_i
+ o(2)=graphics
+ model(13)=" ";model(14)=list()
+ o(3)=model
+ o=replace_firing(o)
+ return
+ end
+ ok=%t
+ select blocktype
+ case "GAIN_f" then
+ [in,out]=model(2:3)
+ gain=matrix(model(8),out,in)
+ label=[strcat(sci2exp(gain))]
+ gr_i=["[nin,nout]=model(2:3);";
+ "if nin*nout==1 then gain=string(model(8)),else gain=''Gain'',end";
+ "dx=sz(1)/5;";
+ "dy=sz(2)/10;";
+ "xx=orig(1)+ [1 4 1 1]*dx;";
+ "yy=orig(2)+sz(2)-[1 5 9 1]*dy;";
+ "xpoly(xx,yy,''lines'');";
+ "w=sz(1)-2*dx;h=sz(2)-2*dy;";
+ "xstringb(orig(1)+dx,orig(2)+dy,gain,w,h,''fill'');"]
+ case "GENERAL_f" then
+ in=model(2);out=model(5)
+ label=[strcat(sci2exp(in));strcat(sci2exp(out))]
+ gr_i=["xstringb(orig(1),orig(2),''GENERAL'',sz(1),sz(2),''fill'');"]
+ case "GENSIN_f" then
+ rpar=model(8)
+ label=[string(rpar(1));string(rpar(2));string(rpar(3))]
+ gr_i=["txt=[''sinusoid'';''generator''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
+ case "GENSQR_f" then
+ //rpar=model(8); ?
+ Amplitude=model(7)
+ label=string(Amplitude)
+ gr_i=["txt=[''square wave'';''generator''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
+ case "HALT_f" then
+ n=model(9);
+ label=string(n)
+ gr_i=["xstringb(orig(1),orig(2),''STOP'',sz(1),sz(2),''fill'');"]
+ case "IFTHEL_f" then
+ label=[]
+ model(11)=[-1,-1]
+ gr_i=["txt=[''If in>=0'';'' '';'' then else''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
+ case "INTEGRAL_f" then
+ x0=model(6);
+ label=strcat(sci2exp(x0))
+ gr_i=["xstringb(orig(1),orig(2),'' 1/s '',sz(1),sz(2),''fill'');"]
+ case "INVBLK_f" then
+ model(2)=-1;model(3)=-1
+ label=" "
+ gr_i=["xstringb(orig(1),orig(2),''1/u'',sz(1),sz(2),''fill'');"]
+ case "IN_f" then
+ prt=model(9);
+ label=[string(prt)]
+ model(3)=-1
+ gr_i=[]
+ case "LOGBLK_f" then
+ a=model(8)
+ in=model(2)
+ label=[string(a)]
+ model(2)=-1;model(3)=-1
+ gr_i=["xstringb(orig(1),orig(2),''log'',sz(1),sz(2),''fill'');"]
+ case "LOOKUP_f" then
+ model(10)="c"
+ gr_i=["rpar=model(8);n=size(rpar,''*'')/2;";
+ "thick=xget(''thickness'');xset(''thickness'',2);";
+ "xx=rpar(1:n);yy=rpar(n+1:2*n);";
+ "mnx=min(xx);xx=xx-mnx*ones(xx);mxx=max(xx);";
+ "xx=orig(1)+sz(1)*(1/10+(4/5)*xx/mxx);";
+ "mnx=min(yy);yy=yy-mnx*ones(yy);mxx=max(yy);";
+ "yy=orig(2)+sz(2)*(1/10+(4/5)*yy/mxx);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick);"]
+ label=[]
+ case "MAX_f" then
+ in=model(2);nin=sum(in)
+ if nin<>1 then
+ write(%io(2),["Pb with MAX_f block";
+ "previously block has more than one input port";
+ "It is better to change it with the new block version";
+ "preceded by a multiplexer"])
+ end
+ label=" "
+ gr_i=["xstringb(orig(1),orig(2),''Max'',sz(1),sz(2),''fill'');"]
+ case "MCLOCK_f" then
+ label=[]
+ gr_i=["txt=[''2freq clock'';'' f/n f''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
+ case "MFCLCK_f" then
+ dt=model(8)
+ nn=model(9)
+ label=[string(dt);string(nn)]
+ gr_i=["txt=[''M. freq'';''clock''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
+ case "MIN_f" then
+ in=model(2);nin=sum(in)
+ if nin<>1 then
+ write(%io(2),["Pb with MIN_f block";
+ "previously block has more than one input port";
+ "It is better to change it with the new block version";
+ "preceded by a multiplexer"])
+ end
+ label=" "
+ gr_i=["xstringb(orig(1),orig(2),''MIN'',sz(1),sz(2),''fill'')"]
+ case "NEGTOPOS_f" then
+ label=[]
+ gr_i=["xstringb(orig(1),orig(2),'' - to + '',sz(1),sz(2),''fill'');"]
+ case "OUT_f" then
+ prt=model(9);
+ model(2)=-1
+ label=[string(prt)]
+ gr_i=[]
+ case "POSTONEG_f" then
+ label=[]
+ gr_i=["xstringb(orig(1),orig(2),'' + to - '',sz(1),sz(2),''fill'')"]
+ case "POWBLK_f" then
+ in=model(2);nin=sum(in)
+ if nin<>1 then
+ write(%io(2),["Pb with MIN_f block";
+ "previously block has more than one input port";
+ "It is better to change it with the new block version";
+ "preceded by a multiplexer and followed by a demux"])
+ end
+ if model(8)<>[] then
+ a=model(8)
+ else
+ a=model(9)
+ end
+ in=model(2)
+ label=[string(a)]
+ gr_i=["xstringb(orig(1),orig(2),''u^a'',sz(1),sz(2),''fill'');"]
+ case "PROD_f" then
+ label=[]
+ gr_i=[]
+ model(1)=list("prod",2)
+ case "QUANT_f" then
+ rpar=model(8);ipar=model(9);
+ pas=rpar(1)
+ meth=ipar
+ label=[string(pas);string(meth)]
+ gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
+ "xx=orig(1)+[1;2;2;3;3;4;4]/5*sz(1);";
+ "yy= orig(2)+[1;1;2;2;3;3;4]/5*sz(2);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick);"]
+ case "RAND_f" then
+ rpar=model(8);flag=model(9);
+ out=model(3);nout=sum(out)
+ if nout<>1 then
+ write(%io(2),["Pb with RAND_f block";
+ "previously block has more than one output port";
+ "It is better to change it with the new block version";
+ " followed by a demux"])
+ end
+
+ a=rpar(1:nout)
+ b=rpar(nout+1:2*nout)
+ label=[string(flag);sci2exp(a(:));sci2exp(b(:))]
+ gr_i=["txt=[''random'';''generator''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
+ case "REGISTER_f" then
+ z0=model(7)
+ label=strcat(string(z0),";")
+
+ gr_i=["dly=model(8);";
+ "txt=[''Shift'';''Register'';string(dly)];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
+ else
+ ok=%f
+ end
+ if ok then
+ graphics(4)=label
+ graphics(9)=gr_i
+ o(2)=graphics
+ model(13)=" ";model(14)=list()
+ o(3)=model
+ o=replace_firing(o)
+ return
+ end
+ ok=%t
+ select blocktype
+ case "RFILE_f" then
+ [out,state,ipar]=model([3 7 9])
+ nout=sum(out)
+ ievt=ipar(3);N=ipar(4);
+ imask=5+ipar(1)+ipar(2)
+ if ievt<>0 then tmask=ipar(imask),else tmask=[],end
+ outmask=ipar(imask+ievt:imask+nout+ievt-1)
+ lunit=state(2)
+ ievt=ipar(3);N=ipar(4);
+ imask=5+ipar(1)+ipar(2)
+ if ievt<>0 then tmask=ipar(imask),else tmask=[],end
+ outmask=ipar(imask+ievt:imask+nout+ievt-1)
+ lfil=ipar(1)
+ lfmt=ipar(2)
+ if lfil>0 then fname=_code2str(ipar(5:4+lfil)),else fname=" ",end
+ if lfmt>0 then Fmt=_code2str(ipar(5+lfil:4+lfil+lfmt)),else Fmt=" ",end
+ label=[ sci2exp(tmask);
+ sci2exp(outmask);
+ fname;
+ Fmt;
+ string(N);
+ sci2exp(out)]
+ gr_i=["txt=[''read from'';''input file''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
+ case "SAT_f" then
+ rpar=model(8)
+ minp=rpar(1),maxp=rpar(2),pente=rpar(3)
+ label=[string(minp);string(maxp);string(pente)]
+
+ gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
+ "xx=orig(1)+[4/5;1/2+1/5;1/2-1/5;1/5]*sz(1);";
+ "yy=orig(2)+[1-1/5;1-1/5;1/5;1/5]*sz(2);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick)"]
+ case "SAWTOOTH_f" then
+ model(10)="c"
+ gr_i=["txt=[''sawtooth'';''generator''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
+ case "SCOPE_f" then
+ [in,rpar,ipar]=model([2 8 9])
+ in=model(2);nin=sum(in)
+ if nin<>1 then
+ write(%io(2),["Pb with SCOPE_f block";
+ "previously block has more than one input port";
+ "It is better to change it with the new block version";
+ "preceded by a multiplexer"])
+ end
+ win=ipar(1);N=ipar(3);
+ clrs=-ipar(4:nin+3)
+ if size(clrs,"*")<8 then clrs(8)=1;end
+
+ wdim=[-1;-1]
+ wpos=[-1;-1]
+ model(9)=[win;1;N;clrs;wpos(:);wdim(:)]
+ dt=rpar(1);ymin=rpar(2);ymax=rpar(3);per=rpar(4)
+ label=[strcat(string(clrs)," ");
+ string(win);
+ sci2exp([]);
+ sci2exp([]);
+ string(ymin);
+ string(ymax);
+ string(per);
+ string(N)];
+
+ gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
+ "xrect(orig(1)+sz(1)/10,orig(2)+(1-1/10)*sz(2),sz(1)*8/10,sz(2)*8/10);";
+ "xx=[orig(1)+sz(1)/5,orig(1)+sz(1)/5;";
+ "orig(1)+(1-1/5)*sz(1),orig(1)+sz(1)/5];";
+ "yy=[orig(2)+sz(2)/5,orig(2)+sz(2)/5;";
+ "orig(2)+sz(2)/5,orig(2)+(1-1/5)*sz(2)];";
+ "xarrows(xx,yy);";
+ "t=(0:0.3:2*%pi)'';";
+ "xx=orig(1)+(1/5+3*t/(10*%pi))*sz(1);";
+ "yy=orig(2)+(1/4.3+(sin(t)+1)*3/10)*sz(2);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick)"]
+ case "SCOPXY_f" then
+ [rpar,ipar]=model(8:9)
+ win=ipar(1);N=ipar(3);clrs=-ipar(4);siz=ipar(5)
+ xmin=rpar(1);xmax=rpar(2);ymin=rpar(3);ymax=rpar(4)
+ wdim=[-1;-1]
+ wpos=[-1;-1]
+ label=[sci2exp(clrs);
+ sci2exp(siz);
+ string(win);
+ sci2exp([]);
+ sci2exp([]);
+ string(xmin);
+ string(xmax);
+ string(ymin);
+ string(ymax);
+ string(N)];
+ model(9)=[win;1;N;clrs;siz;1;wpos(:);wdim(:)]
+ gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
+ "t=(0:0.2:2*%pi)'';";
+ "xx=orig(1)+(1/5+(cos(3*t)+1)*3/10)*sz(1);";
+ "yy=orig(2)+(1/4.3+(sin(t+1)+1)*3/10)*sz(2);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick)"]
+ case "SELECT_f" then
+ z0=model(7);nin=size(model(2),1);
+ label=[string(nin);string(z0-1)]
+ model(1)=list("selector",2)
+ gr_i=["xstringb(orig(1),orig(2),''Selector'',sz(1),sz(2),''fill'');"]
+ case "SINBLK_f" then
+ in=model(2);nin=sum(in)
+ if nin<>1 then
+ write(%io(2),["Pb with MIN_f block";
+ "previously block has more than one input port";
+ "It is better to change it with the new block version";
+ "preceded by a multiplexer and followed by a demux"])
+ end
+ label=" "
+ gr_i=["xstringb(orig(1),orig(2),''sin'',sz(1),sz(2),''fill'')"]
+ case "SOM_f" then
+ sgn=model(8);
+ label=sci2exp(sgn)
+ model(1)=list("sum",2)
+ gr_i=[]
+ case "SPLIT_f" then
+ label=[]
+ gr_i=[]
+ case "SUPER_f" then
+ label=[]
+ gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
+ "xx=orig(1)+ [2 4 4]*(sz(1)/7);";
+ "yy=orig(2)+sz(2)-[2 2 6]*(sz(2)/10);";
+ "xrects([xx;yy;[sz(1)/7;sz(2)/5]*ones(1,3)]);";
+ "xx=orig(1)+ [1 2 3 4 5 6 3.5 3.5 3.5 4 5 5.5 5.5 5.5]*sz(1)/7;";
+ "yy=orig(2)+sz(2)-[3 3 3 3 3 3 3 7 7 7 7 7 7 3 ]*sz(2)/10;";
+ "xsegs(xx,yy,0);";
+ "xset(''thickness'',thick)"]
+ case "TANBLK_f" then
+ in=model(2);nin=sum(in)
+ if nin<>1 then
+ write(%io(2),["Pb with TANBLK_f block";
+ "previously block has more than one input port";
+ "It is better to change it with the new block version";
+ "preceded by a multiplexer and followed by a demux"])
+ end
+ label=" "
+ gr_i=["xstringb(orig(1),orig(2),''tan'',sz(1),sz(2),''fill'');"]
+ case "TCLSS_f" then
+ in=model(2);nin=sum(in)
+ out=model(3);nout=sum(out)
+ x0=model(6),rpar=model(8)
+
+ ns=prod(size(x0));nin=nin-ns
+ A=matrix(rpar(1:ns*ns),ns,ns)
+ B=matrix(rpar(ns*ns+1:ns*(ns+nin)),ns,nin)
+ C=matrix(rpar(ns*(ns+nin)+1:ns*(ns+nin+nout)),nout,ns)
+ D=matrix(rpar(ns*(ns+nin+nout)+1:ns*(ns+nin+nout)+(nin*nout)),nout,nin)
+ nin1=nin;nout1=nout
+
+ label=[strcat(sci2exp(A));
+ strcat(sci2exp(B));
+ strcat(sci2exp(C));
+ strcat(sci2exp(D));
+ strcat(sci2exp(x0))]
+ gr_i=["txt=[''Jump'';''(A,B,C,D)''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
+ else
+ ok=%f
+ end
+ if ok then
+ graphics(4)=label
+ graphics(9)=gr_i
+ o(2)=graphics
+ model(13)=" "
+ model(14)=list()
+ o(3)=model
+ o=replace_firing(o)
+ return
+ end
+ ok=%t
+ select blocktype
+ case "TEXT_f" then
+ ipar=model(9)
+ font=ipar(1);siz=ipar(2)
+ label=[graphics(4);string(font);string(siz)]
+ gr_i=[]
+ case "TIME_f" then
+ label=[]
+ gr_i=["wd=xget(''wdim'').*[1.016,1.12];";
+ "thick=xget(''thickness'');xset(''thickness'',2);";
+ "p=wd(2)/wd(1);p=1;";
+ "rx=sz(1)*p/2;ry=sz(2)/2;";
+ "xarc(orig(1)+0.05*sz(1),orig(2)+0.95*sz(2),0.9*sz(1)*p,0.9*sz(2),0,360*64);";
+ "xset(''thickness'',1);";
+ "xx=[orig(1)+rx orig(1)+rx;";
+ "orig(1)+rx orig(1)+rx+0.6*rx*cos(%pi/6)];";
+ "yy=[orig(2)+ry orig(2)+ry ;";
+ " orig(2)+1.8*ry orig(2)+ry+0.6*ry*sin(%pi/6)];";
+ "xsegs(xx,yy,0);";
+ "xset(''thickness'',thick);"]
+ case "TRASH_f" then
+ in=model(2);nin=sum(in)
+ if nin<>1 then
+ write(%io(2),["Pb with MIN_f block";
+ "previously block has more than one input port";
+ "It is better to change it with the new block version";
+ "preceded by a multiplexer"])
+ end
+ label=" "
+ gr_i=["xstringb(orig(1),orig(2),''Trash'',sz(1),sz(2),''fill'')"]
+ case "WFILE_f" then
+ state=model(7)
+ [in,ipar]=model([2 9])
+ N=ipar(3);
+ lunit=state(2)
+ N=ipar(4)
+ lfil=ipar(1)
+ lfmt=ipar(2)
+ if lfil>0 then fname=_code2str(ipar(5:4+lfil)),else fname=" ",end
+ if lfmt>0 then Fmt=_code2str(ipar(5+lfil:4+lfil+lfmt)),else Fmt=" ",end
+ label=[sci2exp(in);
+ fname;
+ Fmt;
+ string(N)]
+
+ gr_i=["txt=[''write to'';''output file''];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
+ case "ZCROSS_f" then
+ in=model(2)
+ label=strcat(sci2exp(in))
+ gr_i=["xstringb(orig(1),orig(2),''Zcross'',sz(1),sz(2),''fill'');"]
+ case "func_block" then
+ write(%io(2),["PB with func_block";
+ "version change is not implemented"])
+ label=[]
+ gr_i=["xstringb(orig(1),orig(2),''Func'',sz(1),sz(2),''fill'');"]
+ case "m_sin" then
+ rpar=model(8);gain=rpar(1);phase=rpar(2)
+ label=[string(gain);string(phase)]
+ gr_i=[]
+ case "sci_block" then
+ write(%io(2),["PB with sci_block";
+ "version change is not implemented"])
+ label=[]
+ gr_i=["xstringb(orig(1),orig(2),''Sci_Block'',sz(1),sz(2),''fill'');"]
+ case "scifunc_block" then
+ write(%io(2),["PB with scifunc_block";
+ "version change is not implemented"])
+ i1=model(2);o1=model(3);ci1=model(4);co1=model(5);x1=model(6);
+ z1=model(7);auto1=model(11);type_1=model(10);
+ tt=model(9),rpar=model(8)
+ label=list([sci2exp(i1);sci2exp(o1);sci2exp(ci1);sci2exp(co1);
+ strcat(sci2exp(x1));strcat(sci2exp(z1));type_1;
+ strcat(sci2exp(rpar));sci2exp(auto1)],tt)
+
+ gr_i=["xstringb(orig(1),orig(2),''Scifunc'',sz(1),sz(2),''fill'');"]
+ case "standard_block" then
+ write(%io(2),["PB with standard_block";
+ "version change is not implemented"])
+ label=[]
+ gr_i=[]
+ else
+ disp(blocktype+" unknown, parameters values may be lost, please check")
+ label=[]
+ gr_i=[]
+ end
+ graphics(4)=label
+ graphics(9)=gr_i
+ o(2)=graphics
+ model(13)=" "
+ model(14)=list()
+ o(3)=model
+ o=replace_firing(o)
+
+endfunction
+
+function o=replace_firing(o)
+ firing=o(3)(11)
+ cout=o(3)(5)
+ if firing==%f|firing==0 then
+ o(3)(11)=-ones(cout)
+ //disp('firing changed from %f to '+sci2exp(o(3)(11))+' in '+o(3)(1)(1))
+ elseif firing==%t|firing==1 then
+ o(3)(11)=0*cout
+ //disp('firing changed from %t to '+sci2exp(o(3)(11))+' in '+o(3)(1)(1))
+ elseif firing==[] then
+ o(3)(11)=[]
+ else
+ write(%io(2),"Problem with block "+o(3)(1)(1))
+ pause
+ end
+
+endfunction
+function x_new=do_version22(scs_m)
+ x_new=list()
+ wpar=scs_m(1)
+ wsiz=wpar(1)
+
+ if size(wsiz,"*")>=4 then x_new=scs_m,return,end
+
+ wpar(3)(4)=wpar(4)+1
+ x_new(1)=wpar
+ nx=size(scs_m)
+ for k=2:nx
+ o=scs_m(k)
+ if o(1)=="Link" then
+ elseif o(1)=="Block" then
+ model=o(3)
+ if model(1)=="super"|model(1)=="csuper" then
+ model(8)=do_version22(model(8))
+ o(3)=model
+ o=block_version(o)
+ scs_m(k)=o
+ else
+ o=block_version(o)
+ end
+ elseif o(1)=="Text" then
+ o=block_version(o)
+ end
+ x_new(k)=o;
+ end
+endfunction
+
+function scs_m_new=do_version27(scs_m)
+ if typeof(scs_m)=="diagram" then
+ //following code reported into do_version273
+ // scs_m_new=scs_m,
+ // nlstsize=lstsize(scs_m_new.objs)
+ // for k=1:nlstsize
+ // if typeof(scs_m_new.objs(k))=='Link' then
+ // o=scs_m_new.objs(k)
+ // if size(o.from,'*')==2 then o.from(3)=0,end
+ // if size(o.to,'*')==2 then o.to(3)=1,end
+ // scs_m_new.objs(k)=o
+ // elseif typeof(scs_m_new.objs(k))=='Block' then
+
+ // end
+ // end
+ scs_m_new=scs_m
+ return,
+ end
+ scs_m_new=scicos_diagram()
+ tf=scs_m(1)(4)
+ if tf==[] then tf=100;end
+ tol=scs_m(1)(3)
+ if size(tol,"*")<4 then tol(4)=tf+1,end
+ if size(tol,"*")<5 then tol(5)=0,end
+ if size(tol,"*")<6 then tol(6)=0,end
+ for iix=size(scs_m(1))+1:10,scs_m(1)(iix)=[];end
+ scs_m_new.props=scicos_params(wpar=scs_m(1)(1),Title=scs_m(1)(2),..
+ tol=tol,tf=tf,..
+ context=scs_m(1)(5),options=scs_m(1)(7),..
+ doc=scs_m(1)(10))
+
+ if scs_m(1)(7).Background==[] then
+ scs_m_new.props.options.Background=[8 1]
+ end
+
+ scs_m_new.objs(1)=mlist("Deleted") // not to change the internal numbering
+ n=lstsize(scs_m)
+ back_col=8 //white background
+
+ mprintf(".")
+
+ for i=2:n //loop on objects
+ o=scs_m(i);
+ if o(1)=="Block" then
+ if size(o(2)) > 8 then
+ if type(o(2)(9))==15 then
+ gr_io=o(2)(9)(1);
+ if o(2)(9)(2)<>[] then
+ back_col=o(2)(9)(2);,
+ end
+ else
+ gr_io=o(2)(9);
+ back_col=8
+ end
+ gr_i=convert_gri(o(5),gr_io);
+ if gr_i==[] then gr_i=gr_io;, end
+ elseif size(o(2)) < 9 then
+ gr_i=[];
+ back_col=8
+ end
+ gr_i=list(gr_i,back_col)
+
+ mdl=o(3);
+ if size(o(3))<=12 then
+ mdl(13)=""; mdl(14)=[] ; mdl(15)="";
+ elseif size(o(3))<=13 then
+ mdl(14)=[] ; mdl(15)="";
+ elseif size(o(3))<=14 then
+ mdl(15)="";
+ end
+
+ if mdl(1)(1)=="super"|mdl(1)(1)=="csuper" then
+ if type(mdl(8))==15 then
+ mdl(8)=do_version27(mdl(8))
+ end
+ end
+
+ graphics=scicos_graphics27(orig=o(2)(1),sz=o(2)(2),flip=o(2)(3),..
+ exprs=o(2)(4),pin=o(2)(5),pout=o(2)(6),..
+ pein=o(2)(7),peout=o(2)(8),gr_i=gr_i,..
+ id=mdl(15))
+
+
+ model=scicos_model27(sim=mdl(1),in=mdl(2),out=mdl(3),evtin=mdl(4),..
+ evtout=mdl(5),state=mdl(6),dstate=mdl(7),..
+ rpar=mdl(8),ipar=mdl(9),blocktype=mdl(10),..
+ firing=mdl(11),dep_ut=mdl(12),label=mdl(13))
+
+
+ objsi=scicos_block(graphics=graphics,model=model,gui=o(5),..
+ doc=mdl(14))
+ if objsi.gui=="ESELECT_f" then objsi.model.sim(2)=-2,end
+ scs_m_new.objs(i)=objsi
+
+ elseif o(1)=="Link" then
+ from=o(8);from(3)=0;
+ to=o(9);to(3)=1;
+
+ objsi=scicos_link(xx=o(2),yy=o(3),id=o(5),thick=o(6),..
+ ct=o(7),from=from,to=to)
+ scs_m_new.objs(i)=objsi
+ elseif o(1)=="Text" then
+
+ objsi=TEXT_f("define")
+ objsi.model.rpar=o(3)(8)
+ objsi.model.ipar=o(3)(9)
+ objsi.graphics.orig=o(2)(1)
+ objsi.graphics.sz=o(2)(2)
+ objsi.graphics.exprs=o(2)(4)
+ scs_m_new.objs(i)=objsi
+ elseif o(1)=="Deleted" then
+ scs_m_new.objs(i)=tlist("Deleted")
+ end
+ end
+
+ [%cpr,edited]=resume(list(),%t) // doit etre enleve
+endfunction
+
+function gr_i=convert_gri(name,gri)
+ gr_i=[];
+ select name
+ case "BIGSOM_f" then
+ gr_i=["[x,y,typ]=standard_inputs(o) ";
+ "sgn=o.model.rpar";
+ "for k=1:size(x,''*'')";
+ " if sgn(k)>0 then";
+ " xstring(orig(1)+sz(1)/8 ,y(k)-4,''+'')";
+ " else";
+ " xstring(orig(1)+sz(1)/8 ,y(k)-4,''-'')";
+ " end";
+ "end";
+ "xx=sz(1)*[.8 .4 0.75 .4 .8]+orig(1)";
+ "yy=sz(2)*[.8 .8 .5 .2 .2]+orig(2)";
+ "xpoly(xx,yy,''lines'')"]
+
+ case "CONST_f" then
+ gr_i=["dx=sz(1)/5;dy=sz(2)/10;";
+ "w=sz(1)-2*dx;h=sz(2)-2*dy;";
+ "txt=C;"
+ "xstringb(orig(1)+dx,orig(2)+dy,txt,w,h,''fill'');"]
+
+ case "CURV_f" then
+ gr_i=["model=arg1.model;rpar=model.rpar;ipar=model.ipar;n=ipar(1);";
+ "thick=xget(''thickness'');xset(''thickness'',2);";
+ "xx=rpar(1:n);yy=rpar(n+1:2*n);";
+ "rect=rpar(2*n+1:2*n+4);";
+ "mxx=rect(3)-rect(1);";
+ "mxy=rect(4)-rect(2);";
+ "xx=orig(1)+sz(1)*(1/10+(4/5)*((xx-rect(1))/mxx));";
+ "yy=orig(2)+sz(2)*(1/10+(4/5)*((yy-rect(2))/mxy));";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick);"]
+
+ case "EVTDLY_f" then
+ gr_i=["dt=model.rpar;";
+ "txt=[''Delay'';string(dt)];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
+
+ case "EVTGEN_f" then
+ gr_i=["tt=model.firing;";
+ "txt=[''Event at'';''time ''+string(tt)];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
+
+ case "GAIN_f" then
+
+ gr_i=["gain=C,"
+ "dx=sz(1)/5;";
+ "dy=sz(2)/10;";
+ "xx=orig(1)+ [1 4 1 1]*dx;";
+ "yy=orig(2)+sz(2)-[1 5 9 1]*dy;";
+ "xpoly(xx,yy,''lines'');";
+ "w=sz(1)-2*dx;h=sz(2)-2*dy;";
+ "xstringb(orig(1)+dx,orig(2)+dy,gain,w,h,''fill'');"]
+
+ case "LOOKUP_f" then
+ gr_i=["rpar=model.rpar;n=size(rpar,''*'')/2;";
+ "thick=xget(''thickness'');xset(''thickness'',2);";
+ "xx=rpar(1:n);yy=rpar(n+1:2*n);";
+ "mnx=min(xx);xx=xx-mnx*ones(xx);mxx=max(xx);";
+ "xx=orig(1)+sz(1)*(1/10+(4/5)*xx/mxx);";
+ "mnx=min(yy);yy=yy-mnx*ones(yy);mxx=max(yy);";
+ "yy=orig(2)+sz(2)*(1/10+(4/5)*yy/mxx);";
+ "xpoly(xx,yy,''lines'');";
+ "xset(''thickness'',thick);"]
+
+ case "REGISTER_f" then
+
+ gr_i=["dly=model.rpar;";
+ "txt=[''Shift'';''Register'';string(dly)];";
+ "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
+ case "SWITCH_f" then
+
+ gr_i="xstringb(orig(1),orig(2),[''switch'';string(model.ipar+1)],sz(1),sz(2),''fill'');"
+ case "EXPBLK_f" then
+ gr_i="xstringb(orig(1),orig(2),''a^u'',sz(1),sz(2),''fill'');"
+ case "POWBLK_f" then
+ gr_i="xstringb(orig(1),orig(2),''u^a'',sz(1),sz(2),''fill'');"
+
+ end
+endfunction
+
+
+function scs_m_new=do_versionxx(scs_m)
+ //A SUPPRIMER CF ci dessus
+ if typeof(scs_m)=="diagram" then scs_m_new=scs_m,return,end
+ if typeof(scs_m(1))<>"params" then scs_m_new=scs_m,return,end
+ scs_m_new=scicos_diagram()
+ scs_m_new.props=scs_m(1)
+ scs_m_new.objs(1)=mlist("Deleted") // not to change the internal numbering
+ n=lstsize(scs_m)
+ for i=2:n //loop on objects
+ o=scs_m(i)
+ scs_m_new.objs(i)=o
+ if typeof(o)=="Block" then
+ if o.model.sim(1)=="super"| o.model.sim(1)=="csuper" then
+ scs_m_new.objs(i).model.rpar=do_versionxx(o.model.rpar)
+ end
+ end
+ end
+ edited=resume(%t)
+endfunction
+
+
+function model=scicos_model27(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13)
+ //initialisation de model mlist
+ if exists("sim","local")==0 then sim="",end
+ if exists("in","local")==0 then in=[],end
+ if exists("out","local")==0 then out=[],end
+ if exists("evtin","local")==0 then evtin=[],end
+ if exists("evtout","local")==0 then evtout=[],end
+ if exists("state","local")==0 then state=[],end
+ if exists("dstate","local")==0 then dstate=[],end
+ if exists("rpar","local")==0 then rpar=[],end
+ if exists("ipar","local")==0 then ipar=[],end
+ if exists("blocktype","local")==0 then blocktype="c",end
+ if exists("firing","local")==0 then firing=[],end
+ if exists("dep_ut","local")==0 then dep_ut=[%f %f],end
+ if exists("label","local")==0 then label="",end
+
+ model=mlist(["model","sim","in","out","evtin","evtout","state","dstate",..
+ "rpar","ipar","blocktype","firing","dep_ut","label"],..
+ sim,in,out,evtin,evtout,state,dstate,..
+ rpar,ipar,blocktype,firing,dep_ut,label)
+endfunction
+
+function graphics=scicos_graphics27(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10)
+ //initialisation de graphics mlist
+ if exists("orig","local")==0 then orig=[0 0],end
+ if exists("sz","local")==0 then sz=[20 20],end
+ if exists("flip","local")==0 then flip=%t,end
+ if exists("exprs","local")==0 then exprs=[],end
+ if exists("pin","local")==0 then pin=[],end
+ if exists("pout","local")==0 then pout=[],end
+ if exists("pein","local")==0 then pein=[],end
+ if exists("peout","local")==0 then peout=[],end
+ if exists("gr_i","local")==0 then gr_i=[],end
+ if exists("id","local")==0 then id="",end
+
+ graphics=mlist(["graphics","orig","sz","flip","exprs","pin",..
+ "pout","pein","peout","gr_i","id"],..
+ orig,sz,flip,exprs,pin,pout,pein,peout,gr_i,id)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/entity_menu.sce b/modules/scicos/macros/scicos_scicos/entity_menu.sce
new file mode 100755
index 000000000..c0b94bdfc
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/entity_menu.sce
@@ -0,0 +1,520 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function add_entity_menu(win, emen)
+ if argn(2)<1 then
+ win = get(gcf(),"figure_id")
+ scf(win)
+ end
+ if argn(2)<2 then emen="Edit",end
+ old = gcf()
+ EntityMenus=["Browser","Copy","Paste","Move","Delete","Insert","Ok","Cancel"];
+ //delmenu(win,'Entities')
+
+ addmenu(win,emen,EntityMenus,list(2,"entity_menu"));
+ //seteventhandler('entity_handler')
+ scf(old)
+endfunction
+
+
+
+function entity_menu(k,win)
+ old=gcf();fig=scf(win)
+ seteventhandler("")
+ select k
+ case 1 then //browser
+ ged(5,win)
+ case 2 then //copy
+ copy_entity()
+ case 3 then //past
+ paste_entity()
+ case 4 then //move
+ move_entity()
+ case 5 then //Delete Entity
+ delete_entity()
+ case 6 then //New entity
+ new_entity()
+ case 7 then //ok
+ fig.user_data="ok"
+ case 8 then //cancel
+ fig.user_data="cancel"
+ //txt=gen_code()
+ //mputl(txt,TMPDIR+'/foo.txt')
+ end
+ seteventhandler("ged_eventhandler")
+ scf(old)
+endfunction
+
+function new_entity()
+ entities=["Rectangle","Segment","Polyline","Text","Circle"]
+ sel=x_choose(entities,"Select the Entity type")
+ f=gcf();
+ rep(3)=-1
+ select sel
+ case 1 then //Rectangle
+ [btn,xc,yc]=xclick()
+ xrect(xc,yc,0,0)
+ r=gce();r.foreground=-1;
+ while rep(3)==-1 do
+ rep=xgetmouse()
+ r.data=[min(xc,rep(1)),max(yc,rep(2)),abs(xc-rep(1)),abs(yc-rep(2))]
+ end
+
+ case 2 then //Segment
+ [btn,xc,yc]=xclick()
+ xsegs([xc;xc],[yc;yc])
+ r=gce();r.foreground=-1;
+ while rep(3)==-1 do
+ rep=xgetmouse()
+ r.data=[xc,yc;rep(1),rep(2)]
+ end
+
+ case 3 then //Polyline
+ [btn,xc,yc]=xclick()
+ xpoly([xc;xc],[yc;yc])
+ r=gce();r.foreground=-1;
+ while %t
+ while rep(3)==-1 do
+ rep=xgetmouse()
+ r.data($,:)=[rep(1),rep(2)]
+ end
+ if rep(3)==2 then break,end
+ rep(3)=-1;
+ r.data=[r.data;r.data($,:)]
+ end
+ case 4 then //Text
+ text = x_dialog("Enter the new text here.","") ;
+ if ( text <> [] & text <> "" ) then
+ // do nothing if cancel button has been pressed or no text entered
+ // get the position of the text
+ xstring(0, 0, text ) ;
+ r=gce();
+ if r.type=="Text" then
+ while rep(3)==-1 do
+ rep=xgetmouse()
+ r.data=[rep(1),rep(2)]
+ end
+ else //compound
+ y0=0
+ while rep(3)==-1 do
+ rep=xgetmouse()
+ y0=r.children($).data(2)
+ for k=1:size(r.children,"*")
+ rk=r.children(k)
+ rk.data=[rep(1),rk.data(2)+rep(2)-y0]
+ end
+ y0=rep(2)
+ end
+ end
+ end
+ case 5 then //Circle
+ [btn,xc,yc]=xclick()
+ xarc(xc,yc,0,0,0,64*360)
+ r=gce();r.foreground=-1;
+ while rep(3)==-1 do
+ rep=xgetmouse()
+ r.data=[min(xc,rep(1)),max(yc,rep(2)),abs(xc-rep(1)),abs(yc-rep(2)),0,360]
+ end
+
+ end
+endfunction
+
+function delete_entity()
+ gedx=ged
+ [btn,xc,yc]=xclick()
+ [xc,yc]=xchange(xc,yc,"f2i")
+ h=ged_getobject([xc,yc])
+ if h<>[] then delete(h),end
+endfunction
+
+function move_entity()
+ gedx=ged
+ [btn,xc,yc]=xclick()
+ pos=[xc,yc]
+ [xc,yc]=xchange(xc,yc,"f2i")
+ r=ged_getobject([xc,yc])
+ if r==[] return,end
+ mprintf("debut move\n")
+ rep(3)=-1
+ select r.type
+ case "Rectangle" then
+ while rep(3)==-1 do
+ rep=xgetmouse()
+ r.data(1:2)= r.data(1:2)+(rep(1:2)-pos)
+ pos=rep(1:2)
+ end
+ case "Segs" then //Segment
+ while rep(3)==-1 do
+ rep=xgetmouse()
+ r.data=r.data+ones(r.data(:,1))*(rep(1:2)-pos)
+ pos=rep(1:2)
+ end
+ case "Polyline" then //Polyline
+ while rep(3)==-1 do
+ rep=xgetmouse()
+ r.data=r.data+ones(r.data(:,1))*(rep(1:2)-pos)
+ pos=rep(1:2)
+ end
+ case "Text" then //Text
+ if r.parent.type=="Axes" then
+ while rep(3)==-1 do
+ rep=xgetmouse()
+ r.data=r.data+(rep(1:2)-pos)
+ pos=rep(1:2)
+ end
+ else
+ r=r.parent
+ while rep(3)==-1 do
+ rep=xgetmouse()
+ for k=1:size(r.children,"*")
+ rk=r.children(k)
+ rk.data=rk.data+(rep(1:2)-pos)
+ end
+ pos=rep(1:2)
+ end
+ end
+ case "Arc" then //Circle
+ while rep(3)==-1 do
+ rep=xgetmouse()
+ r.data(1:2)= r.data(1:2)+(rep(1:2)-pos)
+ pos=rep(1:2)
+ end
+
+ end
+ mprintf("fin move\n")
+endfunction
+
+
+function copy_entity()
+ gedx=ged;
+ [btn,xc,yc]=xclick()
+ [xc,yc]=xchange(xc,yc,"f2i")
+ r=ged_getobject([xc,yc])
+ if r==[] return,end
+ twinkle(r,1);
+ save(TMPDIR+"/G_Clipboard",r)
+endfunction
+
+
+function paste_entity()
+ // check the file
+ [info,err] = fileinfo(TMPDIR + "/G_Clipboard" ) ;
+
+ if err <> 0 then
+ return ;
+ end
+
+ // create the saved object
+ load(TMPDIR+"/G_Clipboard") ;
+endfunction
+
+function txt=gen_code(win)
+ old=gcf()
+ if argn(2)>=1 then scf(win);end
+ ax=gca()
+ txt=[]
+ for k=size(ax.children,"*"):-1:1
+ txt=[txt;
+ graphical_object_code(ax.children(k))]
+
+ end
+ if txt==[] then txt=" ",end
+ scf(old)
+endfunction
+
+function txt=graphical_object_code(rk)
+ txt=[]
+ select rk.type
+ case "Rectangle" then
+ dx="orig(1)+sz(1)*"+num2string(rk.data(1))
+ dy="orig(2)+sz(2)*"+num2string(rk.data(2))
+ sx="sz(1)*"+num2string(rk.data(3))
+ sy="sz(2)*"+num2string(rk.data(4))
+ txt=[txt;
+ "xrect("+strcat([dx,dy,sx,sy],",")+");"
+ rect_opt(rk)]
+
+ case "Arc" then
+ dx="orig(1)+sz(1)*"+num2string(rk.data(1))
+ dy="orig(2)+sz(2)*"+num2string(rk.data(2))
+ sx="sz(1)*"+num2string(rk.data(3))
+ sy="sz(2)*"+num2string(rk.data(4))
+ a1=num2string(rk.data(5)*64)
+ a2=num2string(rk.data(6)*64)
+
+ txt=[txt;
+ "xarc("+strcat([dx,dy,sx,sy,a1,a2],",")+");"
+ arc_opt(rk)]
+
+ case "Segs" then
+ dx="orig(1)+sz(1)*["+strcat(num2string(rk.data(:,1)),";")+"]"
+ dy="orig(2)+sz(2)*["+strcat(num2string(rk.data(:,2)),";")+"]"
+ col=sci2exp(rk.segs_color,0)
+ txt=[txt;
+ "xsegs("+dx+","+dy+","+col+");"
+ seg_opt(rk)]
+
+ case "Polyline" then
+ dx="orig(1)+sz(1)*["+strcat(num2string(rk.data(:,1)),";")+"]"
+ dy="orig(2)+sz(2)*["+strcat(num2string(rk.data(:,2)),";")+"]"
+ txt=[txt;
+ "xpoly("+dx+","+dy+");"
+ poly_opt(rk)]
+
+ case "Text" then
+ dx="orig(1)+sz(1)*"+num2string(rk.data(1))
+ dy="orig(2)+sz(2)*"+num2string(rk.data(2))
+ t=sci2exp(rk.text,0)
+ t="["+strsubst(t,char(10),""";""")+"]"
+ if rk.text_box_mode <> "filled" then
+ txt=[txt;
+ "xstring("+dx+","+dy+","+t+");"
+ text_opt(rk)]
+ else //patch because of xstringb patch in scicos
+ w="sz(1)*"+num2string(rk.text_box(1))
+ h="sz(2)*"+num2string(rk.text_box(2))
+
+ txt=[txt;
+ "xstringb("+dx+","+dy+","+t+","+w+","+h+",''fill'');"
+ textb_opt(rk)]
+ end
+ case "Compound" then //multiple line string
+ n=size(rk.children,"*")
+ if n==1 then
+ txt=[txt;
+ graphical_object_code(rk.children)];
+ else
+ for i=n:-1:1
+ txt=[txt;
+ graphical_object_code(rk.children(i));
+ "e"+string(i)+"=e;"]
+ end
+ txt=[txt;
+ "glue(["+strcat("e"+string(1:n),",")+"]);"]
+ end
+ else
+ mprintf("Graphical object of type "+rk.type+" not yet handled\n")
+ end
+endfunction
+
+function opts=rect_opt(e)
+ opts=[mark_opt(e);line_opt(e);fill_opt(e);clip_opt(e)];
+ if opts<>[] then
+ opts=["e=gce()";opts]
+ opts=strcat(opts,";")+";"
+ end
+endfunction
+
+function opts=arc_opt(e)
+ opts=[line_opt(e);fill_opt(e);clip_opt(e)];
+ if opts<>[] then
+ opts=["e=gce()";opts]
+ opts=strcat(opts,";")+";"
+ end
+endfunction
+
+function opts=seg_opt(e)
+ markopt=mark_opt(e)
+ lineopt=line_opt(e)
+ if rk.arrow_size>0 then
+ arrowopt="e.arrow_size="+string(e.arrow_size)
+ else
+ arrowopt=[]
+ end
+ opts=[markopt;lineopt;arrowopt];
+ if opts<>[] then
+ opts=["e=gce()";opts]
+ opts=strcat(opts,";")+";"
+ end
+endfunction
+
+function opts=poly_opt(e)
+ markopt=mark_opt(e)
+ lineopt=line_opt(e)
+ fillopt=fill_opt(e)
+ arrowopt=arrow_opt(e)
+
+ opts=[markopt;lineopt;fillopt;arrowopt];
+ if opts<>[] then
+ opts=["e=gce()";opts]
+ opts=strcat(opts,";")+";"
+ end
+endfunction
+
+function opts=text_opt(e)
+ fontopt=font_opt(e)
+ boxopt=box_opt(e)
+ lineopt=[];
+ if rk.fill_mode == "on" then
+ lineopt="e.fill_mode="+sci2exp(e.fill_mode)
+ if e.foreground<>-1 then
+ lineopt=[lineopt
+ "e.foreground="+sci2exp(e.foreground)]
+ end
+ end
+ opts=[fontopt;boxopt;lineopt]
+ if opts<>[] then
+ opts=["e=gce()";opts]
+ opts= strcat(opts,";")+";"
+ end
+endfunction
+
+function opts=textb_opt(e)
+ fontopt=font_opt(e)
+ lineopt=[];
+ if rk.fill_mode == "on" then
+ lineopt="e.fill_mode="+sci2exp(e.fill_mode)
+ if e.foreground<>-1 then
+ lineopt=[lineopt
+ "e.foreground="+sci2exp(e.foreground)]
+ end
+ end
+ opts=[fontopt;lineopt]
+ if opts<>[] then
+ opts=["e=gce()";opts]
+ opts= strcat(opts,";")+";"
+ end
+endfunction
+
+function markopt=mark_opt(e)
+ markopt=[]
+ if e.mark_mode=="on" then
+ markopt=[markopt;
+ "e.mark_mode=''on''"]
+ if e.mark_style<>0 then
+ markopt=[markopt;
+ "e.mark_style="+string(e.mark_style)]
+ end
+ if e.mark_size<>0 then
+ markopt=[markopt;
+ "e.mark_size="+string(e.mark_size)]
+ end
+ if e.mark_foreground<>-1 then
+ markopt=[markopt;
+ "e.mark_foreground="+string(e.mark_foreground)]
+ end
+ if e.mark_background<>-1 then
+ markopt=[markopt;
+ "e.mark_background="+string(e.mark_background)]
+ end
+ end
+endfunction
+function lineopt=line_opt(e)
+ lineopt=[]
+ t=e.type
+ if e.line_mode=="on" then
+ lineopt=[lineopt;
+ "e.line_mode="+sci2exp(e.line_mode)]
+ if e.line_style<>0 then
+ lineopt=[lineopt;
+ "e.line_style="+string(e.line_style)]
+ end
+ if e.thickness>1 then
+ lineopt=[lineopt;
+ "e.thickness="+string(e.thickness)]
+ end
+ if t<>"Segs"&e.foreground<>-1 then
+ lineopt=[lineopt;
+ "e.foreground="+string(e.foreground)]
+ end
+ end
+endfunction
+
+function fillopt=fill_opt(e)
+ fillopt=[]
+ if e.fill_mode=="on" then
+ fillopt=[fillopt;
+ "e.fill_mode="+sci2exp(e.fill_mode)]
+ if e.background<>-2 then
+ fillopt=[fillopt;
+ "e.background="+string(e.background)]
+ end
+ end
+endfunction
+function arrowopt=arrow_opt(e)
+ arrowopt=[]
+ if e.polyline_style<>1 then
+ arrowopt=[arrowopt;
+ "e.polyline_style="+sci2exp(e.polyline_style)
+ "e.arrow_size_factor="+string(e.arrow_size_factor)]
+ end
+endfunction
+function fontopt=font_opt(e)
+ fontopt=[]
+ if e.font_foreground<>-1 then
+ fontopt=[fontopt;
+ "e.font_foreground="+string(e.font_foreground)]
+ end
+ if e.font_style<>6 then
+ fontopt=[fontopt;
+ "e.font_style="+string(e.font_style)]
+ end
+ if e.font_size<>1 then
+ fontopt=[fontopt;
+ "e.font_size="+string(e.font_size)]
+ end
+ if e.font_angle<>0 then
+ fontopt=[fontopt;
+ "e.font_angle="+string(e.font_angle)]
+ end
+endfunction
+
+function boxopt=box_opt(e)
+ boxopt=[]
+ if e.text_box_mode<>"off" then
+ boxopt=[boxopt;
+ "e.text_box_mode="+sci2exp(e.text_box_mode)]
+ end
+ if or(e.text_box<>[0 0]) then
+ boxopt=[boxopt;
+ "e.text_box="+sci2exp(e.text_box)]
+ end
+ if e.box<>"off" then
+ boxopt=[boxopt;
+ "e.box="+sci2exp(e.box)]
+ end
+ if e.background<>-2 then
+ boxopt=[boxopt;
+ "e.background="+sci2exp(e.background)]
+ end
+ if e.fill_mode<>"off" then
+ boxopt=[boxopt;
+ "e.fill_mode="+sci2exp(e.fill_mode)];
+
+ end
+endfunction
+
+function clipopt=clip_opt(e)
+ clipopt=[]
+ if e.clip_state<>"off" then
+ clipopt=[clipopt;
+ "e.clip_state="+sci2exp(e.clip_state)
+ "e.clip_box="+sci2exp(e.clip_box)]
+ end
+endfunction
+
+
+function s=num2string(a)
+ s=matrix(msprintf("%.2f\n",a(:)),size(a))
+ s=strsubst(s,".00","")
+endfunction
+
+
diff --git a/modules/scicos/macros/scicos_scicos/extract_implicit.bin b/modules/scicos/macros/scicos_scicos/extract_implicit.bin
new file mode 100755
index 000000000..2799c07e6
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/extract_implicit.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/extract_implicit.sci b/modules/scicos/macros/scicos_scicos/extract_implicit.sci
new file mode 100755
index 000000000..cb112049b
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/extract_implicit.sci
@@ -0,0 +1,144 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [blklstr,cmatr,ccmat,cor,corinv,ok]=extract_implicit(blklst,cmat,ccmat)
+
+ imp=[];blklstr=[];cmatr=[];ok=%t
+
+ nb=size(blklst);
+ for k=1:nb
+ if or(getfield(1,blklst(k))=="equations") then
+ if blklst(k).equations<>list() then imp=[imp,k];end
+ end
+ end
+ if imp==[] then [blklstr,cmatr]=(blklst,cmat), return,end
+
+ if size(ccmat,1)>0 then
+ if or(dsearch(ccmat(:,1),imp,"d")<>0) then
+ messagebox("An implicit block has an event input","modal","error");
+ ok=%f
+ return
+ end
+ if or(dsearch(ccmat(:,3),imp,"d")<>0) then
+ messagebox("An implicit block has an event output","modal","error");
+ ok=%f
+ return
+ end
+ end
+ indfrom=dsearch(cmat(:,1),imp,"d")
+ indto=dsearch(cmat(:,4),imp,"d")
+
+ I=find(indfrom<>0&indto<>0) //links between two implicit blocs
+ Iin=find(indfrom==0&indto<>0)
+ Iout=find(indfrom<>0&indto==0)
+
+ blklsti=list(blklst(imp)); //the implicit blocks list
+ cmati=cmat(I,:);
+
+ //add blocks for input and outputs
+ nbi=size(blklsti);
+ N=size(Iin,"*");
+ if N>0
+ mo=modelica();mo.model="InPutPort";mo.outputs="vo";mo.inputs="vi";
+ for k=1:N
+ blklsti($+1)=scicos_model(equations=mo);
+ end
+ ci=cmat(Iin,:);ci(:,1)=-(nbi+(1:N))';ci(:,2)=1;
+ cmati=[cmati;ci];
+ nbi=nbi+N;
+ end
+ N=size(Iout,"*")
+ if N>0
+ mo=modelica();mo.model="OutPutPort";mo.outputs="vo";mo.inputs="vi";
+ for k=1:N
+ blklsti($+1)=scicos_model(equations=mo);
+ end
+ co=cmat(Iout,:);co(:,4)=-(nbi+(1:N)');co(:,5)=1;
+ cmati=[cmati;co];
+ nbi=nbi+N;
+ end
+
+ //renumber links connecting implicit blocs
+ for k=1:size(cmati,1)
+ l=find(cmati(k,1)==imp);if l<>[] then cmati(k,1)=l;end
+ l=find(cmati(k,4)==imp);if l<>[] then cmati(k,4)=l;end
+ end
+ cmati=abs(cmati)
+
+ name="imppart_"+stripblanks(scs_m.props.title(1));
+ txt=create_modelica( blklsti,cmati,name);
+ mputl(txt,scs_m.props.title(2)+name+".mo");
+ [ok,name1,nx,ng]=compile_modelica(scs_m.props.title(2)+name+".mo");
+ if ~ok then return,end
+ reg=1:nb;reg(imp)=[];
+ blklstr=list(blklst(reg)); //the regular blocks list
+
+ //add the block equivalent to the implicit part
+ nx=nx*2//should be read from generated C code
+ blklstr($+1)=scicos_model(sim=list(name,10002),..
+ in=ones(Iin'),out=ones(Iout'),state=zeros(nx,1),..
+ dep_ut=[%f %t],nzcross=ng)
+ nbr=size(blklstr)
+ cmatr=cmat;cmatr([I,Iin,Iout],:)=[];
+ //renumber links connecting regular blocs
+ N=size(Iin,"*");
+ if N>0
+ ci=cmat(Iin,:);ci(:,4)=-nbr;ci(:,5)=(1:N)';
+ cmatr=[cmatr;ci];
+ end
+ N=size(Iout,"*")
+ if N>0
+ co=cmat(Iout,:);co(:,1)=-nbr;co(:,2)=(1:N)';
+ cmatr=[cmatr;co];
+ end
+ for k=1:size(cmatr,1)
+ l=find(cmatr(k,1)==reg);if l<>[] then cmatr(k,1)=l;end
+ l=find(cmatr(k,4)==reg);if l<>[] then cmatr(k,4)=l;end
+ end
+ cmatr=abs(cmatr)
+
+ //renumber ccmat
+ for k=1:size(ccmat,1)
+ l=find(ccmat(k,1)==reg);if l<>[] then ccmat(k,1)=l;end
+ l=find(ccmat(k,3)==reg);if l<>[] then ccmat(k,3)=l;end
+ end
+ //update corinv, we choose imp(1) to represent all implicits blocs!
+ corinv=list(corinv([reg,imp(1)]))
+ //update cor
+
+ cor=update_cor(cor,reg)
+endfunction
+
+function cor=update_cor(cor,reg)
+ n=size(cor)
+ for k=1:n
+ if type(cor(k))==15 then
+ cor(k)=update_cor(cor(k),reg)
+ else
+ p=find(cor(k)==reg)
+ if p<>[] then
+ cor(k)=p
+ elseif cor(k)<>0 then
+ cor(k)=size(reg,"*")+1
+ end
+ end
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/findinlist.bin b/modules/scicos/macros/scicos_scicos/findinlist.bin
new file mode 100755
index 000000000..95e35f043
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/findinlist.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/findinlist.sci b/modules/scicos/macros/scicos_scicos/findinlist.sci
new file mode 100755
index 000000000..5b88da13c
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/findinlist.sci
@@ -0,0 +1,38 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [path]=findinlist(L,v,path)
+ //recherche si un element de valeur v existe dans la liste L
+ global paths
+ if and(type(L)<>(15:17)) then error("First argument should be a list"),end
+ firstlevel=argn(2)<3
+ if firstlevel then paths=list(),path=[];end
+ for k=1:size(L)
+ l=L(k)
+ if or(type(l)==(15:17)) then
+ findinlist(l,v,[path,k])
+ elseif isequal(l,v) then
+ paths($+1)=[path k]
+ else
+ end
+ end
+ if firstlevel then path=paths,clearglobal paths,end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/findinlistcmd.bin b/modules/scicos/macros/scicos_scicos/findinlistcmd.bin
new file mode 100755
index 000000000..b229b9391
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/findinlistcmd.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/findinlistcmd.sci b/modules/scicos/macros/scicos_scicos/findinlistcmd.sci
new file mode 100755
index 000000000..07ebce7e6
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/findinlistcmd.sci
@@ -0,0 +1,51 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [path]=findinlistcmd(L,v,oper,path)
+ //recherche si un element de valeur v existe dans la liste L
+ global paths
+ if and(type(L)<>(15:17)) then error("First argument should be a list"),end
+ firstlevel=argn(2)<4
+ if firstlevel then paths=list(),path=[];end
+ for k=1:size(L)
+ l=L(k)
+ if or(type(l)==(15:17)) then
+ findinlistcmd(l,v,oper,[path,k])
+ else
+ if oper=="=" then
+ if and(l(:)==v) then
+ paths($+1)=[path k]
+ end
+ elseif oper==">" then
+ if or(l(:) > v) then
+ paths($+1)=[path k]
+ end
+ elseif oper=="<" then
+ if or(l(:) < v) then
+ paths($+1)=[path k]
+ end
+ else
+ end
+ end
+ end
+ if firstlevel then path=paths,clearglobal paths,end
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/gen_modelica.bin b/modules/scicos/macros/scicos_scicos/gen_modelica.bin
new file mode 100755
index 000000000..9bfc327ea
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/gen_modelica.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/gen_modelica.sci b/modules/scicos/macros/scicos_scicos/gen_modelica.sci
new file mode 100755
index 000000000..890207d82
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/gen_modelica.sci
@@ -0,0 +1,114 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function txt=gen_modelica(scs_m,name)
+ txt=[];tab=ascii(9)
+ models=[]
+ eqns=[]
+ Pin=[]
+ Bnumbers=[]
+ Bnames=[]
+
+ IN=[];OUT=[];
+ scs_m;
+ for i=1:size(scs_m.objs)
+ if typeof(scs_m.objs(i))=="Block" then
+ if scs_m.objs(i).gui=="IN_f" then
+ scs_m.objs(i).gui="INPUTPORT";
+ mo=modelica();mo.model="InPutPort";mo.outputs="vo";mo.inputs="vi";
+ scs_m.objs(i).model.equations=mo;
+ IN=[IN scs_m.objs(i).model.ipar]
+ elseif scs_m.objs(i).gui=="OUT_f" then
+ scs_m.objs(i).gui="OUTPUTPORT";
+ mo=modelica();mo.model="OutPutPort";mo.outputs="vo";mo.inputs= "vi";
+ scs_m.objs(i).model.equations=mo
+ OUT=[OUT scs_m.objs(i).model.ipar]
+ end
+ end
+ end
+
+ [blklst,cmat,ccmat,cor,corinv,ok]=pass1(scs_m);
+ if ~ok then return,end
+
+ //blocks
+ for k=1:size(blklst)
+ o=blklst(k);
+ if and(getfield(1,o)<>"equations")
+ messagebox("block numbered "+string(k)+" is not a Modelica block","modal")
+ txt=[]
+ return
+ end
+ if typeof(o.equations)<>"modelica" then
+ messagebox("block numbered "+string(k)+" is not a Modelica block","modal")
+ txt=[]
+ return
+ end
+ mo=o.equations;
+ np=size(mo.parameters(1),1);
+ P=[];
+ for l=1:np
+ pexp=sci2exp(mo.parameters(2)(l))
+
+ P=[P;
+ mo.parameters(1)(l)+"="+value2modelica(mo.parameters(2)(l))];
+ end
+ Bnumbers=[Bnumbers k];
+ Bnames=[Bnames,"B"+string(k)];
+ if P==[] then
+ models=[models;" "+mo.model+" "+tab+"B"+string(k)+";"];
+ else
+ models=[models;" "+mo.model+" "+tab+"B"+string(k)+"("+strcat(P,", ")+");"];
+ end
+ end
+ //links
+ for k=1:size(cmat,1)
+ from=cmat(k,1:3)
+ to=cmat(k,4:6)
+ if from(3)==1 then
+ p1=blklst(from(1)).equations.inputs(from(2))
+ else
+ p1=blklst(from(1)).equations.outputs(from(2))
+ end
+ n1=Bnames(find(Bnumbers==from(1)))
+ if to(3)==1 then
+ p2=blklst(to(1)).equations.inputs(to(2))
+ else
+ p2=blklst(to(1)).equations.outputs(to(2))
+ end
+ n2=Bnames(find(Bnumbers==to(1)))
+ if or(blklst(from(1)).equations.model==["InPutPort","OutPutPort"]) ...
+ | or(blklst(to(1)).equations.model==["InPutPort","OutPutPort"]) ...
+ then
+ eqns=[eqns
+ " "+n1+"."+p1+" = "+n2+"."+p2+";"]
+ else
+ eqns=[eqns
+ " connect ("+n1+"."+p1+","+n2+"."+p2+");"]
+ end
+ end
+ txt=[txt;
+ "class "+name
+ models
+ "equation"
+ eqns
+ "end "+name+";"]
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/genfunc.bin b/modules/scicos/macros/scicos_scicos/genfunc.bin
new file mode 100755
index 000000000..1b883fdec
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/genfunc.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/genfunc.sci b/modules/scicos/macros/scicos_scicos/genfunc.sci
new file mode 100755
index 000000000..64684f4c2
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/genfunc.sci
@@ -0,0 +1,58 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [ok,mac,txt]=genfunc(txt)
+ [lhs,rhs]=argn(0)
+ if rhs<1 then txt=" ",end
+ mac=[]
+ while %t do
+ txt=dialog(["Set Function Block";
+ " "
+ "Enter Scilab instructions defining"
+ "y as a function of u"],txt)
+
+
+ if txt==[] then ok=%f,return,end
+ // check if txt defines y from u
+ deff("[]=mac()",txt)
+ vars=macrovar(mac)
+ if or(vars(3)=="u")&or(vars(5)=="y") then break,end
+ end
+ ok=%t
+ deff("[%_1,%_2]=mac(%_model,%_x,%_z,u,%_clock,%_flag,%_rpar,%_ipar)",..
+ ["%_1=[];%_2=[];";
+ "select %_flag";
+ "case 1 then";
+ txt
+ "%_1=y";
+ "case -1 then ";
+ " %_model=list(%_model(1),1,1,[],[],[],[],[],[],''c'',%f,[%t %f])";
+ " %_1=list(%_model,'' '')";
+ "case -2 then ";
+ " txt=%_model.ipar";
+ " [ok,mac,txt]=genfunc(txt)";
+ " if ok then "
+ " %_model.sim=mac"
+ " %_model.ipar=txt"
+ " %_1=list(model,%_x)"
+ " end"
+ "end"])
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/genfunc1.bin b/modules/scicos/macros/scicos_scicos/genfunc1.bin
new file mode 100755
index 000000000..ed096beac
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/genfunc1.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/genfunc1.sci b/modules/scicos/macros/scicos_scicos/genfunc1.sci
new file mode 100755
index 000000000..1b888b384
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/genfunc1.sci
@@ -0,0 +1,260 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [ok,tt,dep_ut]=genfunc1(tt,inp,out,nci,nco,nx,nz,nrp,type_)
+ // manages dialog to get definition (with scilab instruction) of a new scicos
+ // block
+ //!
+ ni=size(inp,"*")
+ no=size(out,"*")
+
+ mac=[];ok=%f,dep_ut=[]
+ if size(tt)<>7 then
+ [txt1,txt0,txt2,txt3,txt4,txt5,txt6]=(" "," "," "," "," "," "," ")
+ else
+ [txt1,txt0,txt2,txt3,txt4,txt5,txt6]=tt(1:7)
+ end
+ dep_u=%f;dep_t=%f
+ depp="t";deqq="t";
+
+ u=emptystr(),
+ for k=1:ni,u=u+"u"+string(k)+",",end
+ dep=["t,","x,","z,",u,"n_evi,","rpar"]
+
+
+
+ if nx==0 then dep(2)=emptystr(),end
+ if nz==0 then dep(3)=emptystr(),end
+ //if nci==0 then dep(5)=emptystr(),end
+ if nrp==0 then dep(6)=emptystr(),end
+
+
+ //flag = 1
+ if no>0 then
+ depp=strcat(dep([1:5,6]))
+ w=[]
+ for k=1:no,w=[w;"y"+string(k)+" (size: "+string(out(k))+")"],end
+ while %t do
+ txt1=dialog(["Define function which computes the output";
+ " "
+ "Enter Scilab instructions defining";
+ w;
+ "as a functions of "+depp],txt1)
+ if txt1==[] then return,end
+ // check if txt defines y from u
+ mac=null();deff("[]=mac()",txt1,"n")
+ ok1=check_mac(mac)
+ if ok1 then
+ vars=macrovar(mac)
+ for k=1:ni
+ if or(vars(3)=="u"+string(k)) then dep_u=%t,end
+ end
+ if or(vars(3)=="t") then dep_t=%t,end
+ w=[];w(no)=%f;
+ for k=1:no,if or(vars(5)=="y"+string(k)) then w(k)=%t,end,end
+ if ~and(w) then
+ k1=find(~w)
+ w=[];for k=1:size(k1,"*"),w=[w;"y"+string(k)+" (size: "+string(out(k))+")"],end
+ messagebox("You did not define "+strcat(w,",")+" !","modal")
+ else
+ break
+ end
+ end
+ end
+ else
+ txt1=[]
+ end
+
+ //flag = 2
+ if nx>0 then
+ // xdot
+ depp=strcat(dep([1:4,6]))
+ while %t do
+ if txt0==[] then txt0=" ",end
+ txt0=dialog(["Define continuous states evolution";
+ " "
+ "Enter Scilab instructions defining:";
+ "derivative of continuous state xd (size:"+string(nx)+")"
+ "as function(s) of "+depp],txt0)
+
+ if txt0==[] then return,end
+ mac=null();deff("[]=mac()",txt0,"n")
+ ok1=check_mac(mac)
+ if ok1 then
+ vars=macrovar(mac)
+ if or(vars(5)=="xd") then
+ break,
+ else
+ messagebox("You did not define xd !","modal")
+ end
+ end
+ end
+ else
+ txt0="xd=[]"
+ end
+ if (nci>0&(nx>0|nz>0))|nz>0 then // x+ z+
+ depp=strcat(dep([1:5,6]))
+ while %t do
+ if txt2==[] then txt2=" ",end
+ t1=[]
+ if nx>0 then
+ t1=[t1;"-new continuous state x (size:"+string(nx)+")"]
+ end
+ if nz>0 then
+ t1=[t1;"-new discrete state z (size:"+string(nz)+")"]
+ end
+
+ txt2=dialog(["You may define:";
+ t1
+ "at event time, as functions of "+depp],txt2)
+ if txt2==[] then return,end
+ mac=null();deff("[]=mac()",txt2,"n")
+ ok1=check_mac(mac)
+ if ok1 then
+ vars=macrovar(mac)
+ if ~or(vars(5)=="x") then txt3=[txt3;"x=[]"];end
+ if ~or(vars(5)=="z") then txt3=[txt3;"z=[]"];end
+ break;
+ end
+ end
+ else
+ txt2=" "
+ end // end of x+ z+
+
+ //flag = 3
+ if nci>0&nco>0 then
+ depp=strcat(dep)
+
+ while %t do
+ if txt3==[] then txt3=" ",end
+ txt3=dialog(["Using "+depp+",you may set "
+ "vector of output time events t_evo (size:"+string(nco)+")"
+ "at event time. "],txt3)
+ if txt3==[] then return,end
+ mac=null();deff("[]=mac()",txt3,"n")
+ // alan.layec
+ ok1=check_mac(mac)
+ if ok1 then
+ vars=macrovar(mac)
+ if ~or(vars(5)=="t_evo") then txt3=[txt3;"t_evo=[]"];end
+ break;
+ end
+ end
+ else
+ txt3=" "
+ end
+
+ //flag = 4
+ depp=strcat(dep([2 3 6]))
+ t1=[]
+ if nx>0 then
+ t1=[t1;"- continuous state x (size:"+string(nx)+")"]
+ end
+ if nz>0 then
+ t1=[t1;"- discrete state z (size:"+string(nz)+")"]
+ end
+ if t1<>[] then
+ t1=["You may also reinitialize:";
+ t1]
+ end
+ while %t do
+ if txt4==[] then txt4=" ",end
+ txt4=dialog(["You may do whatever needed for initialization :"
+ "File or graphic opening...,"
+ t1
+ "as function(s) of "+depp],txt4)
+ if txt4==[] then return,end
+ mac=null();deff("[]=mac()",txt4,"n")
+ ok1=check_mac(mac)
+ if ok1 then break,end
+ end
+
+ //flag = 5
+ depp=strcat(dep([2 3 6]))
+ t1=[]
+ if nx>0 then
+ t1=[t1;"- continuous state x (size:"+string(nx)+")"]
+ end
+ if nz>0 then
+ t1=[t1;"- discrete state z (size:"+string(nz)+")"]
+ end
+ if t1<>[] then
+ t1=["You may also change final value of:";t1]
+ end
+ while %t do
+ if txt5==[] then txt5=" ",end
+ txt5=dialog(["You may do whatever needed to finish :"
+ "File or graphic closing...,"
+ t1
+ "as function(s) of "+depp],txt5)
+ if txt5==[] then return,end
+ mac=null();deff("[]=mac()",txt5,"n")
+ ok1=check_mac(mac)
+ if ok1 then break,end
+ end
+
+ //flag = 6
+ if nx>0|nz>0|no>0 then
+ t1=[]
+ if nx>0 then
+ t1=[t1;"- state x (size:"+string(nx)+")"]
+ end
+ if nz>0 then
+ t1=[t1;"- state z (size:"+string(nz)+")"]
+ end
+ w=[]
+ for k=1:no
+ w=[w;"- output y"+string(k)+" (size : "+string(out(k))+")"]
+ end
+ t1=[t1;w]
+
+ depp=strcat(dep([2:4,6]))
+
+ while %t do
+ txt6=dialog(["You may define here functions imposing contraints";
+ "on initial inputs, states and outputs";
+ "Note: these functions may be called more than once";
+ " ";
+ "Enter Scilab instructions defining:"
+ t1;
+ "as a function of "+depp],txt6)
+ if txt6==[] then return,end
+
+ mac=null();deff("[]=mac()",txt6,"n")
+ ok1=check_mac(mac)
+ if ok1 then
+ vars=macrovar(mac)
+ for k=1:no
+ if and(vars(5)<>"y"+string(k)) then txt6=[txt6;"y"+string(k)+"=[]"],end
+ end
+ break,
+ end
+ end
+ else
+ txt6=[]
+ end
+
+ ok=%t
+ tt=list(txt1,txt0,txt2,txt3,txt4,txt5,txt6)
+
+
+ dep_ut=[dep_u dep_t]
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/genfunc2.bin b/modules/scicos/macros/scicos_scicos/genfunc2.bin
new file mode 100755
index 000000000..96821677a
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/genfunc2.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/genfunc2.sci b/modules/scicos/macros/scicos_scicos/genfunc2.sci
new file mode 100755
index 000000000..9bd66fd02
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/genfunc2.sci
@@ -0,0 +1,260 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [ok,tt,dep_ut]=genfunc2(tt,inp,out,nci,nco,nx,nz,nrp,type_)
+ // manages dialog to get definition (with scilab instruction) of a new scicos
+ // block
+ //!
+ ni=size(inp,1)
+ no=size(out,1)
+
+ mac=[];ok=%f,dep_ut=[]
+ if size(tt)<>7 then
+ [txt1,txt0,txt2,txt3,txt4,txt5,txt6]=(" "," "," "," "," "," "," ")
+ else
+ [txt1,txt0,txt2,txt3,txt4,txt5,txt6]=tt(1:7)
+ end
+ dep_u=%f;dep_t=%f
+ depp="t";deqq="t";
+
+ u=emptystr(),
+ for k=1:ni,u=u+"u"+string(k)+",",end
+ dep=["t,","x,","z,",u,"n_evi,","rpar"]
+
+
+
+ if nx==0 then dep(2)=emptystr(),end
+ if nz==0 then dep(3)=emptystr(),end
+ //if nci==0 then dep(5)=emptystr(),end
+ if nrp==0 then dep(6)=emptystr(),end
+
+
+ //flag = 1
+ if no>0 then
+ depp=strcat(dep([1:5,6]))
+ w=[]
+ for k=1:no,w=[w;"y"+string(k)+" (size: "+string(out(k))+")"],end
+ while %t do
+ txt1=dialog(["Define function which computes the output";
+ " "
+ "Enter Scilab instructions defining";
+ w;
+ "as a functions of "+depp],txt1)
+ if txt1==[] then return,end
+ // check if txt defines y from u
+ mac=null();deff("[]=mac()",txt1,"n")
+ ok1=check_mac(mac)
+ if ok1 then
+ vars=macrovar(mac)
+ for k=1:ni
+ if or(vars(3)=="u"+string(k)) then dep_u=%t,end
+ end
+ if or(vars(3)=="t") then dep_t=%t,end
+ w=[];w(no)=%f;
+ for k=1:no,if or(vars(5)=="y"+string(k)) then w(k)=%t,end,end
+ if ~and(w) then
+ k1=find(~w)
+ w=[];for k=1:size(k1,"*"),w=[w;"y"+string(k)+" (size: "+string(out(k))+")"],end
+ messagebox("You did not define "+strcat(w,",")+" !","modal")
+ else
+ break
+ end
+ end
+ end
+ else
+ txt1=" "
+ end
+
+ //flag = 2
+ if nx>0 then
+ // xdot
+ depp=strcat(dep([1:4,6]))
+ while %t do
+ if txt0==[] then txt0=" ",end
+ txt0=dialog(["Define continuous states evolution";
+ " "
+ "Enter Scilab instructions defining:";
+ "derivative of continuous state xd (size:"+string(nx)+")"
+ "as function(s) of "+depp],txt0)
+
+ if txt0==[] then return,end
+ mac=null();deff("[]=mac()",txt0,"n")
+ ok1=check_mac(mac)
+ if ok1 then
+ vars=macrovar(mac)
+ if or(vars(5)=="xd") then
+ break,
+ else
+ messagebox("You did not define xd !","modal")
+ end
+ end
+ end
+ else
+ txt0="xd=[]"
+ end
+ if (nci>0&(nx>0|nz>0))|nz>0 then // x+ z+
+ depp=strcat(dep([1:5,6]))
+ while %t do
+ if txt2==[] then txt2=" ",end
+ t1=[]
+ if nx>0 then
+ t1=[t1;"-new continuous state x (size:"+string(nx)+")"]
+ end
+ if nz>0 then
+ t1=[t1;"-new discrete state z (size:"+string(nz)+")"]
+ end
+
+ txt2=dialog(["You may define:";
+ t1
+ "at event time, as functions of "+depp],txt2)
+ if txt2==[] then return,end
+ mac=null();deff("[]=mac()",txt2,"n")
+ ok1=check_mac(mac)
+ if ok1 then
+ vars=macrovar(mac)
+ if ~or(vars(5)=="x") then txt3=[txt3;"x=[]"];end
+ if ~or(vars(5)=="z") then txt3=[txt3;"z=[]"];end
+ break;
+ end
+ end
+ else
+ txt2=" "
+ end // end of x+ z+
+
+ //flag = 3
+ if nci>0&nco>0 then
+ depp=strcat(dep)
+
+ while %t do
+ if txt3==[] then txt3=" ",end
+ txt3=dialog(["Using "+depp+",you may set "
+ "vector of output time events t_evo (size:"+string(nco)+")"
+ "at event time. "],txt3)
+ if txt3==[] then return,end
+ mac=null();deff("[]=mac()",txt3,"n")
+ ok1=check_mac(mac)
+ if ok1 then
+ vars=macrovar(mac)
+ if ~or(vars(5)=="t_evo") then txt3=[txt3;"t_evo=[]"];end
+ break;
+ end
+ end
+ else
+ txt3=" "
+ end
+
+ //flag = 4
+ depp=strcat(dep([2 3 6]))
+ t1=[]
+ if nx>0 then
+ t1=[t1;"- continuous state x (size:"+string(nx)+")"]
+ end
+ if nz>0 then
+ t1=[t1;"- discrete state z (size:"+string(nz)+")"]
+ end
+ if t1<>[] then
+ t1=["You may also reinitialize:";
+ t1]
+ end
+ while %t do
+ if txt4==[] then txt4=" ",end
+ txt4=dialog(["You may do whatever needed for initialization :"
+ "File or graphic opening...,"
+ t1
+ "as function(s) of "+depp],txt4)
+ if txt4==[] then return,end
+ mac=null();deff("[]=mac()",txt4,"n")
+ ok1=check_mac(mac)
+ if ok1 then break,end
+ end
+
+ //flag = 5
+ depp=strcat(dep([2 3 6]))
+ t1=[]
+ if nx>0 then
+ t1=[t1;"- continuous state x (size:"+string(nx)+")"]
+ end
+ if nz>0 then
+ t1=[t1;"- discrete state z (size:"+string(nz)+")"]
+ end
+ if t1<>[] then
+ t1=["You may also change final value of:";t1]
+ end
+ while %t do
+ if txt5==[] then txt5=" ",end
+ txt5=dialog(["You may do whatever needed to finish :"
+ "File or graphic closing...,"
+ t1
+ "as function(s) of "+depp],txt5)
+ if txt5==[] then return,end
+ mac=null();deff("[]=mac()",txt5,"n")
+ ok1=check_mac(mac)
+ if ok1 then break,end
+ end
+
+ //flag = 6
+ if nx>0|nz>0|no>0 then
+ t1=[]
+ if nx>0 then
+ t1=[t1;"- state x (size:"+string(nx)+")"]
+ end
+ if nz>0 then
+ t1=[t1;"- state z (size:"+string(nz)+")"]
+ end
+ w=[]
+ for k=1:no
+ w=[w;"- output y"+string(k)+" (size : "+string(out(k))+")"]
+ end
+ t1=[t1;w]
+
+ depp=strcat(dep([2:4,6]))
+
+ while %t do
+ if txt6==[] then txt6=" ",end
+ txt6=dialog(["You may define here functions imposing contraints";
+ "on initial inputs, states and outputs";
+ "Note: these functions may be called more than once";
+ " ";
+ "Enter Scilab instructions defining:"
+ t1;
+ "as a function of "+depp],txt6)
+ if txt6==[] then return,end
+
+ mac=null();deff("[]=mac()",txt6,"n")
+ ok1=check_mac(mac)
+ if ok1 then
+ vars=macrovar(mac)
+ for k=1:no
+ if and(vars(5)<>"y"+string(k)) then txt6=[txt6;"y"+string(k)+"=[]"],end
+ end
+ break,
+ end
+ end
+ else
+ txt6=" "
+ end
+
+ ok=%t
+ tt=list(txt1,txt0,txt2,txt3,txt4,txt5,txt6)
+
+
+ dep_ut=[dep_u dep_t]
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/genmac.bin b/modules/scicos/macros/scicos_scicos/genmac.bin
new file mode 100755
index 000000000..f6a82d29c
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/genmac.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/genmac.sci b/modules/scicos/macros/scicos_scicos/genmac.sci
new file mode 100755
index 000000000..d838c2a0a
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/genmac.sci
@@ -0,0 +1,90 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function mac=genmac(tt,nin,nout)
+ [txt1,txt0,txt2,txt3,txt4,txt5,txt6]=tt(1:7)
+ mac=null()
+ // [y, x, z, tvec,xd]=func(flag,nevprt,t,x,z,rpar,ipar,u)
+ blank=" "
+ // if txt2_1<>' ' then
+ // txt2=[txt2;
+ // 'if n_evi<>0 then'
+ // blank(ones(txt2_1))+txt2_1
+ // 'end']
+ //end
+ semi=";"
+
+
+ txt1=blank(ones(txt1))+txt1+semi(ones(txt1))
+ txt2=blank(ones(txt2))+txt2+semi(ones(txt2))
+ txt3=blank(ones(txt3))+txt3+semi(ones(txt3))
+ txt4=blank(ones(txt4))+txt4+semi(ones(txt4))
+ txt5=blank(ones(txt5))+txt5+semi(ones(txt5))
+ txt6=blank(ones(txt6))+txt6+semi(ones(txt6))
+
+ u="u"
+ if nin>0 then
+ get_u=blank+"["+strcat(u(ones(1,nin))+string(1:nin),",")+"]=u(:)"
+ else
+ get_u=[]
+ end
+ y="y"
+ set_y=blank+"y=list("+strcat(y(ones(1,nout))+string(1:nout),",")+")"
+ mac_txt=[
+ get_u
+ "select %_flag";
+ "case 0 then";
+ txt0
+ " t_evo=[]";
+ " y=list()";
+ "case 1 then";
+ txt1
+ " t_evo=[]";
+ " xd=[]";
+ set_y;
+ "case 2 then";
+ txt2
+ " y=list()";
+ " t_evo=[]";
+ " xd=[]";
+ "case 3 then";
+ txt3
+ " xd=[]";
+ " y=list()";
+ "case 4 then";
+ txt4
+ " y=list()";
+ " t_evo=[]";
+ " xd=[]";
+ "case 5 then";
+ txt5
+ " y=list()";
+ " t_evo=[]";
+ " xd=[]";
+ "case 6 then";
+ txt6
+ " t_evo=[]";
+ " xd=[]";
+ set_y
+ "end";]
+
+ deff("[y,x,z,t_evo,xd]=mac(%_flag,n_evi,t,x,z,rpar,ipar,u)",mac_txt)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/get2index.bin b/modules/scicos/macros/scicos_scicos/get2index.bin
new file mode 100755
index 000000000..b39fc3a1e
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get2index.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/get2index.sci b/modules/scicos/macros/scicos_scicos/get2index.sci
new file mode 100755
index 000000000..fdaf4478b
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get2index.sci
@@ -0,0 +1,81 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [scs_m_i, cpr_i, sflag] = get2index(object, k)
+ //
+ //** scs_m_i : Object numeber (index) in the diagram (scs_m)
+ //**
+ //** cpr_i : Compiled structure index
+ //**
+ //** the code is derived from
+ //**
+ //** "Info" -> GetInfo -> do_block_info -> get_block_info -> standard_document
+ //
+ //
+ //pause
+
+ sflag=[]
+ object_type = typeof(object)
+ //
+ if object_type=="Block" then
+
+ scs_m_i = k ;
+ //disp('ici');pause
+ if %cpr<>list()&needcompile<>4&k<>-1 then
+ cor = %cpr.cor
+ corinv = %cpr.corinv
+ path = list()
+ for kp=1:size(super_path,"*")
+ path(kp) = super_path(kp)
+ end
+ path($+1) = k
+ ind = cor(path)
+
+ //** if ind>0 & ind<=size(corinv) then
+ cpr_i = cor(path) ; //** the good one
+ //disp('ici');pause
+ if type(cpr_i)==15 then
+ tmp_cpr=[];
+ sflag="*"
+ ssflag=""
+ for i=1:size(cpr_i)
+ if type(cpr_i(i))<>15 then
+ if cpr_i(i)<>0&cpr_i(i)<=size(corinv) then
+ tmp_cpr=[tmp_cpr,cpr_i(i)]
+ end
+ else //another sblock
+ ssflag=" *"
+ end
+ end
+ cpr_i="["+strcat(string(tmp_cpr)," ")+ssflag+"]";
+ end
+ //** else
+ //** cpr_i= -7; //** ['Compiled structure Index : suppressed'; ' ']
+ //**end
+ else
+ cpr_i= -9; //** ['Compiled structure Index : Not available';' ']
+ end
+ else
+ scs_m_i = [] ;
+ cpr_i = [] ;
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/get_connected.bin b/modules/scicos/macros/scicos_scicos/get_connected.bin
new file mode 100755
index 000000000..7ae848231
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get_connected.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/get_connected.sci b/modules/scicos/macros/scicos_scicos/get_connected.sci
new file mode 100755
index 000000000..f32b939f2
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get_connected.sci
@@ -0,0 +1,65 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function connected=get_connected(scs_m,k,typ)
+ //return the vector of number of link connected to a given block
+ // scs_m : structure of blocks and links
+ // k : block_number
+ // typ : 'in','out','clkin','clkout'
+ // connected : vector of connected link numbers
+ [lhs,rhs]=argn(0)
+
+ connected=[]
+
+ //disp('get_connected')
+ // pause
+ if rhs<=2 then // all connected links
+ graphics=scs_m.objs(k).graphics
+
+ ip=graphics.pin
+ connected=[connected ip(find(ip>0))']
+
+ op=graphics.pout
+ connected=[connected op(find(op>0))']
+
+ cip=graphics.pein
+ connected=[connected cip(find(cip>0))']
+
+ cop=graphics.peout
+ connected=[connected cop(find(cop>0))']
+ else
+
+ if typ=="in" then
+ ip=scs_m.objs(k).graphics.pin
+ connected=[connected ip(find(ip>0))'],
+ elseif typ=="out" then
+ op=scs_m.objs(k).graphics.pout
+ connected=[connected op(find(op>0))'],
+ elseif typ=="clkin" then
+ cip=scs_m.objs(k).graphics.pein
+ connected=[connected cip(find(cip>0))'],
+ elseif typ=="clkout" then
+ cop=scs_m.objs(k).graphics.peout
+ connected=[connected cop(find(cop>0))'],
+ end
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/get_dynamic_lib_dir.bin b/modules/scicos/macros/scicos_scicos/get_dynamic_lib_dir.bin
new file mode 100755
index 000000000..74313ffcf
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get_dynamic_lib_dir.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/get_dynamic_lib_dir.sci b/modules/scicos/macros/scicos_scicos/get_dynamic_lib_dir.sci
new file mode 100755
index 000000000..bb16abc43
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get_dynamic_lib_dir.sci
@@ -0,0 +1,51 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+function [libss,ok,cancel]=get_dynamic_lib_dir(tt,funam,flag)
+ // Copyright INRIA
+ cancel=%f
+ cur_wd = pwd();
+ chdir(TMPDIR);
+ mputl(tt,funam+"."+flag);
+ libss="";
+ label="";
+ ok=%f
+ while ~ok then
+ [ok,libss,label]=scicos_getvalue("Linking the "+funam+" function","External libraries (if any)",list("str",1),label);
+ if ~ok then chdir(cur_wd);cancel=%t,return;end
+ // for multiple libraries
+ if strindex(libss,"''")<>[] | strindex(libss,"""")<>[] then
+ ierr=execstr("libss=evstr(libss)","errcatch")
+ if ierr<>0 then
+ messagebox(["Can''t solve other files to link"],"modal")
+ chdir(cur_wd);
+ ok=%f;
+ end
+ else
+ libss=tokens(libss,[" ",";"])
+ end
+ for i=1:size(libss,"*")
+ lib_dll=libss(i) + getdynlibext();
+ ifexst=fileinfo(lib_dll)
+ if ifexst==[] then messagebox ("the library "+lib_dll+" doesn''t exists","modal");ok=%f;end
+ end
+ end
+ chdir(cur_wd);
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/get_errorcmd.bin b/modules/scicos/macros/scicos_scicos/get_errorcmd.bin
new file mode 100755
index 000000000..312248578
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get_errorcmd.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/get_errorcmd.sci b/modules/scicos/macros/scicos_scicos/get_errorcmd.sci
new file mode 100755
index 000000000..452935b57
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get_errorcmd.sci
@@ -0,0 +1,108 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// - Alan Layec <alan.layec@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function cmd=get_errorcmd(path,scs_m_in,title_err,mess_err)
+ //** get_errorcmd : return a Scicos_commands strings
+ //** to select/hilite and display error messages for block
+ //** defined by his main scs_m path.
+ //** If the block is included in a super block, the editor
+ //** will open the correspondig windows by the use of the
+ //** scicos global variable %diagram_path_objective and
+ //** %scicos_navig.
+ //**
+ //** exemple of use :
+ //** path=corinv(kfun);
+ //** global Scicos_commands;
+ //** Scicos_commands=get_errorcmd(path,'my Title error','error message');
+ //**
+ //** inputs : path : the path of the object which have
+ //** generated an error in a scs_m
+ //**
+ //** scs_m_in : a scicos diagram data structure
+ //** (if any. if not scs_m is semi global)
+ //**
+ //** title_err : the title of the error box message
+ //** (if any)
+ //**
+ //** mess_err : the message of the error box message
+ //** (if any)
+ //**
+ //** nb : the string message will be formated as this :
+ //** str_err=[title;
+ //** specific message for type of block;
+ //** mess_err]
+ //**
+ //** output : cmd : the Scicos_commands strings
+ //**
+ //** Alan, 11/10/07 : Initial rev
+ //Copyright INRIA
+
+ //** first generate an empty cmd
+ cmd=[]
+
+ //** generte empty spec_err
+ spec_err=[]
+
+ //** check number of rhs arg
+ rhs = argn(2) ;
+ if (rhs == 1) then
+ title_err=[]
+ mess_err=[]
+ elseif (rhs == 2) then
+ if typeof(scs_m_in)=="diagram" then
+ scs_m=scs_m_in
+ mess_err=[]
+ elseif typeof(scs_m_in)=="string" then
+ title_err=scs_m_in
+ mess_err=[]
+ end
+ elseif (rhs == 3) then
+ if typeof(scs_m_in)=="diagram" then
+ scs_m=scs_m_in
+ elseif typeof(scs_m_in)=="string" then
+ mess_err=title_err
+ title_err=scs_m_in
+ end
+ end
+
+ //** **************
+ //** modelica block
+ //** **************
+ if type(path)==15 then
+
+ spec_err="The modelica block returns the error :";
+ //** create cmd
+ cmd=["messagebox([''"+title_err+"'';"+...
+ "''"+spec_err+"'';"+...
+ strcat("''"+mess_err+"''",";")+"],''modal'');"]
+
+ //** ************************
+ //** all other type of blocks
+ //** ************************
+ else
+ msg = "<html><body>" + title_err + ": <br/>";
+ msg = msg + strcat(mess_err, "<br/>");
+ msg = msg + "</body></html>";
+ hilite_path(path, msg);
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/get_model_name.bin b/modules/scicos/macros/scicos_scicos/get_model_name.bin
new file mode 100755
index 000000000..0e7bca72e
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get_model_name.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/get_model_name.sci b/modules/scicos/macros/scicos_scicos/get_model_name.sci
new file mode 100755
index 000000000..0a98ce7ae
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get_model_name.sci
@@ -0,0 +1,45 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function model_name=get_model_name(mo_model,Bnames)
+ //Copyright INRIA
+ //## return an unique name for a modelica model
+ //## for the compiled modelica structure
+ //##
+ //## inputs :
+ //## mo_model : a string that gives the name of the model
+ //## in the modelica list (equations) of a modelica block.
+ //##
+ //## Bnames : vector of strings of already attribuate models name
+ //##
+ //## output :
+ //## model_name : the output string of the model name
+ //##
+
+ ind = 1;
+ model_name = strsubst(mo_model," ","") + string(ind);
+
+ while find(model_name==Bnames) <> [] then
+ ind = ind + 1;
+ model_name=strsubst(mo_model," ","") + string(ind);
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/get_subobj_path.bin b/modules/scicos/macros/scicos_scicos/get_subobj_path.bin
new file mode 100755
index 000000000..1eed497ce
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get_subobj_path.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/get_subobj_path.sci b/modules/scicos/macros/scicos_scicos/get_subobj_path.sci
new file mode 100755
index 000000000..6c252422f
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get_subobj_path.sci
@@ -0,0 +1,36 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function full_path=get_subobj_path(path)
+ // path : vector of integer gives the path of the required block from
+ // top level (main diagram) to bottom level (required block).
+ // Each vector entry is a block index in the current level structure.
+ // full_path : is the path relative to scs_m of the required block
+ // scs_m.objs(full_path) is the data structure of the required block
+
+ full_path=list("objs",path(1));
+ for l=path(2:$),
+ full_path($+1)="model";
+ full_path($+1)="rpar";
+ full_path($+1)="objs";
+ full_path($+1)=l;
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/get_tree_elt.bin b/modules/scicos/macros/scicos_scicos/get_tree_elt.bin
new file mode 100755
index 000000000..51ad3a14f
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get_tree_elt.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/get_tree_elt.sci b/modules/scicos/macros/scicos_scicos/get_tree_elt.sci
new file mode 100755
index 000000000..6e08308db
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/get_tree_elt.sci
@@ -0,0 +1,34 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function value=get_tree_elt(tree,path)
+ // tree : a recursive list
+ // path : a vector of index giving top to bottom path
+ // value : new value for the pointed tree element
+
+ n=prod(size(path))
+
+
+ for k=1:n
+ tree=tree(path(k))
+ end
+ value=tree
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/getmodelicacpath.bin b/modules/scicos/macros/scicos_scicos/getmodelicacpath.bin
new file mode 100755
index 000000000..65016a20b
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/getmodelicacpath.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/getmodelicacpath.sci b/modules/scicos/macros/scicos_scicos/getmodelicacpath.sci
new file mode 100755
index 000000000..fbaed02f3
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/getmodelicacpath.sci
@@ -0,0 +1,67 @@
+//
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009 - DIGITEO - Vincent COUVERT
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+//
+//
+function compilerpath = getmodelicacpath()
+
+ MODELICAC_FILENAME = "modelicac";
+
+ compilerpath = "";
+
+ if getos() == "Windows" then
+ // --- WINDOWS ---
+ MODELICAC_FILENAME = MODELICAC_FILENAME + ".exe";
+ defaultPath = SCI + "/bin/";
+
+ if isfile(defaultPath + MODELICAC_FILENAME) then
+ compilerpath = defaultPath;
+ else
+ compilerpath = "";
+ end
+
+ else
+ // --- LINUX/MACOS ---
+
+ // Check if source tree version
+ if isdir(SCI+"/modules/core/includes/") then
+ defaultPath = SCI + "/modules/scicos/";
+
+ if isfile(defaultPath + MODELICAC_FILENAME) then
+ compilerpath = defaultPath;
+ else
+ compilerpath = "";
+ end
+ end
+
+ // Check if binary version
+ if compilerpath=="" & isdir(SCI+"/../../include/scilab/") then
+ defaultPath = SCI + "/../../bin/";
+
+ if isfile(defaultPath + MODELICAC_FILENAME) then
+ compilerpath = defaultPath;
+ else
+ compilerpath = "";
+ end
+ end
+
+ // Check if system version
+ if compilerpath=="" & isdir("/usr/include/scilab/") then
+ defaultPath = "/usr/bin/";
+
+ if isfile(defaultPath + MODELICAC_FILENAME) then
+ compilerpath = defaultPath;
+ else
+ compilerpath = "";
+ end
+ end
+
+ end
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/global_case.bin b/modules/scicos/macros/scicos_scicos/global_case.bin
new file mode 100755
index 000000000..ddc40eddf
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/global_case.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/global_case.sci b/modules/scicos/macros/scicos_scicos/global_case.sci
new file mode 100755
index 000000000..55214c2e3
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/global_case.sci
@@ -0,0 +1,48 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [links_table,sco_mat,ok]=global_case(links_table,sco_mat)
+ [s,k]=gsort(sco_mat(:,2))
+ sco_mat=sco_mat(k,:);
+ index=find((sco_mat(:,2)=="1")&(sco_mat(:,4)=="3"))
+ if index<> [] then
+ for i=1:size(index,"*")
+ indexx=find((sco_mat(index(:),3)==sco_mat(index(i),3))&(sco_mat(index(:),5)==sco_mat(index(i),5)))
+ if size(indexx,"*")>1 then
+ messagebox(["Error In Compilation";"You cannot have multiple global GOTO with the same tag"],"modal")
+ ok=%f
+ return
+ end
+ end
+ for i=index
+ index1=find((sco_mat(:,2)=="-1")&(sco_mat(:,3)==sco_mat(i,3))&(sco_mat(:,5)==sco_mat(i,5)))
+ if index1<>[] then
+ for j=index1
+ index2=find(links_table(:,1)==-evstr(sco_mat(j,1)))
+ if index2<>[] then
+ links_table(index2',1)=-evstr(sco_mat(i,1))
+ end
+ end
+ sco_mat(index1,:)=[]
+ end
+ end
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/haltscicos.bin b/modules/scicos/macros/scicos_scicos/haltscicos.bin
new file mode 100755
index 000000000..30aac9d44
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/haltscicos.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/haltscicos.sci b/modules/scicos/macros/scicos_scicos/haltscicos.sci
new file mode 100755
index 000000000..b4c082af7
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/haltscicos.sci
@@ -0,0 +1,27 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function haltscicos(menus, win_id)
+ //** This is just a *CLEVER* function used for the "halt" button that
+ //** stop the Scicos simulation
+ sleep(1); //** DO NOT REMOVE IT
+ sci_haltscicos();
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/hilite_path.bin b/modules/scicos/macros/scicos_scicos/hilite_path.bin
new file mode 100755
index 000000000..784538047
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/hilite_path.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/hilite_path.sci b/modules/scicos/macros/scicos_scicos/hilite_path.sci
new file mode 100755
index 000000000..ab1320f15
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/hilite_path.sci
@@ -0,0 +1,68 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function hilite_path(path,mess,with_intermediates)
+ //hilite a block included in a superblock hierarchy and displays a
+ //message. If required all the intermediate superblocs are displayed
+ //first entry of the path must be a bloc of currently opened diagram
+
+ if argn(2)<2 then mess=" ",end
+
+ // retrieve the root diagram
+ if isdef("scs_m_s") then
+ diagram = scs_m_s;
+ elseif isdef("scs_m") then
+ diagram = scs_m;
+ else
+ error("scs_m variable does not exist");
+ end
+
+ uid = []; // empty uid path
+
+ // construct the uid path from the index path
+ for i = 1:length(path)
+ index = path(i);
+ if typeof(diagram.objs(index)) == "Block" then
+ o = diagram.objs(index);
+
+ // masked superblock case
+ if isempty(o.doc) then
+ // we abort because blocks do not have uuid inside
+ // masked superblocks
+ break;
+ end
+
+ // normal case
+ uid($+1) = diagram.objs(index).doc(1) + "";
+
+ if diagram.objs(index).model.sim == "super" then
+ diagram = diagram.objs(index).model.rpar;
+ else
+ break;
+ end
+ end
+ end
+
+ if uid <> [] then
+ warnBlockByUID(uid, strcat(mess, " "));
+ end
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/init_agenda.bin b/modules/scicos/macros/scicos_scicos/init_agenda.bin
new file mode 100755
index 000000000..572faf795
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/init_agenda.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/init_agenda.sci b/modules/scicos/macros/scicos_scicos/init_agenda.sci
new file mode 100755
index 000000000..f1f8f44f0
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/init_agenda.sci
@@ -0,0 +1,53 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [tevts,evtspt,pointi]=init_agenda(initexe,clkptr)
+
+ // order initial firing events in chronological order.
+ nblk=size(clkptr,1)-1
+ timevec=initexe(:,3)
+ if timevec<>[] then
+ [timevec,indtime]=gsort(-timevec)
+ initexe=initexe(indtime,:)
+ else
+ initexe=[]
+ end
+ timevec=[]
+ //initialize agenda
+ ninit=size(initexe,1)
+ pointi=0
+ nevts=clkptr(nblk+1)-1 //time events agenda size
+ tevts=0*ones(nevts,1)
+ if initexe<>[] then
+ tevts(clkptr(initexe(:,1))+initexe(:,2)-1)=initexe(:,3)
+ end
+ evtspt=-ones(nevts,1)
+
+ if ninit>0 then
+ pointi=clkptr(initexe(1,1))+initexe(1,2)-1;
+ evtspt(pointi)=0
+ end
+ if ninit>1 then
+ evtspt(clkptr(initexe(1:ninit-1,1))+initexe(1:ninit-1,2)-1)=..
+ clkptr(initexe(2:ninit,1))+initexe(2:ninit,2)-1;
+ evtspt(clkptr(initexe(ninit,1))+initexe(ninit,2)-1)=0;
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/is_modelica_block.bin b/modules/scicos/macros/scicos_scicos/is_modelica_block.bin
new file mode 100755
index 000000000..33982d45c
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/is_modelica_block.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/is_modelica_block.sci b/modules/scicos/macros/scicos_scicos/is_modelica_block.sci
new file mode 100755
index 000000000..e221e49bd
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/is_modelica_block.sci
@@ -0,0 +1,29 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function r=is_modelica_block(o)
+ //checks if the block o is a modelica block
+ if or(getfield(1,o.model)=="equations") then
+ r=o.model.equations<>list()
+ else
+ r=%f
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/lib b/modules/scicos/macros/scicos_scicos/lib
new file mode 100755
index 000000000..2cad4137f
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/lib
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/link_olibs.bin b/modules/scicos/macros/scicos_scicos/link_olibs.bin
new file mode 100755
index 000000000..431b7e1f4
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/link_olibs.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/link_olibs.sci b/modules/scicos/macros/scicos_scicos/link_olibs.sci
new file mode 100755
index 000000000..e158a9874
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/link_olibs.sci
@@ -0,0 +1,104 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// - Alan Layec <alan.layec@inria.fr> - 2007
+// - Allan CORNET - 2008
+// - Rachid Djenidi
+// - Simone Mannori
+//
+// Copyright (C) DIGITEO - Allan CORNET - 2010
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+//**
+//------------------------------------------------------------------------
+//** link_olibs : links otherlibs in scilab
+// for scicos C generated block
+//
+// Input : libs : a matrix of string containing path + name
+// of the libraries
+//
+// rpat : a target directory for temporary generated files
+//
+// Output : ok : a boolean variable to say if job has succed
+// libs : a matrix of string containing path + name
+// of the libraries
+// for_link : a vector of strings with link cmd
+// for exec or for loader.sce
+//
+function [ok, libs, for_link] = link_olibs(libs,rpat)
+
+ //** get lhs,rhs nb paramaters
+ [lhs,rhs] = argn(0);
+
+ //** declare and set local variables
+ ok = %t;
+ xlibs = [];
+ for_link = [],
+
+ //** get out from this function if
+ // there is nothing to do
+ if ( (libs == "") | (libs == []) ) then return, end
+
+ for i = 1:size(libs, "*")
+ [_path, _name , _ext] = fileparts(libs(i));
+ dynlibname = _path + _name + getdynlibext();
+ if isfile(dynlibname) then
+ for_link = [for_link; dynlibname];
+ ierr = execstr("link(for_link($))","errcatch");
+ if ierr <> 0 then
+ messagebox(_("Cannot load dynamic library: ") + for_link($) ,"modal","error");
+ libs = [];
+ for_link = [];
+ ok = %f;
+ return
+ else
+ if getos() == "Windows" then
+ xlibs = [xlibs; _path + _name + ".lib"];
+ else
+ xlibs = [xlibs; libs(i)];
+ end
+ end
+ else
+ messagebox([_("Can''t include ") + dynlibname; _("This file does not exist"); lasterror()], "modal", "error");
+ libs = [];
+ for_link = [];
+ ok = %f;
+ return
+ end
+ end
+
+ //** add double quote for include in
+ // Makefile
+ libs = xlibs;
+ if getos() == "Windows" then
+ libs = """" + libs + """";
+ else
+ libs = "''" + libs + "''";
+ end
+
+ //** return link cmd for for_link
+ if (for_link <> []) then
+ for_link = "link(""" + for_link + """);";
+ end
+
+ //** concatenate libs for Makefile
+ if (size(libs,1) <> 1) then
+ libs = strcat(libs," ");
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/lnkptrcomp.bin b/modules/scicos/macros/scicos_scicos/lnkptrcomp.bin
new file mode 100755
index 000000000..cfb81871f
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/lnkptrcomp.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/lnkptrcomp.sci b/modules/scicos/macros/scicos_scicos/lnkptrcomp.sci
new file mode 100755
index 000000000..08fa682f3
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/lnkptrcomp.sci
@@ -0,0 +1,50 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// - Alan Layec <alan.layec@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [lnksz,lnktyp]=lnkptrcomp(bllst,inpptr,outptr,inplnk,outlnk)
+
+ lnkbsz=[];ptlnk=[];lnksz=[];lnktyp=[];
+ for blkout=1:length(bllst)
+ for portout=1:outptr(blkout+1)-outptr(blkout)
+ ptlnk=outlnk(outptr(blkout)+portout-1)
+ lnkbsz(outlnk(outptr(blkout)+portout-1))=bllst(blkout).out(portout);
+ lnksz(ptlnk,1)=bllst(blkout).out(portout);
+ lnksz(ptlnk,2)=bllst(blkout).out2(portout);
+ lnktyp(ptlnk)=bllst(blkout).outtyp(portout);
+ end
+ end
+
+ //27/09/07 Alan's patch : do test here for unconnected inputs
+ if inplnk<>[] | outlnk<>[] then
+ unco=find(inplnk>max(outlnk))
+ for j=unco
+ m=max(find(inpptr<=j))
+ n=j-inpptr(m)+1
+ lnksz($+1,1)=bllst(m).in(n);
+ lnksz($,2)=bllst(m).in2(n);
+ lnktyp($+1)=bllst(m).intyp(n);
+ end
+ end
+
+ //lnkptr=cumsum([1;lnkbsz])
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/loadpallibs.bin b/modules/scicos/macros/scicos_scicos/loadpallibs.bin
new file mode 100755
index 000000000..593acde3c
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/loadpallibs.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/loadpallibs.sci b/modules/scicos/macros/scicos_scicos/loadpallibs.sci
new file mode 100755
index 000000000..ce92620bf
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/loadpallibs.sci
@@ -0,0 +1,33 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function loadpallibs()
+ //to be called by exec(loadpallibs)
+ if ~(exists("scicos_pal_libs")) then
+ [modelica_libs, scicos_pal_libs, %scicos_with_grid, %scs_wgrid] = initial_scicos_tables();
+ end
+ for d = scicos_pal_libs
+ execstr(["if exists(''scs"+convstr(d)+"lib'')==0 then"
+ " load(''SCI/modules/scicos_blocks/macros/"+d+"/lib'');"
+ "end"]);
+ end
+ clear d
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/mark_prt.bin b/modules/scicos/macros/scicos_scicos/mark_prt.bin
new file mode 100755
index 000000000..d03da6347
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/mark_prt.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/mark_prt.sci b/modules/scicos/macros/scicos_scicos/mark_prt.sci
new file mode 100755
index 000000000..833244481
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/mark_prt.sci
@@ -0,0 +1,47 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function o=mark_prt(o,prt_number,inout,typ,v)
+ //mark a port of a block free or used
+ // o : block data structure
+ // prt_number : port number
+ // inout : port orientation ('in' or 'out')
+ // typ : port type
+ // 1 : standard port
+ // -1 : event port
+ // v : value to assign
+ // k>0 : port is connected to link #k
+ // 0 : port is free
+
+ if inout=="out" then //set an output port
+ if typ==1 | typ==2 then //standard (regular or implicit) port
+ o.graphics.pout(prt_number)=v;
+ else //clock port
+ o.graphics.peout(prt_number)=v;
+ end
+ else //set an input port
+ if typ==1 | typ==2 then //standard (regular or implicit) port
+ o.graphics.pin(prt_number)=v;
+ else //clock port
+ o.graphics.pein(prt_number)=v;
+ end
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/message.bin b/modules/scicos/macros/scicos_scicos/message.bin
new file mode 100755
index 000000000..0a956bf59
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/message.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/message.sci b/modules/scicos/macros/scicos_scicos/message.sci
new file mode 100755
index 000000000..65ee509f1
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/message.sci
@@ -0,0 +1,45 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function num=message(strings ,buttons, modal)
+ //interface to message primitive to allow simple overloading for live demo
+ [lhs,rhs]=argn(0)
+ if rhs==3 then
+ if modal == %t then
+ if buttons == "" then
+ num=messagebox(strings, "modal", "scilab");
+ else
+ num=messagebox(strings, "modal", "scilab", buttons);
+ end
+ else //non modal messagebox
+ if buttons == "" then
+ num=messagebox(strings,"scilab");
+ else
+ num=messagebox(strings, "scilab", buttons);
+ end
+ end
+ elseif rhs==2 then
+ num=messagebox(strings, "modal", "scilab", buttons);
+ else
+ num=1
+ messagebox(strings, "modal", "scilab");
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/mfrequ_clk.bin b/modules/scicos/macros/scicos_scicos/mfrequ_clk.bin
new file mode 100755
index 000000000..e08a6b0c0
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/mfrequ_clk.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/mfrequ_clk.sci b/modules/scicos/macros/scicos_scicos/mfrequ_clk.sci
new file mode 100755
index 000000000..ee372f990
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/mfrequ_clk.sci
@@ -0,0 +1,104 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+function [m,den,off,count,m1,fir,frequ,offset,ok]=mfrequ_clk(frequ,offset)
+ // copyright: INRIA
+ // Anthor: Fady NASSIF
+ // Date: 2007-2008
+ m=[];den=[];off=[];count=[];m1=[];fir=[];
+ v=[frequ;offset];
+ v=v(find(v<>0));
+ min_v=min(v);max_v=max(v);
+ if (max_v/min_v)>1e5 then message(["The difference between the frequencies is very large";..
+ "the clocks could not be synchronized"]);
+ ok=%f;
+ return;
+ end
+ // we call this function to get the least common denominator.
+ [pgcd,den]=fixedpointgcd(v);//find the pgcd and the common denominator of the vector v
+ [m1,k]=uni(frequ,offset); // m1 is a vector of different frequencies or same frequencies with different offsets
+ // k is the index.
+ frequ=frequ(k); // delete the dupplicated frequencies.
+ frd1=uint32(round((frequ.*double(den)))); // this will be used to construct the counter of the simulation.
+ ppcm=lcm(frd1); // find the least common multiple of the frequencies.
+ frd1=double(frd1);
+ offset=offset(k); // delete the dupplicated offset.
+ //constructing the first element of the opar of the m_frequ block.
+ // the first column contains the delay.
+ // the second element contains the event output number to activate.
+ // the third column contains the time.
+ if size(frequ,"*")>1 then // more than one frequency
+ mat=[];
+ for i=1:size(frequ,"*")
+ mat1=[offset(i)*den:frd1(i):double(ppcm)]';// for each frequency
+ mat=[mat;[mat1 2^(i-1)*ones(size(mat1,"*"),1)]]; // contains the frequency and the corresponding output.
+ end
+ [n,k]=gsort(mat(:,1),"g","i");
+ mat=mat(k,:); // sorting the mat matrix (increasingly).
+ // if two outputs are called at the same time they are replaced by an other output; the intersection of the two.
+ if size(mat,1)>10000 then
+ num=messagebox(["Warning: Your system is too hard to synchronize it will take some time";
+ "And the stacksize has to be increase";
+ " A scilab crash may occur";
+ "Do You want me to continue?"],"modal",["No","Yes"])
+ if num==1 then
+ ok=%f;
+ return
+ end
+ end
+ vv=mat(2:$,1)-mat(1:$-1,1);
+ vv=[1;vv;1];
+ kkk=find(vv(:)==0);
+ kk=find(vv);
+ for i=1:size(kk,2)-1
+ mat(kk(i),2)=sum(mat(kk(i):kk(i+1)-1,2));
+ end
+ mat(kkk(:),:)=[];
+
+ //constructing the first element of opar
+ m=[mat(1,1);mat(2:$,1)-mat(1:$-1,1)]; //contains the first element of the chain and the delay.
+ last_delay=double(ppcm)-mat($,1)+mat(1,1) // finding the last delay.
+ // In other world finding the delay between the last element
+ // and the first element of mat. So we can have a cycle.
+ if last_delay<>0 then // all the offset are different from 0.
+ m($+1)=last_delay // we add the last delay to m.
+ m=[m,[mat(:,2);mat(1,2)],[mat(:,1);double(ppcm)+mat(1,1)]] // the event output for the last element
+ // will be equal to the first one.
+ // the time will be the lcm+the delay of the first element
+ else // there is at least one offset that is equal to 0.
+ m=[m,mat(:,2),mat(:,1)]; // we don't have to add the last delay because in this case it will be equal to 0.
+ end
+ count=int32(m(1,1)); // we put the first element of the matrix in a variable that will initialise the counter.
+ m(1,:)=[]; // we delete the first row of the matrix. the delay is conserv in the variable count.
+ mn=(2**size(m1,"*"))-1; // find the number of event output.
+ fir=-ones(1,mn); // put all the element of the firing to -1
+ fir(mat(1,2))=mat(1,1)/double(den);// programming the corresponding event output
+ // by the first element of the matrix mat.(first delay).
+ off=0; // the offset in this case will be equal to 0 because it is implemented in the calculation
+ // of the delay.
+ else
+ // case of one frequency
+ m=[frd1 1 frd1]; // put the delay in the matrix. the delay will be equal to the one frequency.
+ count=int32(0); // the counter will begin by 0.
+ mat=m;
+ off=offset; // the offset is put in the variable off. used by the simulator.
+ fir=off; // program the event output of the block by the corresponding offset.
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/modelica.bin b/modules/scicos/macros/scicos_scicos/modelica.bin
new file mode 100755
index 000000000..4242d7b87
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/modelica.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/modelica.sci b/modules/scicos/macros/scicos_scicos/modelica.sci
new file mode 100755
index 000000000..ac21e626e
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/modelica.sci
@@ -0,0 +1,31 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function mo=modelica(v1,v2,v3,v4)
+
+ if exists("model","local")==0 then model=[], end
+ if exists("inputs","local")==0 then inputs=[], end
+ if exists("outputs","local")==0 then outputs=[], end
+ if exists("parameters","local")==0 then parameters=list([],list()), end
+
+ mo=tlist(["modelica","model","inputs","outputs","parameters"],...
+ model,inputs,outputs,parameters)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/modelicac.bin b/modules/scicos/macros/scicos_scicos/modelicac.bin
new file mode 100755
index 000000000..355e3ed21
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/modelicac.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/modelicac.sci b/modules/scicos/macros/scicos_scicos/modelicac.sci
new file mode 100755
index 000000000..67fd4ced5
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/modelicac.sci
@@ -0,0 +1,79 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function ok = modelicac(Flat, Flat_functions, xmlfileTMP, Jacobian, Cfile, with_gui, init)
+ //Scilab interface with external tool modelicac
+
+ MODELICAC_FILENAME = "modelicac";
+ if getos() == "Windows" then
+ MODELICAC_FILENAME = MODELICAC_FILENAME + ".exe";
+ end
+
+ if argn(2) < 7 then init = %f,end
+ incidence = "";
+ tmpdir = pathconvert(TMPDIR, %t, %t); //for error log and shell scripts
+ xmlfileTMP = pathconvert(xmlfileTMP, %f, %t);
+ Cfile = pathconvert(Cfile, %f, %t);
+
+ if fileinfo(Flat_functions) == [] then
+ Flat_functions = " ";
+ else
+ Flat_functions = """" + Flat_functions + """";
+ end
+
+ if ( (with_gui) & (fileinfo(xmlfileTMP) <> []) ) then // if GUI is running
+ XMLfiles = " -with-init-in """ + strsubst(xmlfileTMP, "\", "/") + """ -with-init-out """ + strsubst(xmlfileTMP,"\","/") + """";
+ else
+ XMLfiles = "";
+ end
+
+ exe = """" + pathconvert(getmodelicacpath() + MODELICAC_FILENAME, %f, %t) + """";
+
+ Flat = """" + Flat + """";
+ out = "-o """ + Cfile + """";
+
+ if Jacobian then
+ JAC = " -jac ";
+ else
+ JAC="";
+ end
+
+ instr = strcat([exe, Flat, Flat_functions, XMLfiles, out, JAC], " ");
+
+ if getos() == "Windows" then
+ if init then
+ mputl(instr,tmpdir+"igenm.bat");
+ instr = tmpdir + "igenm.bat";
+ else
+ mputl(instr, tmpdir + "genm2.bat");
+ instr = tmpdir + "genm2.bat";
+ end
+ end
+
+ [rep,stat,err]=unix_g(instr);
+ if stat <> 0 then
+ messagebox(err, _("Modelica compiler"), "error", "modal");
+ ok=%f;
+ return
+ end
+
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/modipar.bin b/modules/scicos/macros/scicos_scicos/modipar.bin
new file mode 100755
index 000000000..ed504b1e9
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/modipar.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/modipar.sci b/modules/scicos/macros/scicos_scicos/modipar.sci
new file mode 100755
index 000000000..bbdf7d65a
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/modipar.sci
@@ -0,0 +1,304 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [%state0,state,sim,ok]=modipar(newparameters,%state0,state,sim,scs_m,cor)
+ //store modified parameters in compiled structure state,sim
+ //newparameters gives modified blocks numbers in original structure scs_m
+ //cor is the correspondance table from original structure to compiled one
+ xptr=sim.xptr
+ zptr=sim.zptr
+ ozptr=sim.ozptr
+ rpptr=sim.rpptr
+ ipptr=sim.ipptr
+ opptr=sim.opptr
+ ipar=sim.ipar
+ rpar=sim.rpar
+ opar=sim.opar
+ ztyp=sim.ztyp
+ labels=sim.labels
+ st=state.x
+ dst=state.z
+ odst=state.oz
+ st0=%state0.x
+ dst0=%state0.z
+ odst0=%state0.oz
+
+ Impl=%f
+ if xptr($)-1 < size(st,"*") then
+ std=st($/2+1:$)
+ st=st(1:$/2)
+ std0=st0($/2+1:$)
+ st0=st0(1:$/2)
+ Impl=%t
+ end
+
+ nb=prod(size(rpptr))-1
+ for k=newparameters
+ if prod(size(k))==1 then //parameter of a simple block
+ kc=cor(k) //index of modified block in compiled structure
+ o=scs_m.objs(k)
+ else
+ kc=get_tree_elt(cor,k);
+ o=scs_m(get_subobj_path(k))
+ end
+ if is_modelica_block(o) then
+ parameters=o.model.equations.parameters
+ rpark=[];for p=parameters(2),rpark=[rpark;p(:)];end
+ ipark=ipar(ipptr(kc):ipptr(kc+1)-1)
+ corinvm=%cpr.corinv(kc);
+ J=[];
+ if findinlistcmd(%cpr.corinv,size(cor),">")<>list() then ok=%f;return; end
+ //if %cpr.corinv(kc-1)>size(cor) then ok=%f;return;end
+ for jj=1:size(corinvm)
+ if and(corinvm(jj)==k) then J=jj;break,end
+ end
+ nek=size(rpark,"*")-(ipark(J+1)-ipark(J))
+ if nek<>0 then
+ warning("variying number of parameter for modelica block is not yet implemented")
+ end
+ rpar(rpptr(kc)+ipark(J)-1:rpptr(kc)+ipark(J+1)-2)=rpark
+ else
+ statekd=[]
+ om=o.model
+ [fun,statek,dstatek,odstatek,rpark,ipark,opark]=...
+ (om.sim,om.state,om.dstate,om.odstate,om.rpar,om.ipar,om.opar);
+ if type(fun)==15 then
+ if (fun(2)==3 | fun(2)==5 | fun(2)==10005) then
+ if rpark<>[] then rpark=var2vec(rpark); end
+ if dstatek<>[] then dstatek=var2vec(dstatek),end
+ end
+ if fun(2)>10000 then
+ statekd=statek($/2+1:$)
+ statek=statek(1:$/2)
+ end
+ end
+
+ if kc>0 then
+ //Change continuous state
+ nek=prod(size(statek))-(xptr(kc+1)-xptr(kc))
+ sel=xptr(kc+1):xptr($)-1
+ if nek<>0&sel<>[] then
+ st(nek+sel)=st(sel)
+ st0(nek+sel)=st0(sel)
+ if Impl then
+ std(nek+sel)=std(sel)
+ std0(nek+sel)=std0(sel)
+ end
+ end
+
+ if nek<0 then
+ st($+nek+1:$)=[],st0($+nek+1:$)=[],
+ if Impl then std($+nek+1:$)=[],std0($+nek+1:$)=[],end
+ end
+
+ xptr(kc+1:$)=xptr(kc+1:$)+nek
+ st(xptr(kc):xptr(kc+1)-1)=statek(:),
+ st0(xptr(kc):xptr(kc+1)-1)=statek(:),
+ if Impl then
+ if statekd==[] then statekd=0*statek,end
+ std(xptr(kc):xptr(kc+1)-1)=statekd(:),
+ std0(xptr(kc):xptr(kc+1)-1)=statekd(:),
+ end
+
+ //Change discrete state
+ nek=prod(size(dstatek))-(zptr(kc+1)-zptr(kc))
+ sel=zptr(kc+1):zptr($)-1
+ if nek<>0&sel<>[] then
+ dst(nek+sel)=dst(sel)
+ dst0(nek+sel)=dst0(sel)
+ end
+
+ if nek<0 then
+ dst($+nek+1:$)=[],dst0($+nek+1:$)=[],
+ end
+
+ zptr(kc+1:$)=zptr(kc+1:$)+nek
+ dst(zptr(kc):zptr(kc+1)-1)=dstatek(:)
+ dst0(zptr(kc):zptr(kc+1)-1)=dstatek(:)
+
+ //Change objects discrete state
+ if ((type(odstatek)<>15) | ...
+ (type(fun)<>15)) then //old sci blocks or odstatek not a list
+ nek=-(ozptr(kc+1)-ozptr(kc))
+ elseif ((fun(2)==5) | (fun(2)==10005)) then // sciblocks type 5 | 10005
+ if lstsize(odstatek)>0 then
+ nek=1-(ozptr(kc+1)-ozptr(kc)) //nombre d'états supplémentaires
+ else
+ nek=-(ozptr(kc+1)-ozptr(kc))
+ end
+ elseif ((fun(2)==4) | (fun(2)==10004) | (fun(2)==2004)) then // C blocks type 4 | 10004
+ nek=lstsize(odstatek)-(ozptr(kc+1)-ozptr(kc))
+ else // other C and sci blocks
+ nek=-(ozptr(kc+1)-ozptr(kc))
+ end
+ sel=ozptr(kc+1):ozptr($)-1
+
+ if nek<>0&sel<>[] then
+ while lstsize(odst)<max(nek+sel), odst($+1)=[], end
+ while lstsize(odst0)<max(nek+sel), odst0($+1)=[], end
+ if nek>0 then sel=gsort(sel), end
+ for j=sel
+ odst(j+nek)=odst(j)
+ odst0(j+nek)=odst0(j)
+ end
+ end
+ ozptr(kc+1:$)=ozptr(kc+1:$)+nek;
+
+ if ((type(odstatek)==15) & (type(fun)==15)) then
+ if ((fun(2)==5) | (fun(2)==10005)) then // sciblocks
+ if lstsize(odstatek)>0 then
+ odst(ozptr(kc))=odstatek;
+ odst0(ozptr(kc))=odstatek;
+ end
+ elseif ((fun(2)==4) | (fun(2)==10004) | (fun(2)==2004)) then // C blocks
+ for j=1:lstsize(odstatek)
+ odst(ozptr(kc)+j-1)=odstatek(j);
+ odst0(ozptr(kc)+j-1)=odstatek(j);
+ end
+ end
+ end
+
+ //## rebuild odst list if nek < 0
+ if nek < 0 then
+ n_odst = list(); n_odst0 = list();
+ for j=1:max(ozptr)-1
+ n_odst(j)=odst(j);
+ n_odst0(j)=odst0(j);
+ end
+ odst = n_odst; odst0 = n_odst0;
+ clear n_odst; clear n_odst0;
+ end
+
+ //Change real parameters
+ nek=prod(size(rpark))-(rpptr(kc+1)-rpptr(kc))
+ sel=rpptr(kc+1):rpptr($)-1
+ if nek<>0&sel<>[] then
+ rpar(nek+sel)=rpar(sel)
+ end
+
+ if nek<0 then
+ rpar($+nek+1:$)=[]
+ end
+
+ rpptr(kc+1:$)=rpptr(kc+1:$)+nek
+ rpar(rpptr(kc):rpptr(kc+1)-1)=rpark(:),
+
+ //Change integer parameters
+ if type(ipark)==1 then //scifunc
+ nek=prod(size(ipark))-(ipptr(kc+1)-ipptr(kc))
+ sel=ipptr(kc+1):ipptr($)-1
+ if nek<>0&sel<>[] then
+ ipar(nek+sel)=ipar(sel)
+ end
+
+ if nek<0 then
+ ipar($+nek+1:$)=[]
+ end
+
+ ipptr(kc+1:$)=ipptr(kc+1:$)+nek
+ ipar(ipptr(kc):ipptr(kc+1)-1)=ipark(:),
+ end
+ //Change objects parameters
+ if ((type(opark)<>15) | ...
+ (type(fun)<>15)) then //old sci blocks or odstatek not a list
+ nek=-(opptr(kc+1)-opptr(kc))
+ elseif ((fun(2)==5) | (fun(2)==10005)) then // sciblocks
+ if lstsize(opark)>0 then
+ nek=1-(opptr(kc+1)-opptr(kc)) //nombre de param�tres suppl�mentaires
+ else
+ nek=-(opptr(kc+1)-opptr(kc))
+ end
+ elseif ((fun(2)==4) | (fun(2)==10004) | (fun(2)==2004)) then //C blocks
+ nek=lstsize(opark)-(opptr(kc+1)-opptr(kc))
+ else // other C and sci blocks
+ nek=-(opptr(kc+1)-opptr(kc))
+ end
+ sel=opptr(kc+1):opptr($)-1
+ if nek<>0&sel<>[] then
+ while lstsize(opar)<max(nek+sel), opar($+1)=[], end
+ if nek>0 then sel=gsort(sel), end
+ for j=sel, opar(j+nek)=opar(j); end
+ end
+ opptr(kc+1:$)=opptr(kc+1:$)+nek;
+ if ((type(opark)==15) & (type(fun)==15)) then
+ if ((fun(2)==5) | (fun(2)==10005)) then // sciblocks
+ if lstsize(opark)>0 then
+ opar(opptr(kc))=opark;
+ end
+ elseif ((fun(2)==4) | (fun(2)==10004) | (fun(2)==2004)) then //C blocks
+ for j=1:lstsize(opark), opar(opptr(kc)+j-1)=opark(j), end
+ end
+ end
+ //## rebuild opar list if nek < 0
+ if nek < 0 then
+ n_opar = list();
+ for j=1:max(opptr)-1
+ n_opar(j)=opar(j);
+ end
+ opar = n_opar;
+ clear n_opar;
+ end
+
+
+ //Change simulation routine
+ if type(sim("funs")(kc))<>13 then //scifunc
+ sim("funs")(kc)=fun(1);
+ if prod(size(fun))> 1 then
+ sim("funtyp")(kc)=fun(2);
+ else
+ sim("funtyp")(kc)==0;
+ end
+ end
+
+ //Change label
+ labels(kc)=o.model.label
+ end
+ end
+ end
+
+ sim.xptr=xptr
+ sim.zptr=zptr
+ sim.ozptr=ozptr
+ sim.rpar=rpar
+ sim.rpptr=rpptr
+ sim.ipar=ipar
+ sim.ipptr=ipptr
+ sim.opar=opar
+ sim.opptr=opptr
+ sim.labels=labels
+
+ if Impl then
+ state.x=[st;std]
+ else
+ state.x=st
+ end
+
+ state.z=dst
+ state.oz=odst
+ if Impl then
+ %state0.x=[st0;std0]
+ else
+ %state0.x=st0
+ end
+ %state0.z=dst0
+ %state0.oz=odst0
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/names b/modules/scicos/macros/scicos_scicos/names
new file mode 100755
index 000000000..93868a63f
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/names
@@ -0,0 +1,126 @@
+%Block_e
+%Block_p
+%b_i_graphics
+%b_i_model
+%c_i_block
+%c_i_graphics
+%c_i_model
+%debug_scicos
+%diagram_p
+%graphics_e
+%graphics_i_Block
+%graphics_p
+%l_i_block
+%l_i_graphics
+%l_i_model
+%model_e
+%model_i_Block
+%model_p
+%params_p
+%s_i_block
+%s_i_graphics
+%s_i_model
+CC4
+CFORTR
+CFORTR2
+Compute_cic
+FORTR
+Link_modelica_C
+MODCOM
+adjust
+adjust_in2out2
+bad_connection
+build_block
+build_modelica_block
+buildnewblock
+c_pass1
+c_pass2
+c_pass3
+check_io
+check_mac
+compile_init_modelica
+compile_modelica
+context_evstr
+cos2cosf
+countblocks
+create_modelica
+default_color
+default_options
+delete_unconnected
+dialog
+dig_bound_compound
+do_compile
+do_compile_superblock42
+do_delete1
+do_eval
+do_purge
+do_terminate
+do_update
+do_version
+extract_implicit
+findinlist
+findinlistcmd
+gen_modelica
+genfunc
+genfunc1
+genfunc2
+genmac
+get2index
+get_connected
+get_dynamic_lib_dir
+get_errorcmd
+get_model_name
+get_subobj_path
+get_tree_elt
+getmodelicacpath
+global_case
+haltscicos
+hilite_path
+init_agenda
+is_modelica_block
+link_olibs
+lnkptrcomp
+loadpallibs
+mark_prt
+message
+mfrequ_clk
+modelica
+modelicac
+modipar
+reading_incidence
+recur_scicos_block_link
+sample_clk
+scicos_block
+scicos_block_link
+scicos_cpr
+scicos_diagram
+scicos_flat
+scicos_graphics
+scicos_include_paths
+scicos_link
+scicos_model
+scicos_params
+scicos_sim
+scicos_state
+scicos_txtedit
+script2var
+scs_full_path
+scs_show
+scstxtedit
+set_io
+setvalue
+shiftcors
+split_lasterror
+standard_define
+standard_draw
+standard_draw_ports
+standard_draw_ports_up
+standard_inputs
+standard_origin
+standard_outputs
+translator
+update_scs_m
+update_version
+validvar
+value2modelica
+xml2modelica
diff --git a/modules/scicos/macros/scicos_scicos/reading_incidence.bin b/modules/scicos/macros/scicos_scicos/reading_incidence.bin
new file mode 100755
index 000000000..33bc93d39
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/reading_incidence.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/reading_incidence.sci b/modules/scicos/macros/scicos_scicos/reading_incidence.sci
new file mode 100755
index 000000000..c989429f1
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/reading_incidence.sci
@@ -0,0 +1,128 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+function [nipar,nrpar,nopar,nz,nx,nx_der,nx_ns,nin,nout,nm,ng,dep_u]=reading_incidence(incidence)
+ // this function creates the matrix dep_u given by the xml format.
+ // It is used for modelica compiler.
+ // number of lines represents the number of input, number of columns represents the number of outputs.
+ // Fady 02/09/08
+ xmlformat=mgetl(incidence);
+ typ=[];input_name=[];order=[];depend=[];
+ global txtline;txtline=0;
+ corresp_table=["<number_of_integer_parameters","nipar";
+ "<number_of_real_parameters","nrpar";
+ "<number_of_string_parameters","nopar";
+ "<number_of_discrete_variables","nz";
+ "<number_of_continuous_states","nx_der";
+ "<number_of_continuous_variables","nx_ns";
+ "<number_of_continuous_unknowns","nx";
+ "<number_of_inputs","nin";
+ "<number_of_outputs","nout";
+ "<number_of_modes","nm";
+ "<number_of_zero_crossings","ng"]
+ while and(typ<>"</model") do
+ typ=get_typ(xmlformat);
+ if typ(1)=="<model_info" then
+ typ=get_typ(xmlformat);
+ while typ(1)<>"</model_info" do
+ val=corresp_table(find(corresp_table==typ(1)),2)
+ ttyp=tokens(typ(2),"<");
+ execstr(val+"="+ttyp(1)+";");
+ typ=get_typ(xmlformat);
+ end
+ elseif typ(1)=="<identifiers" then
+ while typ(1)<>"</identifiers"
+ typ=get_typ(xmlformat);
+ if typ(1)=="<input" then
+ ttyp=tokens(typ(2),"<");
+ input_name=[input_name;ttyp(1)];
+ end
+ end
+ elseif typ(1)=="<outputs" then
+ while typ(1)<>"</outputs" do
+ typ=get_typ(xmlformat);
+ if typ(1)=="<output" then
+ while typ(1)<>"</output" do
+ typ=get_typ(xmlformat);
+ if typ(1)=="<order" then
+ ttyp=tokens(typ(2),"<");
+ ord=evstr(ttyp(1));
+ elseif typ(1)=="<dependencies"
+ dep_flag=%f;
+ while typ(1)<>"</dependencies" then
+ typ=get_typ(xmlformat);
+ if typ(1)=="<input" then
+ dep_flag=%t;
+ ttyp=tokens(typ(2),"<");
+ depend=[depend;ttyp(1)];
+ order=[order;ord];
+ end
+ end
+ if ~dep_flag then
+ order=[order;ord]
+ depend=[depend;"NAN"];
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+ clearglobal txtline;
+ // if depend<>[] then
+ // dep_u=(ones(size(input_name,'*'),size(unique(depend),'*'))==zeros(size(input_name,'*'),size(unique(depend),'*')))
+ // else
+ // dep_u=%f
+ // end
+ // ind=find(depend=='NAN')
+ // depend(ind(:))=[];
+ // order(ind(:))=[];
+ // for i=1:size(depend,'*')
+ // in_num=find(input_name==depend(i));
+ // dep_u(in_num,order(i)+1)=%t;
+ // end
+
+ nu=size(input_name,"*");
+ dep_u=ones(1,nu)==zeros(1,nu);
+ for i=1:nu
+ if find(depend==input_name(i))==[] then
+ dep_u(1,i)=%f;
+ else
+ dep_u(1,i)=%t;
+ end
+ end
+ // remind taht inputs are numbered according to their position in the
+ // diagram and not in the Modelica block.InPutPortx.viis the x-th
+ // input in the whole diagram!
+
+endfunction
+
+
+function t=read_new_line(txt)
+ global txtline
+ txtline=txtline+1;
+ t=txt(txtline)
+endfunction
+
+function typ=get_typ(txt)
+ t=read_new_line(txt);
+ typ=tokens(t);
+ typ=tokens(typ(1),">");
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/recur_scicos_block_link.bin b/modules/scicos/macros/scicos_scicos/recur_scicos_block_link.bin
new file mode 100755
index 000000000..f7c2dfdfe
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/recur_scicos_block_link.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/recur_scicos_block_link.sci b/modules/scicos/macros/scicos_scicos/recur_scicos_block_link.sci
new file mode 100755
index 000000000..032d01a17
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/recur_scicos_block_link.sci
@@ -0,0 +1,79 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+function [model,ok]=recur_scicos_block_link(o,flag)
+ // Copyright INRIA
+ model=o.model;ok=%t;
+ if or(o.model.sim(1)==["super","csuper","asuper"]) then
+ obj=o.model.rpar;
+ for i=1:size(obj.objs)
+ o1=obj.objs(i);
+ if typeof(o1)=="Block"
+
+ if (or(o1.model.sim(1)==["super","csuper","asuper"])) then
+ [model,ok]=recur_scicos_block_link(o1,flag)
+ if ~ok then return; end
+ elseif type(o1.model.sim)==15
+ if or(int(o1.model.sim(2)/1000)==[1,2]) then
+ model=o1.model
+ funam=o1.model.sim(1)
+ if ~c_link(funam) then
+ tt=o1.graphics.exprs(2)
+ mputl(tt,TMPDIR+"/"+funam+".c")
+ ok=buildnewblock(funam,funam,"","","",TMPDIR,"","")
+ if ~ok then return; end
+ end
+ end
+ end
+ end
+ end
+ if o.model.sim(1)=="asuper" then
+ model=o.graphics.exprs(3)
+ funam=model.sim(1)
+ if ~c_link(funam) then
+ if size(o.graphics.exprs)==4 then
+ if type(o.graphics.exprs(4))==15 then
+ intern_funam=o.graphics.exprs(4)(2);
+ if ~c_link(intern_funam) then
+ tt=o.graphics.exprs(4)(1);
+ mputl(tt,TMPDIR+"/"+intern_funam+"."+flag)
+ ok=buildnewblock(intern_funam,intern_funam,"","","",TMPDIR,"","")
+ if ~ok then return; end
+ end
+ end
+ end
+ tt=o.graphics.exprs(2)
+ mputl(tt,TMPDIR+"/"+funam+".c")
+ ok=buildnewblock(funam,funam,"","","",TMPDIR,"","")
+ if ~ok then return; end
+ end
+ end
+ elseif or(int(o.model.sim(2)/1000)==[1,2]) then
+ model=o.model
+ funam=o.model.sim(1)
+ if ~c_link(funam) then
+ tt=o.graphics.exprs(2)
+ mputl(tt,TMPDIR+"/"+funam+".c")
+ ok=buildnewblock(funam,funam,"","","",TMPDIR,"","")
+ if ~ok then return; end
+ end
+ end
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/sample_clk.bin b/modules/scicos/macros/scicos_scicos/sample_clk.bin
new file mode 100755
index 000000000..45144859d
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/sample_clk.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/sample_clk.sci b/modules/scicos/macros/scicos_scicos/sample_clk.sci
new file mode 100755
index 000000000..0a7ad3c37
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/sample_clk.sci
@@ -0,0 +1,295 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [Ts,bllst,corinv,indout,ok,scs_m,flgcdgen,freof]=sample_clk(MAT,Ts,bllst,corinv,scs_m,indout,flgcdgen)
+
+ // This function takes care of the synchronize clocks.
+ // Two ways are used for that calculation.
+ // the first one uses a fast clock connected to a counter which is connected to an event select.
+ // This method used the two functions clock_major and update_diag. It is used for the moment in the code generation
+ // and it may be used in the future in the atomics blocks.
+ // The second method generates an event at a specific time using the multifrequency block.
+ // It uses the s_clk2 function. it is used in the compilation of all the diagram.
+ // The compilation using the second method is faster than using the first one but the first method generates periodic events.
+ // Fady NASSIF 2008. Copyright INRIA.
+
+ //input: -MAT: a M*5 matrix. This matrix is the sco_mat given by the scicos_flat function.
+ // When the fifth column is equal to '4' then the corresponding block is the SampleCLK block.
+ // -Ts: the links_table given by th scicos_flat function.
+ // -bllst: block list.same definition as in c_pass1.
+ // -corinv: same definition as in c_pass1.
+ // -scs_m: diagram
+ // -indout: index used in c_pass1 to separate modelica blocks from regular blocks.
+ // -flgcdgen: -1 when the function is not called by the code generation
+ // it takes the number of event input of the superblock when it is called under the code generation.
+ //
+ // This part can be used in the next version to choose between the two methods.
+ // ------------
+ // [num]=x_choose(['event select';'multiple frequency'],..
+ // ["You have to choose a method for the sample time computation:";..
+ // "The first method is a periodic synchronize system";..
+ // "it uses the event select block to generate events"; "at every clock time (regular period)";..
+ // "The number of outputs is equal to the least common"; "multiple of the input frequencies ";..
+ // "The second method uses the multi-frequency block";..
+ // "it generates an event only on the used time";..
+ // "The default value is select method"])
+ //num=scs_m.props.tol(8)
+ //the test will be done on num and not on the flgcdgen
+ //---------------------------------------------------------------------
+
+ if flgcdgen==-1 then
+ [Ts,bllst,corinv,indout,ok]=s_clk2(MAT,Ts,bllst,corinv,scs_m,indout)
+ else
+ [frequ,offset,freqdiv,den,flg,ok]=clock_major(MAT)
+ if ok then
+ [Ts,corinv,bllst,indout,ok,scs_m,flgcdgen,freof]=update_diag(scs_m,corinv,Ts,frequ,offset,freqdiv,bllst,den,flg,indout,flgcdgen)
+ end
+ end
+endfunction
+
+function [frequ,offset,freqdiv,den,flg,ok]=clock_major(MAT)
+
+ // this function calculates the frequency and the offset of the fastest clock
+ //modification to support double
+ // output parameters: -frequ: the frequency of the major clock.
+ // -offset: the offset of the major clock.
+ // -freqdiv: A vector containing the frequencies of all the SampleClk multiplied by the common denominator.
+ // -den: The common denominator.
+ // -flg: 0 if there is one frequency and one offset
+ // 1 else case.
+ // -ok: flag for error.
+
+ ok=%t;
+ flg=1;
+ index=find(MAT(:,5)==string(4));
+ if index<>[] then
+ freq1=evstr(MAT(index,3));
+ offset1=evstr(MAT(index,4));
+ end
+ freqdiv=unique(freq1);
+ if size(unique(offset1),"*")==1 then // case of one offset
+ if size(freqdiv,"*")==1 then flg=0;end // case of one offset and one frequency.
+ v=freq1;
+ v=v(find(v<>0));
+ min_v=min(v);max_v=max(v);
+ if (max_v/min_v)>1e5 then messagebox(["The difference between the frequencies is very large";..
+ "the clocks could not be synchronized"],"modal");
+ ok=%f;Ts=[];bllst=[];corinv=list();indout=[];
+ return;
+ end
+ [frequ,den]=fixedpointgcd(v); //computing the pgcd of the frequencies
+ offset=offset1(1);
+ else // case of multiple offset
+ v=[freq1;offset1]
+ v=v(find(v<>0));
+ min_v=min(v);max_v=max(v);
+ if (max_v/min_v)>1e5 then messagebox(["The difference between the frequencies is very large";..
+ "the clocks could not be synchronized"],"modal");
+ ok=%f;Ts=[];bllst=[];corinv=list();indout=[];
+ return;
+ end
+ [frequ,den]=fixedpointgcd(v);//computes the pgcd of the frequencies and the offsets.
+ offset=0;
+ end
+ freqdiv=uint32(freqdiv*double(den));
+ frequ=double(frequ)/double(den);
+ if frequ==[] then frequ=0;end
+ if offset==[] then offset=0; end
+ if (offset > frequ) then
+ offset=modulo(offset,frequ)
+ if (offset~=0) then ok=%f; end
+ end
+endfunction
+
+function [Ts,corinv,bllst,indout,ok,scs_m,flgcdgen,freof]=update_diag(scs_m,corinv,Ts,frequ,offset,freqdiv,bllst,den,flg,indout,flgcdgen)
+ //modification to support double
+ ok=%t
+ n=lstsize(scs_m.objs)
+
+ // when the function is called by the code generator we add an input event to the diagram
+ // the major clock will be put outside the superblock. it will be explicitly drawn.
+ // In the other case the major clock will be implicitly used in the diagram.
+
+ if flgcdgen<>-1 then // when the function is called by the codegeneration.
+ flgcdgen=flgcdgen+1 // the flgcdgen contains the number of event input.
+ // we incremented to be able to add the sampleclk to the diagram at the end
+ // Adding the event input block.
+ bllst($+1)=scicos_model(sim=list("bidon",0),in=[],in2=[],intyp=1,out=[],out2=[],..
+ outtyp=1,evtin=[],evtout=1,state=[],dstate=[],odstate=list(),..
+ rpar=[],ipar=flgcdgen,opar=list(),blocktype="d",firing=-1,..
+ dep_ut=[%f,%f],label="",nzcross=0,nmode=0,equations=list());
+ freof=[frequ;offset];
+ // Drawing the block in the scs_m
+ blk=CLKINV_f("define");
+ blk.gui="EVTGEN_f";
+ blk.model.ipar=flgcdgen;
+ blk.model.sim(1)="bidon";
+ blk.graphics.exprs=sci2exp(flgcdgen);
+ blk.graphics.sz=[20 30];
+ blk.graphics.peout=20
+ scs_m.objs($+1)=blk
+ else
+ bllst($+1)=scicos_model(sim=list("evtdly4",4),in=[],in2=[],intyp=1,out=[],out2=[],..
+ outtyp=1,evtin=1,evtout=1,state=[],dstate=[],odstate=list(),..
+ rpar=[frequ;offset],ipar=[],opar=list(),blocktype="d",firing=offset,..
+ dep_ut=[%f,%f],label="",nzcross=0,nmode=0,equations=list());
+ scs_m.objs(n+1)=EVTDLY_c("define");
+ scs_m.objs(n+1).model.rpar=[frequ;offset];
+ scs_m.objs(n+1).model.firing=offset;
+ freof=[frequ;offset];
+ end
+ corinv($+1)=n+1
+ nb=size(corinv)
+ nc=size(bllst);
+ // nb and nc defers in the diagrams that contains modelicas blocks.
+ indout($+1)=nc;
+ if flgcdgen==-1 then
+ // linking the output of the evtdly to its input.
+ Ts($+1:$+2,:)=[nb 1 -1 -1;..
+ nb 1 1 -1]
+ end
+ if flg then //more then one frequency or offset
+
+ nn=lcm(freqdiv);
+ nn=double(nn)/(frequ*(double(den)));// the number of output of the event select block
+ //Adding the counter to the block list.
+ bllst($+1)=scicos_model(sim=list("counter",4),in=[],in2=[],intyp=1,out=1,out2=1,..
+ outtyp=1,evtin=1,evtout=[],state=[],dstate=0,odstate=list(),..
+ rpar=[],ipar=[1;double(nn);1],opar=list(),blocktype="c",firing=[],..
+ dep_ut=[%f,%f],label="",nzcross=0,nmode=0,equations=list());
+ // Adding the event select to the block list.
+ bllst($+1)=scicos_model(sim=list("eselect",-2),in=1,in2=1,intyp=-1,out=[],out2=[],..
+ outtyp=1,evtin=[],evtout=ones(nn,1),state=[],dstate=[],odstate=list(),..
+ rpar=[],ipar=[],opar=list(),blocktype="l",firing=-ones(nn,1),..
+ dep_ut=[%t,%f],label="",nzcross=0,nmode=0,equations=list());
+
+ corinv($+1)=n+2
+ //we have to add the counter and the eventselect block to the scs_m
+ //to be compatible with the code generation
+ scs_m.objs(n+2)=Counter("define");
+ scs_m.objs(n+2).model.ipar=[1;double(nn);1];
+ corinv($+1)=n+3
+ scs_m.objs(n+3)=ESELECT_f("define");
+ scs_m.objs(n+3).model.evtout=ones(nn,1);
+ scs_m.objs(n+3).model.firing=-ones(nn,1);
+ nc=size(bllst)
+ nb=size(corinv)
+ indout($+1)=nc-1;
+ indout($+1)=nc;
+ // linking the event output of the evntdly or the bidon to the counter.
+ // and linking the regular output of the counter to the event select.
+ Ts($+1:$+4,:)=[nb-2 1 -1 -1;..
+ nb-1,1,1,-1;..
+ nb-1,1,-1,1;..
+ nb,1,1,1]
+ // replacing the SampleClk by the output of the event select
+ index=find(MAT(:,5)==string(4))
+ for i=index
+ num=-evstr(MAT(i,1))
+ Ts(find(Ts(:,1)==num),1)=-num
+ K=0:nn-1;
+ M=find(modulo(int(K*frequ*den),int(evstr(MAT(i,3))*double(den)))==0)';
+ ON=ones(size(M,"*"),1)
+ Ts($+1:2:$+2*size(M,"*"),:)=[nb*ON M+ON*(evstr(MAT(i,4))-offset)*double(den) -ON -ON]
+ N=[1:size(M,"*")]';
+ Ts($+1-(2*size(M,"*")-2):2:$+1,:)=[-num*ON N ON -ON]
+ end
+ else
+ nb=size(corinv)
+ index=find(MAT(:,5)==string(4))
+ ON=ones(size(index,"*"),1)
+ Ts($+1:2:$+2*size(index,"*"),:)=[nb*ON ON -ON -ON]
+ num=-evstr(MAT(index,1))
+ // N=[1:size(index,'*')]';
+ Ts($+1-(2*size(index,"*")-2):2:$+1,:)=[-num ON ON -ON]
+ for i=1:size(index,"*")
+ Ts(find(Ts(:,1)==num(i)),1)=-num(i)
+ end
+ end
+endfunction
+
+function [Ts,bllst,corinv,indout,ok]=s_clk2(MAT,Ts,bllst,corinv,scs_m,indout)
+ ok=%t
+ index=find(MAT(:,5)==string(4)) //index of SampleCLK blocks
+ MAT1=MAT(index,:);
+ frequ=evstr(MAT1(:,3)); // frequencies of the sampleCLK
+ offset=evstr(MAT1(:,4)); // offsets of the SampleCLK
+ offset=offset(:);frequ=frequ(:);
+ [m,den,off,count,m1,fir,frequ,offset,ok]=mfrequ_clk(frequ,offset);
+ if ~ok then return;end
+ mn=(2**size(m1,"*"))-1;//number of event outputs.
+ n=lstsize(scs_m.objs);
+ bllst($+1)=scicos_model(sim=list("m_frequ",4),in=[],in2=[],intyp=1,out=[],out2=[],outtyp=1,..
+ evtin=1,evtout=ones(mn,1),state=[],dstate=[],odstate=list(),rpar=[],ipar=[],..
+ opar=list(m,double(den),off,count),blocktype="d",firing=fir,dep_ut=[%f,%f],..
+ label="",nzcross=0,nmode=0,equations=list());
+ corinv($+1)=n+1;
+ nb=size(corinv);
+ nc=size(bllst);// nc differs from nb if the diagram contains modelica's block
+ indout($+1)=nc;
+ k=1:mn;
+ //connecting all the event outputs to the event input of the M_Frequ block
+ Ts($+1:2:$+2*mn,:)=[nb*ones(mn,1) k' -ones(mn,2)]
+ Ts($+1-(2*mn-2):2:$+1,:)=[nb*ones(mn,1) ones(mn,2) -ones(mn,1)]
+ //replacing the SampleCLK by the outputs of the M_frequ
+ for i=1:size(frequ,"*")
+ num=evstr(MAT1(find((evstr(MAT1(:,3))==frequ(i))&(evstr(MAT1(:,4))==offset(i))),1))
+ for ii=num'
+ Ts(find(Ts(:,1)==-ii),1)=ii;
+ j=2**(i-1):2**i:mn;
+ v=j;
+ for k=1:2**(i-1)-1;
+ v=[v,j+k]
+ end
+ v=(unique(v))
+ ON=ones(size(v,"*"),1)
+ N=[1:size(v,"*")]';
+ Ts($+1:2:$+2*size(v,"*"),:)=[nb*ON v' -ON -ON]
+ Ts($+1-(2*size(v,"*")-2):2:$+1,:)=[ii*ON N ON -ON]
+ end
+ end
+endfunction
+
+function [m,k]=uni(fr,of)
+ k=[];
+ m=[];
+ ot=[];
+ for i=1:size(fr,"*")
+ istreated=%f;
+ ind=find(m==fr(i));
+ if ind==[] then
+ m=[m;fr(i)];
+ ot=[ot;of(i)];
+ k=[k;i];
+ else
+ for j=ind
+ if of(i)==ot(j) then
+ istreated=%t
+ end
+ end
+ if ~istreated then
+ m=[m;fr(i)];
+ ot=[ot;of(i)]
+ k=[k;i];
+ end
+ end
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/scicos_block.bin b/modules/scicos/macros/scicos_scicos/scicos_block.bin
new file mode 100755
index 000000000..453fd4d83
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_block.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scicos_block.sci b/modules/scicos/macros/scicos_scicos/scicos_block.sci
new file mode 100755
index 000000000..598e10dcc
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_block.sci
@@ -0,0 +1,30 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function blk=scicos_block(v1,v2,v3,v4,v5)
+ //Block data structure initialization
+ if exists("graphics","local")==0 then graphics=scicos_graphics(),end
+ if exists("model","local")==0 then model=scicos_model(),end
+ if exists("gui","local")==0 then gui="",end
+ if exists("doc","local")==0 then doc=list(),end
+
+ blk=mlist(["Block","graphics","model","gui","doc"],graphics,model,gui,doc)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/scicos_block_link.bin b/modules/scicos/macros/scicos_scicos/scicos_block_link.bin
new file mode 100755
index 000000000..1e5b1d24b
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_block_link.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scicos_block_link.sci b/modules/scicos/macros/scicos_scicos/scicos_block_link.sci
new file mode 100755
index 000000000..e6231391b
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_block_link.sci
@@ -0,0 +1,59 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// Copyright (C) DIGITEO - Clément DAVID <clement.david@scilab.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function ok = scicos_block_link(funam, txt, flag, libs)
+ // Link a new funame block with txt implementation.
+ //
+ // Parameters:
+ // funam: the name of the function
+ // txt: the code
+ // flag: language type ('c' or 'f')
+ // libs: the libs to link with
+
+ // pre-condition
+ if flag <> "c" & flag <> "f" then
+ ok = %f;
+ messagebox(gettext("Sorry: Only C or FORTRAN languages are supported","modal"));
+ return;
+ end
+ if stripblanks(funam)==emptystr() then
+ ok = %f;
+ messagebox(gettext("Sorry file name not defined in "+flag+" block","modal"));
+ return;
+ end
+ if ~exists("libs", "l") then
+ libs = "";
+ end
+
+ // put the txt to a temp file
+ cur_wd = pwd();
+ chdir(TMPDIR);
+ mputl(txt, funam + "." + flag);
+
+ // call the standard block link function
+ ok = buildnewblock(funam, funam + "." + flag, "", "", libs, TMPDIR, "", "");
+
+ // post
+ chdir(cur_wd);
+ ok = %t;
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/scicos_cpr.bin b/modules/scicos/macros/scicos_scicos/scicos_cpr.bin
new file mode 100755
index 000000000..69bcc4ac6
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_cpr.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scicos_cpr.sci b/modules/scicos/macros/scicos_scicos/scicos_cpr.sci
new file mode 100755
index 000000000..9889448a1
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_cpr.sci
@@ -0,0 +1,30 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function cpr=scicos_cpr(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10)
+ //initialisation de cpr tlist
+ if exists("state","local")==0 then state=scicos_state(),end
+ if exists("sim","local")==0 then sim=scicos_sim(),end
+ if exists("cor","local")==0 then cor=list(),end
+ if exists("corinv","local")==0 then corinv=list(),end
+ cpr=tlist(["cpr","state","sim","cor","corinv"],..
+ state,sim,cor,corinv)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/scicos_diagram.bin b/modules/scicos/macros/scicos_scicos/scicos_diagram.bin
new file mode 100755
index 000000000..b39e9c8a0
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_diagram.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scicos_diagram.sci b/modules/scicos/macros/scicos_scicos/scicos_diagram.sci
new file mode 100755
index 000000000..5ea1793aa
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_diagram.sci
@@ -0,0 +1,30 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function scs_m=scicos_diagram(v1,v2,v3)
+ if exists("props","local")==0 then props=scicos_params(),end
+ if exists("objs","local")==0 then objs=list(),end
+ if exists("version","local")==0 then version="",end
+ if exists("contrib","local")==0 then contrib=list(),end
+
+ scs_m=mlist(["diagram","props","objs","version","contrib"],...
+ props,objs,version,contrib)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/scicos_flat.bin b/modules/scicos/macros/scicos_scicos/scicos_flat.bin
new file mode 100755
index 000000000..43d90e60a
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_flat.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scicos_flat.sci b/modules/scicos/macros/scicos_scicos/scicos_flat.sci
new file mode 100755
index 000000000..5610397fb
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_flat.sci
@@ -0,0 +1,456 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// - Ramine Nikoukhah <ramine.nikoukhah@inria.fr> - 2003
+// - Serge Steer <serge.steer@inria.fr> - 2003
+// - Fady Nassif <fady.nassif@inria.fr> - 2007
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [cor,corinv,links_table,cur_fictitious,sco_mat,ok, IN, OUT, EIN, EOUT]=scicos_flat(scs_m,ksup,MaxBlock)
+ //This function takes a hierarchical Scicos diagram and computes the
+ //"flat" equivalent, removing "non computational" blocs like splits.
+ //S. Steer, R. Nikoukhah 2003. Copyright INRIA
+
+ //NB::--------------------------------------------------------------
+ // Modifying this function to take care of the GOTO FROM SampleCLK and VirtualCLK0 blocks.
+ // A negatif number in cor and in links_table is refer to a GOTO,FROM
+ // GotoTagVisibility, SampleCLK, VirtualCLK0. in other words the blocks that are virtual.
+ // These blocks are removed in the compilation part.
+ // Modification of shiftcors. It will not shift the negatives numbers.
+ // A sco_mat is a string matrix composed by the :
+ // For the blocks GOTO, FROM, VirtualCLK0
+ // - the first column : the negatif of the number of the virtual block in the cor.
+ // - the second column: 1 if it is a GOTO; -1 if it is a FROM.
+ // The VirtualCLK0 is considered as a GOTO.
+ // - the third column : the tag value. 'scicostimeclk0' is used in the case of the VirtualCLK0
+ // - the forth column : the tag visibility
+ // For the GOTO: + 2: scoped
+ // + 3: global
+ // For the FROM: + 1
+ // For the VirtualCLK0: 2
+ // - the fifth column : 1=regular 2=event 3=modelica 10=VirtualCLK0
+ // For the SampleCLK:
+ // - the first column : the negatif of the number of the virtual block in the cor.
+ // - the second column: the value 1.
+ // - the third column : The frequency value.
+ // - the forth column : The offset value.
+ // - the fifth column : the value 4.
+ // Another two string matrices are used for the GOTO/FROM blocks. The loc_mat it is used when the GOTO
+ // block is local. The from_mat to match the local from with the local goto.
+ // A tag_exprs matrices is used for the GotoTagVisibility and the VirtualCLK0:
+ // it is composed by:
+ // - the first column: The tag value. 'scicostimeclk0' in the VirtualCLK0 case.
+ // - the second column: 1=regular 2=event 3=modelica 10=VirtualCLK0
+ // The local and scoped cases are studied in this function.
+ // The global case is studied in the function global_case in c_pass1.
+ // A Modification of update_cor in c_pass1. For the negatives numbers
+ // the cor will be set to 0. (In this case the blocks are considered as IN_f ...)
+ // Fady NASSIF 2007. INRIA.
+ //-------------------------------------------------------------------
+
+ if argn(2)<=1 then ksup=0;end //used for recursion
+ if ksup==0 then // main scheme
+ MaxBlock=countblocks(scs_m);
+ //last created fictitious block (clock split,clock sum,super_blocks, superbloc))
+ cur_fictitious=MaxBlock
+ path=[]; // for delete_unconnected
+ scs_m_s=scs_m ;// for delete_unconnected
+ end
+ //-------------- suppress blocks with an unconnected regular port --------------
+ scs_m=delete_unconnected(scs_m);
+
+ //list of blocks with are not retained in the final block list
+ blocks_to_remove=["CLKSPLIT_f" "SPLIT_f" "IMPSPLIT_f" "CLKSOM_f" "CLKSOMV_f" "NRMSOM_f" "PAL_f" "xcos_block"]
+ port_blocks=["IN_f","INIMPL_f","OUT_f","OUTIMPL_f","CLKIN_f","CLKINV_f","CLKOUT_f","CLKOUTV_f"]
+ block_goto=["GOTO","CLKGOTO","GOTOMO"]
+ block_from=["FROM","CLKFROM","FROMMO"]
+ block_tag=["GotoTagVisibility","CLKGotoTagVisibility","GotoTagVisibilityMO"]
+ n=lstsize(scs_m.objs) //number of "objects" in the data structure
+ //-------------- initialize outputs --------------
+ nb=0;
+ links_table=[]; //
+ corinv=list();
+ cor=list();for k=1:n, cor(k)=0;end
+
+ ok=%t;
+ IN=[];OUT=[];EIN=[];EOUT=[];
+ Links=[] //to memorize links position in the data structure
+ mod_blk_exist=%f;
+ //-------------- Analyse blocks --------------
+ loc_mat=[];from_mat=[];tag_exprs=[];sco_mat=[];
+ for k=1:n //loop on all objects
+ o=scs_m.objs(k);
+ x=getfield(1,o);
+ cor(k)=0
+ if x(1)=="Block" then
+ if or(o.gui==block_goto) then
+ cur_fictitious=cur_fictitious+1;
+ cor(k)=-cur_fictitious;
+ if (o.graphics.exprs(2)=="1") then
+ loc_mat=[loc_mat;[string(cur_fictitious),string(1),(o.graphics.exprs(1)),string(find(block_goto(:)==o.gui))]]
+ locomat=[];
+ for i=1:size(loc_mat,1)
+ locomat=[locomat;strcat([loc_mat(i,3) loc_mat(i,4)])]
+ end
+ vec=unique(locomat)
+ if size(vec,1)<>size(loc_mat,1) then
+ if flgcdgen<>-1 then path=[numk path];scs_m=all_scs_m; end
+ if (ksup==0)|flgcdgen<>-1 then
+ hilite_path([path,k],"There is another local GOTO in this diagram with the same tag ''"+loc_mat($,3)+"''",%t);
+ else
+ hilite_path([path,k], "There is another local GOTO in this diagram with the same tag ''"+loc_mat($,3)+"''",%t);
+ end
+ disp(mprintf("%s: goto tag not unique", "scicos_flat"));
+ ok=%f;return
+ end
+ else
+ sco_mat=[sco_mat;[string(cur_fictitious),string(1),o.graphics.exprs(1),o.graphics.exprs(2),string(find(block_goto(:)==o.gui))]]
+ end
+ elseif or(o.gui==block_from) then
+ cur_fictitious=cur_fictitious+1;
+ cor(k)=-cur_fictitious
+ sco_mat=[sco_mat;[string(cur_fictitious),string(-1),o.graphics.exprs(1),string(1),string(find(block_from(:)==o.gui))]]
+ from_mat=[from_mat;[string(cur_fictitious),string(-1),o.graphics.exprs(1),string(find(block_from(:)==o.gui))]]
+ elseif or(o.gui==block_tag) then
+ tag_exprs=[tag_exprs;[o.graphics.exprs(1),string(find(block_tag(:)==o.gui))]]
+ cur_fictitious=cur_fictitious+1;
+ cor(k)=-cur_fictitious
+ elseif o.gui=="SampleCLK" then
+ if o.graphics.peout<>0 then
+ cur_fictitious=cur_fictitious+1;
+ cor(k)=-cur_fictitious
+ [Nf,Df]=rat(o.model.rpar(1),1d-9);
+ [No,Do]=rat(o.model.rpar(2),1d-9);
+ sco_mat=[sco_mat;[string(cur_fictitious),string(1),string(Nf)+"/"+string(Df),..
+ string(No)+"/"+string(Do),string(4)]]
+ end
+ //Adding the VirtualCLK0. Fady 18/11/2007
+ elseif o.gui=="VirtualCLK0" then
+ cur_fictitious=cur_fictitious+1;
+ cor(k)=-cur_fictitious
+ sco_mat=[sco_mat;[string(cur_fictitious),string(1),"scicostimeclk0",..
+ string(2),string(10)]]
+ tag_exprs=[tag_exprs;["scicostimeclk0",string(10)]]
+ elseif or(o.gui==blocks_to_remove) then
+ cur_fictitious=cur_fictitious+1;
+ cor(k)=cur_fictitious
+ elseif o.gui=="SUM_f"|o.gui=="SOM_f" then
+ nb=nb+1;
+ corinv(nb)=k;
+ cor(k)=nb
+ //scs_m=adjust_sum(scs_m,k)
+ elseif or(o.gui==port_blocks) then
+ //here we suppose to be inside a superblock
+ //may be we can handle this blocks just as blocks_to_remove
+ if ksup==0 then
+ scs_m=scs_m_s
+ hilite_path([path,k],gettext("I/O blocks must be only used in a Super Block"),%f)
+ disp(mprintf("%s: Port out of hierarchy", "scicos_flat"));
+ ok=%f;return
+ end
+ connected=get_connected(scs_m,k)
+ if connected==[] then
+ scs_m=scs_m_s
+ hilite_path([path,k],gettext("This Super block input port is not connected."),%t)
+ disp(mprintf("%s: Not connected super block input", "scicos_flat"));
+ ok=%f;return
+ end
+ if or(o.gui==["IN_f","INIMPL_f"]) then
+ pind=Pind(1)
+ IN=[IN o.model.ipar]
+ elseif or(o.gui==["OUT_f","OUTIMPL_f"]) then
+ pind=Pind(2)
+ OUT=[OUT o.model.ipar]
+ elseif or(o.gui==["CLKIN_f","CLKINV_f"]) then
+ pind=Pind(3)
+ EIN=[EIN o.model.ipar]
+ elseif or(o.gui==["CLKOUT_f","CLKOUTV_f"]) then
+ pind=Pind(4)
+ EOUT=[EOUT o.model.ipar]
+ end
+ //connect the link to the fictitious bloc replacing the superblock
+ if scs_m.objs(connected).from(1)==k then
+ scs_m.objs(connected).from(1)=-(pind+o.model.ipar)
+ end
+ if scs_m.objs(connected).to(1)==k then
+ scs_m.objs(connected).to(1)=-(pind+o.model.ipar)
+ end
+ elseif o.model.sim(1)=="asuper" then
+ nb=nb+1
+ corinv(nb)=k
+ cor(k)=nb
+ if o.graphics.exprs(3).dep_ut($)==%t then
+ sco_mat=[sco_mat;[string(nb) "-1" "scicostimeclk0" "1" "10"]]
+ end
+ elseif o.model.sim=="super"|o.model.sim=="csuper" then
+ path=[path k] //superbloc path in the hierarchy
+ //replace superbloc by a set of fictitious blocks (one per port)
+ //and reconnect links connected to the superblock to these
+ //ficitious blocks
+ Pinds=[];if exists("Pind") then Pinds=Pind,end
+ Pind=[] //base of ports numbering
+ //mprintf("entering superblock at level "+string(size(path,'*'))+"\r\n")
+ nb_pin=size(scs_m.objs(k).graphics("pin"),1);
+ nb_pein=size(scs_m.objs(k).graphics("pein"),1);
+ for port_type=["pin","pout","pein","peout"]
+ Pind=[Pind cur_fictitious]
+ ip=scs_m.objs(k).graphics(port_type);
+ ki=find(ip>0)
+ for kk=ki
+ kc=ip(kk)
+ //** a link is connected to the same sblock on both ends
+ if scs_m.objs(kc).to(1)==scs_m.objs(kc).from(1) then
+ //** regular input port
+ if port_type=="pin" then
+ scs_m.objs(kc).to(1)=-(cur_fictitious+scs_m.objs(kc).to(2));
+ scs_m.objs(kc).to(2)=1
+
+ if scs_m.objs(kc).from(3)==0 then //** in connected to out
+ scs_m.objs(kc).from(1)=-(cur_fictitious+scs_m.objs(kc).from(2)+nb_pin);
+ scs_m.objs(kc).from(2)=1
+ else //** in connected to in
+ scs_m.objs(kc).from(1)=-(cur_fictitious+scs_m.objs(kc).from(2));
+ scs_m.objs(kc).from(2)=1
+ end
+
+ //** regular output port
+ elseif port_type=="pout" then
+ scs_m.objs(kc).from(1)=-(cur_fictitious+scs_m.objs(kc).from(2));
+ scs_m.objs(kc).from(2)=1
+
+ if scs_m.objs(kc).to(3)==0 then //** out connected to out
+ scs_m.objs(kc).to(1)=-(cur_fictitious+scs_m.objs(kc).to(2));
+ scs_m.objs(kc).to(2)=1
+ end
+
+ //** event input port
+ elseif port_type=="pein" then
+ scs_m.objs(kc).to(1)=-(cur_fictitious+scs_m.objs(kc).to(2));
+ scs_m.objs(kc).to(2)=1
+
+ scs_m.objs(kc).from(1)=-(cur_fictitious+scs_m.objs(kc).from(2)+nb_pein);
+ scs_m.objs(kc).from(2)=1
+
+ //** peout and pein are never connected to themselves
+ end
+
+ elseif scs_m.objs(kc).to(1)==k then // a link going to the superblock
+ scs_m.objs(kc).to(1)=-(cur_fictitious+scs_m.objs(kc).to(2));
+ scs_m.objs(kc).to(2)=1
+
+ elseif scs_m.objs(kc).from(1)==k then // a link coming from the superblock
+ scs_m.objs(kc).from(1)=-(cur_fictitious+scs_m.objs(kc).from(2));
+ scs_m.objs(kc).from(2)=1
+ end
+ end
+ cur_fictitious=cur_fictitious+size(ip,"*")
+ end
+
+
+ //Analyze the superblock contents
+ [cors,corinvs,lt,cur_fictitious,scop_mat,ok, localIN, localOUT, localEIN, localEOUT]=scicos_flat(o.model.rpar,cur_fictitious,MaxBlock)
+ if ~ok then
+ disp(mprintf("%s: Invalid super block at %d", "scicos_flat", k));
+ return
+ end
+
+ // check if the ports has the right order
+ localIN=-gsort(-localIN);
+ if or(localIN<>[1:size(localIN,"*")]) then
+ ok=%f;
+ msg=gettext("Input ports are not numbered properly.")
+ hilite_path(path,msg,%t)
+ disp(mprintf("%s: Input ports are not numbered properly.", "scicos_flat"))
+ return
+ end
+ localOUT=-gsort(-localOUT);
+ if or(localOUT<>[1:size(localOUT,"*")]) then
+ ok=%f;
+ msg=gettext("Output ports are not numbered properly.")
+ hilite_path(path,msg,%t)
+ disp(mprintf("%s: Output ports are not numbered properly.", "scicos_flat"))
+ return
+ end
+ localEIN=-gsort(-localEIN);
+ if or(localEIN<>[1:size(localEIN,"*")]) then
+ ok=%f;
+ msg=gettext("Event input ports are not numbered properly.")
+ hilite_path(path,msg,%t)
+ disp(mprintf("%s: Event input ports are not numbered properly.", "scicos_flat"))
+ return
+ end
+ localEOUT=-gsort(-localEOUT);
+ if or(localEOUT<>[1:size(localEOUT,"*")]) then
+ ok=%f;
+ msg=gettext("Event output ports are not numbered properly.")
+ hilite_path(path,msg,%t)
+ disp(mprintf("%s: Event output ports are not numbered properly.", "scicos_flat"))
+ return
+ end
+
+ //shifting the scop_mat for regular blocks. Fady 08/11/2007
+ if scop_mat<>[] then
+ v_mat=find(eval(scop_mat(:,1))<MaxBlock)
+ v_mat=v_mat(:)
+ for j=v_mat
+ scop_mat(j,1)=string(eval(scop_mat(j,1))+nb)
+ end
+ end
+ //Adding the scop_mat to the old sco_mat.
+ sco_mat=[sco_mat;scop_mat]
+ nbs=size(corinvs)
+
+ //catenate superbloc data with current data
+
+ f=find(lt(:,1)>0&lt(:,1)<=nbs);if f<>[] then lt(f,1)=lt(f,1)+nb,end
+ links_table=[links_table;lt]
+
+ for kk=1:nbs, corinv(nb+kk)=[k,corinvs(kk)];end
+ cors=shiftcors(cors,nb)
+ // cur_fictitious=cur_fictitious+nb
+ cor(k)=cors
+ nb=nb+nbs
+ Pind=Pinds
+ path($)=[]
+
+ else //standard blocks
+ nb=nb+1
+ corinv(nb)=k
+ //[model,ok]=build_block(o.model)
+ cor(k)=nb
+ //Adding the always activated blocks to the sco_mat to take care of the enabling if exists.
+ //Fady 18/11/2007
+ if ~is_modelica_block(o) then
+ if o.model.dep_ut($) then
+ sco_mat=[sco_mat;[string(nb) "-1" "scicostimeclk0" "1" "10"]]
+ end
+ else
+ mod_blk_exist=%t // Flag for the existance of modelica's blocks
+ end
+ end
+ elseif x(1)=="Deleted"|x(1)=="Text" then
+ //this objects are ignored
+ else //links
+ Links=[Links k] // memorize their position for use during links analysis
+ end
+ end //end of loop on objects
+
+ if ksup==0&nb==0 then
+ messagebox(msprintf(gettext("%s: Empty diagram"), "Xcos"),"modal")
+ ok=%f
+ disp(msprintf("%s: Empty diagram", "scicos_flat"));
+ return
+ end
+ //-------------- Analyse links --------------
+ for k=Links
+ o=scs_m.objs(k);
+ f=0
+ if o.from(1)<0|o.from(1)>MaxBlock then //Link coming from a superblock input port
+ else
+ o.from(1)=cor(o.from(1));
+ end
+ if o.to(1)<0 |o.to(1)>MaxBlock then //Link going to a superblock output port
+ else
+ o.to(1)=cor(o.to(1)),
+ end
+
+ if o.ct(2)==2 //implicit links
+ //if abs(o.from(1))==125|abs(o.to(1))==125 then pause,end
+ links_table=[links_table
+ o.from(1:3) o.ct(2)
+ o.to(1:3) o.ct(2) ]
+ else //regular or event links
+ links_table=[links_table
+ o.from(1:2) -1 o.ct(2) //outputs are tagged with -1
+ o.to(1:2) 1 o.ct(2) ] //inputs are tagged with 1
+ end
+ end
+ // Warning in case of modelica's blocks in an enabled diagram.
+ // Fady 18/11/2007
+ tof=find((sco_mat(:,2)=="1")& (sco_mat(:,5)=="10"))
+ if tof<>[] then
+ if mod_blk_exist then
+ messagebox("Warning the enable does not consider the modelica blocks","modal")
+ end
+ end
+ //----------------------Goto From Analyses--------------------------
+ // Local case
+ if loc_mat<>[] then
+ for i=1:size(loc_mat,1)
+ index1=find((from_mat(:,2)=="-1")&(from_mat(:,3)==loc_mat(i,3))&(from_mat(:,4)==loc_mat(i,4)))
+ for j=index1
+ index2=find(links_table(:,1)==-evstr(from_mat(j,1)))
+ // for k=index2
+ // links_table(k,1)=-evstr(loc_mat(i,1))
+ // end
+ if index2<>[] then
+ links_table(index2',1)=-evstr(loc_mat(i,1))
+ end
+ index2=find(sco_mat(:,1)==from_mat(j,1))
+ sco_mat(index2',:)=[]
+ end
+ end
+ end
+ //scoped case
+ if tag_exprs<>[] then
+ //to be modified !!!!!
+ // vec=unique(tag_exprs)
+ for i=1:size(tag_exprs,1)
+ index=find((tag_exprs(:,1)==tag_exprs(i,1))&(tag_exprs(:,2)==tag_exprs(i,2)))
+ if size(index,"*") > 1 then
+ messagebox(["Error In Compilation. You cannot have multiple GotoTagVisibility";..
+ " with the same tag value in the same scs_m"],"modal")
+ ok=%f;
+ disp(mprintf("%s: Multiple GotoTagVisibility at the same level", "scicos_flat"));
+ return
+ end
+ end
+
+ for i=1:size(tag_exprs,1)
+ index=find((sco_mat(:,2)=="1")&(sco_mat(:,3)==tag_exprs(i,1))&(sco_mat(:,4)=="2")&(sco_mat(:,5)==tag_exprs(i,2)))
+ if index<>[] then
+ if size(index,"*")>1 then
+ messagebox(["Error in compilation";"Multiple GOTO are taged by the same GotoTagVisibility"],"modal")
+ ok=%f
+ disp(mprintf("%s: Shared GotoTagVisibility across GOTO", "scicos_flat"));
+ return
+ end
+ index1=find((sco_mat(:,2)=="-1")&(sco_mat(:,3)==tag_exprs(i,1))&(sco_mat(:,5)==tag_exprs(i,2)))
+ if index1<>[] then
+ for j=index1
+ index2=find(links_table(:,1)==-evstr(sco_mat(j,1)))
+ if index2<>[] then
+ links_table(index2',1)=-evstr(sco_mat(index,1))
+ end
+ //linking the always active blocks to the VirtualCLK0 if exists.
+ if sco_mat(j,5)=="10" then
+ links_table($+1,:)=[-evstr(sco_mat(index,1)) 1 -1 -1]
+ links_table($+1,:)=[evstr(sco_mat(j,1)) 0 1 -1]
+ end
+ end
+ end
+ sco_mat([index1';index'],:)=[]
+ //sco_mat(index,:)=[]
+ end
+ end
+ end
+ //global case
+ // function global_case in c_pass1
+ //------------------------------------------------------------------------
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/scicos_graphics.bin b/modules/scicos/macros/scicos_scicos/scicos_graphics.bin
new file mode 100755
index 000000000..68d6fd830
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_graphics.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scicos_graphics.sci b/modules/scicos/macros/scicos_scicos/scicos_graphics.sci
new file mode 100755
index 000000000..bf385ca07
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_graphics.sci
@@ -0,0 +1,61 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function graphics=scicos_graphics(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,...
+ v11,v12,v13,v14,v15,v16,v17,v18,v19,v20)
+ //initialisation de graphics mlist
+ if exists("orig","local")==0 then orig=[0 0],end
+ if exists("sz","local")==0 then sz=[20 20],end
+ if exists("flip","local")==0 then flip=%t,end
+ if exists("theta","local")==0 then theta=0,end
+ if exists("exprs","local")==0 then exprs=[],end
+ if exists("pin","local")==0 then pin=[],end
+ if exists("pout","local")==0 then pout=[],end
+ if exists("pein","local")==0 then pein=[],end
+ if exists("peout","local")==0 then peout=[],end
+ if exists("gr_i","local")==0 then gr_i=[],end
+ if exists("id","local")==0 then id="",end
+ if exists("in_implicit","local")==0 then
+ I="E";
+ in_implicit=I(ones(pin(:)));
+ end
+ if exists("out_implicit","local")==0 then
+ I="E";
+ out_implicit=I(ones(pout(:)));
+ end
+ if exists("in_style","local")==0 then
+ in_style=emptystr(pin);
+ end
+ if exists("out_style","local")==0 then
+ out_style=emptystr(pout);
+ end
+ if exists("in_label","local")==0 then
+ in_label=emptystr(pin);
+ end
+ if exists("out_label","local")==0 then
+ out_label=emptystr(pout);
+ end
+ if exists("style","local")==0 then style="" + [],end
+
+ graphics=mlist(["graphics","orig","sz","flip","theta","exprs","pin",..
+ "pout","pein","peout","gr_i","id","in_implicit","out_implicit","in_style","out_style","in_label","out_label","style"],..
+ orig,sz,flip,theta,exprs,pin,pout,pein,peout,gr_i,id,in_implicit,out_implicit,in_style,out_style,in_label,out_label,style)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/scicos_include_paths.bin b/modules/scicos/macros/scicos_scicos/scicos_include_paths.bin
new file mode 100755
index 000000000..f9c3b9eb1
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_include_paths.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scicos_include_paths.sci b/modules/scicos/macros/scicos_scicos/scicos_include_paths.sci
new file mode 100755
index 000000000..17c0a4e92
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_include_paths.sci
@@ -0,0 +1,46 @@
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// Copyright (C) DIGITEO - 2010 - Allan CORNET
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function p = scicos_include_paths(modules)
+
+ if argn(2) < 1 then
+ modules = ["scicos_blocks", "dynamic_link", "scicos", "core"];
+ end
+
+ p = [];
+
+ if getos() == "Windows" then
+ // Windows
+ p= """" + SCI + "/modules/" + modules + "/includes" + """";
+ else
+ //Unix
+ if isdir(SCI+"/modules/core/includes/") then
+ // source version
+ p = SCI + "/modules/" + modules + "/includes";
+ elseif isdir(SCI+"/../../include/scilab/core/") then
+ // binary version
+ p = SCI + "/../../include/scilab/" + modules;
+ elseif isdir("/usr/include/scilab/") then
+ // packaged version
+ p = [];
+ end
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/scicos_link.bin b/modules/scicos/macros/scicos_scicos/scicos_link.bin
new file mode 100755
index 000000000..49785c7d3
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_link.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scicos_link.sci b/modules/scicos/macros/scicos_scicos/scicos_link.sci
new file mode 100755
index 000000000..0f42bbaa9
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_link.sci
@@ -0,0 +1,34 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function lnk=scicos_link(v1,v2,v3,v4,v5,v6,v7,v8)
+ //initialisation de link mlist
+ if exists("xx","local")==0 then xx=[],end
+ if exists("yy","local")==0 then yy=[],end
+ if exists("id","local")==0 then id="",end
+ if exists("thick","local")==0 then thick=[0,0],end
+ if exists("ct","local")==0 then ct=[1,1],end
+ if exists("from","local")==0 then from=[],end
+ if exists("to","local")==0 then to=[],end
+ lnk=mlist(["Link","xx","yy","id","thick","ct","from","to"],..
+ xx,yy,id,thick,ct,from,to)
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/scicos_model.bin b/modules/scicos/macros/scicos_scicos/scicos_model.bin
new file mode 100755
index 000000000..c3024fcc2
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_model.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scicos_model.sci b/modules/scicos/macros/scicos_scicos/scicos_model.sci
new file mode 100755
index 000000000..a0c4d8757
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_model.sci
@@ -0,0 +1,56 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function model=scicos_model(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,...
+ v17,v18,v19,v20,v21,v22,v23,v24,v25,v26)
+
+ //initialisation de model mlist
+ if exists("sim","local")==0 then sim="",end
+ if exists("in","local")==0 then in=[],end
+ if exists("in2","local")==0 then in2=[],end
+ if exists("intyp","local")==0 then intyp=1,end
+ if exists("out","local")==0 then out=[],end
+ if exists("out2","local")==0 then out2=[],end
+ if exists("outtyp","local")==0 then outtyp=1,end
+ if exists("evtin","local")==0 then evtin=[],end
+ if exists("evtout","local")==0 then evtout=[],end
+ if exists("state","local")==0 then state=[],end
+ if exists("dstate","local")==0 then dstate=[],end
+ if exists("odstate","local")==0 then odstate=list(),end
+ if exists("opar","local")==0 then opar=list(),end
+ if exists("rpar","local")==0 then rpar=[],end
+ if exists("ipar","local")==0 then ipar=[],end
+ if exists("blocktype","local")==0 then blocktype="c",end
+ if exists("firing","local")==0 then firing=[],end
+ if exists("dep_ut","local")==0 then dep_ut=[%f %f],end
+ if exists("label","local")==0 then label="",end
+ if exists("nzcross","local")==0 then nzcross=0,end
+ if exists("nmode","local")==0 then nmode=0,end
+ if exists("equations","local")==0 then equations=list(),end
+ if exists("uid","local")==0 then uid="",end
+
+ model=mlist(["model","sim","in","in2","intyp","out","out2","outtyp",...
+ "evtin","evtout","state","dstate","odstate","rpar","ipar","opar",...
+ "blocktype","firing","dep_ut","label","nzcross",..
+ "nmode","equations","uid"],..
+ sim,in,in2,intyp,out,out2,outtyp,evtin,evtout,state,dstate,odstate,..
+ rpar,ipar,opar,blocktype,firing,dep_ut,label,nzcross,nmode,equations,uid)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/scicos_params.bin b/modules/scicos/macros/scicos_scicos/scicos_params.bin
new file mode 100755
index 000000000..7e9a1ca8e
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_params.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scicos_params.sci b/modules/scicos/macros/scicos_scicos/scicos_params.sci
new file mode 100755
index 000000000..9deaf8c1e
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_params.sci
@@ -0,0 +1,48 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function params=scicos_params(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10)
+ if exists("wpar","local")==0 then wpar=[600,450,0,0,600,450],end
+ if exists("title","local")==0 & exists("Title","local")==0 then
+ titlex="Untitled"
+ else
+ if exists("title","local")==1 then
+ titlex=title
+ elseif exists("Title","local")==1 then
+ titlex=Title
+ end
+ end
+ if exists("tf","local")==0 then tf=100000,end
+ if exists("tol","local")==0 then tol=[1.d-6,1.d-6,1.d-10,tf+1,0,1,0],end
+ if exists("context","local")==0 then context=[],end
+ void1=[]
+ if exists("options","local")==0 then options=default_options(),end
+ void2=[]
+ void3=[]
+ if exists("doc","local")==0 then doc=list(),end
+
+ params=tlist(["params","wpar","title","tol","tf","context",..
+ "void1","options","void2","void3","doc"],..
+ wpar,titlex,tol,tf,context,void1,options,void2,..
+ void3,doc)
+
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/scicos_sim.bin b/modules/scicos/macros/scicos_scicos/scicos_sim.bin
new file mode 100755
index 000000000..8f12b04b0
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_sim.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scicos_sim.sci b/modules/scicos/macros/scicos_scicos/scicos_sim.sci
new file mode 100755
index 000000000..3a32c7211
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_sim.sci
@@ -0,0 +1,75 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function sim=scicos_sim(v1,v2,v3,v4,v5,..
+ v6,v7,v8,v9,v10,..
+ v11,v12,v13,v14,v15,..
+ v16,v17,v18,v19,v20,..
+ v21,v22,v23,v24,v25,..
+ v26,v27,v28,v29,v30,..
+ v31,v32,v33,v34,v35,..
+ v36,v37,v38,v39,v40)
+ if exists("funs","local")==0 then funs=[],end
+ if exists("xptr","local")==0 then xptr=[],end
+ if exists("zptr","local")==0 then zptr=[],end
+ if exists("ozptr","local")==0 then ozptr=[],end
+ if exists("zcptr","local")==0 then zcptr=[],end
+ if exists("inpptr","local")==0 then inpptr=[],end
+ if exists("outptr","local")==0 then outptr=[],end
+ if exists("inplnk","local")==0 then inplnk=[],end
+ if exists("outlnk","local")==0 then outlnk=[],end
+ if exists("rpar","local")==0 then rpar=[],end
+ if exists("rpptr","local")==0 then rpptr=[],end
+ if exists("ipar","local")==0 then ipar=[],end
+ if exists("ipptr","local")==0 then ipptr=[],end
+ if exists("opar","local")==0 then opar=list(),end
+ if exists("opptr","local")==0 then opptr=[],end
+ if exists("clkptr","local")==0 then clkptr=[],end
+ if exists("ordptr","local")==0 then ordptr=[],end
+ if exists("execlk","local")==0 then execlk=[],end
+ if exists("ordclk","local")==0 then ordclk=[],end
+ if exists("cord","local")==0 then cord=[],end
+ if exists("oord","local")==0 then oord=[],end
+ if exists("zord","local")==0 then zord=[],end
+ if exists("critev","local")==0 then critev=[],end
+ if exists("nb","local")==0 then nb=[],end
+ if exists("ztyp","local")==0 then ztyp=[],end
+ if exists("nblk","local")==0 then nblk=[],end
+ if exists("ndcblk","local")==0 then ndcblk=[],end
+ if exists("subscr","local")==0 then subscr=[],end
+ if exists("funtyp","local")==0 then funtyp=[],end
+ if exists("iord","local")==0 then iord=[],end
+ if exists("labels","local")==0 then labels=[],end
+ if exists("modptr","local")==0 then modptr=[],end
+ if exists("uids","local")==0 then uids=[],end
+ sim=tlist(["scs","funs","xptr","zptr","ozptr",..
+ "zcptr","inpptr","outptr","inplnk","outlnk","rpar",..
+ "rpptr","ipar","ipptr","opar","opptr",..
+ "clkptr","ordptr","execlk","ordclk","cord","oord","zord",..
+ "critev","nb","ztyp","nblk","ndcblk","subscr","funtyp",..
+ "iord","labels","modptr","uids"],..
+ funs,xptr,zptr,ozptr,zcptr,inpptr,..
+ outptr,inplnk,outlnk,rpar,rpptr,ipar,ipptr,..
+ opar,opptr,clkptr,ordptr,..
+ execlk,ordclk,cord,oord,zord,..
+ critev,nb,ztyp,nblk,ndcblk,..
+ subscr,funtyp,iord,labels,modptr,uids)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/scicos_state.bin b/modules/scicos/macros/scicos_scicos/scicos_state.bin
new file mode 100755
index 000000000..4e367e025
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_state.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scicos_state.sci b/modules/scicos/macros/scicos_scicos/scicos_state.sci
new file mode 100755
index 000000000..06d2b731f
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_state.sci
@@ -0,0 +1,34 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function state=scicos_state(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11)
+ //initialisation de state mlist
+ if exists("x","local")==0 then x=[],end
+ if exists("z","local")==0 then z=[],end
+ if exists("oz","local")==0 then oz=list,end
+ if exists("iz","local")==0 then iz=[],end
+ if exists("tevts","local")==0 then tevts=[],end
+ if exists("evtspt","local")==0 then evtspt=[],end
+ if exists("pointi","local")==0 then pointi=1,end
+ if exists("outtb","local")==0 then outtb=list(),end
+ state=tlist(["xcs","x","z","oz","iz","tevts","evtspt","pointi","outtb"],..
+ x,z,iz,tevts,evtspt,pointi,outtb)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/scicos_txtedit.bin b/modules/scicos/macros/scicos_scicos/scicos_txtedit.bin
new file mode 100755
index 000000000..24cb0fd12
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_txtedit.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scicos_txtedit.sci b/modules/scicos/macros/scicos_scicos/scicos_txtedit.sci
new file mode 100755
index 000000000..a7155b304
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scicos_txtedit.sci
@@ -0,0 +1,30 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+function param=scicos_txtedit(v1,v2,v3,v4,v5)
+ // Copyright INRIA
+ // Scicos text editor param structure
+ if exists("typ","local")==0 then typ="", end
+ if exists("ttitle","local")==0 then ttitle="", end
+ if exists("head","local")==0 then head=[], end
+ if exists("clos","local")==0 then clos=0, end
+
+ param=mlist(["TxtEdit","typ","title","head","clos"],typ,ttitle,head,clos)
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/script2var.bin b/modules/scicos/macros/scicos_scicos/script2var.bin
new file mode 100755
index 000000000..b1e8e3ff1
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/script2var.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/script2var.sci b/modules/scicos/macros/scicos_scicos/script2var.sci
new file mode 100755
index 000000000..635ffbeb8
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/script2var.sci
@@ -0,0 +1,89 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// Copyright (C) 2011 - INRIA - Serge Steer
+
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [%ll,%ierr] = script2var(%txt, %ll)
+ //** [%scicos_context, ierr] = script2var(context, %scicos_context)
+ //** context is the scs_m.props.context (string array) associated with the current level
+ //** %scicos_context is a struct containing the values defined by the
+ // calling contexts
+ //**
+ //** 10 Jan 2006
+ //local variable names are prefixed with a % to limit conflicts with
+ //variables defined in %txt instructions
+ %ierr = 0 ; //** init
+
+ //next lines checks if variable defined in %ll struct can be evaluated
+ //why ???
+ %mm = fieldnames(%ll)';
+ for %mi=%mm
+ if execstr(%mi+"=%ll(%mi)","errcatch")<>0 then
+ mprintf("%s\n",lasterror())
+ %ierr=1
+ return
+ end
+ end
+ [%ll,%ierr] = getvardef(%txt,%ll)
+ if %ierr<>0 then return, end
+endfunction
+
+//**--------------------------------------------------------------------------
+function [%ll,%ierr]=getvardef(%txt,%ll)
+ //extend and modify the %scicos_context variable (%ll) with the variable
+ //defined in the current level scs_m.props.context (%txt) instructions
+
+ //local variable names are prefixed with a % to limit conflicts with
+ //variables defined in %txt instructions
+
+ %nww="";%ierr=0; // to make sure %nww and %ierr does not enter the difference
+ if isempty(%txt) then return,end
+ %nww=size(who("get"),"*")
+
+ %ierr=execstr(%txt,"errcatch")
+ if %ierr<>0 then mprintf("%s\n",lasterror()), return,end
+
+ %mm=who("get")
+ %mm=%mm(1:size(%mm,"*")-%nww)
+ //%mm contains the list of the variables defined by execstr(%txt,'errcatch')
+ for %mi=%mm(:)'
+ if %mi=="scs_m" then
+ mprintf(_("The variable name %s cannot be used as block parameter: ignored"),"scs_m");
+ continue
+ elseif %mi=="ans" then
+ continue
+ end
+
+ clear %v
+ %v=evstr(%mi);
+
+ if typeof(%v)=="scs_m" then
+ mprintf(_("The variable name %s cannot be used as block parameter: ignored"),"scs_m")
+ continue
+ elseif or(type(%v)==[11 13 14]) then
+ continue
+ end
+
+ %ll(%mi)=%v;
+ clear %v
+ end
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/scs_full_path.bin b/modules/scicos/macros/scicos_scicos/scs_full_path.bin
new file mode 100755
index 000000000..5897dde40
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scs_full_path.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scs_full_path.sci b/modules/scicos/macros/scicos_scicos/scs_full_path.sci
new file mode 100755
index 000000000..4986982b2
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scs_full_path.sci
@@ -0,0 +1,31 @@
+// Scicos
+//
+// Copyright (C) INRIA - Serge Steer <serge.steer@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function path=scs_full_path(P)
+ // Given a path in the superclock hierachy, this function returns a path
+ // in the scs_m data structure
+ // P is a vector of numbers. All but the last entries are Superblocks index
+ // path is a list such as scs_m(path) is the required object
+
+ path=list("objs");
+ for l=P(1:$-1),path($+1)=l;path($+1)="model";path($+1)= "rpar";path($+1)="objs";end
+ path($+1)=P($);
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/scs_show.bin b/modules/scicos/macros/scicos_scicos/scs_show.bin
new file mode 100755
index 000000000..34d6a5fe5
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scs_show.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scs_show.sci b/modules/scicos/macros/scicos_scicos/scs_show.sci
new file mode 100755
index 000000000..61aea6699
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scs_show.sci
@@ -0,0 +1,47 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function scs_show(scs_m, win)
+ //**
+ //** 24 Nov 2006: Super simplified version
+ //**
+
+ if %scicos_debug_gr then
+ disp(_("scs_show active..."))
+ end
+
+ gh_curwin = scf(win) ;
+
+ if ~set_cmap(scs_m.props.options("Cmap")) then // add colors if required
+ scs_m.props.options("3D")(1)=%f //disable 3D block shape
+ end
+
+ options = scs_m.props.options ; //** not used
+
+ set_background(gh_curwin) ;
+ pwindow_set_size(gh_curwin) ;
+ window_set_size(gh_curwin) ;
+
+ scs_m.props.title(1) = msprintf(_("Scilab Graphics of %s"),scs_m.props.title(1))
+
+ drawobjs(scs_m, gh_curwin)
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/scstxtedit.bin b/modules/scicos/macros/scicos_scicos/scstxtedit.bin
new file mode 100755
index 000000000..f2b31006e
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scstxtedit.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/scstxtedit.sci b/modules/scicos/macros/scicos_scicos/scstxtedit.sci
new file mode 100755
index 000000000..0d60cbbbe
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/scstxtedit.sci
@@ -0,0 +1,62 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+//## scstxtedit : Input function of the text editor
+//## We exit from that function if Quit or use
+//## the commit button.
+//##
+//## Inputs : str_in : the input text to edit
+//## clos : a flag to close the window
+//## 0 : No
+//## 1 : close
+//##
+//## str_out : the edited output text
+//## can be [] if abort
+//## Quit : a flag to say if the buffer has been
+//## closed
+//## 0 : No
+//## 1 : Quit
+//##
+function [str_out,Quit] = scstxtedit(str_in,ptxtedit)
+ //** check lhs/rhs arg
+ [lhs,rhs]=argn(0)
+
+ //## param from ptxtedit
+ clos = ptxtedit.clos
+ typ = ptxtedit.typ
+ head = ptxtedit.head
+
+ if clos<>1 then
+ if head==[] then
+ str_out = dialog(["DIALOG"], str_in) ;
+ else
+ str_out = dialog([head], str_in) ;
+ end
+ else
+ str_out=[];
+ end
+
+ if str_out == [] then
+ Quit = 1
+ else
+ Quit = 0
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/set_io.bin b/modules/scicos/macros/scicos_scicos/set_io.bin
new file mode 100755
index 000000000..867dae496
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/set_io.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/set_io.sci b/modules/scicos/macros/scicos_scicos/set_io.sci
new file mode 100755
index 000000000..429854bf4
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/set_io.sci
@@ -0,0 +1,284 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [model,...
+ graphics,...
+ ok]=set_io(model,...
+ graphics,...
+ in#,...
+ out#,...
+ clkin,...
+ clkout,...
+ in_implicit,...
+ out_implicit)
+ // CHECK
+ if argn(2)<=6 then
+ in_implicit=[]
+ out_implicit=[], end
+ deff("[str__err]=str__err(err__,"+...
+ "str__#)",...
+ ["str__err=''ERROR''"
+ "select err__"
+ "case 1 then"
+ "str__err=str__#+...
+ ''put port "+...
+ "must be "+...
+ " list''"
+ "case 2 then"
+ "str__err=str__#+...
+ ''put list "+...
+ "must have "+...
+ "a size "+...
+ "of 2''"
+ "case 3 then"
+ "str__err=''First entry of ''+...
+ str__#+...
+ ''put list "+...
+ " must be "+...
+ "double "+...
+ "or integer''"
+ "case 4 then"
+ "str__err=''Second entry of ''+...
+ str__#+...
+ ''put list "+...
+ "must be "+...
+ "double "+...
+ "or integer''"
+ "case 10 then"
+ "str__err=str__#+...
+ ''put port "+...
+ "sizes "+...
+ "must have "+...
+ "a dimension "+...
+ "of nx2''"
+ "case 11 then"
+ "str__err=str__#+...
+ ''put port "+...
+ "sizes and ''+...
+ str__#+...
+ ''put port "+...
+ "type "+...
+ "must have "+...
+ "the same number "+...
+ "of rows''"
+ "case 100 then"
+ "str__err=str__#+...
+ ''put port "+...
+ "type must "+...
+ "be <=8''"
+ "end"])
+ deff("[var,"+...
+ "vart,"+...
+ "ierr,"+...
+ "ko]=extract__(var#)",...
+ ["ko=%f"
+ "ierr=0"
+ "var=[]"
+ "vart=1"
+ "if type(var#)<>15 then"
+ "ierr=1,"
+ "resume, end"
+ "if var#<>list() then"
+ "if lstsize(var#)<>2 then"
+ "ierr=2,"
+ "resume, end"
+ "for i=1:2"
+ "if ~(type(var#(i))==1|"+...
+ "type(var#(i))==8) then"
+ "ierr=2+i,"
+ "resume, end"
+ "end"
+ "if var#(1)<>[] then"
+ "if size(var#(1),2)<>2 then"
+ "ierr=10,"
+ "resume, end"
+ "if size(var#(1),1)<>"+...
+ "size(var#(2)(:),1) then"
+ "ierr=11,"
+ "resume, end"
+ "if max(var#(2))>8 then"
+ "ierr=100,"
+ "resume, end"
+ "var=int(var#(1))"
+ "vart=int(var#(2)(:))"
+ "end"
+ "end"
+ "ko=%t"])
+ [in,...
+ in_t,...
+ err__,...
+ ko]=extract__(in#)
+ if ~ko then
+ messagebox("set_io : "+ str__err(err__,"in") , "modal")
+ ok=%f
+ return, end
+ [out,..
+ out_t,...
+ err__,...
+ ko]=extract__(out#)
+ if ~ko then
+ messagebox("set_io : "+ str__err(err__, "out") ,"modal")
+ ok=%f
+ return, end
+
+ clkin=int(clkin(:))
+ nclkin=size(clkin,1)
+ if nclkin>0 then
+ if min(clkin)<1 then
+ messagebox("set_io : " + "Event input ports sizes must be positive","modal")
+ ok=%f
+ return, end
+ end
+ clkout=int(clkout(:))
+ nclkout=size(clkout,1)
+ if nclkout>0 then
+ if min(clkout)<1 then
+ messagebox("set_io : "+ "Event output ports sizes must be positive","modal")
+ ok=%f
+ return, end
+ end
+
+ // set_io first check if given numbe
+ // of ports agree with block connection
+ [label,...
+ ip1,...
+ op1,...
+ cip1,...
+ cop1]=(graphics.exprs,...
+ graphics.pin,...
+ graphics.pout,...
+ graphics.pein,...
+ graphics.peout)
+ [in1,...
+ in2,...
+ intyp,...
+ out1,...
+ out2,...
+ outtyp,...
+ clkin1,...
+ clkout1]=(model.in,...
+ model.in2,...
+ model.intyp,...
+ model.out,...
+ model.out2,...
+ model.outtyp,...
+ model.evtin,...
+ model.evtout)
+
+ n1=size(in1(:,1),"*") //current number of input port of model
+ n=size(in(:,1),"*") //given number of input port
+ if n1>n then
+ // if or(ip1(n+1:$)>0) then
+ // messagebox('set_io : '+'Connected ports cannot be suppressed','modal')
+ // ok=%f
+ // return, end
+ ip1=ip1(1:n)
+ else
+ ip1=[ip1;zeros(n-n1,1)]
+ end
+ n1=size(out1(:,1),"*")
+ n=size(out(:,1),"*")
+ if n1>n then
+ // if or(op1(n+1:$)>0) then
+ // messagebox('set_io : '+...
+ // 'Connected ports cannot be suppressed', 'modal')
+ // ok=%f
+ // return, end
+ op1=op1(1:n)
+ else
+ op1=[op1;zeros(n-n1,1)]
+ end
+
+ n1=size(clkin1,"*")
+ n=size(clkin,"*")
+ if n1>n then
+ // if or(cip1(n+1:$)>0) then
+ // messagebox('set_io : '+...
+ // 'Connected ports cannot be suppressed','modal')
+ // ok=%f
+ // return, end
+ cip1=cip1(1:n)
+ else
+ cip1=[cip1;zeros(n-n1,1)]
+ end
+ n1=size(clkout1,"*")
+ n=size(clkout,"*")
+ if n1>n then
+ // if or(cop1(n+1:$)>0) then
+ // messagebox('set_io : '+...
+ // 'Connected ports cannot be suppressed','modal')
+ // ok=%f
+ // return, end
+ cop1=cop1(1:n)
+ else
+ cop1=[cop1;zeros(n-n1,1)]
+ end
+
+ I="E"
+
+ if ip1<>[] then
+ in_impl=I(ones(ip1))
+ in_impl(in_implicit)="I"
+ // kk=size(graphics.in_implicit,'*')
+ // k=find(ip1<>0) //connected links
+ // k=k(find(k<=kk))
+ // if or(graphics.in_implicit(k)<>in_impl(k)) then
+ // messagebox('set_io : '+...
+ // 'Connected ports types cannot be changed','modal')
+ // ok=%f
+ // return, end
+ else
+ in_impl=[]
+ end
+ if op1<>[] then
+ out_impl=I(ones(op1))
+ out_impl(out_implicit)="I"
+ // kk=size(graphics.out_implicit,'*')
+ // k=find(op1<>0) //connected links
+ // k=k(find(k<=kk))
+ // if or(graphics.out_implicit(k)<>out_impl(k)) then
+ // messagebox('set_io : '+...
+ // 'Connected ports types cannot be changed','modal')
+ // ok=%f
+ // return, end
+ else
+ out_impl=[]
+ end
+
+ // SET
+ ok=%t
+ graphics.pin=ip1
+ graphics.pout=op1
+ graphics.pein=cip1
+ graphics.peout=cop1
+ graphics.in_implicit=in_impl
+ graphics.out_implicit=out_impl
+ model.in=in(:,1)
+ model.in2=in(:,2)
+ model.intyp=in_t
+ model.out=out(:,1)
+ model.out2=out(:,2)
+ model.outtyp=out_t
+ model.evtin=clkin
+ model.evtout=clkout
+
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/setvalue.bin b/modules/scicos/macros/scicos_scicos/setvalue.bin
new file mode 100755
index 000000000..0d1ad7bfd
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/setvalue.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/setvalue.sci b/modules/scicos/macros/scicos_scicos/setvalue.sci
new file mode 100755
index 000000000..742c1aac3
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/setvalue.sci
@@ -0,0 +1,282 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// - Alan Layec <alan.layec@inria.fr>
+// Copyright (C) 2010 - DIGITEO - Clément DAVID <clement.david@scilab.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [%ok,%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]=setvalue(%desc,%lables,%typ,%ini)
+
+ // To avoid infinite loops in set section of blocks during eval
+ if %scicos_prob==%t then
+ %ok=%f
+ [%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]=(0,0,0,0,0,...
+ 0,0,0,0,0,...
+ 0,0,0,0,0,...
+ 0,0,0,0,0,...
+ 0,0,0,0,0,...
+ 0,0,0,0,0)
+ return;end
+ // setvalues - data acquisition, getvalue equivalent without dialog
+ //%Syntax
+ // [%ok,x1,..,x18]=setvalue(desc,labels,typ,ini)
+ //%Parameters
+ // desc : column vector of strings, dialog general comment
+ // labels : n column vector of strings, labels(i) is the label of
+ // the ith required value
+ // typ : list(typ1,dim1,..,typn,dimn)
+ // typi : defines the type of the ith required value
+ // if may have the following values:
+ // 'mat' : stands for matrix of scalars
+ // 'col' : stands for column vector of scalars
+ // 'row' : stands for row vector of scalars
+ // 'vec' : stands for vector of scalars
+ // 'str' : stands for string
+ // 'lis' : stands for list
+ // 'pol' : stands for polynomials
+ // 'r' : stands for rational
+ // dimi : defines the size of the ith required value
+ // it must be
+ // - an integer or a 2-vector of integers (-1 stands for
+ // arbitrary dimension)
+ // - an evaluatable character string
+ // ini : n column vector of strings, ini(i) gives the suggested
+ // response for the ith required value
+ // %ok : boolean ,%t if %ok button pressed, %f if cancel button pressed
+ // xi : contains the ith required value if %ok==%t
+ //%Description
+ // getvalues function uses ini strings to evaluate required args
+ // with error checking,
+ //%Remarks
+ // All correct scilab syntax may be used as responses, for matrices
+ // and vectors getvalues automatically adds [ ] around the given response
+ // before numerical evaluation
+ //%Example
+ // labels=['magnitude';'frequency';'phase '];
+ // [ampl,freq,ph]=setvalue('define sine signal',labels,..
+ // list('vec',1,'vec',1,'vec',1),['0.85';'10^2';'%pi/3'])
+ //
+ //%See also
+ // x_mdialog, dialog
+ //!
+ // 17/01/07 -Alan- - %scicos_context behavior reviewed in accordance to context_evstr macro
+ // - pass int in field of type vec/mat/row/col (F. Nassif's Work)
+ //
+ // 05/02/07 -Alan- : update to %20 rhs parameters
+ //
+ // Copyright INRIA
+ [%lhs,%rhs]=argn(0)
+
+ %nn=prod(size(%lables))
+ if %lhs<>%nn+2&%lhs<>%nn+1 then error(41),end
+ if size(%typ)<>2*%nn then
+ error("typ : list(''type'',[sizes],...)")
+ end
+ %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=[];
+
+ if %rhs==3 then %ini=emptystr(%nn,1),end
+ %ok=%t
+ while %t do
+ %str=%ini;
+ if %str==[] then %ok=%f,break,end
+ for %kk=1:%nn
+ %cod=ascii(%str(%kk))
+ %spe=find(%cod==10)
+ if %spe<>[] then
+ %semi=ascii(";")
+ %cod(%spe)=%semi*ones(%spe')
+ %str(%kk)=ascii(%cod)
+ end
+ end
+
+ [%vv_list,%ierr_vec]=context_evstr(%str,%scicos_context,%typ);
+
+ %noooo=0
+ for %kk=1:%nn
+ %vv=%vv_list(%kk)
+ %ierr=%ierr_vec(%kk)
+ select part(%typ(2*%kk-1),1:6)
+ case "mat "
+ if %ierr<>0 then
+ %noooo=-%kk,break,
+ end
+ //29/12/06
+ //the type of %vv is accepted if it is constant or integer
+ if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ [%mmmm,%nnnnn]=size(%vv)
+ %ssss=string(%sz(1))+"-by-"+string(%sz(2)) + " matrix"
+ if %mmmm*%nnnnn==0 then
+ if %sz(1)>=0&%sz(2)>=0&%sz(1)*%sz(2)<>0 then %noooo=%kk,break,end
+ else
+ if %sz(1)>=0 then if %mmmm<>%sz(1) then %noooo=%kk,break,end,end
+ if %sz(2)>=0 then if %nnnnn<>%sz(2) then %noooo=%kk,break,end,end
+ end
+ case "vec "
+ if %ierr<>0 then
+ %noooo=-%kk,break,
+ end
+ //17/01/07
+ //the type of %vv is accepted if it is constant or integer
+ if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ %ssss=string(%sz(1))
+ %nnnnn=prod(size(%vv))
+ if %sz(1)>=0 then if %nnnnn<>%sz(1) then %noooo=%kk,break,end,end
+ case "intvec"
+ if %ierr<>0 then
+ %noooo=-%kk,break,
+ end
+ //the type of %vv is accepted if it is constant or integer
+ if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ %ssss=string(%sz(1))
+ %nnnnn=prod(size(%vv))
+ if %sz(1)>=0 then if %nnnnn<>%sz(1) then %noooo=%kk,break,end,end
+ case "pol "
+ if %ierr<>0 then
+ %noooo=-%kk,break,
+ end
+ if %ierr<>0 then %noooo=-%kk;break,end
+ if (type(%vv)>2 & type(%vv)<>8) then %noooo=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ %ssss=string(%sz(1))
+ %nnnnn=prod(size(%vv))
+ if %sz(1)>=0 then if %nnnnn<>%sz(1) then %noooo=%kk,break,end,end
+ case "row "
+ if %ierr<>0 then
+ %noooo=-%kk,break,
+ end
+ //17/01/07
+ //the type of %vv is accepted if it is constant or integer
+ if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ if %sz(1)<0 then
+ %ssss="1-by-n matrix"
+ else
+ %ssss="1-by-"+string(%sz(1))+" matrix"
+ end
+ [%mmmm,%nnnnn]=size(%vv)
+ if %mmmm<>1 then %noooo=%kk,break,end,
+ if %sz(1)>=0 then if %nnnnn<>%sz(1) then %noooo=%kk,break,end,end
+ case "col "
+ if %ierr<>0 then
+ %noooo=-%kk,break,
+ end
+ //17/01/07
+ //the type of %vv is accepted if it is constant or integer
+ if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ if %sz(1)<0 then
+ %ssss="m-by-1 matrix"
+ else
+ %ssss=string(%sz(1))+"-by-1 matrix"
+ end
+ [%mmmm,%nnnnn]=size(%vv)
+ if %nnnnn<>1 then %noooo=%kk,break,end,
+ if %sz(1)>=0 then if %nnnnn<>%sz(1) then %noooo=%kk,break,end,end
+ case "str "
+ clear %vv
+ %vv=%str(%kk)
+ if type(%vv)<>10 then %noooo=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ %ssss=string(%sz(1))
+ %nnnnn=prod(size(%vv))
+ if %sz(1)>=0 then if %nnnnn<>1 then %noooo=%kk,break,end,end
+ case "lis "
+ if %ierr<>0 then
+ %noooo=-%kk,break,
+ end
+ if type(%vv)<>15& type(%vv)<>16& type(%vv)<>17 then %noooo=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ %ssss=string(%sz(1))
+ %nnnnn=size(%vv)
+ if %sz(1)>=0 then if %nnnnn<>%sz(1) then %noooo=%kk,break,end,end
+ case "r "
+ if %ierr<>0 then
+ %noooo=-%kk,break,
+ end
+ if type(%vv)<>16 then %noooo=-%kk,break,end
+ if typeof(%vv)<>"rational" then %noooo=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ [%mmmm,%nnnnn]=size(%vv(2))
+ %ssss=string(%sz(1))+"-by-"+string(%sz(2))
+ if %mmmm*%nnnnn==0 then
+ if %sz(1)>=0&%sz(2)>=0&%sz(1)*%sz(2)<>0 then %noooo=%kk,break,end
+ else
+ if %sz(1)>=0 then if %mmmm<>%sz(1) then %noooo=%kk,break,end,end
+ if %sz(2)>=0 then if %nnnnn<>%sz(2) then %noooo=%kk,break,end,end
+ end
+ case "gen "
+ //accept all
+ else
+ str = gettext("%s: Type %s is not implemented.\n");
+ mess = msprintf(str, arg1.gui + "(''set'')", %typ(2*%kk-1));
+ if length(arg1.doc) > 0 then
+ warnBlockByUID(arg1.doc(1), mess); // arg1 is from the block interface function
+ else
+ error(mess);
+ end
+ end
+ execstr("%"+string(%kk)+"=%vv")
+ clear %vv
+ end
+ if %noooo>0 then
+ str = gettext("%s: Wrong size for block parameter ''%s'': %s expected, getting %s");
+ mess = msprintf(str, arg1.gui + "(''set'')", %lables(%noooo), %ssss, %ini(%noooo));
+ if length(arg1.doc) > 0 then
+ warnBlockByUID(arg1.doc(1), mess); // arg1 is from the block interface function
+ else
+ disp(mess);
+ end
+ %ini=%str
+ %ok=%f;break
+ elseif %noooo<0 then
+ str = gettext("%s: Wrong type for block parameter ''%s'': %s(%s) expected, getting %s");
+ mess = msprintf(str, arg1.gui + "(''set'')", %lables(-%noooo), %typ(-2*%noooo-1), strcat(string(%typ(-2*%noooo))," by "), %ini(-%noooo));
+ if length(arg1.doc) > 0 then
+ warnBlockByUID(arg1.doc(1), mess); // arg1 is from the block interface function
+ else
+ disp(mess);
+ end
+ %ini=%str
+ %ok=%f;break
+ else
+ break
+ end
+ end
+ if %lhs==%nn+2 then
+ execstr("%"+string(%lhs-1)+"=%str")
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/shiftcors.bin b/modules/scicos/macros/scicos_scicos/shiftcors.bin
new file mode 100755
index 000000000..c3827b83e
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/shiftcors.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/shiftcors.sci b/modules/scicos/macros/scicos_scicos/shiftcors.sci
new file mode 100755
index 000000000..c96b11d71
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/shiftcors.sci
@@ -0,0 +1,32 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function cors=shiftcors(cors,ns)
+ n=size(cors)
+ for k=1:n
+ if type(cors(k))==15 then
+ cors(k)=shiftcors(cors(k),ns)
+ else
+ if cors(k)<0 then cors(k)=cors(k);
+ elseif cors(k)<>0 then cors(k)=cors(k)+ns,end
+ end
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/split_lasterror.bin b/modules/scicos/macros/scicos_scicos/split_lasterror.bin
new file mode 100755
index 000000000..473217102
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/split_lasterror.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/split_lasterror.sci b/modules/scicos/macros/scicos_scicos/split_lasterror.sci
new file mode 100755
index 000000000..5ee5d1aa1
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/split_lasterror.sci
@@ -0,0 +1,47 @@
+// Scicos
+//
+// Copyright (C) INRIA - Alan Layec <alan.layec@inria.fr>
+// Copyright (C) 2012-2012 - Scilab Enterprises - Bruno JOFRET
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function str_out=split_lasterror(str_in)
+ //** Fix the unreadable error messages
+ //** returned by the simulator.
+ //** Alan, 11/10/07 : Initial rev
+ str_out = [];
+ for nLine = 1:size(str_in, "r")
+ ind_bl=strindex(str_in(nLine)," ");
+
+ // Find some room in a line with more than 50 characters.
+ if find(ind_bl > 50) <> [] then
+ ind_bl2 = ind_bl;
+ nind = [];
+ for i = 1:size(ind_bl,2)
+ if ind_bl2(i) > 50 then
+ nind = [nind ; ind_bl(i)];
+ ind_bl2 = ind_bl2 - ind_bl2(i);
+ end
+ end
+ str_out = [str_out ; strsplit(str_in(nLine),nind)]
+ else
+ str_out = [str_out ; str_in(nLine)];
+ end
+
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/standard_define.bin b/modules/scicos/macros/scicos_scicos/standard_define.bin
new file mode 100755
index 000000000..dbe5283a1
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_define.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/standard_define.sci b/modules/scicos/macros/scicos_scicos/standard_define.sci
new file mode 100755
index 000000000..f0d390cea
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_define.sci
@@ -0,0 +1,52 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function o=standard_define(sz,model,label,gr_i)
+ //initialize graphic part of the block data structure
+
+ if argn(2)<4 then gr_i=[],end
+
+ nin=size(model.in,1);
+ if nin>0 then pin(nin,1)=0,else pin=[],end
+
+ nout=size(model.out,1);
+ if nout>0 then pout(nout,1)=0,else pout=[],end
+
+ ncin=size(model.evtin,1);
+ if ncin>0 then pein(ncin,1)=0,else pein=[],end
+
+ ncout=size(model.evtout,1);
+ if ncout>0 then peout(ncout,1)=0,else peout=[],end
+
+ if type(gr_i)<>15 then gr_i=list(gr_i,8),end
+ if gr_i(2)==[] then gr_i(2)=8,end
+ if gr_i(2)==0 then gr_i(2)=[],end
+
+ graphics=scicos_graphics(sz=sz,pin=pin,pout=pout,pein=pein,peout=peout, ...
+ gr_i=gr_i,exprs=label)
+
+ // if model.sim(1)=='super' then
+ // o=scicos_block(graphics=graphics,model=model,gui='SUPER_f')
+ // else
+ [ln,mc]=where()
+ o=scicos_block(graphics=graphics,model=model,gui=mc(2))
+ // end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/standard_draw.bin b/modules/scicos/macros/scicos_scicos/standard_draw.bin
new file mode 100755
index 000000000..3041e473d
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_draw.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/standard_draw.sci b/modules/scicos/macros/scicos_scicos/standard_draw.sci
new file mode 100755
index 000000000..569358f36
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_draw.sci
@@ -0,0 +1,251 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function standard_draw (o, frame, draw_ports, up)
+ //
+ //
+ //** This function is used to draw the object from the most of (but NOT all) the interface functions
+ //**
+ //** 21 Nov 2006 : some save/restore patch moved to upper level "drawobj.sci"
+ //** 22 Jun 2009 (Serge Steer INRIA)
+ // - gh_curwin.children use replaced by gh_axes to get the
+ // axes children because uimenu are now children of the figure
+ // - use gh_blk for argument of dig_bound_compound
+ // - use of gh_text to set text properties of the indentifier (instead
+ // of modifying the correponding axes properties
+
+ xf = 60 ; yf = 40 ;
+
+ [lhs,rhs] = argn(0)
+
+ if rhs==1 then
+ frame=%t
+ end
+
+ if rhs<3 then
+ draw_ports = standard_draw_ports //** left right ports
+ //** the function 'standard_draw_ports' it's copied in 'draw_ports'
+ elseif rhs==4 then //** otherwise
+ draw_ports = standard_draw_ports_up //** up / down ports
+ end //** the function 'standard_draw_ports_up' it's copied in 'draw_ports'
+
+ nin = size(o.model.in,1);
+ nout = size(o.model.out,1);
+ clkin = size(o.model.evtin,1);
+ clkout= size(o.model.evtout,1);
+ [orig,sz,orient] = (o.graphics.orig,o.graphics.sz,o.graphics.flip)
+
+ //** Default values -------------------
+ thick = 1 ; //** patch Simone
+ e = 4 ;
+ With3D = options("3D")(1)
+ //** ----------------------------------
+
+ gr_i = o.graphics.gr_i
+
+ if type(gr_i) == 15 then
+ [gr_i,coli] = gr_i(1:2) ;
+ else
+ coli = [] ;
+ end
+
+ //** --------------------------------------- draw box ------------------------------------------------
+ if frame then
+ if With3D then //** this is the code relative to the block's "window dressing"
+ //**---------- 3D Mode ON -----------------------------------------------------------------------
+ #Color3D = options("3D")(2)
+ // xpoly([orig(1)+e;orig(1)+sz(1);orig(1)+sz(1)],[orig(2)+sz(2);orig(2)+sz(2);orig(2)+e],'lines')
+ xrect( orig(1)+e, orig(2)+sz(2), sz(1)-e, sz(2)-e) ;
+ gh_e = gce(); //** new graphics :)
+ gh_e.thickness = 0 ;
+ gh_e.foreground = #Color3D ;
+
+ if coli<>[] then
+ gh_e.fill_mode = "on" ;
+ gh_e.background = coli ;
+ end
+
+ xx = [ orig(1) , orig(1)
+ orig(1) , orig(1)+sz(1)-e
+ orig(1)+e , orig(1)+sz(1)
+ orig(1)+e , orig(1)+e] ;
+
+ yy = [orig(2) , orig(2)
+ orig(2)+sz(2)-e , orig(2)
+ orig(2)+sz(2) , orig(2)+e
+ orig(2)+e , orig(2)+e];
+
+ xfpolys(xx,yy,-[1,1]*#Color3D); //** fill a set of polygons
+ gh_e = gce() ;
+ gh_c = gh_e.children(1:2) ;
+ gh_c.foreground = default_color(0) ;
+ gh_c.thickness = 2 ;
+
+ else //** not in 3D mode
+ //**----------3D Mode OFF -------------------------------------------------------------------------
+ e = 0 ;
+ xrect(orig(1),orig(2)+sz(2),sz(1),sz(2)) ;
+ gh_e = gce() ;
+ gh_e.thickness = 2 ;
+
+ if coli<>[] then
+ gh_e.fill_mode = "on" ;
+ gh_e.background = coli ;
+ end
+
+ end //** of 3D mode ON/OFF
+ end //** of the frame mode
+ draw_ports(o) ; //** 'standard_draw_ports' or 'standard_draw_ports_up'
+ //** --------------------------------------------------------------------------------------------------------------
+
+ //** ---- scs_m , %cpr Indexes Show including information on internal superblocks ---------------------------------
+ if exists("%scicos_with_grid") then
+ if %scicos_with_grid then
+ scs_m_i=[]; cpr_i=[] ; sflag=[] ;
+ win_id = gh_current_window.figure_id
+
+ kc = find(win_id==windows(:,2))
+
+ pal = windows(kc,1);
+
+ if pal > 0 then
+ if ~exists("scs_m_index") then scs_m_index=-1, end
+ [scs_m_i, cpr_i, sflag] = get2index(o, scs_m_index);
+
+ txt_index = [];
+ if scs_m_i<>[] & cpr_i<>[] then
+ if sflag<>[] then
+ txt_index = string(scs_m_i)+"s, "+cpr_i+"c";
+ else
+ txt_index = string(scs_m_i)+"s, "+string(cpr_i)+"c";
+ end
+ end
+
+ gh_axes = gca(); //** get the Axes proprieties
+
+ // draw indexes
+ if txt_index<>[] then
+
+ //@@ compute bbox
+ rect = stringbox(txt_index, orig(1), orig(2), 0,...
+ options.ID(1)(1), options.ID(1)(2));
+
+ w = (rect(1,3)-rect(1,2)) * %zoom;
+ w = max(w, sz(1));
+ h = (rect(2,2)-rect(2,4)) * 1.3 * %zoom/1.4;
+
+ //@@ fill txt_index in a box
+ xstringb(orig(1) + sz(1) / 2 - w / 2, orig(2) + sz(2), txt_index , w, h,"fill") ;
+ gh_txt = gce();
+ gh_txt.font_style = options.ID(1)(1) ;
+ gh_txt.font_size = options.ID(1)(2) ;
+
+ end
+ end
+ end
+ end //** of on/off control
+ //** --------------------------------------------------------------------------------------------------------------
+
+ //** --------------------------------- draw gr_i ---------------------------------
+ o_size=size(gh_axes.children)
+ deff("c=scs_color(c)"," ") ; //** on line function definition
+ gr_i = [gr_i]; //** simple but not simpler :)
+ model = o.model
+ if With3D & frame then
+ orig = orig + e ;
+ sz = sz - e ;
+ end
+ //@@ Alan,28/11/08 : protect variables of standard_draw
+ deff("ierr=exec_gr_i(gr_i)","ierr=execstr(gr_i,''errcatch'',''n'');") ; //** on line function definition
+ //** Check of the graphics object has generated any error
+ if exec_gr_i(gr_i)<>0 then
+ messagebox(["Error in Icon defintion"; lasterror()],"modal")
+ end
+ //** -----------------------------------------------------------------------------
+
+ //** -------------------------------- Identification --------------------------------------------------------------
+
+ ident = o.graphics.id
+
+ // draw Identification
+ if ident<>[] & ident<>"" then
+
+
+ //@@ compute bbox of gr object
+
+ p_size=size(gh_axes.children);
+ if p_size(1)-o_size(1)<>0 then
+ gh_blk=glue(gh_axes.children(1:(p_size(1)-o_size(1))));
+ rect=dig_bound_compound(gh_blk)
+ //@@ Alan,28/11/08 : I redraw all here because glue/unglue op change
+ //@@ some properties of objects in the compound
+ //unglue(gh_blk)
+ delete(gh_blk)
+ exec_gr_i(gr_i) //@@ no test here : this have been done previously
+ else
+ rect=[orig(1) orig(2) orig(1)+sz(1) orig(2)+sz(2)]
+ end
+ if With3D & frame then
+ rect(1,1)=rect(1,1)-e
+ rect(1,2)=rect(1,2)-e
+ orig = orig - e ;
+ sz = sz + e ;
+ end
+ //rect(1,1)=min(rect(1,1),orig(1))
+ rect(1,2)=min(rect(1,2),orig(2))
+ //rect(1,3)=max(rect(1,3),orig(1)+sz(1))
+ rect(1,4)=max(rect(1,4),orig(2)+sz(2))
+
+ //@@ compute bbox
+ rectstr = stringbox(ident, rect(1,1), rect(1,2), 0,...
+ options.ID(1)(1), options.ID(1)(2));
+ w=(rectstr(1,3)-rectstr(1,2)) * %zoom;
+ h=(rectstr(2,2)-rectstr(2,4)) * %zoom;
+
+ //@@ fill ident in a box
+ xstringb(orig(1) + sz(1) / 2 - w / 2, rect(1,2) - (h*1.1) , ident , ...
+ w, h,"fill") ;
+ //@@ Serge 22 Jun 2009
+ gh_text=gce();
+ gh_text.font_style = options.ID(1)(1) ;
+ gh_text.font_size = options.ID(1)(2) ;
+ gh_text.font_foreground = options.ID(1)(3) ; //@@
+
+ //@@ set visible
+ if gh_axes.children(1).type == "Text" then
+ if options.ID(1)(4)==0 then
+ gh_axes.children(1).visible="off"
+ else
+ gh_axes.children(1).visible="on"
+ end
+ else //@@compound
+ for i=1:size(gh_axes.children(1).children,1)
+ if options.ID(1)(4)==0 then
+ gh_axes.children(1).children(i).visible="off"
+ else
+ gh_axes.children(1).children(i).visible="on"
+ end
+ end
+ end
+ end
+ //** --------------------------- Identification End --------------------------------------------------------------
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/standard_draw_ports.bin b/modules/scicos/macros/scicos_scicos/standard_draw_ports.bin
new file mode 100755
index 000000000..69330a7f8
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_draw_ports.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/standard_draw_ports.sci b/modules/scicos/macros/scicos_scicos/standard_draw_ports.sci
new file mode 100755
index 000000000..f5045b0c5
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_draw_ports.sci
@@ -0,0 +1,211 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function standard_draw_ports(o)
+
+ nin = size(o.model.in,1);
+ nout= size(o.model.out,1);
+ inporttype = o.graphics.in_implicit
+ outporttype = o.graphics.out_implicit
+ clkin = size(o.model.evtin,1);
+ clkout = size(o.model.evtout,1);
+
+ [orig,sz,orient]=(o.graphics.orig,o.graphics.sz,o.graphics.flip)
+
+ // xset('pattern',default_color(0));
+ // xset('thickness',1)
+ // draw input/output ports
+ //------------------------
+
+ //** --------- For the implict mode only ----------
+ //if o.model.sim=='inimpl' then pause, end
+ //** -----------------------------------------------
+
+
+ if orient then //standard orientation
+ // set port shape
+ out1=[ 0 -1
+ 1 0
+ 0 1
+ 0 -1]*diag([xf/7,yf/14])
+
+ in1= [-1 -1
+ 0 0
+ -1 1
+ -1 -1]*diag([xf/7,yf/14])
+
+ out2=[ 0 -1
+ 1 -1
+ 1 1
+ 0 1]*diag([xf/7,yf/14])
+
+ in2= [-1 -1
+ 0 -1
+ 0 1
+ -1 1]*diag([xf/7,yf/14])
+ dy=sz(2)/(nout+1)
+
+ //** xset('pattern',default_color(1))
+
+ for k=1:nout
+
+ if outporttype==[] then
+ xfpoly( out1(:,1)+ones(4,1)*(orig(1)+sz(1)), out1(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*k), 1)
+ else
+ if outporttype(k)=="E" then
+ xfpoly(out1(:,1)+ones(4,1)*(orig(1)+sz(1)),out1(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*k),1)
+ elseif outporttype(k)=="I" then
+ xpoly(out2(:,1)+ones(4,1)*(orig(1)+sz(1)), out2(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*k),"lines",1)
+ end
+ end
+
+ // gh_e = gce();
+ // gh_e.thickness = 1 ;
+ // gh_e.foreground = default_color(1)
+
+
+ end //** end of for
+
+ dy=sz(2)/(nin+1)
+
+ for k=1:nin
+
+ if inporttype==[] then
+ xfpoly(in1(:,1)+ones(4,1)*orig(1), in1(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*k),1)
+ else
+ if inporttype(k)=="E" then
+ xfpoly(in1(:,1)+ones(4,1)*orig(1), in1(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*k),1)
+ elseif inporttype(k)=="I" then
+ xfpoly(in2(:,1)+ones(4,1)*orig(1), in2(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*k),1)
+ end
+ end
+
+ // gh_e = gce();
+ // gh_e.thickness = 1 ;
+ // gh_e.foreground = default_color(1)
+
+
+ end //** end of for
+
+ else //tilded orientation
+ out1=[0 -1
+ -1 0
+ 0 1
+ 0 -1]*diag([xf/7,yf/14])
+
+ in1= [1 -1
+ 0 0
+ 1 1
+ 1 -1]*diag([xf/7,yf/14])
+
+ out2=[0 -1
+ -1 -1
+ -1 1
+ 0 1]*diag([xf/7,yf/14])
+
+ in2= [1 -1
+ 0 -1
+ 0 1
+ 1 1]*diag([xf/7,yf/14])
+
+
+ dy=sz(2)/(nout+1)
+
+ // xset('pattern',default_color(1))
+ for k=1:nout
+
+ if outporttype==[] then
+ xfpoly(out1(:,1)+ones(4,1)*orig(1)-1, out1(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*k),1)
+ else
+ if outporttype(k)=="E" then
+ xfpoly(out1(:,1)+ones(4,1)*orig(1)-1, out1(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*k),1)
+ elseif outporttype(k)=="I" then
+ xpoly(out2(:,1)+ones(4,1)*orig(1)-1, out2(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*k),"lines",1)
+ end
+ end
+
+ //gh_e = gce();
+ //gh_e.thickness = 1 ;
+ // gh_e.foreground = default_color(1)
+
+ end //** end of for
+
+ dy=sz(2)/(nin+1)
+ for k=1:nin
+ if inporttype==[] then
+ xfpoly(in1(:,1)+ones(4,1)*(orig(1)+sz(1))+1, in1(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*k),1)
+ else
+ if inporttype(k)=="E" then
+ xfpoly(in1(:,1)+ones(4,1)*(orig(1)+sz(1))+1, in1(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*k),1)
+ elseif inporttype(k)=="I" then
+ xfpoly(in2(:,1)+ones(4,1)*(orig(1)+sz(1))+1, in2(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*k),1)
+ end
+ end
+
+ end //** end of for
+
+ // gh_e = gce();
+ // gh_e.thickness = 1 ;
+ // gh_e.foreground = default_color(1)
+
+ end
+
+ //**----------------------------------------------------------------------------------------------------
+ // draw input/output clock ports
+ //------------------------
+ // set port shape
+
+ out= [-1 0
+ 0 -1
+ 1 0
+ -1 0]*diag([xf/14,yf/7])
+
+
+ in= [-1 1
+ 0 0
+ 1 1
+ -1 1]*diag([xf/14,yf/7])
+
+
+ dx=sz(1)/(clkout+1)
+ //** xset('pattern',default_color(-1))
+
+ for k=1:clkout
+ xfpoly(out(:,1)+ones(4,1)*(orig(1)+k*dx), out(:,2)+ones(4,1)*orig(2),1)
+ gh_e = gce();
+ // gh_e.thickness = 1 ;
+ gh_e.foreground = default_color(-1); //** non so perche' ...
+ gh_e.background = default_color(-1); //** ... ma funziona :)
+ // pause
+ end
+
+ dx=sz(1)/(clkin+1)
+ for k=1:clkin
+ xfpoly(in(:,1)+ones(4,1)*(orig(1)+k*dx), in(:,2)+ones(4,1)*(orig(2)+sz(2)),1);
+ gh_e = gce();
+ // gh_e.thickness = 1 ;
+ gh_e.foreground = default_color(-1);
+ gh_e.background = default_color(-1);
+ end
+
+ //** xset('pattern',default_color(0))
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/standard_draw_ports_up.bin b/modules/scicos/macros/scicos_scicos/standard_draw_ports_up.bin
new file mode 100755
index 000000000..d31c1564f
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_draw_ports_up.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/standard_draw_ports_up.sci b/modules/scicos/macros/scicos_scicos/standard_draw_ports_up.sci
new file mode 100755
index 000000000..e01d882e3
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_draw_ports_up.sci
@@ -0,0 +1,56 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function standard_draw_ports_up(o)
+
+ nin=size(o.model.in,1);
+
+ inporttype=o.graphics.in_implicit
+ nout=size(o.model.out,1);
+ outporttype=o.graphics.out_implicit
+ [orig,sz,orient]=(o.graphics.orig,o.graphics.sz,o.graphics.flip)
+ xset("pattern",default_color(0));
+
+ // set port shape
+
+ out2=[0 -1
+ -1 -1
+ -1 1
+ 0 1]*diag([xf/7,yf/14])
+
+ in2= [1 -1
+ 0 -1
+ 0 1
+ 1 1]*diag([xf/7,yf/14])
+
+
+ dy=sz(2)/3
+ xset("pattern",default_color(1))
+ xpoly(out2(:,1)+ones(4,1)*orig(1)-1,..
+ out2(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*2),"lines",1)
+ xpoly(in2(:,1)+ones(4,1)*(orig(1)+sz(1))+1,..
+ in2(:,2)+ones(4,1)*(orig(2)+sz(2)-dy*2),"lines",1)
+ xfpoly(out2(:,1)+ones(4,1)*orig(1)-1,..
+ out2(:,2)+ones(4,1)*(orig(2)+sz(2)-dy),1)
+ xfpoly(in2(:,1)+ones(4,1)*(orig(1)+sz(1))+1,..
+ in2(:,2)+ones(4,1)*(orig(2)+sz(2)-dy),1)
+
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/standard_inputs.bin b/modules/scicos/macros/scicos_scicos/standard_inputs.bin
new file mode 100755
index 000000000..92307a1da
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_inputs.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/standard_inputs.sci b/modules/scicos/macros/scicos_scicos/standard_inputs.sci
new file mode 100755
index 000000000..6bd490a4e
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_inputs.sci
@@ -0,0 +1,76 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [x,y,typ]=standard_inputs(o)
+ //get position of inputs ports and clock inputs port for a standard block
+ // the input ports are located on the left (or rigth if tilded) vertical
+ // side of the block, regularly located from top to bottom
+ // the clock input ports are located on the top horizontal side
+ // side of the block, regularly located from left to right
+ xf=60
+ yf=40
+ graphics=o.graphics
+ model=o.model
+ orig=graphics.orig;sz=graphics.sz;orient=graphics.flip;
+ inp=size(model.in,1);clkinp=size(model.evtin,1);
+ if orient then
+ xo=orig(1)
+ dx=-xf/7
+ else
+ xo=orig(1)+sz(1)
+ dx=yf/7
+ end
+
+ typ=[];
+
+ //if o.model.sim=='valve' then pause,end
+ if inp==0 then
+ x=[];y=[];
+ else
+ y=orig(2)+sz(2)-(sz(2)/(inp+1))*(1:inp)
+ x=(xo+dx)*ones(y)
+ for k=1:inp
+ if o.graphics.in_implicit==[] then
+ typ=ones(x)
+ else
+ if o.graphics.in_implicit(k)=="E" then
+ typ=[typ ones(x(k))]
+ elseif o.graphics.in_implicit(k)=="I" then
+ typ=[typ 2*ones(x(k))]
+ end
+ end
+ end
+ end
+
+ if clkinp<>0 then
+ x=[x,orig(1)+(sz(1)/(clkinp+1))*(1:clkinp)]
+ y=[y,(orig(2)+yf/7+sz(2))*ones(1,clkinp)]
+ typ=[typ,-ones(1,clkinp)]
+ end
+endfunction
+
+
+
+
+
+
+
+
diff --git a/modules/scicos/macros/scicos_scicos/standard_origin.bin b/modules/scicos/macros/scicos_scicos/standard_origin.bin
new file mode 100755
index 000000000..c1c889283
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_origin.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/standard_origin.sci b/modules/scicos/macros/scicos_scicos/standard_origin.sci
new file mode 100755
index 000000000..ff0b54119
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_origin.sci
@@ -0,0 +1,26 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [x,y]=standard_origin(o)
+ //orig=o(2)(1)
+ orig=o.graphics.orig
+ x=orig(1);y=orig(2);
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/standard_outputs.bin b/modules/scicos/macros/scicos_scicos/standard_outputs.bin
new file mode 100755
index 000000000..9ca50ec11
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_outputs.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/standard_outputs.sci b/modules/scicos/macros/scicos_scicos/standard_outputs.sci
new file mode 100755
index 000000000..a2d1ad9b3
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/standard_outputs.sci
@@ -0,0 +1,75 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function [x,y,typ]=standard_outputs(o)
+ //get position of inputs ports and clock inputs port for a standard block
+ // the output ports are located on the right (or left if tilded) vertical
+ // side of the block, regularly located from bottom to top
+ // the clock output ports are located on the bottom horizontal side
+ // of the block, regularly located from left to right
+ //!
+ xf=60
+ yf=40
+
+ graphics=o.graphics
+ model=o.model
+ orig=graphics.orig;sz=graphics.sz;orient=graphics.flip;
+
+ out=size(model.out,1);clkout=size(model.evtout,1);
+
+ if orient then
+ xo=orig(1)+sz(1)
+ dx=xf/7
+ else
+ xo=orig(1)
+ dx=-xf/7
+ end
+
+ typ=[];
+
+ // output port location
+ if out==0 then
+ x=[];y=[];
+ else
+ y=orig(2)+sz(2)-(sz(2)/(out+1))*(1:out)
+ x=(xo+dx)*ones(y)
+ for k=1:out
+ if o.graphics.out_implicit==[] then
+ typ=ones(x)
+ else
+ if o.graphics.out_implicit(k)=="E" then
+ typ=[typ ones(x(k))]
+ elseif o.graphics.out_implicit(k)=="I" then
+ typ=[typ 2*ones(x(k))]
+ end
+ end
+ end
+ end
+
+
+ // clock output port location
+ if clkout<>0 then
+ x=[x,orig(1)+(sz(1)/(clkout+1))*(1:clkout)]
+ y=[y,(orig(2)-yf/7)*ones(1,clkout)]
+ typ=[typ,-ones(1,clkout)]
+ end
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/translator.bin b/modules/scicos/macros/scicos_scicos/translator.bin
new file mode 100755
index 000000000..5ccd5e60b
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/translator.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/translator.sci b/modules/scicos/macros/scicos_scicos/translator.sci
new file mode 100755
index 000000000..2c03c0952
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/translator.sci
@@ -0,0 +1,113 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+function [ok]=translator(filemo,Mblocks,_Modelica_libs,Flat)
+ //Generate the flat model of the Modelica model given in the filemo file
+ //and the Modelica libraries. Interface to the external tool
+ //translator.
+ // if <name> is the basename of filemo this function produces
+ // - the flat Modelica model file in outpath+name+'f.mo'
+ // - the flat xml representation file in outpath+name+'f_init.xml'
+ // - the flat xml file in outpath+name+'f_relations.xml'
+
+ // TO DO : rename filename too generic
+ TRANSLATOR_FILENAME = "modelicat";
+ if getos() == "Windows" then
+ TRANSLATOR_FILENAME = TRANSLATOR_FILENAME + ".exe";
+ end
+
+ mlibs = pathconvert(_Modelica_libs,%f,%t);
+ filemo = pathconvert(filemo,%f,%t);
+ Flat = pathconvert(Flat,%f,%t);
+
+ name = basename(filemo);
+ namef = name + "f";
+
+ [modelica_libs,modelica_directory] = getModelicaPath();
+
+ molibs = [];
+
+ for k = 1:size(Mblocks,"r")
+ funam = stripblanks(Mblocks(k));
+ [dirF, nameF, extF] = fileparts(funam);
+ if (extF == ".mo") then
+ molibs = [molibs; """" + funam + """"];
+ else
+ molibs = [molibs; """" + modelica_directory + funam + ".mo" + """"]
+ end
+ end
+
+ // directories for translator libraries
+ for k = 1:size(mlibs,"*")
+ modelica_directories = mlibs(k);
+ if modelica_directories<> [] then
+ molibs = [molibs; """" + modelica_directories + """"];
+ end
+ end
+
+ translator_libs = strcat(" -lib "+ molibs);
+
+ // build the sequence of -lib arguments for translator
+ if getos() == "Windows" then, Limit=1000;else, Limit=3500;end
+ if (length(translator_libs)>Limit) then
+ // OS limitation may restrict the length of shell command line
+ // arguments. If there are too many .mo file we catenate them into a
+ // single MYMOPACKAGE.mo file
+ messagebox(msprintf(_("There are too many Modelica files.\n" + ..
+ "it would be better to define several \n" + ..
+ "Modelica programs in a single file.")),"warning","modal");
+ mymopac = pathconvert(outpath+"MYMOPACKAGE.mo",%f,%t);
+ txt = [];
+ for k = 1:size(molibs,"*")
+ [pathx,fnamex,extensionx] = fileparts(molibs(k));
+ if (fnamex <> "MYMOPACKAGE") then
+ txt = [txt; mgetl(evstr(molibs(k)))];
+ end
+ end
+ mputl(txt, mymopac);
+ translator_libs= " -lib """+mymopac+"""";
+ end
+ translator_libs = translator_libs + " -lib """ + filemo + """"
+
+ //Build the shell instruction for calling the translator
+
+ exe = getmodelicacpath() + TRANSLATOR_FILENAME
+ exe = """" + pathconvert(getmodelicacpath() + TRANSLATOR_FILENAME,%f,%t) + """ ";
+
+ out =" -o """+Flat+"""" //flat modelica
+ Errfile = outpath + "S_translator.err""";
+
+ // with the with-init option
+ instr = exe + translator_libs + out + " -with-init -command """ + name + " " + namef + ";"" >""" + Errfile
+
+ if getos() == "Windows" then
+ mputl(instr,outpath+"/gent.bat")
+ instr = outpath + "/gent.bat";
+ end
+
+ if execstr("unix_s(instr)","errcatch") <> 0 then
+ messagebox([_("-------Modelica translator error message:-----");
+ mgetl(outpath + "S_translator.err")], "error", "modal");
+ ok = %f,
+ else
+ ok = %t
+ end
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/update_scs_m.bin b/modules/scicos/macros/scicos_scicos/update_scs_m.bin
new file mode 100755
index 000000000..dd3b02f5e
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/update_scs_m.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/update_scs_m.sci b/modules/scicos/macros/scicos_scicos/update_scs_m.sci
new file mode 100755
index 000000000..710e4ab3a
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/update_scs_m.sci
@@ -0,0 +1,242 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+function scs_m_new = update_scs_m(scs_m,version)
+ // update_scs_m : function to do certification of
+ // main data structure of
+ // a scicos diagram (scs_m)
+ // for current version of scicos
+ //
+ // certification is done through initial value of fields in :
+ // scicos_diagram()
+ // scicos_params()
+ // scicos_block()
+ // scicos_graphics()
+ // scicos_model()
+ // scicos_link()
+ //
+ // Initial rev 12/05/07 : Alan
+ // Copyright INRIA
+ rhs = argn(2)
+ if rhs<2 then
+ version=get_scicos_version();
+ end
+
+ scs_m_new = scicos_diagram();
+
+ F = getfield(1,scs_m);
+
+ for i=2:size(F,2)
+
+ select F(i)
+
+ //******************* props *******************//
+ case "props" then
+
+ sprops = scs_m.props;
+ T = getfield(1,scs_m.props);
+ T_txt = [];
+ for j=2:size(T,2)
+ T_txt = T_txt + strsubst(T(1,j),"title","Title") + ...
+ "=" + "sprops." + T(1,j);
+ if j<>size(T,2) then
+ T_txt = T_txt + ",";
+ end
+ end
+ T_txt = "sprops=scicos_params(" + T_txt + ")";
+ execstr(T_txt)
+ scs_m_new.props = sprops;
+ //*********************************************//
+
+ //******************** objs *******************//
+ case "objs" then
+
+ for j=1:lstsize(scs_m.objs) //loop on objects
+
+ o=scs_m.objs(j);
+
+ select typeof(o)
+
+ //************** Block ***************//
+ case "Block" then
+
+ o_new=scicos_block();
+ T = getfield(1,o);
+
+ for k=2:size(T,2)
+ select T(k)
+ //*********** graphics **********//
+ case "graphics" then
+ ogra = o.graphics;
+ G = getfield(1,ogra);
+ G_txt = [];
+ for l=2:size(G,2)
+ G_txt = G_txt + G(1,l) + ...
+ "=" + "ogra." + G(1,l);
+ if l<>size(G,2) then
+ G_txt = G_txt + ",";
+ end
+ end
+ G_txt = "ogra=scicos_graphics(" + G_txt + ")";
+ execstr(G_txt)
+ o_new.graphics = ogra;
+ //*******************************//
+
+ //************* model ***********//
+ case "model" then
+ omod = o.model;
+ M = getfield(1,o.model);
+ M_txt = [];
+ for l=2:size(M,2)
+ M_txt = M_txt + M(1,l) + ...
+ "=" + "omod." + M(1,l);
+ if l<>size(M,2) then
+ M_txt = M_txt + ",";
+ end
+ end
+ M_txt = "omod=scicos_model(" + M_txt + ")";
+ execstr(M_txt)
+ //******** super block case ********//
+ if omod.sim=="super"|omod.sim=="csuper" then
+ rpar=update_scs_m(omod.rpar,version)
+ omod.rpar=rpar
+ end
+ o_new.model = omod;
+ //*******************************//
+
+ //************* doc ***********//
+ case "doc" then
+ o_new.doc = list();
+ //*******************************//
+
+ //************* other ***********//
+ else
+ T_txt = "o."+T(k);
+ T_txt = "o_new." + T(k) + "=" + T_txt;
+ execstr(T_txt)
+ //*******************************//
+
+ end //end of select T(k)
+ end //end of for k=
+ scs_m_new.objs(j) = o_new;
+ //************************************//
+
+ //************** Link ****************//
+ case "Link" then
+
+ T = getfield(1,o);
+ T_txt = [];
+ for k=2:size(T,2)
+ T_txt = T_txt + T(1,k) + ...
+ "=" + "o." + T(1,k);
+ if k<>size(T,2) then
+ T_txt = T_txt + ",";
+ end
+ end
+ T_txt = "o_new=scicos_link(" + T_txt + ")";
+ execstr(T_txt)
+ scs_m_new.objs(j) = o_new;
+ //************************************//
+
+ //************** Text ****************//
+ case "Text" then
+ o_new = mlist(["Text","graphics","model","void","gui"],...
+ scicos_graphics(),scicos_model()," ","TEXT_f")
+
+ T = getfield(1,o);
+ T_txt = [];
+ for k=2:size(T,2)
+ select T(k)
+ //*********** graphics **********//
+ case "graphics" then
+ ogra = o.graphics;
+ G = getfield(1,ogra);
+ G_txt = [];
+ for l=2:size(G,2)
+ G_txt = G_txt + G(1,l) + ...
+ "=" + "ogra." + G(1,l);
+ if l<>size(G,2) then
+ G_txt = G_txt + ",";
+ end
+ end
+ G_txt = "ogra=scicos_graphics(" + G_txt + ")";
+ execstr(G_txt)
+ o_new.graphics = ogra;
+ //*******************************//
+
+ //************* model ***********//
+ case "model" then
+ omod = o.model;
+ M = getfield(1,o.model);
+ M_txt = [];
+ for l=2:size(M,2)
+ M_txt = M_txt + M(1,l) + ...
+ "=" + "omod." + M(1,l);
+ if l<>size(M,2) then
+ M_txt = M_txt + ",";
+ end
+ end
+ M_txt = "omod=scicos_model(" + M_txt + ")";
+ execstr(M_txt)
+ //******** super block case ********//
+ if omod.sim=="super"|omod.sim=="csuper" then
+ rpar=update_scs_m(omod.rpar,version)
+ omod.rpar=rpar
+ end
+ o_new.model = omod;
+ //*******************************//
+
+ //************* other ***********//
+ else
+ T_txt = "o."+T(k);
+ T_txt = "o_new." + T(k) + "=" + T_txt;
+ execstr(T_txt)
+ //*******************************//
+
+ end //end of select T(k)
+ end //end of for k=
+ scs_m_new.objs(j) = o_new;
+ //************************************//
+
+ //************* other ***********//
+ else // JESAISPASIYADAUTRESOBJS
+ // QUEDESBLOCKSDESLINKETDUTEXTESDANSSCICOS
+ // ALORSICIJEFAISRIEN
+ scs_m_new.objs(j) = o;
+ //************************************//
+
+ end //end of select typeof(o)
+
+ end //end of for j=
+ //*********************************************//
+
+ //** version **//
+ case "version" then
+ //do nothing here
+ //this should be done later
+
+ end //end of select F(i)
+
+ end //end of for i=
+
+ //**update version **//
+ scs_m_new.version = version;
+endfunction
+
diff --git a/modules/scicos/macros/scicos_scicos/update_version.bin b/modules/scicos/macros/scicos_scicos/update_version.bin
new file mode 100755
index 000000000..97ef9933f
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/update_version.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/update_version.sci b/modules/scicos/macros/scicos_scicos/update_version.sci
new file mode 100755
index 000000000..a1d5d3edd
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/update_version.sci
@@ -0,0 +1,40 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+function [ierr,scicos_ver,scs_m_out]=update_version(scs_m_in)
+
+ //## contrib update
+
+ //## scicos update
+ current_version = get_scicos_version()
+ scicos_ver = find_scicos_version(scs_m_in)
+
+ if scicos_ver<>current_version then
+ txt_to_run = "scs_m_out=do_version(scs_m_in,scicos_ver)"
+ ierr=execstr(txt_to_run,"errcatch")
+ if ierr<>0 then
+ scs_m_out=scs_m_in
+ end
+ else
+ scs_m_out=scs_m_in
+ ierr=0
+ end
+
+endfunction \ No newline at end of file
diff --git a/modules/scicos/macros/scicos_scicos/validvar.bin b/modules/scicos/macros/scicos_scicos/validvar.bin
new file mode 100755
index 000000000..912eec051
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/validvar.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/validvar.sci b/modules/scicos/macros/scicos_scicos/validvar.sci
new file mode 100755
index 000000000..6301dff37
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/validvar.sci
@@ -0,0 +1,48 @@
+// Scicos
+//
+// Copyright (C) INRIA - Serge Steer <serge.steer@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function r=validvar(s)
+ //Serge Steer, 08/10/2007
+ //Alan restricted validvar for operation, 29/03/08
+
+ //check if the string s is a valid identifier
+ s=stripblanks(s)
+ r=%f
+ if size(s,"*")<>1 then return, end
+ if s=="" then return, end
+
+ //create a function with s as single statement
+ if execstr("deff(''foo'',s)","errcatch") then return, end
+ t=macr2tree(foo) //syntax tree
+ instr=t.statements(2) //ignore leading and trailing EOL
+
+ //lhs should be "ans"
+ if size(instr.lhs)<>1 then return,end
+ if instr.lhs(1).name<>"ans" then return,end
+
+ //expression should be just a reference to s
+ if typeof(instr.expression)<>"operation" then return, end
+ if instr.expression.operator<>"ext" then return,end
+ if size(instr.expression.operands)<>1 then return,end
+ if instr.expression.operands(1).name<>s then return,end
+
+ r=%t
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/value2modelica.bin b/modules/scicos/macros/scicos_scicos/value2modelica.bin
new file mode 100755
index 000000000..e53818cc5
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/value2modelica.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/value2modelica.sci b/modules/scicos/macros/scicos_scicos/value2modelica.sci
new file mode 100755
index 000000000..a85aeb247
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/value2modelica.sci
@@ -0,0 +1,49 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+
+function txt=value2modelica(v)
+ [m,n]=size(v)
+ if m==1&n==1 then
+ txt=stripblanks(sci2exp(v))
+ kdot=strindex(txt,".")
+ if kdot==[] then return,end
+ if kdot==1 then
+ txt="0"+txt
+ else
+ if or(part(txt,kdot-1)==["+","-"]) then
+ txt=part(txt,1:kdot-1)+"0"+part(txt,kdot:length(txt))
+ end
+ end
+ else //matrix case
+ txt=stripblanks(sci2exp(v,0))
+ kdot=strindex(txt,".")
+ if kdot==[] then return,end
+ k=strindex(part(txt,kdot-1),["+","-",",",";","["])
+ if k==[] then return,end
+ t=txt;txt="";k0=1;
+ for i=k
+ ki=kdot(i);
+ txt=txt+part(t,k0:ki-1)+"0";
+ k0=ki;
+ end
+ txt=txt+part(t,k0:length(t))
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_scicos/xml2modelica.bin b/modules/scicos/macros/scicos_scicos/xml2modelica.bin
new file mode 100755
index 000000000..7a26b4e09
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/xml2modelica.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_scicos/xml2modelica.sci b/modules/scicos/macros/scicos_scicos/xml2modelica.sci
new file mode 100755
index 000000000..ff79a1888
--- /dev/null
+++ b/modules/scicos/macros/scicos_scicos/xml2modelica.sci
@@ -0,0 +1,60 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ../license.txt
+//
+function ok=xml2modelica(xmlfile,Flati)
+ // Generate the Modelica model file Flati with
+ // the xml file given by the initialization interface.
+ // Interface to the external tool xml2modelica.exe
+ // if <name> is the basename of filemo this function produces
+ // - the flat Modelica model file in outpath+name+'fi.mo'
+
+ //Scilab interface with external tool xml2modelica
+
+ XML2MODELICA_FILENAME = "XML2Modelica";
+ if getos() == "Windows" then
+ XML2MODELICA_FILENAME = XML2MODELICA_FILENAME + ".exe";
+ end
+
+ tmpdir = pathconvert(TMPDIR, %t, %t); //for error log and shell scripts
+ xmlfile = pathconvert(xmlfile, %f, %t);
+ Flati = pathconvert(Flati, %f, %t);
+
+ exe = """" + pathconvert(XML2MODELICA_FILENAME, %f, %t) + """ ";
+ in = """" + xmlfile + """";
+ out = "-o """ + Flati + """";
+ option = "-init"; // generates a flat modelica file for the initialization
+ instr = strcat([exe in option out], " ");
+
+ if getos() == "Windows" then,
+ mputl(instr, tmpdir + "igenx.bat");
+ instr = tmpdir + "igenx.bat";
+ end
+
+ [rep,stat,err]=unix_g(instr);
+ if stat == 0 then
+ mprintf("%s\n", " xml->Modelica : " + Flati);
+ ok = %t;
+ else
+ messagebox(err, _("XML to Modelica"), "error", "modal");
+ ok = %f;
+ return
+ end
+endfunction
+
diff --git a/modules/scicos/macros/scicos_utils/block_parameter_error.bin b/modules/scicos/macros/scicos_utils/block_parameter_error.bin
new file mode 100755
index 000000000..74bb203f7
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/block_parameter_error.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_utils/block_parameter_error.sci b/modules/scicos/macros/scicos_utils/block_parameter_error.sci
new file mode 100755
index 000000000..c02fdf16f
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/block_parameter_error.sci
@@ -0,0 +1,32 @@
+//
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2011 - Bernard DUJARDIN <develop.dujardin@numericable.fr>
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+//
+//
+
+function block_parameter_error(inform, expected)
+ // Displays a parameter input error box for an Xcos block
+ // Parameters
+ // inform: a string, type of the error
+ // expected: a string, expected value
+
+ rhs=argn(2)
+ if rhs <> 2 then
+ error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"), "block_parameter_error", 2))
+ end
+ if typeof(inform) <> "string" then
+ error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"), "block_parameter_error", 1 ))
+ end
+ if typeof(expected) <> "string"
+ error(msprintf(gettext("%s: Wrong type for input argument #%d: String array expected.\n"),"block_parameter_error", 2));
+ end
+
+ boxmsg = [" "; inform; " "; expected];
+ messagebox(boxmsg, gettext("Xcos block parameter error"), "error","modal");
+endfunction
diff --git a/modules/scicos/macros/scicos_utils/buildmacros.sce b/modules/scicos/macros/scicos_utils/buildmacros.sce
new file mode 100755
index 000000000..383855a59
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/buildmacros.sce
@@ -0,0 +1,16 @@
+
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2007-2008 - INRIA - Allan CORNET <allan.cornet@inria.fr>
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+
+if (isdef("genlib") == %f) then
+ exec(SCI+"/modules/functions/scripts/buildmacros/loadgenlib.sce");
+end
+//------------------------------------
+genlib("scicos_utilslib","SCI/modules/scicos/macros/scicos_utils",%f,%t);
+//------------------------------------
diff --git a/modules/scicos/macros/scicos_utils/find_scicos_version.bin b/modules/scicos/macros/scicos_utils/find_scicos_version.bin
new file mode 100755
index 000000000..373c13184
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/find_scicos_version.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_utils/find_scicos_version.sci b/modules/scicos/macros/scicos_utils/find_scicos_version.sci
new file mode 100755
index 000000000..3b143c85f
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/find_scicos_version.sci
@@ -0,0 +1,78 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ./license.txt
+//
+
+function [scicos_ver]=find_scicos_version(scs_m)
+ //**
+ //** find_scicos_version try to retrieve a version of a
+ //** scs_m
+ //**
+ //** 21/08/07: Alan, inital revision
+ //**
+
+ if ~exists("scicos_ver") then
+ scicos_ver = "scicos2.2";
+ else
+ scicos_ver = scicos_ver;
+ end
+
+ if type(scs_m)==17 then
+ //case for diagrams >= 4.2
+ if find(getfield(1,scs_m)=="version")<>[] then
+ if scs_m.version<>"" then
+ scicos_ver=scs_m.version
+ else
+ n=size(scs_m.objs);
+ for j=1:n //loop on objects
+ o=scs_m.objs(j);
+ if typeof(o)=="Block" then
+ if find(getfield(1,o.model)=="equations")<>[] then
+ scicos_ver = "scicos2.7.3"
+ break;
+ else
+ //** the last version supported here is scicos2.7
+ //** other tests can be done
+ scicos_ver = "scicos2.7"
+ break;
+ end
+ end
+ end //** end for
+ end
+ //case for diagrams < 4.2
+ else
+ n=size(scs_m.objs);
+ for j=1:n //loop on objects
+ o=scs_m.objs(j);
+ if typeof(o)=="Block" then
+ if find(getfield(1,o.model)=="equations")<>[] then
+ scicos_ver = "scicos2.7.3"
+ break;
+ else
+ //** the last version supported here is scicos2.7
+ //** other tests can be done
+ scicos_ver = "scicos2.7"
+ break;
+ end
+ end
+ end //** end for
+ end
+ end
+
+endfunction
diff --git a/modules/scicos/macros/scicos_utils/fixedpointgcd.bin b/modules/scicos/macros/scicos_utils/fixedpointgcd.bin
new file mode 100755
index 000000000..50056875b
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/fixedpointgcd.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_utils/fixedpointgcd.sci b/modules/scicos/macros/scicos_utils/fixedpointgcd.sci
new file mode 100755
index 000000000..e6c9248dd
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/fixedpointgcd.sci
@@ -0,0 +1,13 @@
+function [value,denom_com]=fixedpointgcd(v)
+ // This function computes the PGCD of a double vector.
+ x=log10(v);
+ f=round((min(x)+max(x))/2);
+ v=v./10^(f);
+ [N,D]=rat(v,1d-9);
+ denom_com=lcm(uint32(D));
+ N=uint32(N)*denom_com./uint32(D);
+ value=gcd(N);
+ if f>0 then value=value*10^f;
+ else denom_com=double(denom_com)*10^(-f);
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_utils/get_scicos_version.bin b/modules/scicos/macros/scicos_utils/get_scicos_version.bin
new file mode 100755
index 000000000..a7d664def
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/get_scicos_version.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_utils/get_scicos_version.sci b/modules/scicos/macros/scicos_utils/get_scicos_version.sci
new file mode 100755
index 000000000..7ef336c02
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/get_scicos_version.sci
@@ -0,0 +1,25 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ./license.txt
+//
+
+function [scicos_ver]=get_scicos_version()
+ //INRIA
+ scicos_ver = "scicos4.3";
+endfunction
diff --git a/modules/scicos/macros/scicos_utils/initial_scicos_tables.bin b/modules/scicos/macros/scicos_utils/initial_scicos_tables.bin
new file mode 100755
index 000000000..28d0b5297
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/initial_scicos_tables.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_utils/initial_scicos_tables.sci b/modules/scicos/macros/scicos_utils/initial_scicos_tables.sci
new file mode 100755
index 000000000..3d0192d0a
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/initial_scicos_tables.sci
@@ -0,0 +1,20 @@
+
+function [modelica_libs, scicos_pal_libs, ..
+ %scicos_with_grid, %scs_wgrid] = initial_scicos_tables()
+
+ //** This function is called from "scicos" "scicos_simulate" "lincos" "steadycos"
+
+
+ %scicos_with_grid = %f;//** define grid
+ %scs_wgrid = [10;10;12];//**define aspect of grid
+
+
+ //Scicos palettes libs list ========================================================
+ scicos_pal_libs = ["Branching","Events","Misc","Sinks","Threshold","Linear","MatrixOp","NonLinear","Sources","Electrical","Hydraulics","PDE","IntegerOp"];
+
+ //Scicos Modelica librabry path definitions========================================
+ modelica_libs = getModelicaPath();
+
+ //** This is the END, the END my friend". By The Doors, Apocalypse Now.
+endfunction
+
diff --git a/modules/scicos/macros/scicos_utils/lib b/modules/scicos/macros/scicos_utils/lib
new file mode 100755
index 000000000..3c03be8a2
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/lib
Binary files differ
diff --git a/modules/scicos/macros/scicos_utils/names b/modules/scicos/macros/scicos_utils/names
new file mode 100755
index 000000000..c91bf1217
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/names
@@ -0,0 +1,9 @@
+block_parameter_error
+find_scicos_version
+fixedpointgcd
+get_scicos_version
+initial_scicos_tables
+returntoscilab
+scicos_getvalue
+scicos_workspace_init
+with_modelica_compiler
diff --git a/modules/scicos/macros/scicos_utils/returntoscilab.bin b/modules/scicos/macros/scicos_utils/returntoscilab.bin
new file mode 100755
index 000000000..a6dc26362
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/returntoscilab.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_utils/returntoscilab.sci b/modules/scicos/macros/scicos_utils/returntoscilab.sci
new file mode 100755
index 000000000..df3acfbbf
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/returntoscilab.sci
@@ -0,0 +1,39 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ./license.txt
+//
+
+function [txt,files]=returntoscilab()
+ files= listfiles(TMPDIR+"/Workspace")
+ n=size(files,1)
+ if n==0 then
+ txt=[],
+ return,
+ else
+ txtg="["+files(1)
+ txtd="resume("+files(1)
+ for i=2:n
+ txtg=txtg+","+files(i)
+ txtd=txtd+","+files(i)
+ end
+ txtg=txtg+"]"
+ txtd=txtd+")"
+ txt=txtg+"="+txtd
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_utils/scicos_getvalue.bin b/modules/scicos/macros/scicos_utils/scicos_getvalue.bin
new file mode 100755
index 000000000..4092be6fa
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/scicos_getvalue.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_utils/scicos_getvalue.sci b/modules/scicos/macros/scicos_utils/scicos_getvalue.sci
new file mode 100755
index 000000000..37bafdda3
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/scicos_getvalue.sci
@@ -0,0 +1,311 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// Copyright (C) 2010 - DIGITEO - Clément DAVID <clement.david@scilab.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ./license.txt
+//
+
+function [%ok,%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]=scicos_getvalue(%desc,%labels,%typ,%ini)
+ // getvalues - %window dialog for data acquisition
+ //%Synta%
+ // [%ok,%1,..,%30]=getvalue(desc,labels,typ,ini)
+ //%Parameters
+ // desc : column vector of strings, dialog general comment
+ // labels : n column vector of strings, labels(i) is the label of
+ // the ith required value
+ // typ : list(typ1,dim1,..,typn,dimn)
+ // typi : defines the type of the ith required value
+ // if may have the following values:
+ // 'mat' : stands for matrix of scalars
+ // 'col' : stands for column vector of scalars
+ // 'row' : stands for row vector of scalars
+ // 'vec' : stands for vector of scalars
+ // 'intvec' : stands for vector of integers i.e int(x) == x
+ // 'str' : stands for vector of strings
+ // 'lis' : stands for list
+ // 'pol' : stands for polynomials
+ // 'r' : stands for rational
+ // dimi : defines the size of the ith required value
+ // it must be
+ // - an integer or a 2-vector of integers (-1 stands for
+ // arbitrary dimension)
+ // - an evaluatable character string
+ // ini : n column vector of strings, ini(i) gives the suggested
+ // response for the ith required value
+ // %ok : boolean ,%t if %ok button pressed, %f if cancel button pressed
+ // xi : contains the ith required value if %ok==%t
+ //%Description
+ // getvalues macro encapsulate x_mdialog function with error checking,
+ // evaluation of numerical response, ...
+ //%Remarks
+ // All correct scilab syntax may be used as responses, for matrices
+ // and vectors getvalues automatically adds [ ] around the given response
+ // before numerical evaluation
+ //%Example
+ // labels=['magnitude';'frequency';'phase '];
+ // [ampl,freq,ph]=getvalue('define sine signal',labels,..
+ // list('vec',1,'vec',1,'vec',1),['0.85';'10^2';'%pi/3'])
+ //
+ //%See also
+ // x_mdialog, x_dialog
+
+ //!
+ // 01/09/10 Clément DAVID: update to %30 rhs parameters
+ // 17/01/07 -Alan- This version of getvalue is different of scilab 4.1 :
+ // - %scicos_context behavior reviewed in accordance to context_evstr macro
+ // - (u)int(8/16/32) allowed in field of type vec/mat/row/col (F. Nassif's Work)
+ //
+ // 05/02/07 -Alan- : update to %20 rhs parameters
+ //
+ // 12/02/07 -Alan- : fix (variable evaluation of %scicos_context)
+ //
+ // Copyright INRIA
+ [%lhs,%rhs]=argn(0)
+
+ %nn=prod(size(%labels))
+ if %lhs<>%nn+2&%lhs<>%nn+1 then error(41),end
+ if size(%typ)<>2*%nn then
+ error("%typ : list(''type'',[sizes],...)")
+ end
+ %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=[];
+
+ if %rhs==3 then %ini=emptystr(%nn,1),end
+
+ // Transform a list of strings into a vector of strings
+ // Has no effect if %ini is already a vector of strings
+ // An empty item in the source list is converted to an empty string in the
+ // destination vector
+ // %ini = cat(1,%ini(:))
+ if typeof(%ini) <> "string"
+ %new_ini = []
+ for k = 1:length(%ini)
+ if isempty(%ini(k))
+ %new_ini(k) = ""
+ else
+ %new_ini(k) = %ini(k)
+ end
+ end
+ %ini = %new_ini
+ end
+
+ %ok=%t
+ while %t do
+ %ini=matrix(%ini, size(%labels));
+ %str=x_mdialog(%desc,%labels,%ini)
+ if %str==[] then %ok=%f,%str=[];break,end
+ for %kk=1:%nn
+ %cod=ascii(%str(%kk))
+ %spe=find(%cod==10)
+ if %spe<>[] then
+ %semi=ascii(";")
+ %cod(%spe)=%semi*ones(%spe')
+ %str(%kk)=ascii(%cod)
+ end
+ end
+
+ if exists("%scicos_context")
+ %mm=getfield(1,%scicos_context)
+ for %mi=%mm(3:$)
+ if execstr(%mi+"=%scicos_context(%mi)","errcatch")<>0 then
+ disp(lasterror())
+ %ok=%f
+ return
+ end
+ end
+ end
+
+ %nok=0
+ for %kk=1:%nn
+ select part(%typ(2*%kk-1),1:6)
+ case "mat "
+ if exists("%scicos_context") then
+ [%vv,%ierr]=evstr(%str(%kk))
+ else
+ %ierr=execstr("%vv=["+%str(%kk)+"]","errcatch");
+ end
+ if %ierr<>0 then %nok=-%kk;break,end
+ //29/12/06
+ //the type of %vv is accepted if it is constant or integer
+ if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ [%mv,%nv]=size(%vv)
+ %ssz=string(%sz(1))+" x "+string(%sz(2))
+ if %mv*%nv==0 then
+ if %sz(1)>=0&%sz(2)>=0&%sz(1)*%sz(2)<>0 then %nok=%kk,break,end
+ else
+ if %sz(1)>=0 then if %mv<>%sz(1) then %nok=%kk,break,end,end
+ if %sz(2)>=0 then if %nv<>%sz(2) then %nok=%kk,break,end,end
+ end
+ case "vec "
+ if exists("%scicos_context") then
+ [%vv,%ierr]=evstr(%str(%kk))
+ else
+ %ierr=execstr("%vv=["+%str(%kk)+"]","errcatch")
+ end
+ if %ierr<>0 then %nok=-%kk;break,end
+ //17/01/07
+ //the type of %vv is accepted if it is constant or integer
+ if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ %ssz=string(%sz(1))
+ %nv=prod(size(%vv))
+ if %sz(1)>=0 then if %nv<>%sz(1) then %nok=%kk,break,end,end
+ case "intvec"
+ if exists("%scicos_context") then
+ [%vv,%ierr]=evstr(%str(%kk))
+ else
+ %ierr=execstr("%vv=["+%str(%kk)+"]","errcatch")
+ end
+ if %ierr<>0 then %nok=-%kk;break,end
+ //17/01/07
+ //the type of %vv is accepted if it is constant or integer
+ if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ if and(int(%vv) == %vv) == %f then
+ %nok=-%kk;
+ break;
+ end
+ %ssz=string(%sz(1))
+ %nv=prod(size(%vv))
+ if %sz(1)>=0 then if %nv<>%sz(1) then %nok=%kk,break,end,end
+ case "pol "
+ if exists("%scicos_context") then
+ [%vv,%ierr]=evstr(%str(%kk))
+ else
+ %ierr=execstr("%vv=["+%str(%kk)+"]","errcatch");
+ end
+ if %ierr<>0 then %nok=-%kk;break,end
+ if type(%vv)>2 then %nok=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ %ssz=string(%sz(1))
+ %nv=prod(size(%vv))
+ if %sz(1)>=0 then if %nv<>%sz(1) then %nok=%kk,break,end,end
+ case "row "
+ if exists("%scicos_context") then
+ [%vv,%ierr]=evstr(%str(%kk))
+ else
+ %ierr=execstr("%vv=["+%str(%kk)+"]","errcatch");
+ end
+ if %ierr<>0 then %nok=-%kk;break,end
+ //17/01/07
+ //the type of %vv is accepted if it is constant or integer
+ if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ if %sz(1)<0 then
+ %ssz="1 x *"
+ else
+ %ssz="1 x "+string(%sz(1))
+ end
+ [%mv,%nv]=size(%vv)
+ if %mv<>1 then %nok=%kk,break,end,
+ if %sz(1)>=0 then if %nv<>%sz(1) then %nok=%kk,break,end,end
+ case "col "
+ if exists("%scicos_context") then
+ [%vv,%ierr]=evstr(%str(%kk))
+ else
+ %ierr=execstr("%vv=["+%str(%kk)+"]","errcatch");
+ end
+ if %ierr<>0 then %nok=-%kk;break,end
+ //17/01/07
+ //the type of %vv is accepted if it is constant or integer
+ if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ if %sz(1)<0 then
+ %ssz="* x 1"
+ else
+ %ssz=string(%sz(1))+" x 1"
+ end
+ [%mv,%nv]=size(%vv)
+ if %nv<>1 then %nok=%kk,break,end,
+ if %sz(1)>=0 then if %mv<>%sz(1) then %nok=%kk,break,end,end
+ case "str "
+ %sde=%str(%kk)
+ %spe=find(ascii(%str(%kk))==10)
+ %spe($+1)=length(%sde)+1
+ %vv=[];%kk1=1
+ for %kkk=1:size(%spe,"*")
+ %vv(%kkk,1)=part(%sde,%kk1:%spe(%kkk)-1)
+ %kk1=%spe(%kkk)+1
+ end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ %ssz=string(%sz(1))
+ %nv=prod(size(%vv))
+ if %sz(1)>=0 then if %nv<>%sz(1) then %nok=%kk,break,end,end
+ case "lis "
+ if exists("%scicos_context") then
+ [%vv,%ierr]=evstr(%str(%kk))
+ else
+ %ierr=execstr("%vv="+%str(%kk),"errcatch");
+ end
+ if %ierr<>0 then %nok=-%kk;break,end
+ if type(%vv)<>15& type(%vv)<>16& type(%vv)<>17 then %nok=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ %ssz=string(%sz(1))
+ %nv=size(%vv)
+ if %sz(1)>=0 then if %nv<>%sz(1) then %nok=%kk,break,end,end
+ case "r "
+ if exists("%scicos_context") then
+ [%vv,%ierr]=evstr(%str(%kk))
+ else
+ %ierr=execstr("%vv=["+%str(%kk)+"]","errcatch");
+ end
+ if %ierr<>0 then %nok=-%kk;break,end
+ if type(%vv)<>16 then %nok=-%kk,break,end
+ if typeof(%vv)<>"rational" then %nok=-%kk,break,end
+ %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
+ [%mv,%nv]=size(%vv(2))
+ %ssz=string(%sz(1))+" x "+string(%sz(2))
+ if %mv*%nv==0 then
+ if %sz(1)>=0&%sz(2)>=0&%sz(1)*%sz(2)<>0 then %nok=%kk,break,end
+ else
+ if %sz(1)>=0 then if %mv<>%sz(1) then %nok=%kk,break,end,end
+ if %sz(2)>=0 then if %nv<>%sz(2) then %nok=%kk,break,end,end
+ end
+ else
+ error(msprintf(_("%s: Type %s is not implemented.\n"),"getvalue", %typ(2*%kk-1)))
+ end
+ execstr("%"+string(%kk)+"=%vv")
+ end
+ if %nok>0 then
+ messagebox(msprintf(_("Answer given for %s \n has invalid dimension: \n waiting for dimension %s.\n"), %labels(%nok), %ssz), "modal");
+ %ini=%str
+ elseif %nok<0 then
+ if %ierr==0 then
+ messagebox(msprintf(_("Answer given for %s \n has incorrect type %s.\n"), %labels(-%nok), %typ(-2*%nok-1)), "modal");
+ else
+ messagebox(msprintf(_("Answer given for %s \n is incorrect: %s.\n"), %labels(-%nok), lasterror()), "modal");
+ end
+ %ini=%str
+ else
+ break
+ end
+ end
+ if %lhs==%nn+2 then
+ execstr("%"+string(%lhs-1)+"=%str")
+ end
+endfunction
diff --git a/modules/scicos/macros/scicos_utils/scicos_workspace_init.bin b/modules/scicos/macros/scicos_utils/scicos_workspace_init.bin
new file mode 100755
index 000000000..d1500c5a2
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/scicos_workspace_init.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_utils/scicos_workspace_init.sci b/modules/scicos/macros/scicos_utils/scicos_workspace_init.sci
new file mode 100755
index 000000000..e3b7008d7
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/scicos_workspace_init.sci
@@ -0,0 +1,56 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ./license.txt
+//
+//
+function scicos_workspace_init()
+ //preserve all variables of type struct having a "time" and a "value"
+ //field in temporary binary files
+ path=TMPDIR+"/Workspace/"
+ mkdir(path);
+
+
+ //prepare the fromworkspace stuff We need to store all variables of
+ //type struct which have 2 fields "values" and "time". these variables
+ //are stored into Scilab binary files whose name are the variable names
+ //and which contain 2 variables "x" and "t"
+ //
+ prt=funcprot(),funcprot(0)
+ varnames = who("get") ;
+ varnames = varnames(1:$-predef()+1); //** exclude protected variables
+ varnames(varnames=="ans")=[];
+ for var=varnames'
+ v=evstr(var);
+ if typeof(v)=="st" then
+ fn=fieldnames(v)
+ if and(fn==["values";"time"] | fn==["time";"values"]) then
+ if execstr("x=v.values","errcatch")==0 then
+ if execstr("t=v.time","errcatch") ==0 then
+ // remove deprecation warning on save, this will be reimplemented on 6.x
+ warnMode = warning("query");
+ warning("off");
+ execstr("save("""+path+var+""",x,t)")
+ warning(warnMode);
+ end
+ end
+ end
+ end
+ end
+ funcprot(prt)
+endfunction
diff --git a/modules/scicos/macros/scicos_utils/with_modelica_compiler.bin b/modules/scicos/macros/scicos_utils/with_modelica_compiler.bin
new file mode 100755
index 000000000..a51850bd9
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/with_modelica_compiler.bin
Binary files differ
diff --git a/modules/scicos/macros/scicos_utils/with_modelica_compiler.sci b/modules/scicos/macros/scicos_utils/with_modelica_compiler.sci
new file mode 100755
index 000000000..bce2d1b95
--- /dev/null
+++ b/modules/scicos/macros/scicos_utils/with_modelica_compiler.sci
@@ -0,0 +1,33 @@
+// Scicos
+//
+// Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+// Copyright (C) INRIA - 2008 - Allan CORNET
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See the file ./license.txt
+//
+
+function r = with_modelica_compiler()
+
+ if exists("scicos_scicoslib") == 0 then
+ load("SCI/modules/scicos/macros/scicos_scicos/lib") ;
+ end
+
+ // check if modelica compiler exists in current $PATH
+ r = ~isempty(getmodelicacpath());
+
+endfunction
+