Discussions related to Visual Prolog
User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post 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 !
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

Use string::concatWithDelimiter

Unread post 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.
TIA, Regards,
Frank Nagy
User avatar
Thomas Linder Puls
VIP Member
Posts: 1399
Joined: 28 Feb 2000 0:01

Re:

Unread post 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.
Regards Thomas Linder Puls
PDC
User avatar
Ferenc Nagy
VIP Member
Posts: 215
Joined: 24 Apr 2007 12:26

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

Unread post 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.]
TIA, Regards,
Frank Nagy
Post Reply