% IO_writeTraffString
%
% Usage: [traffString] = IO_writeTraffString(traff_trafficMatrix)
%
% Abstract: This function writes a traffic string, that is, a string of
% characters equal to a string of a Traffic File (*.traff). A Traffic File
% (*.traff) contains the Traffic Matrix, that is, the table of the
% traffic demands for all the possible node pairs.
%
% In the whole file the columns (fields) are separated by TABS and the rows
% by RETURNS. Each field column is represented according to C language
% FORMAT. The FORMAT is a string containing C language conversion specifications.
%A conversion specification controls the notation, alignment, significant digits,
%field width, and other aspects of output format. The format string can
%contain escape characters to represent nonprinting characters such as
%newline characters and tabs. Conversion specifications begin with
%the % character and contain these optional and required elements:
% Flags (optional)
% Width and precision fields (optional)
% A subtype specifier (optional)
% .Conversion character (required)
%
% Arguments:
% o In:
% traff_trafficMatrix(NxN): Average traffic flow offered between node pairs. The
% Traffic Matrix is a two-dimensional matrix with N (N: number of nodes) rows
% and N columns. An entry(s,d) means the average traffic flow from node 's'
% to node 'd', measured as the number of bits per second.
%
% o Out:
% traffString: String with all the characters to be written in a Traffic
% File (*.traff)
%
%
% Ramon Aparicio Pardo,2007
function [traffString] = IO_writeTraffString(traff_trafficMatrix)
%We check input arguments
if (nargin==0), help IO_writeTraffString;return, end %help calling
if (nargin~=1), error('1: Incorrect number of arguments.'),end %Number of input arguments different of 1
if(size(traff_trafficMatrix,1) ~= size(traff_trafficMatrix,2)), error('2: Argument "traff_trafficMatrix" must be a square matrix'), end
if(isa(traff_trafficMatrix, 'numeric')~=1), error('3: Argument "traff_trafficMatrix" must be an integer or floating-point array'), end
numberOfNodes=size(traff_trafficMatrix,1);
%We create the string-file
CellOfTraffString=cell(5+numberOfNodes,1);
%0.Information File
text=['// Information File \n'];
CellOfTraffString(1)={sprintf(text)};
text=['//Number of Nodes'];
CellOfTraffString(2)={sprintf(text)};
CellOfTraffString(3)={sprintf('%-3.0f\n', [numberOfNodes])};
%1. Traffic Table - Traffic
text=['//Traffic Table - Traffic \n'];
CellOfTraffString(4)={sprintf(text)};
formatOutput='';
for numberOfColumn=1:numberOfNodes,
formatOutput=[formatOutput '%5.3f \t'];
end
formatOutput=[formatOutput];
for numberOfLine=1:numberOfNodes,
CellOfTraffString(4+numberOfLine)={sprintf(formatOutput, traff_trafficMatrix(numberOfLine,:))};
end
%2.END OF FILE
text=['\n\n****************END_OF_FILE_.TRAFF****************'];
CellOfTraffString(5+numberOfNodes)={sprintf(text)};
%Finnally we transform the cell of strings into an unique string by joining
%the cells with a C-identifier of "New line"
traffString=cell2mat(CellOfTraffString(1));
for k=2:length(CellOfTraffString),
traffString= [traffString '\n' cell2mat(CellOfTraffString(k))];
end
traffString=sprintf(traffString);