question

Aditya Prakash avatar image
0 Likes"
Aditya Prakash asked Phil BoBo edited

exporttable() exports incomplete table.

sample.fsm

Hi, I'm exporting a global table at the OnRunStop trigger, but exporttable() is exporting incomplete table. This problem doesn't occur for the first time, but after deleting the .csv file and re-running the model, this problem starts to occur. Attached is a sample model where I'm trying to export 15 row table, but it exports only 13 rows. Whats happening ?

FlexSim 16.1.0
exporting
pic.png (57.5 KiB)
sample.fsm (14.2 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Jordan Johnson avatar image
1 Like"
Jordan Johnson answered Phil BoBo edited

It looks like there's a bug in the exporttable command in 16.1.0 (and 16.0.2), where it's using the number of columns as the number of rows in the table.

There are a couple possible workarounds. First, you could change your global table to use bundle data. Then exporttable works properly. The downside is that you can't have named rows for bundles.

If bundle data is not an option, you could use exportdataset. The downside there is that it doesn't export row or column headers.

A poor solution (but possibly adequate for your needs) would be to add two extra columns, so that your table is square.

Finally, you could use a script like this one (for non-bundle tables):

// options of the command
string fileName = concat(modeldir(), "sample.csv");
treenode table = reftable("GlobalTable1");
int printRowHeaders = 1;
int printColHeaders = 0;

// additional options
string itemSep = ",";
string lineSep = "\n";

// precision defined by the model settings
int precision = get(node("MAIN:/1/8/1/6"));

// logic for the command
int rows = content(table);
int cols = content(first(table));

int success = fileopen(fileName, "w");
if (!success)
	return 0;

if (printRowHeaders) {
	for (int j = printColHeaders ? 0 : 1; j <= cols; j++) {
		if (j == 0 ) {
			fpt(itemSep);
		} else {
			string colHeader = getname(rank(first(table), j));
			fpt(colHeader);
			fpt(itemSep);
		}
	}
	fpt(lineSep);
}

for (int i = 1; i <= rows; i++) {
	treenode rowNode = rank(table, i);
	for (int j = printColHeaders ? 0 : 1; j <= cols; j++) {
		if (j == 0 ) {
			fpt(getname(rowNode));
			fpt(itemSep);
		} else {
			treenode curCell = rank(rowNode, j);
			int datatype = getdatatype(curCell);
			switch (datatype) {
				case DATATYPE_STRING: 
					fpt(gets(curCell)); 
					break;
				case DATATYPE_NUMBER: 
					fpt(numtostring(get(curCell), 0, precision));
					break;
			}
			fpt(itemSep);
		}
	}
	fpt(lineSep);
}

fileclose();
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Aditya Prakash avatar image Aditya Prakash commented ·

@jordan.johnson Can't use bundle, have different datatypes. (string as well as num)

Even exportdataset(reftable("GlobalTable1"), concat(modeldir(), "sample_dataset.csv") , 1 ); doesn't work. It also has the same column num as row num problem.

Square table is not possible I have lots of rows.

But fpt() saved me. Thanks

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.