next up previous
Next: Simulation Parameters Up: MIRACLE How-To Previous: New Files, Default Values

Output Redirection

This section describes a method to write some data on external files. This is not an aspect related directly to MIRACLE framework, but for a neophite it could be an useful tip. This is an alternative use of printf method. In this how-to we used this method to print datas or messages to standard output, but in this case we redirect output to a file. The code is self-explaining, so we don't write anything but the comments.

// This is the file
	FILE *fd;
//this is the filename
	char filen[100];
//create a file named Nodo_<nodeId_>.out
	sprintf(filen,"Nodo_%d.out", nodeId_);
//open a file with name filen. New data is
//written at the end of existing file or a new one is created
	fd = fopen(filen,"a"); // "a" = append at the end of file
//writes on file fd
	fprintf(fd,"%f %f\n", now, statistica1_);
//closes files

For more documentation, refer to online tutorials on $C++$ such as those on

nsmiracle-users mailing list