Output Node Info to a CSV file

The engine.
Post Reply
jdtoellner
Posts: 71
Joined: Mon Aug 01, 2016 9:45 pm

Output Node Info to a CSV file

Post by jdtoellner »

I wrote a simple c++ program to create a CSV list of nodes and node info:

Code: Select all

// OutputCSVFromNetwork.cpp : main project file.

#include "stdafx.h"
#include "smile.h"
#include <iostream>

using namespace std;

int main()
{
	DSL_network theNet;

	theNet.ReadFile("BBNetwork.xdsl");

	FILE * nodeLogFile;
	int fileOpenStatus = fopen_s(&nodeLogFile, "NodeLogFile.csv", "w");

	fprintf(nodeLogFile, "Handle, Node ID, Node Name, Node Type, Submodel Handle, Number of States, Number of Parents, Number of Children\n");

	int nodeHandle = theNet.GetFirstNode();
	int nodeNumber = 1;

	while (nodeHandle >= 0) {

		if (nodeNumber % 100 == 0 && nodeNumber != 0) cout << "Finished Reading " << nodeNumber << " nodes" << endl;

		string nodeID = string(theNet.GetNode(nodeHandle)->GetId());

		string nodeName = theNet.GetNode(nodeHandle)->Info().Header().GetName();

		string nodeType = theNet.GetNode(nodeHandle)->Definition()->GetTypeName();

		int submodelHandle = theNet.GetNode(nodeHandle)->GetSubmodel();

		int numberOfStates = theNet.GetNode(nodeHandle)->Definition()->GetNumberOfOutcomes();

		int numberOfParents = theNet.NumParents(nodeHandle);

		int numberOfChildren = theNet.NumChildren(nodeHandle);

		fprintf(nodeLogFile, "%i, %s, %s, %s, %i, %i, %i, %i\n",
			nodeHandle,
			nodeID.c_str(),
			nodeName.c_str(),
			nodeType.c_str(),
			submodelHandle,
			numberOfStates,
			numberOfParents,
			numberOfChildren);

		nodeHandle = theNet.GetNextNode(nodeHandle);
		nodeNumber++;
	}
	fclose(nodeLogFile);

    return DSL_OKAY;
}
Post Reply