[ns] How to write an arbitrary variable to file
Nem Vagabon
vagabon at gmail.com
Mon Apr 21 02:03:11 PDT 2008
Hi there,
I added this piece of code to the file god.cc in order to count the number
of neighbors each node in a wireless ad hoc network has. However, I can not
figure out how to write the array which contains this information to a log
file any time inside the simulation period. Could you please guide me how to
do this? In this case, I need to write the array "neighbors" returned by
function countNeighbors() to a file.
Thank you very much.
/////////////////////////////////////////////////
// Count the number of neighbors for all nodes //
/////////////////////////////////////////////////
int *God::countNeighbors()
{
int curNode, otherNode;
int *neighbors = (int *)calloc(num_nodes, sizeof(int)); //this array
contains the number of neighbors for each node
for (curNode = 0; curNode < num_nodes; curNode++)
{
if (mb_node[curNode] -> X() < 0 || mb_node[curNode] -> Y() < 0) //if
this node lies out of simulation range
{
*(neighbors + curNode) = 0;
continue; //proceed to the next node
}
for (otherNode = 0; otherNode < num_nodes; otherNode++)
{
if (otherNode == curNode)
continue;
if (mb_node[otherNode] -> X() < 0 || mb_node[otherNode] -> Y() <
0)
{
continue; //proceed to the next node
}
if (IsNeighbor(curNode, otherNode))
{
*(neighbors + curNode) += 1;
}
}
}
return neighbors;
}
// End of function
/////////////////////////////////////////////////
/////////////////////////////////////////////////
More information about the Ns-users
mailing list