# VARSUB

ModelingCalculates an algebraic value for a user defined variable element.

## Use

User-defined variable calling a VARSUB for the calculation of its algebraic values:

<Reference_Variable
id                  = "30100100"
type                = "USERSUB"
usrsub_param_string = "USER(30131,30100,0.01,1)"
usrsub_dll_name     = "NULL"
/>

## Format

Fortran Calling Syntax
SUBROUTINE VARSUB(ID, TIME, PAR, NPAR, DFLAG, IFLAG, VALUE)
C/C++ Calling Syntax
void STDCALL VARSUB (int *id, double *time, double *par, int *npar, int *dflag, int *iflag, double *value)
Python Calling Syntax
def VARSUB(id, time, par, npar, dflag, iflag):
return value
MATLAB Calling Syntax
function value = VARSUB(id, time, par, npar, dflag, iflag)

## Attributes

ID
[integer]
The user-defined variable element identifier.
TIME
[double precision]
The current simulation time.
PAR
[double precision]
An array that contains the constant arguments from the list provided in the user defined statement.
NPAR
[integer]
The number of entries in the PAR array.
DFLAG
[logical]
The differentiating flag.
IFLAG
[logical]
The initialization flag.

## Output

VALUE
[double precision]
The output that contains the algebraic variable value that the VARSUB has computed.

## Example

def VARSUB(id, time, par, npar, dflag, iflag):

ipar = 2*[0]
ipar[0] = int(par[0])
ipar[1] = int(par[1])
[dz, errflg] = py_sysfnc("DZ", ipar)
py_errmes(errflg,"Error calling SYSFNC for DZ",id,"STOP")
[vz, errflg] = py_sysfnc("VZ", ipar)
py_errmes(errflg,"Error calling SYSFNC for VZ",id,"STOP")

value = -par[2]*vz - par[3]*dz
return value