Please enable JavaScript to view this site.

Vensim Help

Navigation: Reference Guide > DSS Supplement > External Functions

Startup and Terminate Routines

Scroll Prev Top Next More

In addition to the required functions described above you may include and export two optional functions that will be called before and after simulations occur.

It is often useful to do some startup and termination activity.  This might be the allocation and discard of storage, resetting global values or other things.  To do this you should include in your external function library simulation_setup and simulation_shutdown.

int _export PASCAL simulation_setup(int iniflag)

This function is called before simulating the model. iniflag is 1 if the simulation is being prepared and vectors allocated, and 0 if the simulation is about to start.  If any error conditions are detected, it should call vensim_error_message(VERROR,...) as described above in order to terminate the simulation.

This function should return a value of 1 to indicate success and 0 to indicate failure.  If simulate_setup returns 0 when iniflag is 1 then the simulation will be aborted. When iniflag is 0 the return value is ignored.

int _export PASCAL simulation_shutdown(int finalflag)

This function is called after simulation.  If finalflag is 0 then computations have just finished.  IF finalflag is 1 then data storage has been completed and simulation memory is about to be freed.

In a normal simulation these functions are called in the sequence:

simulation_setup(1) ;

simulation_setup(0) ;

simulation_shutdown(0) ;

simulation_shutdown(1) ;

For an optimization, sensitivity or SyntheSim run, the middle two function calls are repeated for each simulation that is made.