Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline tomtit  
#1 Posted : 26 February 2014 00:49:56(UTC)
tomtit


Rank: Advanced Member

Groups: Registered
Joined: 22/02/2014(UTC)
Posts: 81

Was thanked: 11 time(s) in 10 post(s)
Recently, I tried to use Smath to generate simple Verilog code, just a case statement.
First, I created a vector/matrix where each component is a string.
Than I tried to write this structure to the text file. Unfortunately, I haven't find
proper way to do this simple thing. I always saw "" around the strings written to the file.
mwfprintf - doesn't work at all, wfile(2) doesn't work as well, wfile(3) surprisingly works !
Of course, it is a problem of the plugin writers, but ... frustrating.
Next attempt was done to disassemble the matrix using row() function, it worked,
but the type of the created object was not string.
Than I tried to convert it to string using mat2sys(), it also worked, after that I can use strlen(),
it returns valid number of characters. But if I nest the operations, strlen(mat2sys()) fails.
It might be a good idea to sort out this small issues. It, it's confusing now.

Edited by user 26 February 2014 00:55:15(UTC)  | Reason: Not specified

tomtit attached the following image(s):
string_test.png

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Davide Carpi  
#2 Posted : 26 February 2014 02:17:22(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,650
Man
Italy
Location: Italy

Was thanked: 1338 time(s) in 878 post(s)
Hello tomtit Good

I think that the problem is that there's not yet the function that you need... A dirty way could be to export the data to a spreadsheet and then copy and paste all in a text file.

I think that another function to fit your purposes could be easily added in my DataExchang plugin; I accept any suggestion about the input syntax (vector,matrix,system) and the desired output.

F.E. I can imagine a exportData.CODE or something similar where you can add a vector of strings with special flags like {\t} {\q}... to write tabs, quotes...


About the issues:

wfile() is provided to export the data as SMath plain text; the second argument must be a unknown (is not handly, I admit) and the ouput file will be placed in the "%APPDATA%/SMath/user" folder

exportData.CSV() is provided to export mixed data as a CSV file in the most compatible way; because strings may contains commas, or the target program may trim leading/trailing spaces, so any string is quoted.

strlen() measures strings, not matrices or vectors

length() measures matrices/vectors, not strings

row(), mat2sys() are not the right way, use an el(SS,2) instead; row() returns a row vector, a list (or system) of one element hide the system by default but is very error-prone (the value is yet a system if you use the symbolic optimization)


best regards,

Davide

Edited by user 26 February 2014 05:39:24(UTC)  | Reason: Not specified

File Attachment(s):
verilog.sm (9kb) downloaded 16 time(s).
Davide Carpi attached the following image(s):
2014-02-26 00_17_38-SMath Studio Desktop - [verilog.sm_].png
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline tomtit  
#3 Posted : 27 February 2014 18:33:39(UTC)
tomtit


Rank: Advanced Member

Groups: Registered
Joined: 22/02/2014(UTC)
Posts: 81

Was thanked: 11 time(s) in 10 post(s)
Hi Davide,
Thanks a lot for detailed explanation, but there is some misunderstanding of the purpose of my last post.
I do know how to do things right, it was just a way to show that
s11:=mat2sys(s1) followed by strlen(s11) is not equal to strlen(mat2sys(s1)).That is certainly a bug.

Anyway, the suggestion is to implement a function WhatIsTypeOf(expr), returning a string, containing the type of the expr.
It may help a lot in debugging difficult to understand issues of automatic type conversions.
Best regards,
Igor

P.S. Davide, I desperately need an extension to you DataExchang plugin with a functionality of good old fprintf(file,format,par1,..,parn),
or at least just fputs(string, file).

Edited by user 27 February 2014 18:49:31(UTC)  | Reason: Not specified

thanks 1 user thanked tomtit for this useful post.
on 28/02/2014(UTC)
Offline uni  
#4 Posted : 27 February 2014 19:14:00(UTC)
uni


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 10/11/2010(UTC)
Posts: 1,494
Man
Russian Federation

Was thanked: 1274 time(s) in 745 post(s)
mwfprint() not finished. This function works only with numerical matrices not with strings. Simple example can be found here.
wfile(3) and rfile(2) - are the part of Mathcad File Access plugin. They do the same things (like wfile(2) and rfile(1) ), but you can work with any path as you wish.

Edited by user 27 February 2014 19:23:19(UTC)  | Reason: Not specified

Russia ☭ forever
Viacheslav N. Mezentsev
thanks 1 user thanked uni for this useful post.
on 27/02/2014(UTC)
Offline tomtit  
#5 Posted : 27 February 2014 20:09:55(UTC)
tomtit


Rank: Advanced Member

Groups: Registered
Joined: 22/02/2014(UTC)
Posts: 81

Was thanked: 11 time(s) in 10 post(s)
I have another suggestion to Andrey.
The help tool-tips should not only show function prototypes, but should also indicate the plugin containing the function.
Otherwise, in case of issue, it takes a lot of time to find which plugin to blame.
Regards,
Igor
Offline mkraska  
#6 Posted : 27 February 2014 20:42:57(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,988
Germany

Was thanked: 1127 time(s) in 723 post(s)
Originally Posted by: tomtit Go to Quoted Post
The help tool-tips should not only show function prototypes, but should also indicate the plugin containing the function.
Otherwise, in case of issue, it takes a lot of time to find which plugin to blame.

I agree that a generic solution would be nice, e.g. starting the help string with [plugin name]. For the time being every plugin author is free to add such a hint on it's own. In the Maxima plugin, we try to do that (as well as with the error messages).
If you find the function in the function index of the interactive handbook (?-button in the toolbar) then there are good chances that there is information on what plugin the function comes from. Currently, these entries are generated by me and far from being complete, but generally, everybody is free to contribute via SVN.
I also proposed to implement a help feature similar to F12 (now envoking the help string from the dynamic assistant), as of jumping to the function entry in the handbook upon pressing F1. Maybe, that will happen some day.
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
Offline Davide Carpi  
#7 Posted : 28 February 2014 03:29:49(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,650
Man
Italy
Location: Italy

Was thanked: 1338 time(s) in 878 post(s)
A fast solution: you can try fwrite(string,filename) or fwrite(vector/system,filename) from the updated DataExchange.
The function overwrite the file at each call so use a matrix like in your example to write the entire script and then call this function.

{\t}, {\n} and {\q} are special flags to add tabs, new lines and double quotes.

Originally Posted by: tomtit Go to Quoted Post
s11:=mat2sys(s1) followed by strlen(s11) is not equal to strlen(mat2sys(s1)).That is certainly a bug.

You are right about this behavior, I've missed this point...
As I've written SMath has a special feature that converts the system into a simple variable if the system contains only one element; seems this feature is applied after the evaluation, so what is evaluated is always strlen(sys("something",1,1));
I'll try to fix this special case with attention to the optimization, to avoid losses of the sys() features.

Originally Posted by: tomtit Go to Quoted Post
Anyway, the suggestion is to implement a function WhatIsTypeOf(expr), returning a string, containing the type of the expr.

There's an opened project of Infinity about this, if I remember correctly...

Edited by user 28 February 2014 13:41:59(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 28/02/2014(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.