Script debug and batch execution

SCILAB language is often used to drive huge experiments/simulations along with complex computations in batch mode. But to do so, you have to ensure your script is not crashing at every line. In this tutorial we will see together some handy functions for fast script debugging as well utilities to run your scripts/functions in batch mode in Linux or Windows command line.

The script used in this tutorial is available for download using the above button.

Debug scripts: pause/whereami/resume/abort

Let's imagine a first function which aims at deciding (random way) if you are team Captain or team Ironman.

And let's imagine a second function, leveraging the first one, which should conclude with the fact that, eventually the team you belong to does not really matter since you are Groot

And here you see what could be going wrong. Not that you are sharing your life with a talking raccoon, but the infinite loop! So let's try a first case

If you run your script that way, you will see that your script is never stopping. You got some good hints about where the scripts might fail and would like to check the value of the different involved variables at those stage. You will therefore set pause element (uncomment in provided code) and execute your code again.  In your SCILAB console you will then see the -1-> which means that you reach a pause set.

Here you can therefore proceed with different actions:

  • Locate the reached pause set in your code using whereami function. We can for example check that the first one has been reached under line 3 of function myFunc2 and line 14 of myFunc1.
  • Unfold code execution with resume function
  • Access involved variable values within a pause. In this example, we are checking the value of e variable to check for an eventual infinite loop.
  • Stop code execution using abort function. In this case e was TRUE which means that the loop was indeed infinite.

So one way to correct it would be to initialize y at FALSE.

Run SCILAB scripts in batch mode

Now that you understood what went wrong in script, that you corrected it and removed the pause sets, you are now able to run your script in batch mode. To do so you have to access SCILAB provided utilities in installation folder (scilab-6.0.2\bin\). Depending on the OS:

  • On Linux use scilab-cli utility

  • On Windows use Scilex.exe utility

It seems I was team Captain the whole time.