If you have included the set_gv function to set the value for VENGV then you can make use of the elements of the GLOB_VARS structure. This structure is used for both compiled simulations and external functions. You should not make any changes to any of the elements of this, but some of the values can be very useful for referencing. Those elements are discussed here.
BBASE tabbase the base memory position for table values. Use (REAL *)(GV->tabbase+tab->x) to access the x axis and (REAL *)(GV->tabbase+tab->y) to access the y axis.
COMPREAL time the current simulation time.
COMPREAL time_step the current simulation Time Step. Remember that TIME_STEP can be a variable so this might change.
COMPREAL time_plus this is the current simulation time plus Time Step/2. It is useful for doing comparison of the current time with other values without risking incorrect results because a floating point == returns 0.
COMPREAL time_minus this is the current simulation time minus Time Step/2. Also useful for using >. Instead of targtime == GV->time use argtime > GV->time_minus && targtime < GV->time_plus).
COMPREAL final_time is the FINAL_TIME for the simulation.
COMPREAL saveper is the SAVEPER for the simulation.
char simulation_state is the current state of simulation. It takes on the values:
• | SS_IDLE(=0) to indicate nothing is happening. |
• | SS_ONSCREEN(=1) to indicate that the user is making changes on the screen. |
• | SS_LOCKED(=2) to indicate that there is no more user interaction. |
• | SS_INIT(=3) to indicate that initial values are being computed. |
• | SS_ACTIVE(=4) to indicate that active equations are being computed. |
• | SS_INTEG(=5) to indicate that integration is occurring. |
If you need to do something at the time of initialization test to see if the state is SS_INIT. In the SS_INTEG state, which is only invoked for Runge Kutta integration technique, you may want to have the function behave differently - certainly any messages or other output should be suppressed.
char gaming_state specifies the state of a gaming simulation. It is one of:
• | GS_NONE(=0 ) to indicate that Vensim is not in a gaming state. |
• | GS_PREP(=1) to indicate that the game results must be prepared for storage for the first time. |
• | GS_CONTINUE(=2) to indicate that a game is continuing for another step. |
• | GS_FINISHED(=3) to indicate that the model has been gamed to final time. |
• | GS_STARTING(=4) to indicate that the game is just being started or has just been backed up. |
char integ_type specified the integration technique being used. It can be one of:
• | IT_EULER(=0) for Euler integration. |
• | IT_DIFFERENCE(=2) for Difference Equations. |
• | IT_RK2F(=3) for fixed step size second order Runge-Kutta integration. |
• | IT_RK2(=4) for variable step size second order Runge-Kutta integration. |
• | IT_RK4F(=5) for fixed step size fourth order Runge-Kutta integration. |
• | IT_RK4(=1) for variable step size fourth order Runge-Kutta integration. |
char simulation_type specifies the type of simulation being made. It can be one of:
• | ST_NORMAL(=0) for a normal simulation. |
• | ST_PARTIAL(= 1) for a partial model simulation. |
• | ST_GAME(=2) for a gaming simulation. |
• | ST_REALITY_CHECK(=3) for a Reality Check simulation. |
The address of callback functions are also contained in VENGV as described below.