OMNeT++ and how to get more out of your Scalars

This entry was posted by on Friday, 4 February, 2011 at

OMNeT++ enables you to output Scalars, Vectors and Histograms. The scalars are mighily useful as they allow you to save named variables and their value:

recordScalar( "name", value );

Easy as that. But what if we want to save a tuple?

Clearly, using multiple consecutive recordScalars is an option:

recordScalar( "x", xpos );
recordScalar( "y", ypos );
recordScalar( "z", zpos );

But this means that our parser will have to perform an operation on three lines to obtain the coordinate set (or any quantity or metric defined by a tuple or set). This may be troublesome when your parser reads the logfile line by line.

Now what I’m going to propose ain’t pretty, but sure it does work:

int n; //dummy
char buff[50];
n=sprintf(buff,"(%f, %f, %f)", move.getX(), move.getY(), move.getZ());

And there’s your output:

scalar[8].netw (20.0, 50.23, 0.0) 12.560119265303

The position of a node at a certain time.

It may not serve your purpose, but I figured I might share this unorthodox use of the Scalar mechanism in case you want to output more than a single-valued something.

Leave a Reply