The advantages of the C Code is that you can create any type of model and use it in the simulation. No external compiler is required, so that makes it very easy to use!
Local variable can be defied outside the main function as is done in lines 1 and 2. There has to be one main function with opening and closing braces, see lines 3,4 and 8. The variable a is defined as being the input of the block. It doesn't have to be declared, as it is done automatically by Caspoc as a local variable that is defined inside the scope of the main function. The argument of the return function, in this case y in line 7, is the output of the block.
The blocks Cscript2, Cscript3, ... Cscript20 have more inputs labeled from "a" until "t"
Inside the Cscript block you can use loops like for, while do and if-then-else structures. Functions can be called recursively and you can pass local variables as function arguments.
The Caspoc C script block to support the implementation of extensive functions in the programming language C. In the simulation start the built-in compiler translates automatically the ANSI-C code into machine code and embeds it dynamically into the Caspoc model. C scripts communicate closely with the solver in order to enable complex functionality such as systems with different sampling rates.