Please enable JavaScript to view this site.

Vensim Help

Navigation: Reference Guide > DSS Supplement > External Functions

Constant and Data Definition Functions

Scroll Prev Top Next More

Vensim treats external functions as active computations on the inputs.  While it is possible to write functions that have memory of previous calls (see the INTERNAL_ROR example in venext.c) Vensim treats the function as a simple computation on current values.

While this is usually appropriate, there are circumstances where you might want to tell Vensim to treat a function as defining a particular type of variable.  Currently you can do this for Data variables and Constants.  You mark such functions as special by giving them a number of user loops that is less than 0.  Use -1 for a Constant Definition function (this is the definition of CONSTDEF_FUNC in vensim.h) and -2 (DATADEF_FUNC) for a Data Definition function.

Constant definition functions are called whenever a model is checked, and just before the model is simulated.  They are passed information about the array they are expected to populate.  After Constant Definition function has been called you may still change the values of constants onscreen or using changes files.  

Data definition functions are called at the beginning of the simulation process.  The allow you to populate a time valued array of data to be used during the simulation.

Constant and Data Definition functions can only be passed literal arguments.  They make it easier to get information from databases and other external sources without severe performance penalties.  There are example of these types of functions in venext.c.