op_stat_write_t()
Abstract
Writes a (time,value) pair to the specified statistic. Both the value and the time are specified as arguments to this KP.
Syntax
op_stat_write_t (stat_handle, value, time)
| Argument | Type | Description |
|---|---|---|
stat_handle |
Stathandle |
Statistic handle identifying the global or local statistic to receive an updated value [A statistic handle can be obtained via the KP op_stat_reg().] |
value |
double |
Value to write to the specified statistic |
time |
double |
Value to be used as the abscissa of the output vector’s new entry [This is not necessarily related to simulation time but is called “time” due to the fact that most vectors use this variable as their abscissa.] |
Return Type
void
No return value.
Example
/* obtain the arriving packet */
pkptr = op_pk_get (INPUT_STRM);
/* determine the bulk size of the packet */
bulk_size = op_pk_bulk_size_get (pkptr);
/* If the statistic handle for received packet size has not yet */
/* been initialized, do so now. */
if (pk_size_init == OPC_FALSE)
{
pk_size_shandle = op_stat_reg ("Packet Size (bits)", OPC_STAT_INDEX_NONE,
OPC_STAT_GLOBAL);
pk_size_init = OPC_TRUE;
}
/* write out the bulk size of the packet as a global statistic. Don’t */
/* use current time as the independent variable, but instead the time at */
/* which the packet was created. */
op_stat_write_t (pk_size_shandle, (double) bulk_size,
op_pk_creation_time_get (pkptr));
Details
This KP appends a new (time, value) pair to an output vector that is being collected for the specified global or local statistic. Statistics can only be referenced by variables of the type Stathandle that have been initialized by calling the KP op_stat_reg(). Calling this KP with an improperly initialized handle can result in a recoverable simulation error.
Different processes throughout a simulation model can write values to the same output vector through this KP if they use the same statistic handle. The KP op_stat_reg() uses the statistic name that is passed to it to “rendezvous” with other sources of the same statistic and multiplex data into one output vector. A vector can receive values from both this KP and op_stat_write(). The name of the output vector in which the new (time, value) pair is written is specified only at the time that the statistic is registered with op_stat_reg().
The corresponding output vector stores entries in the order they are reported by this KP. Because the time value can be an arbitrary number, the resulting vector might not be ordered.
To generate data in an output vector file, statistics must be probed by a probe object defined in the Probe Editor or selected through the Select statistics operation in the Project Editor. The name of the probe file that contains the probe is specified by the probe attribute of a simulation. To record all global statistics, set the record_gstats attribute of a simulation. This KP behaves identically to op_stat_write() with regard to statistic wires.
Purpose
Contributes a new value to an output vector, tagged with a user-specified time.
This KP is typically used instead of op_stat_write() when a vector is used to relate two variables, neither of which is time, or if the abscissa variable is not the current time, as in the example in this section.
Errors
- Program Abort: Segmentation violation. (due to an invalid statistic handle)
- Recoverable Error: Attempting use of unregistered statistic handle.
Reference
- Use the KP op_stat_local_read() to read the current value of an input statistic
- Use the KP op_stat_write() to write a value to an output statistic, tagged with the current simulation time
- Use the KP op_stat_scalar_write() to write a value to a scalar statistic
- Use the KP op_stat_obj_reg() to access a statistic for any link, path, module or submodule object
- Use the KP op_stat_reg() to obtain a statistic handle