MathcadFileAccess

MathcadFileAccess - The following functions are useful for reading various file types into arrays. - Messages

#1 Posted: 4/11/2012 5:46:21 AM
Вячеслав Мезенцев

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

1402 likes in 1708 posts.

Group: 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 KiB) downloaded 338 time(s).
Russia ☭ forever, Viacheslav N. Mezentsev
2 users liked this post
Radovan Omorjan 4/11/2012 6:07:00 AM, Andrey Ivashov 4/11/2012 11:57:00 AM
#2 Posted: 5/4/2013 10:40:33 AM
Вячеслав Мезенцев

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

1402 likes in 1708 posts.

Group: Moderator

Updated. Fixed bugs in functions for working with images.
Russia ☭ forever, Viacheslav N. Mezentsev
1 users liked this post
Martin Kraska 5/4/2013 11:23:00 AM
#3 Posted: 5/4/2013 11:52:33 AM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: 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 Posted: 5/4/2013 12:10:28 PM
Вячеслав Мезенцев

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

1402 likes in 1708 posts.

Group: 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 Posted: 5/4/2013 3:19:31 PM
Вячеслав Мезенцев

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

1402 likes in 1708 posts.

Group: Moderator

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

[albumimg]107[/albumimg]
Russia ☭ forever, Viacheslav N. Mezentsev
1 users liked this post
Martin Kraska 5/4/2013 4:46:00 PM
#6 Posted: 5/4/2013 5:37:36 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: 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 KiB) downloaded 118 time(s).
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#7 Posted: 5/4/2013 5:44:51 PM
Вячеслав Мезенцев

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

1402 likes in 1708 posts.

Group: 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 Posted: 5/4/2013 6:01:31 PM
Вячеслав Мезенцев

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

1402 likes in 1708 posts.

Group: 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 users liked this post
Martin Kraska 5/4/2013 6:33:00 PM
#9 Posted: 5/4/2013 6:33:11 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: 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 Posted: 5/4/2013 6:51:59 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: 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 Posted: 5/5/2013 1:19:39 PM
Вячеслав Мезенцев

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

1402 likes in 1708 posts.

Group: 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 KiB) downloaded 145 time(s).
Russia ☭ forever, Viacheslav N. Mezentsev
1 users liked this post
ioan92 5/5/2013 1:38:00 PM
#12 Posted: 5/5/2013 5:48:10 PM
Вячеслав Мезенцев

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

1402 likes in 1708 posts.

Group: Moderator

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

[albumimg]115[/albumimg]
Russia ☭ forever, Viacheslav N. Mezentsev
2 users liked this post
Radovan Omorjan 5/5/2013 6:10:00 PM, ioan92 5/6/2013 1:35:00 AM
#13 Posted: 10/13/2013 6:03:31 AM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: 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 Posted: 10/14/2013 4:23:59 PM
Вячеслав Мезенцев

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

1402 likes in 1708 posts.

Group: Moderator

Updated. DocumentDirectory() added. Try now.
Russia ☭ forever, Viacheslav N. Mezentsev
1 users liked this post
Martin Kraska 10/14/2013 4:35:00 PM
#15 Posted: 10/14/2013 4:44:44 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: 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 users liked this post
Вячеслав Мезенцев 10/14/2013 5:02:00 PM
#16 Posted: 10/14/2013 4:48:52 PM
Вячеслав Мезенцев

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

1402 likes in 1708 posts.

Group: Moderator

Updated. Play() function added (for wav files).
Russia ☭ forever, Viacheslav N. Mezentsev
1 users liked this post
Martin Kraska 10/14/2013 6:00:00 PM
#17 Posted: 10/14/2013 6:12:26 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Handbook page for sound files added.
Section file access wave.sm (16 KiB) downloaded 103 time(s).
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 users liked this post
Вячеслав Мезенцев 10/14/2013 6:26:00 PM
#18 Posted: 3/27/2014 5:21:07 AM
Вячеслав Мезенцев

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

1402 likes in 1708 posts.

Group: 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 users liked this post
ioan92 3/27/2014 6:07:00 AM
#19 Posted: 3/27/2014 8:42:48 AM
Вячеслав Мезенцев

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

1402 likes in 1708 posts.

Group: 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 users liked this post
ioan92 3/27/2014 9:08:00 AM
#20 Posted: 3/27/2014 10:02:03 AM
Mike Kaganski

Mike Kaganski

184 likes in 434 posts.

Group: 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 users liked this post
ioan92 3/27/2014 11:58:00 AM
  • New Posts New Posts
  • No New Posts No New Posts