Instead of being passed a Vector Argument Data Definition functions are passed a pointer to a DATA_MATRIX structure as their first argument (all remaining arguments must be literals).
typedef struct
unsigned long keyval ;
char *varname ;
REAL *timevals ;
REAL **vals ;
long nvar ;
long ntime ;
} DATA_MATRIX ;
keyval is must be equal to DATA_MATRIX_KEY (0x33F27413). You can use this to check that you have received a valid DATA_MATRIX.
varname is the name of the variable, fully subscripted with the first subscript to have its value filled. This is passed to make it easier to report errors, and can also be parsed if this is appropriate.
timevals is the vector of times to be filled. This will be null when the function is first called. You need to allocate this - most easily by calling vensim_alloc_simmem after specifying ntime.
vals is the matrix of vals to be filled. When a Constant Definition function is first called each row of this matrix will be empty (that is vals[0] will be null, as will vals[1] and so on). You can call vensim_alloc_simmem and pass the CONSTANT MATRIX received as the second argument to allocate the rows.
ncol is the number of columns to be filled - this is passed from Vensim and is determined by the last varying subscript. for scalars this will be one.
nvar is the number of variables (rows) be filled - this is passed from Vensim and is determined by the first (and only) varying subscript in the equation using the Date Definition function. For scalars this will be one.
ntime is the number of times that will be returned. The function must fill in a value for this, normally before calling vensim_alloc_simmem. Note that the entire vals matrix should be filled in. If a particular variable is not available at a particular time assign it a value of NA at that time and it will be purged when Vensim interprets the data.