Page 2 of 2

Posted: 28 Mar 2014 8:00
by Tonton Luc
:idea:

Code: Select all

clauses     onTest1(_Source, _MenuTag):-         Sep = ";",         ColumnA = ["L1C1","L2C1","L3C1","L4C1"],         ColumnB = ["L1C2","L2C2","L3C2"],         ColumnC = ["L1C3","L2C3","L3C3","L4C3","L5C3"],         Table = [ColumnA, ColumnB, ColumnC],         OutputFile = outputStream_file::create8("C:\\test.csv"),         writeCsv_table(OutputFile,Sep,Table),         OutputFile:close()         .
Works fine !

Use string::concatWithDelimiter

Posted: 8 Apr 2014 10:03
by Ferenc Nagy
The string::concatWithDelimiter predicate makes the lines of CSV with the required separator.
Anyway, if you have terms, write them directly out. Omit the step of converting them to a list.
You can get nice tables if you group your results in a facts section and simply save facts with a single statement and open your output using the text entry wizard of Excel andyou define ( and comma as delimiters.

Re:

Posted: 8 Apr 2014 15:52
by Thomas Linder Puls
ahmednadi wrote:Dear Sir;

could you help me to get the output in an external file *.csv?

Regards;

AHMED
If you mean how to read the contents in an external .csv file, then please start a new mail. This is about writing such contents.

Save a fact section instead of write individual list elements or lines

Posted: 9 Apr 2014 11:11
by Ferenc Nagy
Ahmed,

Define a fact section containing the required results.
Add before them constant header facts.

Code: Select all

domains resdom : r(symbol,real)   facts - results   header(symbol,symbol,symbol). dataline(positive,resdom).   clauses     header("experiment","identifier","yield").
Add the dataline facts using assertZ statements, and write the to a file by

Code: Select all

file::save("results.txt",results)
statements.

You can evaluate the results.txt file by Excel. I recommend you to write an Excel macro in order to get rid the extra parentheses result from the r() facts.

...
On the other hand, reading of files generated by a single file:save statement by a singe consult call is much easier than repeat...fail cycle with checking end-of-file before reading lines and parsing them. I can add to this that nowadays the consultable data files can contain blnk lines and comments. [The Turbo Prolog's original consult reported error when the closing parenthesis of the last term was followed by an eof (code 26) character inserted by the Personal Editor.]