MathcadFileAccess

MathcadFileAccess - The following functions are useful for reading various file types into arrays. - Сообщения

#1 Опубликовано: 11.04.2012 05:46:21
Вячеслав Мезенцев

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

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

Группа: Moderator

Mathcad File Access (now part of the Mathcad Toolbox)

SMath Studio compatibility SMath Viewer compatibility mono compatibility Extension page Sources


Functions list:

Reading and Writing Data using Delimited ASCII files (not implemented yet): READPRN(), READBIN(), READBIN(),

Reading and Writing Binary Data: READBIN(), WRITEBIN(),

Reading and Writing Sound Files: GETWAVINFO(), READWAV(), WRITEWAV(),

Reading and Writing Image Files: READ_IMAGE(), READBMP(), READRGB(), READ_RED(), READ_GREEN(), READ_BLUE(),

Other functions: CurrentDirectory(), DocumentDirectory(), GetFolderPath(), wfile(3), rfile(2), Play().


[albumimg]100[/albumimg] [albumimg]115[/albumimg]
MC15. Reading And Writing Binary Data.pdf (63 КиБ) скачан 302 раз(а).
Russia ☭ forever, Viacheslav N. Mezentsev
2 пользователям понравился этот пост
Radovan Omorjan 11.04.2012 06:07:00, Andrey Ivashov 11.04.2012 11:57:00
#2 Опубликовано: 04.05.2013 10:40:33
Вячеслав Мезенцев

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

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

Группа: Moderator

Updated. Fixed bugs in functions for working with images.
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
Martin Kraska 04.05.2013 11:23:00
#3 Опубликовано: 04.05.2013 11:52:33
Martin Kraska

Martin Kraska

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

Группа: Moderator

In READBIN(), the last argument specifies the number of lines to read. If set to zero, in Mathcad you get as many lines as the file can give, in SMath you get an empty matrix (good for stacking loop init, as I learned yesterday). If I specify more lines than the file can provide, then in Mathcad the result is augmented by zeros, in SMath I get as many lines as the file can give.

Thus, is the intent to provide a very big number of lines if I do not know the size of the file in advance?

Martin

Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#4 Опубликовано: 04.05.2013 12:10:28
Вячеслав Мезенцев

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

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

Группа: Moderator

Ok, I'll try to fix the functions and add a description (you can find it in the Mathcad Help).
Russia ☭ forever, Viacheslav N. Mezentsev
#5 Опубликовано: 04.05.2013 15:19:31
Вячеслав Мезенцев

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

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

Группа: Moderator

Updated. READ_RED(), READ_GREEN() and READ_BLUE() added. READBIN() fixed.

[albumimg]107[/albumimg]
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
Martin Kraska 04.05.2013 16:46:00
#6 Опубликовано: 04.05.2013 17:37:36
Martin Kraska

Martin Kraska

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

Группа: Moderator

Uni, thanks again for the fast debugging response.

However, here are some issues.
- READBIN: in some situations, changes in the sheet trigger the results to become wrong. Manual re-calculation via toolbar button sets the results back to correct values, but otherwise they persist on the sheet. I attach two screenshots, the upper before re-calculation and the lower after. No other difference between these pictures, just pressed the update button. The sm-sheet is included in the zip. The problem is completely reproducible with the given example.

- READBIN: The docs refer to default values for endian, rows, skip and rows. How is the user expected to adress these defaults? Do you plan to provide READBIN(1) as in Mathcad? What would then be the default type?

- READ_xxx: These functions seem to insist on 32bpp images, at least, the one in the attached zip fails to be read in. It is a screenshot, which I intended to use instead of the not so colorful school logo.
The image region is not so picky about that, the image can be displayed without problems. However, if a read statement fails and then the result of that failed op is fed to the image, SMath crashes.
MathcadFileAccess_problems.zip (3 КиБ) скачан 85 раз(а).
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#7 Опубликовано: 04.05.2013 17:44:51
Вячеслав Мезенцев

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

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

Группа: Moderator

Wrote


...
- READ_xxx: These functions seem to insist on 32bpp images, at least, the one in the attached zip fails to be read in. It is a screenshot, which I intended to use instead of the not so colorful school logo.
The image region is not so picky about that, the image can be displayed without problems. However, if a read statement fails and then the result of that failed op is fed to the image, SMath crashes.



Try to update ImageRegion plugin. As for the images. Only two formats are supported for now: 24bppRGB and 32bppRGB (without alpha channel). Your image has an alpha channel (transparency).

[albumimg]109[/albumimg]
Russia ☭ forever, Viacheslav N. Mezentsev
#8 Опубликовано: 04.05.2013 18:01:31
Вячеслав Мезенцев

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

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

Группа: Moderator

Wrote

Uni, thanks again for the fast debugging response.

However, here are some issues.
- READBIN: in some situations, changes in the sheet trigger the results to become wrong. Manual re-calculation via toolbar button sets the results back to correct values, but otherwise they persist on the sheet. I attach two screenshots, the upper before re-calculation and the lower after. No other difference between these pictures, just pressed the update button. The sm-sheet is included in the zip. The problem is completely reproducible with the given example.


That I don't understand. It seems that reading is the same file, but with a different content. Below is running another writing function and it can change the data. Try to disable or enable the calculation for one of them (WRITEBIN). It is better to use a different file for testing in one sheet.

Wrote


- READBIN: The docs refer to default values for endian, rows, skip and rows. How is the user expected to adress these defaults? Do you plan to provide READBIN(1) as in Mathcad? What would then be the default type?


I forgot to remove it when copying, but it is possible to have a simplified version of the function.
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
Martin Kraska 04.05.2013 18:33:00
#9 Опубликовано: 04.05.2013 18:33:11
Martin Kraska

Martin Kraska

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

Группа: Moderator

Wrote

Try to disable or enable the calculation for one of them (WRITEBIN). It is better to use a different file for testing in one sheet.



OK, disabling the second write operation (in fact I just disabled the complete lower part of the sheet) resolves the issue. However, you might consider to change your example WRITEBIM.sm, in order not to encourage the user to do dangerous things.

I guess the trick was, that my changes were between the first write operation and the first read op. SMath upon re-calculation had no reason to go through any stuff above the change. Thus the first read op found the result of the second write op.

Sometimes SMath is simply too smart for me...

As for the Mathcad compatibility, I just do the comparison, you decide if you pay attention and time share to it. However, the name of the plugin is sort of promise...
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#10 Опубликовано: 04.05.2013 18:51:59
Martin Kraska

Martin Kraska

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

Группа: Moderator

Wrote


Try to update ImageRegion plugin. As for the images. Only two formats are supported for now: 24bppRGB and 32bppRGB (without alpha channel). Your image has an alpha channel (transparency).



The update resolved the crash issue. I was irritated by the fact that the read operation did not complain at all, but subsequent ops like asking for the number of rows gave the image format error message. That was due to the default setting of symbolic optimization, i.e. delayed execution of the read op. Obviously, just assigning the result of a read operation to some variable is no read test at all if in symbolic mode.

I am tired of repeating the issue of visually different operators for sym/num assignment and evaluation. Andrey seems to have good reasons for refusing even to give us back the arrow for symbolic evaluation. Is that protected by Mathcad patents?



Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#11 Опубликовано: 05.05.2013 13:19:39
Вячеслав Мезенцев

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

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

Группа: Moderator

Wrote

Hi uni,
Please, where could I find READBIN() and WRITEBIN() functions parameters complete description.
Thanks and Best Regards,
Ioan


I have attached a description.

MC15. Reading And Writing Binary Data.pdf (63 КиБ) скачан 111 раз(а).
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
ioan92 05.05.2013 13:38:00
#12 Опубликовано: 05.05.2013 17:48:10
Вячеслав Мезенцев

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

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

Группа: Moderator

Updated. wfile(3) and rfile(2) added.

[albumimg]115[/albumimg]
Russia ☭ forever, Viacheslav N. Mezentsev
2 пользователям понравился этот пост
Radovan Omorjan 05.05.2013 18:10:00, ioan92 06.05.2013 01:35:00
#13 Опубликовано: 13.10.2013 06:03:31
Martin Kraska

Martin Kraska

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

Группа: Moderator

I propose the same changes like here in order to make relative path names relative to the directory of the currently open document instead of the current directory of the system. Thus you could make portable arrangements of data and SMath documents.

Edit: I'd like to also ask for a function DocumentDirectory() which returns the path name of the currently open document. Thus we could benefit from the same improvements with built-in functions like importData.
path.PNG
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#14 Опубликовано: 14.10.2013 16:23:59
Вячеслав Мезенцев

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

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

Группа: Moderator

Updated. DocumentDirectory() added. Try now.
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
Martin Kraska 14.10.2013 16:35:00
#15 Опубликовано: 14.10.2013 16:44:44
Martin Kraska

Martin Kraska

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

Группа: Moderator

Simply great! Thanks uni. This gives two options: either you build the path for file access ops using concat or you set the current directory to the document directory. This relieves the need for the changes in the access functions, now IMHO having priority "nice to have".

Edit: Don't forget to set file access ops to optimization> numeric. That makes quite a difference in performance.
image.PNG
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 пользователям понравился этот пост
#16 Опубликовано: 14.10.2013 16:48:52
Вячеслав Мезенцев

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

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

Группа: Moderator

Updated. Play() function added (for wav files).
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
Martin Kraska 14.10.2013 18:00:00
#17 Опубликовано: 14.10.2013 18:12:26
Martin Kraska

Martin Kraska

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

Группа: Moderator

Handbook page for sound files added.
Section file access wave.sm (16 КиБ) скачан 70 раз(а).
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 пользователям понравился этот пост
#18 Опубликовано: 27.03.2014 05:21:07
Вячеслав Мезенцев

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

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

Группа: Moderator

I don't understand the problem and do not recommend to use the CurrentDirectory() function for this purpose. If the operating system denies write access, then I can't workaround this. I'm not sure that administrative privileges confirmation during execution is a good idea.
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
ioan92 27.03.2014 06:07:00
#19 Опубликовано: 27.03.2014 08:42:48
Вячеслав Мезенцев

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

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

Группа: Moderator

Windows works with processes. SMath Studio - process, but functions from the plugin are not. You can assign privilegies for processes, for functions (as I know) you can't do that. So, the right way - run SMath Studio with administrative privileges.

As for the dialog box above, I'll think about it. I don't know how to implement this.
Russia ☭ forever, Viacheslav N. Mezentsev
1 пользователям понравился этот пост
ioan92 27.03.2014 09:08:00
#20 Опубликовано: 27.03.2014 10:02:03
Mike Kaganski

Mike Kaganski

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

Группа: User

Wrote

The plugin simply do no execute the write command, without any preventing message ! It takes me some time to understand what happens...



Supposedly fixing this specific (mis)behaviour by simply returning error with clear message would be enough, no need to emit some unexpected dialogs? Suppose the scenario when a sheet has quite a some different IO operations to a number of locations; and this has a potential of emitting endless series of such dialogs. Also, aquiring priveleges may end up in yet another software capable of hosting viruses...
С уважением, Михаил Каганский
1 пользователям понравился этот пост
ioan92 27.03.2014 11:58:00
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений