Types coversion

Types coversion - @Air provides thermodynamic properties and transport properties of moist air. - Сообщения

#1 Опубликовано: 25.02.2014 17:49:56
Igor Skarine

Igor Skarine

14 сообщений из 97 понравились пользователям.

Группа: User

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.
string_test.png
#2 Опубликовано: 25.02.2014 19:17:22
Davide Carpi

Davide Carpi

1415 сообщений из 2872 понравились пользователям.

Группа: Moderator

Hello tomtit

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
verilog.sm (8 КиБ) скачан 34 раз(а).
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#3 Опубликовано: 27.02.2014 11:33:39
Igor Skarine

Igor Skarine

14 сообщений из 97 понравились пользователям.

Группа: User

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).
1 пользователям понравился этот пост
Davide Carpi 27.02.2014 20:38:00
#4 Опубликовано: 27.02.2014 12:14:00
Вячеслав Мезенцев

Вячеслав Мезенцев

1402 сообщений из 1708 понравились пользователям.

Группа: Moderator

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.
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
Igor Skarine 27.02.2014 13:00:00
#5 Опубликовано: 27.02.2014 13:09:55
Igor Skarine

Igor Skarine

14 сообщений из 97 понравились пользователям.

Группа: User

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
#6 Опубликовано: 27.02.2014 13:42:57
Martin Kraska

Martin Kraska

1222 сообщений из 2150 понравились пользователям.

Группа: Moderator

Wrote

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://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#7 Опубликовано: 27.02.2014 20:29:49
Davide Carpi

Davide Carpi

1415 сообщений из 2872 понравились пользователям.

Группа: Moderator

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.

Wrote

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.

Wrote

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...
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 пользователям понравился этот пост
Igor Skarine 28.02.2014 11:08:00
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений